private void DestroyEntityInternal(Entity *entities, int count) { CheckAccess(); m_Entities->AssertCanDestroy(entities, count); EntityDataManager.TryRemoveEntityId(entities, count, m_Entities, ArchetypeManager, SharedComponentDataManager); }
void EntityCreate(Entity *entity) { Debug.Assert(entity->_active == false); entity->_ref._version += 1; entity->_active = true; entity->LocalId = _global->CurLocalId++; }
internal void InstantiateInternal(Entity srcEntity, Entity *outputEntities, int count) { EntityComponentStore->AssertEntitiesExist(&srcEntity, 1); EntityComponentStore->AssertCanInstantiateEntities(srcEntity, outputEntities, count); EntityComponentStore->InstantiateEntities(srcEntity, outputEntities, count); ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker); }
private void CreateEntityInternal(EntityArchetype archetype, Entity *entities, int count) { CheckAccess(); var archetypeManager = (ArchetypeManager)m_ArchetypeManager.Target; m_Entities->CreateEntities(archetypeManager, archetype.Archetype, entities, count); }
private void DestroyEntityInternal(Entity *entities, int count) { CheckAccess(); EntityComponentStore->AssertCanDestroy(entities, count); EntityComponentStore->DestroyEntities(entities, count); ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker); }
protected override unsafe void Start() { init(float3.zero); // no gravity // Enable the joint viewer SetDebugDisplay(new Unity.Physics.Authoring.PhysicsDebugDisplayData { DrawJoints = 1 }); Entity *entities = stackalloc Entity[2]; entities[1] = Entity.Null; for (int i = 0; i < 1; i++) { CollisionFilter filter = new CollisionFilter { MaskBits = (uint)(1 << i), CategoryBits = (uint)~(1 << (1 - i)) }; BlobAssetReference <Collider> collider = BoxCollider.Create( float3.zero, Quaternion.identity, new float3(1.0f, 0.2f, 0.2f), 0.0f, filter); entities[i] = CreateDynamicBody(float3.zero, quaternion.identity, collider, float3.zero, new float3(0, 1 - i, 0), 1.0f); } float3 pivot = float3.zero; float3 axis = new float3(0, 1, 0); float3 perpendicular = new float3(0, 0, 1); //BlobAssetReference<JointData> hingeData = JointData.CreateLimitedHinge(pivot, pivot, axis, axis, perpendicular, perpendicular, 0.2f, (float)math.PI); BlobAssetReference <JointData> hingeData = JointData.CreateLimitedHinge(pivot, pivot, axis, axis, perpendicular, perpendicular, -(float)math.PI, -0.2f); CreateJoint(hingeData, entities[0], entities[1]); }
internal void InstantiateInternal(Entity srcEntity, Entity *outputEntities, int count) { BeforeStructuralChange(); EntityComponentStore->AssertEntitiesExist(&srcEntity, 1); EntityManagerCreateDestroyEntitiesUtility.InstantiateEntities(srcEntity, outputEntities, count, EntityComponentStore, ManagedComponentStore); }
private static Chunk *EntityChunkBatch(EntityDataManager *entityDataManager, Entity *entities, int count, out int indexInChunk, out int batchCount) { /// This is optimized for the case where the array of entities are allocated contigously in the chunk /// Thus the compacting of other elements can be batched // Calculate baseEntityIndex & chunk var baseEntityIndex = entities[0].Index; var chunk = entityDataManager->m_Entities[baseEntityIndex].Chunk; indexInChunk = entityDataManager->m_Entities[baseEntityIndex].IndexInChunk; batchCount = 0; var entityDatas = entityDataManager->m_Entities; while (batchCount < count) { var entityIndex = entities[batchCount].Index; var data = entityDatas + entityIndex; if (data->Chunk != chunk || data->IndexInChunk != indexInChunk + batchCount) { break; } batchCount++; } return(chunk); }
protected override unsafe void Start() { init(); // no gravity Entity *entities = stackalloc Entity[2]; entities[1] = Entity.Null; for (int i = 0; i < 1; i++) { CollisionFilter filter = new CollisionFilter { CollidesWith = (uint)(1 << i), BelongsTo = (uint)~(1 << (1 - i)) }; BlobAssetReference <Collider> collider = BoxCollider.Create( new BoxGeometry { Center = float3.zero, Orientation = quaternion.identity, Size = new float3(1.0f, 0.2f, 0.2f), BevelRadius = 0.0f }, filter, Material.Default); entities[i] = CreateDynamicBody(float3.zero, quaternion.identity, collider, float3.zero, new float3(0, 1 - i, 0), 1.0f); } var jointFrame = new BodyFrame { Axis = new float3(0, 1, 0), PerpendicularAxis = new float3(0, 0, 1) }; PhysicsJoint hingeData = PhysicsJoint.CreateLimitedHinge(jointFrame, jointFrame, new FloatRange(-math.PI, -0.2f)); CreateJoint(hingeData, entities[0], entities[1]); }
void EntityDestroy(Entity *entity) { Debug.Assert(entity->_active); entity->_ref._version += 1; entity->_active = false; entity->LocalId = 0; }
public static void PatchEntitiesForPrefab(EntityPatchInfo *scalarPatches, int scalarPatchCount, BufferEntityPatchInfo *bufferPatches, int bufferPatchCount, byte *data, int indexInChunk, int entityCount, SparseEntityRemapInfo *remapping, int remappingCount) { // Patch scalars (single components) with entity references. for (int p = 0; p < scalarPatchCount; p++) { byte *entityData = data + scalarPatches[p].Offset; for (int e = 0; e != entityCount; e++) { Entity *entity = (Entity *)(entityData + scalarPatches[p].Stride * (e + indexInChunk)); * entity = RemapEntityForPrefab(remapping + e * remappingCount, remappingCount, *entity); } } // Patch buffers that contain entity references for (int p = 0; p < bufferPatchCount; ++p) { byte *bufferData = data + bufferPatches[p].BufferOffset; for (int e = 0; e != entityCount; e++) { BufferHeader *header = (BufferHeader *)(bufferData + bufferPatches[p].BufferStride * (e + indexInChunk)); byte *elemsBase = BufferHeader.GetElementPointer(header) + bufferPatches[p].ElementOffset; int elemCount = header->Length; for (int k = 0; k != elemCount; ++k) { Entity *entityPtr = (Entity *)elemsBase; * entityPtr = RemapEntityForPrefab(remapping + e * remappingCount, remappingCount, *entityPtr); elemsBase += bufferPatches[p].ElementStride; } } } }
// ---------------------------------------------------------------------------------------------------------- // INTERNAL // ---------------------------------------------------------------------------------------------------------- internal void DestroyEntityInternal(Entity *entities, int count) { BeforeStructuralChange(); EntityComponentStore->AssertCanDestroy(entities, count); EntityComponentStore->DestroyEntities(entities, count); ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker); }
public static void CreateEntities(Archetype *archetype, Entity *entities, int count, EntityComponentStore *entityComponentStore, ManagedComponentStore managedComponentStore) { var sharedComponentValues = stackalloc int[archetype->NumSharedComponents]; UnsafeUtility.MemClear(sharedComponentValues, archetype->NumSharedComponents * sizeof(int)); while (count != 0) { var chunk = GetChunkWithEmptySlots(archetype, sharedComponentValues, entityComponentStore, managedComponentStore); int allocatedIndex; var allocatedCount = AllocateIntoChunk(chunk, count, out allocatedIndex, entityComponentStore, managedComponentStore); entityComponentStore->AllocateEntities(archetype, chunk, allocatedIndex, allocatedCount, entities); ChunkDataUtility.InitializeComponents(chunk, allocatedIndex, allocatedCount); chunk->SetAllChangeVersions(entityComponentStore->GlobalSystemVersion); entities += allocatedCount; count -= allocatedCount; } entityComponentStore->IncrementComponentTypeOrderVersion(archetype); }
public static Transform2DVertical *GetTransform2DVertical(Entity *entity) { switch (entity->_ref._type) { } return(null); }
private void DestroyEntityInternal(Entity *entities, int count) { BeforeStructuralChange(); Entities->AssertEntitiesExist(entities, count); Entities->TryRemoveEntityId(entities, count, ArchetypeManager, m_SharedComponentManager, m_GroupManager, m_CachedComponentTypeInArchetypeArray); }
public static CollisionAgent *GetCollisionAgent(Entity *entity) { switch (entity->_ref._type) { } return(null); }
public static NavMeshAgent *GetNavMeshAgent(Entity *entity) { switch (entity->_ref._type) { } return(null); }
public void Execute(Entity *ptr, ref SkillData skillData) { //skillData.IsFiring = skillMonoData.IsFiring; if (skillData.IsNeedFire) { if (skillData.CdTimer <= 0 && !skillData.IsFiring) { skillData.CdTimer = skillData.CD; skillData.IsFiring = true; skillData.DurationTimer = skillData.Duration; RaiseEventOnSkillFire(ptr, ref skillData); } } skillData.CdTimer -= _deltaTime; if (skillData.IsFiring) { skillData.DurationTimer -= _deltaTime; if (skillData.DurationTimer <= 0) { skillData.IsFiring = false; RaiseEventOnSkillDone(ptr, ref skillData); } } skillData.IsNeedFire = false; }
public static Prefab *GetPrefab(Entity *entity) { switch (entity->_ref._type) { } return(null); }
public static object ToBoxedStruct(Entity *entity) { if (entity == null) { return(null); } switch (entity->_ref._type) { case EntityIds.BoidSpawner: return((object)(*((BoidSpawner *)entity))); case EntityIds.BoidCell: return((object)(*((BoidCell *)entity))); case EntityIds.Boid: return((object)(*((Boid *)entity))); case EntityIds.BoidTarget: return((object)(*((BoidTarget *)entity))); case EntityIds.BoidObstacle: return((object)(*((BoidObstacle *)entity))); case EntityIds.Item: return((object)(*((Item *)entity))); case EntityIds.Camp: return((object)(*((Camp *)entity))); case EntityIds.Player: return((object)(*((Player *)entity))); case EntityIds.Enemy: return((object)(*((Enemy *)entity))); case EntityIds.Bullet: return((object)(*((Bullet *)entity))); case EntityIds.Spawner: return((object)(*((Spawner *)entity))); } return(null); }
public unsafe void Sample(Ray materialScatterRay, float3 outgoingLightDirection, HitRecord rec, Material material, ref Random rng, out Ray scatterRay, out float pdfValue, out int?targetEntityId) { int totalOptions = TargetEntities.Length + (Mode == ImportanceSamplingMode.Mixture ? 1 : 0); int chosenOption = rng.NextInt(0, totalOptions); if (chosenOption == TargetEntities.Length) { scatterRay = materialScatterRay; targetEntityId = null; } else { Entity *chosenEntity = (Entity *)TargetEntities.GetUnsafeReadOnlyPtr() + chosenOption; float3 pointOnEntity = chosenEntity->RandomPoint(materialScatterRay.Time, ref rng); scatterRay = new Ray(materialScatterRay.Origin, normalize(pointOnEntity - materialScatterRay.Origin)); targetEntityId = chosenEntity->Id; } pdfValue = 0; if (Mode == ImportanceSamplingMode.Mixture) { pdfValue += material.Pdf(scatterRay.Direction, outgoingLightDirection, rec.Normal); } var basePointer = (Entity *)TargetEntities.GetUnsafeReadOnlyPtr(); for (int i = 0; i < TargetEntities.Length; i++) { pdfValue += (basePointer + i)->Pdf(scatterRay, ref rng); } pdfValue /= totalOptions; }
void DeallocateBuffers(Entity *entities, Chunk *chunk, int batchCount) { var archetype = chunk->Archetype; for (var ti = 0; ti < archetype->TypesCount; ++ti) { var type = archetype->Types[ti]; if (!type.IsBuffer) { continue; } var basePtr = chunk->Buffer + archetype->Offsets[ti]; var stride = archetype->SizeOfs[ti]; for (int i = 0; i < batchCount; ++i) { Entity e = entities[i]; int indexInChunk = m_EntityInChunkByEntity[e.Index].IndexInChunk; byte * bufferPtr = basePtr + stride * indexInChunk; BufferHeader.Destroy((BufferHeader *)bufferPtr); } } }
public static Animator *GetAnimator(Entity *entity) { switch (entity->_ref._type) { } return(null); }
public static Character *CastToCharacter(Entity *entity) { if (entity != null && entity->_ref.Type == EntityTypes.Character) { return((Character *)entity); } return(null); }
public static Projectile *CastToProjectile(Entity *entity) { if (entity != null && entity->_ref.Type == EntityTypes.Projectile) { return((Projectile *)entity); } return(null); }
public static Enemy *CastToEnemy(Entity *entity) { if (entity != null && entity->_ref._type == EntityIds.Enemy) { return((Enemy *)entity); } return(null); }
public static Boid *CastToBoid(Entity *entity) { if (entity != null && entity->_ref._type == EntityIds.Boid) { return((Boid *)entity); } return(null); }
public static Bullet *CastToBullet(Entity *entity) { if (entity != null && entity->_ref._type == EntityIds.Bullet) { return((Bullet *)entity); } return(null); }
public static Spawner *CastToSpawner(Entity *entity) { if (entity != null && entity->_ref._type == EntityIds.Spawner) { return((Spawner *)entity); } return(null); }
public static Player *CastToPlayer(Entity *entity) { if (entity != null && entity->_ref._type == EntityIds.Player) { return((Player *)entity); } return(null); }