Пример #1
0
    public static void CompareAndLogChanges(EntityManagerTrace a, EntityManagerTrace b)
    {
        List <ChunkTrace> chunksA = ListPool <ChunkTrace> .Take();

        List <ChunkTrace> chunksB = ListPool <ChunkTrace> .Take();

        chunksA.AddRange(a.Chunks);
        chunksB.AddRange(b.Chunks);

        ComparisonUtiliy.CompareCummulatedEntities(chunksA, chunksB, a.GlobalSystemVersion);
        ComparisonUtiliy.CompareComponentVersions(chunksA, chunksB);

        ListPool <ChunkTrace> .Release(chunksA);

        ListPool <ChunkTrace> .Release(chunksB);
    }
Пример #2
0
    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());
        }
    }