public unsafe void EntityInChunkCompareTo_Low32BitsMatch_ComparesCorrectly() { // Create a valid Entity and get its EntityInChunk: var ent1 = m_Manager.CreateEntity(typeof(EcsTestData)); var eic1 = m_Manager.EntityComponentStore->GetEntityInChunk(ent1); // Construct an artificial EntityInChunk for a hypothetical entity in a hypothetical // Chunk, exactly 2^32 bytes higher than ent1's (such that comparing only 32 bits of // the chunk pointer would fail): var eic2 = new EntityInChunk { Chunk = (Chunk *)((ulong)eic1.Chunk + (1ul << 32)), IndexInChunk = eic1.IndexInChunk, }; Assert.Greater((ulong)eic2.Chunk, (ulong)eic1.Chunk); Assert.AreEqual((int)eic2.Chunk, (int)eic1.Chunk); // Make sure the EntityInChunks sort correctly (eic2 > eic1): Assert.Greater(eic2.CompareTo(eic1), 0); Assert.Less(eic1.CompareTo(eic2), 0); }
public unsafe void EntityInChunkCompareTo_DifferenceOverflows32Bits_ComparesCorrectly() { // Create a valid Entity and get its EntityInChunk: var ent1 = m_Manager.CreateEntity(typeof(EcsTestData)); var eic1 = m_Manager.EntityComponentStore->GetEntityInChunk(ent1); // Construct an artificial EntityInChunk for a hypothetical entity in a hypothetical // Chunk, whose pointer is just above 2^31 larger than ent1's (such that using lhs-rhs as the // CompareTo result would overflow a signed int and give an incorrect result): var eic2 = new EntityInChunk { Chunk = (Chunk *)((ulong)eic1.Chunk + (1ul << 31) + 65536), IndexInChunk = eic1.IndexInChunk, }; Assert.Greater((ulong)eic2.Chunk, (ulong)eic1.Chunk); Assert.Less((int)((ulong)eic2.Chunk - (ulong)eic1.Chunk), 0); // Make sure the EntityInChunks sort correctly (eic2 > eic1): Assert.Greater(eic2.CompareTo(eic1), 0); Assert.Less(eic1.CompareTo(eic2), 0); }
public EntityInfo(Entity entity, EntityInChunk entityInChunk) { Entity = entity; EntityInChunk = entityInChunk; }