Ejemplo n.º 1
0
        /// <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());
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
 public void Store(T val)
 {
     if (data.Count >= capacity)
     {
         RailPool.Free(data.Dequeue());
     }
     data.Enqueue(val);
     Latest = val;
 }
Ejemplo n.º 4
0
        /// <summary>
        ///     Clears the buffer, freeing all contents.
        /// </summary>
        public void Clear()
        {
            foreach (T val in data)
            {
                RailPool.Free(val);
            }

            data.Clear();
            Latest = null;
        }
Ejemplo n.º 5
0
        /// <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();
        }
Ejemplo n.º 6
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public void Free()
 {
     RailPool.Free(this);
 }