public EntityChunk(EntityArchetype arch) { unsafe { chunkVersion = 0; currentCount = 0; this.arch = arch; TypeCache[] cTypes = arch.GetComponenTypes(); TypeCache[] sTypes = arch.GetSharedTypes(); int entityAmount = arch.GetChunkCapacity(CHUNK_SIZE); entities = new StructArray <Entity>(entityAmount, true); for (int i = 0; i < entityAmount; i++) { entities[i].id = 0; } componentCollections = new ComponentArray[cTypes.Length]; for (int i = 0; i < componentCollections.Length; i++) { componentCollections[i] = new ComponentArray(cTypes[i], entityAmount); } sharedComponents = new ISharedComponent[sTypes.Length]; } }
public bool TryGetComponents(TypeCache componentType, out ComponentArray comp) { for (int i = 0; i < componentCollections.Length; i++) { ComponentArray currCollection = componentCollections[i]; if (currCollection.TypeMatch(componentType)) { comp = currCollection; return(true); } } comp = null; return(false); }
public bool TryGetComponents <T0>(out ComponentArray comp) where T0 : IComponent { for (int i = 0; i < componentCollections.Length; i++) { ComponentArray currCollection = componentCollections[i]; if (currCollection.TypeMatch <T0>()) { comp = currCollection; return(true); } } comp = null; return(false); }
public void DestroyEntity(Entity entity) { for (int i = 0; i < entities.Count; i++) { if (entities[i].id == entity.id) { entities.SwapForLast(entity); for (int c = 0; c < componentCollections.Length; c++) { ComponentArray collection = componentCollections[c]; collection[i] = collection[currentCount - 1]; } currentCount--; break; } } }