Esempio n. 1
0
 private IEnumerable <RailCommandUpdate> ProduceCommandUpdates(
     IEnumerable <RailEntityBase> entities)
 {
     // If we have too many entities to fit commands for in a packet,
     // we want to round-robin sort them to avoid starvation
     return(entities.Select(e => e as RailEntityClient)
            .OrderBy(e => e.LastSentCommandTick, Tick.CreateComparer())
            .Select(e => RailCommandUpdate.Create(Resource, e, e.OutgoingCommands)));
 }
Esempio n. 2
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);
                    }
                }
            }
        }
Esempio n. 3
0
 private void DecodeCommands(IRailCommandConstruction commandCreator, RailBitBuffer buffer)
 {
     commandUpdates.Decode(buffer, buf => RailCommandUpdate.Decode(commandCreator, buf));
 }