public void AddToTest() { var ctx = new SimulationContext(true); Random random = new Random(); List <Entity> testEntities = CreateEntities(ctx.LocalSpace, 100); EntityPool original = new EntityPool(ctx); foreach (var e in testEntities) { Assert.IsTrue(original.Insert(e)); } original.VerifyIntegrity(); var h0 = original.HashDigest; for (int i = 0; i < 100; i++) { EntityPool compare = new EntityPool(ctx); random.Shuffle(testEntities); foreach (var e in testEntities) { Assert.IsTrue(compare.Insert(e)); } compare.VerifyIntegrity(); var h1 = compare.HashDigest; Assert.AreEqual(h0, h1); } }
public void UpdateEntityTest() { var ctx = new SimulationContext(true); Random random = new Random(); EntityPool pool = new EntityPool(ctx); var entities = CreateEntities(ctx.LocalSpace, 3); foreach (var e in entities) { Assert.IsTrue(pool.Insert(e)); } for (int i = 0; i < 10; i++) { Entity old = entities[0]; Entity moved = Relocate(old); Assert.IsTrue(pool.Contains(old.ID)); Assert.IsTrue(pool.UpdateEntity(entities[0], moved), "Update moved entity " + i); Assert.IsFalse(pool.Contains(old.ID)); entities[0] = moved; Assert.AreEqual(pool.Count, entities.Count); foreach (var e in entities) { Assert.IsTrue(pool.Contains(e.ID.Guid)); Assert.IsTrue(pool.Contains(e.ID)); } } }
public void Include(Entity e) { Debug.Assert(box.Contains(e.ID.Position)); if (!pool.Insert(e)) { throw new Exception("Failed to insert " + e); } }
public static EntityPool RandomPool(int numEntities, EntityChange.ExecutionContext ctx) { var rs = new EntityPool(ctx); var entities = CreateEntities(ctx.LocalSpace, numEntities); foreach (var e in entities) { Assert.IsTrue(rs.Insert(e)); } return(rs); }