Exemplo 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());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Stores a value. Will not replace a stored value with an older one.
        /// </summary>
        public bool Store(T value)
        {
            int  index = TickToIndex(value.Tick);
            bool store = false;

            if (latestIdx < 0)
            {
                store = true;
            }
            else
            {
                T latest = data[latestIdx];
                if (value.Tick >= latest.Tick)
                {
                    store = true;
                }
            }

            if (store)
            {
                RailPool.SafeReplace(ref data[index], value);
                latestIdx = index;
            }

            return(store);
        }
Exemplo n.º 3
0
 private void Reset()
 {
     this.tick     = Tick.INVALID;
     this.entityId = EntityId.INVALID;
     RailPool.SafeReplace(ref this.state, null);
     this.IsFrozen = false;
 }
Exemplo n.º 4
0
 private void Reset()
 {
     Tick     = Tick.INVALID;
     EntityId = EntityId.INVALID;
     RailPool.SafeReplace(ref state, null);
     IsFrozen = false;
 }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Clears the buffer, freeing all contents.
        /// </summary>
        public void Clear()
        {
            for (int i = 0; i < data.Length; i++)
            {
                RailPool.SafeReplace(ref data[i], null);
            }

            latestIdx = -1;
        }
Exemplo n.º 7
0
 public void Store(T val)
 {
     if (data.Count >= capacity)
     {
         RailPool.Free(data.Dequeue());
     }
     data.Enqueue(val);
     Latest = val;
 }
Exemplo n.º 8
0
        /// <summary>
        ///     Clears the buffer, freeing all contents.
        /// </summary>
        public void Clear()
        {
            foreach (T val in data)
            {
                RailPool.Free(val);
            }

            data.Clear();
            Latest = null;
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
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);
                    }
                }
            }
        }
Exemplo n.º 11
0
 private void Reset()
 {
     tick = Tick.INVALID;
     RailPool.SafeReplace(ref state, null);
 }
Exemplo n.º 12
0
 public void Free()
 {
     RailPool.Free(this);
 }