Exemplo n.º 1
0
        public void EntityMotionTest()
        {
            int        numEntities = 100;
            var        ctx         = new SimulationContext(true);
            EntityPool pool        = new EntityPool(EntityPoolTests.CreateEntities(ctx.LocalSpace, numEntities, i => new RandomMotion()), ctx);

            InconsistencyCoverage ic = InconsistencyCoverage.NewCommon();

            for (int i = 0; i < 100; i++)
            {
                var             old = pool.ToArray();
                EntityChangeSet set = new EntityChangeSet();
                ctx.SetGeneration(i);
                var errors = pool.TestEvolve(set, InconsistencyCoverage.NewCommon(), i, TimeSpan.FromSeconds(1));
                Assert.IsNull(errors, errors != null ? errors[0].ToString() : "");
                Assert.AreEqual(numEntities, set.FindNamedSet("motions").Size);
                foreach (var e in old)
                {
                    var m = set.FindMotionOf(e.ID.Guid);
                    Assert.IsNotNull(m);
                    Assert.AreNotEqual(m.TargetLocation, m.Origin.Position, i.ToString());
                    Assert.IsTrue(Simulation.FullSimulationSpace.Contains(m.TargetLocation));
                    Assert.IsTrue(Simulation.MySpace.Contains(m.TargetLocation));
                }

                Assert.AreEqual(0, set.Execute(pool, ic, ctx));
                Assert.AreEqual(numEntities, pool.Count);
                Entity e1;
                foreach (var e in old)
                {
                    Assert.IsTrue(pool.Find(e.ID.Guid, out e1));
                    Assert.AreNotEqual(e.ID.Position, e1.ID.Position);
                }
            }
        }
Exemplo n.º 2
0
        public override bool Execute(EntityPool pool, ExecutionContext ctx)
        {
            Int3 opCoords = TargetLocation.FloorInt3;

            if (ctx.LocalSpace.Contains(Origin.Position))
            {
                Entity e;
                if (!pool.Find(Origin.Guid, out e))
                {
                    return(false);
                }
                if (!ctx.CheckM("Motion", TargetLocation, e))
                {
                    return(false);
                }

                if (ctx.LocalSpace.Contains(TargetLocation))
                {
                    pool.ConflictFreeUpdateEntity(Origin, Entity);
                }
                else
                {
                    pool.ConflictFreeFindAndRemove(e.ID);
                }
                return(true);
            }
            else
            {
                if (!ctx.LocalSpace.Contains(TargetLocation))
                {
                    ctx.LogMessage("Motion: Shard coordinate mismatch. Local=" + ctx.LocalSpace + ", target=" + TargetLocation);
                    return(false);
                }
                if (!ctx.CheckM("Motion", Origin.Position, TargetLocation))
                {
                    return(false);
                }
                pool.ConflictFreeInsert(Origin, Entity);
                return(true);
            }
        }