예제 #1
0
        private void EventDataIsSerialized()
        {
            Event instance0 = (Event)eventCreator.Object.CreateEvent(iFactoryType);

            instance0.Attempts = 1;
            instance0.Data     = 43;
            instance0.EventId  = SequenceId.Start + 44;
            eventCreator.Verify(m => m.CreateEvent(iFactoryType), Times.Once());

            // Encode to buffer
            RailBitBuffer buffer = new RailBitBuffer();

            instance0.Encode(eventCreator.Object.EventTypeCompressor, buffer, Tick.START);

            // Read from buffer
            RailEvent instance1Base = RailEvent.Decode(
                eventCreator.Object,
                eventCreator.Object.EventTypeCompressor,
                buffer,
                Tick.START);

            eventCreator.Verify(m => m.CreateEvent(iFactoryType), Times.Exactly(2));
            Assert.Equal(instance0.EventId, instance1Base.EventId);
            Assert.IsType <Event>(instance0);
            Assert.Equal(instance0.Data, ((Event)instance1Base).Data);
        }
예제 #2
0
        public RailEvent CreateEvent(int factoryType)
        {
            RailEvent instance = eventPools[factoryType].Allocate();

            instance.FactoryType = factoryType;
            return(instance);
        }
예제 #3
0
        /// <summary>
        ///     Queues an event to send directly to this peer (used internally).
        /// </summary>
        internal void SendEvent([NotNull] RailEvent evnt, ushort attempts, bool bMakeCopy)
        {
            // TODO: Event scoping
            RailEvent toSend = evnt;

            if (bMakeCopy)
            {
                toSend = evnt.Clone(Resource);
            }
            toSend.EventId  = lastQueuedEventId;
            toSend.Attempts = attempts;

            outgoingEvents.Enqueue(toSend);
            lastQueuedEventId = lastQueuedEventId.Next;
        }
예제 #4
0
        /// <summary>
        ///     Queues an event to broadcast to all present clients.
        ///     Notice that due to the internal object pooling, the event will be cloned and managed
        ///     internally in each client peer. The <paramref name="evnt" /> will be freed if
        ///     <paramref name="freeWhenDone" /> is true, otherwise the caller is responsible to
        ///     free the memory.
        /// </summary>
        /// <param name="evnt"></param>
        /// <param name="attempts"></param>
        /// <param name="freeWhenDone"></param>
        public void BroadcastEvent(
            [NotNull] RailEvent evnt,
            ushort attempts   = 3,
            bool freeWhenDone = true)
        {
            foreach (RailPeer client in Clients)
            {
                client.SendEvent(evnt, attempts, true);
            }

            if (freeWhenDone)
            {
                evnt.Free();
            }
        }
예제 #5
0
        private static void DecodeEvents(
            RailPacketIncoming packet,
            IRailEventConstruction eventCreator,
            RailBitBuffer buffer)
        {
            IEnumerable <RailEvent> decoded = buffer.UnpackAll(
                buf => RailEvent.Decode(
                    eventCreator,
                    eventCreator.EventTypeCompressor,
                    buf,
                    packet.SenderTick));

            foreach (RailEvent evnt in decoded)
            {
                packet.Events.Add(evnt);
            }
        }
예제 #6
0
    internal void OnEventReceived(RailEvent evnt, RailPeer sender)
    {
      if (evnt.EntityId.IsValid)
      {
        RailEntity entity = null;
        this.Room.TryGet(evnt.EntityId, out entity);

#if SERVER
        // Entity events can only be executed on controlled entities
        bool safeToExecute = (entity != null) && (entity.Controller == sender);
#elif CLIENT
        bool safeToExecute = (entity != null);
#endif

        if (safeToExecute)
          evnt.Invoke(this.room, sender, entity);
      }
      else
      {
        evnt.Invoke(this.room, sender);
      }
    }
예제 #7
0
 protected internal virtual bool Evaluate(
     RailEvent evnt)
 {
     return(true);
 }
예제 #8
0
 protected internal virtual bool Evaluate(
   RailEvent evnt)
 {
   return true;
 }
예제 #9
0
 /// <summary>
 /// Queues an event to broadcast to all clients.
 /// Use a RailEvent.SEND_RELIABLE (-1) for the number of attempts
 /// to send the event reliable-ordered (infinite retries).
 /// </summary>
 public void QueueEvent(RailEvent evnt, int attempts = 3)
 {
   this.serverPeer.QueueEvent(evnt, attempts);
 }
예제 #10
0
 protected void OnEventReceived(RailEvent evnt, RailPeer sender)
 {
     evnt.Invoke(Room, sender);
 }
예제 #11
0
 public virtual bool Evaluate(RailEvent evnt)
 {
     return(true);
 }
예제 #12
0
 /// <summary>
 ///     Handles the execution of an incoming event.
 /// </summary>
 private void ProcessEvent(RailEvent evnt)
 {
     EventReceived?.Invoke(evnt, this);
     eventHistory.Store(evnt.EventId);
 }
예제 #13
0
 public bool Includes(RailEvent evnt)
 {
     return(Evaluator.Evaluate(evnt));
 }