public bool StructurallyEquals(ChunkTrace other) { if (other == null) { return(false); } if (other.OrderVersion != OrderVersion) { return(false); } if (other.ComponentTraces.Count != ComponentTraces.Count) { return(false); } for (int i = 0; i < ComponentTraces.Count; i++) { if (other.ComponentTraces[i].ComponentType != ComponentTraces[i].ComponentType) { return(false); } } return(true); }
public static void CompareComponentVersions(List <ChunkTrace> oldChunks, List <ChunkTrace> newChunks) { int iOld = oldChunks.Count - 1; int iNew = newChunks.Count - 1; while (iOld >= 0) { ChunkTrace oldChunk = oldChunks[iOld]; ChunkTrace newChunk = iNew < 0 ? null : newChunks[iNew]; if (!oldChunk.ArchetypeEquals(newChunk)) { LogDestroyedArchetype(oldChunk); oldChunks.RemoveAt(iOld); iOld--; } else { for (int c = 0; c < oldChunk.ComponentTraces.Count; c++) { if (oldChunk.ComponentTraces[c].Version != newChunk.ComponentTraces[c].Version) { LogModifiedComponent(oldChunk, oldChunk.ComponentTraces[c].ComponentType); } } iOld--; iNew--; } } }
public static void CompareCummulatedEntities(List <ChunkTrace> oldChunk, List <ChunkTrace> newChunks, uint globalSystemVersionA) { int _ = 0; for (int i = newChunks.Count - 1; i >= 0; i--) { if (newChunks[i].OrderVersion > globalSystemVersionA) { ChunkTrace changedChunk = newChunks[i]; int newEntityCount = CummulateEntitiesAndRemoveChunksWithIdenticalArchetype(newChunks, ref i, changedChunk); int oldEntityCount = CummulateEntitiesAndRemoveChunksWithIdenticalArchetype(oldChunk, ref _, changedChunk); if (newEntityCount > oldEntityCount) { if (oldEntityCount == 0) { LogNewArchetype(changedChunk); } else { LogNewEntities(changedChunk); } } else { LogDestroyedEntities(changedChunk); } } } }
public static void LogNewArchetype(ChunkTrace chunk) { StringBuilder stringBuilder = StringBuilderPool.Take(); stringBuilder.Append("new "); ArchetypeToString(stringBuilder, chunk); LogChange(stringBuilder.ToString()); StringBuilderPool.Release(stringBuilder); }
public static void LogDestroyedEntities(ChunkTrace chunk) { StringBuilder stringBuilder = StringBuilderPool.Take(); stringBuilder.Append("destroyed entity/entities of "); ArchetypeToString(stringBuilder, chunk); LogChange(stringBuilder.ToString()); StringBuilderPool.Release(stringBuilder); }
public static void LogModifiedComponent(ChunkTrace chunk, ComponentType type) { StringBuilder stringBuilder = StringBuilderPool.Take(); stringBuilder.Append("modified component "); stringBuilder.Append(type); stringBuilder.Append(" of "); ArchetypeToString(stringBuilder, chunk); LogChange(stringBuilder.ToString()); StringBuilderPool.Release(stringBuilder); }
public static ChunkTrace RemoveChunk(List <ChunkTrace> chunks, ref int iterator, int i) { ChunkTrace chunkTrace = chunks[i]; chunks.RemoveAt(i); if (i < iterator) { iterator--; } return(chunkTrace); }
public static void ArchetypeToString(StringBuilder stringBuilder, ChunkTrace chunk) { stringBuilder.Append("archetype ("); bool addComma = false; foreach (var c in chunk.ComponentTraces) { if (addComma) { stringBuilder.Append(", "); } stringBuilder.Append(c.ComponentType.GetManagedType().GetPrettyName()); addComma = true; } stringBuilder.Append(")"); }
public static void RecordEntityTrace(EntityManager entityManager, EntityManagerTrace trace) { int chunkI = 0; trace.GlobalSystemVersion = entityManager.GlobalSystemVersion; using (NativeArray <ArchetypeChunk> chunks = entityManager.GetAllChunks(Allocator.TempJob)) // needs to be temp job to preven unity error :( { for (int i = 0; i < chunks.Length; i++) { ArchetypeChunk chunk = chunks[i]; while (chunkI >= trace.Chunks.Count) { trace.Chunks.Add(s_chunkTracePool.Count > 0 ? s_chunkTracePool.Dequeue() : new ChunkTrace()); } ChunkTrace chunkTrace = trace.Chunks[chunkI++]; chunkTrace.OrderVersion = chunk.GetOrderVersion(); chunkTrace.EntityCount = chunk.ChunkEntityCount; chunkTrace.ComponentTraces.Clear(); foreach (ComponentType componentType in chunk.Archetype.GetComponentTypes(Allocator.Temp)) { chunkTrace.ComponentTraces.Add(new ComponentTrace() { ComponentType = componentType, Version = chunk.GetComponentVersion(componentType) }); } } } int toRemove = trace.Chunks.Count - chunkI; for (int i = 0; i < toRemove; i++) { s_chunkTracePool.Enqueue(trace.Chunks.Pop()); } }
public bool ArchetypeEquals(ChunkTrace other) { if (other == null) { return(false); } if (other.ComponentTraces.Count != ComponentTraces.Count) { return(false); } for (int i = 0; i < ComponentTraces.Count; i++) { if (other.ComponentTraces[i].ComponentType != ComponentTraces[i].ComponentType) { return(false); } } return(true); }
public static int CummulateEntitiesAndRemoveChunksWithIdenticalArchetype(List <ChunkTrace> chunks, ref int iterator, ChunkTrace chunk) { int entityCount = 0; for (int i = chunks.Count - 1; i >= 0; i--) { if (chunks[i].ArchetypeEquals(chunk)) { entityCount += RemoveChunk(chunks, ref iterator, i).EntityCount; } } return(entityCount); }