Exemple #1
0
        private void ProcessCommandUpdate(
            RailServerPeer peer,
            RailCommandUpdate update)
        {
            RailEntity entity;

            if (this.Room.TryGet(update.EntityId, out entity))
            {
                if (entity.Controller == peer)
                {
                    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);
                    }
                }
            }
        }
Exemple #2
0
        private IEnumerable <RailCommandUpdate> ProduceCommandUpdates(
            IEnumerable <RailEntity> entities)
        {
            // If we have too many entities to fit commands for in a packet,
            // we want to round-robin sort them to avoid starvation
            this.sortingList.Clear();
            this.sortingList.AddRange(entities);
            this.sortingList.Sort(
                (x, y) => Tick.Comparer.Compare(
                    x.LastSentCommandTick,
                    y.LastSentCommandTick));

            foreach (RailEntity entity in sortingList)
            {
                RailCommandUpdate commandUpdate =
                    RailCommandUpdate.Create(
                        entity.Id,
                        entity.OutgoingCommands);
                commandUpdate.Entity = entity;
                yield return(commandUpdate);
            }
        }
 protected void DecodeCommands(RailBitBuffer buffer)
 {
     this.commandUpdates.Decode(
         buffer,
         () => RailCommandUpdate.Decode(buffer));
 }