Beispiel #1
0
            public void ApplyTo(EntityChangeSet outChangeSet, EntityLogic logic, byte[] serialLogic, EntityChange.ExecutionContext ctx)
            {
                Vec3 dest = ctx.ClampDestination("Motion", NewPosition, id,
#if STATE_ADV
                                                 SuppressAdvertisements ? ctx.Ranges.R : ctx.Ranges.Motion
#else
                                                 ctx.Ranges.Motion
#endif
                                                 );
                var newID = id.Relocate(dest);

                outChangeSet.Add(new EntityChange.Motion(id, dest,
#if STATE_ADV
                                                         newAppearances,
#endif
                                                         logic, serialLogic)); //motion doubles as logic-state-update
#if STATE_ADV
                if (!SuppressAdvertisements)
                {
                    outChangeSet.Add(new EntityChange.StateAdvertisement(new EntityContact(newID, newAppearances, dest - id.Position)));
                }
#endif
                foreach (var inst in instantiations)
                {
                    outChangeSet.Add(new EntityChange.Instantiation(newID, ctx.ClampDestination("Instantiation", inst.targetLocation, newID, ctx.Ranges.Motion),
#if STATE_ADV
                                                                    inst.appearances,
#endif
                                                                    inst.logic, Helper.SerializeToArray(inst.logic)));
                }
                foreach (var rem in removals)
                {
                    if (ctx.CheckT("Removal", rem.Position, newID))
                    {
                        outChangeSet.Add(new EntityChange.Removal(newID, rem));
                    }
                }
                int messageID       = 0;
                var messageOriginID = ctx.Ranges.DisplacedTransmission ? newID : id;
                foreach (var m in messages)
                {
                    if (m.IsDirectedToClient)
                    {
                        ctx.RelayClientMessage(id.Guid, m.receiver.Guid, m.channel, m.data);
                    }
                    else
                    {
                        outChangeSet.Add(new EntityChange.Message(messageOriginID, messageID++, m.receiver.Guid, m.channel, m.data));
                    }
                }
                foreach (var b in broadcasts)
                {
                    outChangeSet.Add(new EntityChange.Broadcast(messageOriginID, messageID++, b.maxRange, b.channel, b.data));
                }
                if (nowInconsistent)
                {
                    throw new ExecutionException(id, "Inconsistency by logic request");
                }
            }
Beispiel #2
0
 /// <summary>
 /// Evolves all local entities (in parallel), and stores changes in the specified change set
 /// </summary>
 /// <param name="set"></param>
 public List <EntityError> TestEvolve(EntityChangeSet set, InconsistencyCoverage ic, int roundNumber, TimeSpan budget)
 {
     if (roundNumber != ctx.GenerationNumber)
     {
         throw new IntegrityViolation("Expected generation number " + roundNumber + " in execution context, but found " + ctx.GenerationNumber);
     }
     return(set.Evolve(EnumerateEntities().ToList(), null, ic, budget, ctx));
 }
Beispiel #3
0
        /// <summary>
        /// Duplicates all changes in the specified source affecting the specified target space
        /// </summary>
        /// <param name="source"></param>
        /// <param name="targetSpace"></param>
        public EntityChangeSet(EntityChangeSet source, Box targetSpace, EntityChange.ExecutionContext ctx)
        {
            broadcasts.Include(source.broadcasts, targetSpace, ctx);
            messages.Include(source.messages, targetSpace, ctx);
            motions.Include(source.motions, targetSpace, ctx);
            removals.Include(source.removals, targetSpace, ctx);
            instantiations.Include(source.instantiations, targetSpace, ctx);
#if STATE_ADV
            advertisements.Include(source.advertisements, targetSpace, ctx);
#endif
        }
Beispiel #4
0
        public void Include(EntityChangeSet cs)
        {
#if STATE_ADV
            advertisements.Include(cs.advertisements);
#endif
            instantiations.Include(cs.instantiations);
            broadcasts.Include(cs.broadcasts);
            messages.Include(cs.messages);
            motions.Include(cs.motions);
            removals.Include(cs.removals);
        }
Beispiel #5
0
        public EntityChangeSet Clone()
        {
            EntityChangeSet rs = new EntityChangeSet();

#if STATE_ADV
            rs.advertisements = advertisements.Clone();
#endif
            rs.instantiations = instantiations.Clone();
            rs.broadcasts     = broadcasts.Clone();
            rs.messages       = messages.Clone();
            rs.motions        = motions.Clone();
            rs.removals       = removals.Clone();
            return(rs);
        }
Beispiel #6
0
 public RCS(SerialData rcs)
 {
     IC = new InconsistencyCoverage(rcs.IC);
     if (rcs.CS == null)
     {
         CS = new EntityChangeSet();
     }
     else
     {
         using (var ms = new MemoryStream(rcs.CS))
         {
             CS = (EntityChangeSet) new BinaryFormatter().Deserialize(ms);
         }
     }
 }
Beispiel #7
0
        public EntityLogic Evolve(TimeTrace evolutionState, EntityChangeSet outChangeSet, ICollection <ClientMessage> clientMessages, EntityChange.ExecutionContext ctx, bool locationIsInconsistent)
        {
            EntityLogic state = null;

            evolutionState.Begin();
            if (Helper.Length(SerialLogicState) > 0)
            {
                try
                {
                    state = MyLogic;
                    transientDeserializedLogic = null;
                    evolutionState.SignalDeserializationDone();
                    if (state == null)
                    {
                        throw new ExecutionException(ID, "Unable to deserialize logic");
                    }


                    var actions = new EntityLogic.Actions(this);
#if DRY_RUN
                    Debug.Assert(transientDeserializedLogic == null, "Should be null");
#endif
                    state.Execute(ref actions, AddClientMessages(clientMessages), ctx.GenerationNumber, new EntityRandom(this, ctx.GenerationNumber), ctx.Ranges, locationIsInconsistent);
                    evolutionState.SignalEvolutionDone();

                    byte[] serialLogic = Helper.SerializeToArray(state);
                    evolutionState.SignalReserializationDone();

                    actions.ApplyTo(outChangeSet, state, serialLogic, ctx);
                }
                catch
                {
#if STATE_ADV
                    outChangeSet.Add(new EntityChange.StateAdvertisement(new EntityContact(ID, Appearances, Vec3.Zero)));
#endif
                    transientDeserializedLogic = null;
                    throw;
                }
            }
            else
            {
                transientDeserializedLogic = null;
            }

            evolutionState.End();
            return(state);
        }
Beispiel #8
0
 public RCS(EntityChangeSet cs, InconsistencyCoverage ic)
 {
     CS = cs;
     IC = ic;
 }