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))); }
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); } } } }
private void DecodeCommands(IRailCommandConstruction commandCreator, RailBitBuffer buffer) { commandUpdates.Decode(buffer, buf => RailCommandUpdate.Decode(commandCreator, buf)); }