Example #1
0
        public void HashUtility_ZeroPadding_EntityWithBufferEndToEnd_HasExpectedHash()
        {
            using (var world = new World("HashUtilityTests_BufferTestWorld"))
            {
                var bufferElement = new HashUtilityTest_BufferElement {
                    Offset0 = true, Offset4 = 0xBeef
                };

                var entity = world.EntityManager.CreateEntity();
                var buffer = world.EntityManager.AddBuffer <HashUtilityTest_BufferElement>(entity);

                buffer.Add(bufferElement);

                using (var chunks = world.EntityManager.GetAllChunks(Allocator.Persistent))
                {
                    Assert.AreEqual(chunks.Length, 1);

                    var chunk = chunks[0];
                    using (var types = chunk.GetNonzeroComponentTypes(Allocator.Persistent))
                    {
                        Assert.AreEqual(types.Length, 2 /* Entity, HashUtilityTest_BufferElement */);

                        using (var _ = new NativeArray <uint>(3, Allocator.Persistent))
                        {
                            var hashes = _;
                            hashes[0] = HashUtility.GetDenseHash(NativeViewUtility.GetView(ref entity), SeedForTesting);

                            var mask       = NativeViewUtility.GetReadView(Masks.GetTypeMask <HashUtilityTest_BufferElement>());
                            var bufferHash = HashUtility.GetMaskedHash(NativeViewUtility.GetView(ref bufferElement), mask, SeedForTesting);
                            hashes[1] = HashUtility.GetDenseHash(NativeViewUtility.GetView(ref bufferHash), SeedForTesting);

                            hashes[2] = HashUtility.GetChunkHeaderHash(chunk, SeedForTesting);

                            using (var expected = HashUtility.GetChunkHashes(chunk, MaskedHasher, SeedForTesting))
                            {
                                Assert.That(hashes, Is.EquivalentTo(expected), DeterminismTestUtility.PrintAll(hashes, expected));
                            }
                        }
                    }
                }
            }
        }
        static uint MimicChunkedLocalToWorldHash(LocalToWorld ltw, uint seed)
        {
            var h = HashUtility.GetDenseHash(NativeViewUtility.GetView(ref ltw), seed);

            return(HashUtility.GetDenseHash(NativeViewUtility.GetView(ref h), seed));
        }