public RevolutionEntity CreateEntityInChunk(RevolutionChunk chunk) { lastEntity = new RawEntity(lastEntity.Id + 1); chunk.AddEntity(lastEntity); entityToChunk[lastEntity] = chunk; return(new RevolutionEntity(this, lastEntity)); }
internal void AddEntity(RawEntity entity) { entityToIndex[entity] = entities.Count; entities.Add(entity); foreach (var component in Components.Values) { component.Add(entity); } }
public RevolutionWorld(int entityInitialCapacity = 0) { lastEntity = default; Chunks = new RevolutionChunk[1]; // the first chunk has no component Chunks[0] = new RevolutionChunk(new Type[0]); entityToChunk = new Dictionary <RawEntity, RevolutionChunk>(entityInitialCapacity); identifierToEntity = new TwoWayDictionary <EntityIdentifier, RawEntity>(entityInitialCapacity); }
internal void RemoveEntity(RawEntity entity) { var idx = IndexOf(entity); foreach (var component in Components.Values) { component.RemoveAt(idx); } entities.RemoveAt(idx); // swapping back the index of the next entity to the previous index if (idx < entities.Count) { entityToIndex.Remove(entity); entityToIndex[entities[idx]] = idx; Parallel.For(idx, entities.Count, updateEntityIndex); } }
public int IndexOf(RawEntity entity) { //return entities.IndexOf(entity); return(entityToIndex[entity]); }
public void Add(RawEntity entity) { wrapped.Add(); }
public RevolutionEntity(RevolutionWorld world, RawEntity raw) { World = world; Raw = raw; }