public static EntityChangeSet RandomSet(EntityRanges ranges)
        {
            EntityChangeSet rs         = new EntityChangeSet();
            int             numInserts = random.Next(0, 3);

            for (int i = 0; i < numInserts; i++)
            {
                rs.Add(RandomInstantiation(ranges));
            }

            int numRemoval = random.Next(0, 3);

            for (int i = 0; i < numRemoval; i++)
            {
                rs.Add(RandomRemoval(ranges));
            }

            int numMotions = random.Next(0, 3);

            for (int i = 0; i < numMotions; i++)
            {
                rs.Add(RandomMotion(ranges));
            }

            int numBroadcasts = random.Next(0, 3);

            for (int i = 0; i < numBroadcasts; i++)
            {
                rs.Add(RandomBroadcast(ranges));
            }

            int numMessages = random.Next(0, 3);

            for (int i = 0; i < numMessages; i++)
            {
                rs.Add(RandomMessage(ranges.World));
            }

            return(rs);
        }
        public void CloneTest()
        {
            var ctx = RandomContext();

            for (int i = 0; i < 100; i++)
            {
                EntityChangeSet set  = RandomSet(ctx);
                EntityChangeSet copy = set.Clone();

                Assert.AreEqual(set, copy);


                copy.Add(RandomInstantiation(ctx));
                Assert.AreNotEqual(set, copy);
            }
        }
Exemple #3
0
        public void MotionConflictOrderingTest()
        {
            var ctx = new SimulationContext(true);

            for (int i = 0; i < 10; i++)
            {
                var  entities = CreateEntities(ctx.LocalSpace, 1);
                var  e        = entities[0];
                Vec3 original = e.ID.Position;

                EntityChange.Motion[] motions = new EntityChange.Motion[10];
                for (int j = 0; j < motions.Length; j++)
                {
                    motions[j] = new EntityChange.Motion(new EntityID(e.ID.Guid, random.NextVec3(0, 1)), ctx.LocalSpace.Clamp(original + random.NextVec3(-ctx.Ranges.R, ctx.Ranges.R)), e.MyLogic, null);
                }

                Entity e0 = null;

                for (int j = 0; j < motions.Length; j++)
                {
                    var             motions2 = motions.OrderBy(x => random.Next()).ToArray();
                    EntityPool      pool     = new EntityPool(entities, ctx);
                    EntityChangeSet set      = new EntityChangeSet();
                    foreach (var m in motions2)
                    {
                        set.Add(m);
                    }

                    int errors = set.Execute(pool, InconsistencyCoverage.NewAllOne(), ctx);
                    Assert.AreEqual(motions.Length - 1, errors);                        //motions-1 get rejected, one is accepted. must always be the same

                    var e1 = pool.First();
                    Assert.AreNotEqual(e1, e);                          //must have moved
                    if (e0 == null)
                    {
                        e0 = e1;
                    }
                    else
                    {
                        Assert.AreEqual(e0, e1);                         //must have moved to the same location
                    }
                }
            }
        }