/// <summary> /// Removes any acked or expired outgoing events. /// </summary> private void CleanOutgoingEvents(SequenceId ackedEventId) { if (ackedEventId.IsValid == false) { return; } // Stop attempting to send acked events foreach (RailEvent evnt in outgoingEvents) { if (evnt.EventId <= ackedEventId) { evnt.Attempts = 0; } } // Clean out any events with zero attempts left while (outgoingEvents.Count > 0) { if (outgoingEvents.Peek().Attempts > 0) { break; } RailPool.Free(outgoingEvents.Dequeue()); } }
private void OnPacketReceived(RailPacketFromServer packet) { if (Room == null) { foreach (RailStateDelta delta in packet.Deltas) { RailPool.Free(delta); } } else { foreach (RailStateDelta delta in packet.Deltas) { if (Room.ProcessDelta(delta) == false) { RailPool.Free(delta); } } } foreach (RailEvent @event in packet.Events) { @event.Free(); } }
public void Store(T val) { if (data.Count >= capacity) { RailPool.Free(data.Dequeue()); } data.Enqueue(val); Latest = val; }
/// <summary> /// Clears the buffer, freeing all contents. /// </summary> public void Clear() { foreach (T val in data) { RailPool.Free(val); } data.Clear(); Latest = null; }
/// <summary> /// Discards all elements added as pending, regardless whether they have been sent or not. /// </summary> public void Clear() { // Everything in sent is also in pending, so only free pending foreach (T value in pending) { RailPool.Free(value); } pending.Clear(); sent.Clear(); }
private void ProcessCommandUpdate(RailServerPeer peer, RailCommandUpdate update) { if (Room.TryGet(update.EntityId, out RailEntityServer entity)) { bool canReceive = entity.Controller == peer && entity.IsRemoving == false; if (canReceive) { foreach (RailCommand command in update.Commands) { entity.ReceiveCommand(command); } } else // Can't send commands to that entity, so dump them { foreach (RailCommand command in update.Commands) { RailPool.Free(command); } } } }
public void Free() { RailPool.Free(this); }