private static bool HasSameComponents(RevolutionChunk target, IReadOnlyList <Type> components) { var matches = 0; if (target.ComponentTypes.Length != components.Count) { return(false); } for (var i = 0; i != target.ComponentTypes.Length; i++) { for (var y = 0; y != components.Count; y++) { if (target.ComponentTypes[i] == components[y]) { matches++; if (matches > target.ComponentTypes.Length) { goto end; } } } } if (matches == target.ComponentTypes.Length) { return(true); } end: return(false); }
public RevolutionEntity CreateEntityInChunk(RevolutionChunk chunk) { lastEntity = new RawEntity(lastEntity.Id + 1); chunk.AddEntity(lastEntity); entityToChunk[lastEntity] = chunk; return(new RevolutionEntity(this, lastEntity)); }
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); }
private RevolutionChunk GetOrCreateChunk(IReadOnlyList <Type> components) { var currentChunk = default(RevolutionChunk); foreach (var chunk in Chunks) { if (HasSameComponents(chunk, components)) { currentChunk = chunk; break; } } // no chunk found, create it if (currentChunk == null) { currentChunk = new RevolutionChunk(components); Array.Resize(ref Chunks, Chunks.Length + 1); Chunks[^ 1] = currentChunk;
public RevolutionEntity CreateIdentEntityInChunk <TIdentity>(TIdentity identity, RevolutionChunk chunk) { var ent = CreateEntityInChunk(chunk); var id = new EntityIdentifier(); id.Set(identity); identifierToEntity.Set(id, ent.Raw); return(ent); }