/// <summary> /// Handles the execution of an incoming event. /// </summary> private void ProcessEvent(RailEvent evnt) { if (this.EventReceived != null) { this.EventReceived.Invoke(evnt, this); } this.processedEventHistory = this.processedEventHistory.Store(evnt.EventId); }
/// <summary> /// Selects outgoing events to send. /// </summary> private IEnumerable <RailEvent> FilterOutgoingEvents() { // The receiving client can only store SequenceWindow.HISTORY_LENGTH // events in its received buffer, and will skip any events older than // its latest received minus that history length, including reliable // events. In order to make sure we don't force the client to skip a // reliable event, we will throttle the outgoing events if we've been // sending them too fast. For example, if we have a reliable event // with ID 3 pending, the highest ID we can send would be ID 67. If we // send an event with ID 68, then the client may ignore ID 3 when it // comes in for being too old, even though it's reliable. // // In practice this shouldn't be a problem unless we're sending way // more events than is reasonable(/possible) in a single packet, or // something is wrong with reliable event acking. SequenceId firstReliable = SequenceId.INVALID; foreach (RailEvent evnt in this.outgoingEvents) { if (evnt.IsReliable) { if (firstReliable.IsValid == false) { firstReliable = evnt.EventId; } RailDebug.Assert(firstReliable <= evnt.EventId); } if (firstReliable.IsValid) { if (SequenceWindow.AreInRange(firstReliable, evnt.EventId) == false) { string current = "Throttling events due to unacked reliable\n"; foreach (RailEvent evnt2 in this.outgoingEvents) { current += evnt2.EventId + " "; } RailDebug.LogWarning(current); break; } } if (evnt.CanSend) { yield return(evnt); } } }
protected RailPeer( IRailNetPeer netPeer, RailInterpreter interpreter, RailPacket reusableIncoming, RailPacket reusableOutgoing) { this.netPeer = netPeer; this.interpreter = interpreter; this.controlledEntities = new HashSet <RailEntity>(); this.remoteClock = new RailClock(); this.outgoingEvents = new Queue <RailEvent>(); this.reusableIncoming = reusableIncoming; this.reusableOutgoing = reusableOutgoing; this.lastQueuedEventId = SequenceId.START.Next; this.processedEventHistory = new SequenceWindow(SequenceId.START); this.netPeer.PayloadReceived += this.OnPayloadReceived; }