Exemplo n.º 1
0
        public static NativeArray <uint> GetChunkHashes <T>(ArchetypeChunk chunk, T hasher, uint seed) where T : struct, IHasher
        {
            var types = chunk.GetNonzeroComponentTypes(Allocator.Temp);

            var typeCount = types.Length;
            var hashes    = new NativeArray <uint>(typeCount + 1, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

            for (int i = 0; i < typeCount; i++)
            {
                var chunkIndex = new ChunkTypeIndex
                {
                    Value = i
                };

                var type = types[i];

                if (type.IsBuffer)
                {
                    var elementSize = TypeManager.GetTypeInfo(type.TypeIndex).ElementSize;
                    var bufferViews = chunk.GetBufferViews(chunkIndex, elementSize, Allocator.Temp);

                    var bufferCount  = bufferViews.Length;
                    var bufferHashes = new NativeArray <uint>(bufferCount, Allocator.Temp, NativeArrayOptions.UninitializedMemory);

                    for (int j = 0; j < bufferCount; j++)
                    {
                        bufferHashes[j] = hasher.Execute(bufferViews[j], type, seed);
                    }

                    hashes[i] = GetDenseHash(bufferHashes, seed);

                    bufferHashes.Dispose();
                    bufferViews.Dispose();
                }
                else
                {
                    var view = chunk.GetComponentView(chunkIndex);
                    hashes[i] = hasher.Execute(view, type, seed);
                }
            }

            hashes[typeCount] = GetChunkHeaderHash(chunk, seed);
            types.Dispose();

            return(hashes);
        }