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); }
public RailEvent CreateEvent(int factoryType) { RailEvent instance = eventPools[factoryType].Allocate(); instance.FactoryType = factoryType; return(instance); }
/// <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; }
/// <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(); } }
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); } }
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); } }
protected internal virtual bool Evaluate( RailEvent evnt) { return(true); }
protected internal virtual bool Evaluate( RailEvent evnt) { return true; }
/// <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); }
protected void OnEventReceived(RailEvent evnt, RailPeer sender) { evnt.Invoke(Room, sender); }
public virtual bool Evaluate(RailEvent evnt) { return(true); }
/// <summary> /// Handles the execution of an incoming event. /// </summary> private void ProcessEvent(RailEvent evnt) { EventReceived?.Invoke(evnt, this); eventHistory.Store(evnt.EventId); }
public bool Includes(RailEvent evnt) { return(Evaluator.Evaluate(evnt)); }