示例#1
0
    public void EnqueueInput(NetCommand.PlayerInputCommand command, Player player, uint serverWorldTick)
    {
        // Monitoring.
        DebugUI.ShowValue("sv stale inputs", staleInputs);

        // Calculate the last tick in the incoming command.
        uint maxTick = command.StartWorldTick + (uint)command.Inputs.Length - 1;

        // Scan for inputs which haven't been handled yet.
        if (maxTick >= serverWorldTick)
        {
            uint start = serverWorldTick > command.StartWorldTick
          ? serverWorldTick - command.StartWorldTick : 0;
            for (int i = (int)start; i < command.Inputs.Length; ++i)
            {
                // Apply inputs to the associated player controller and simulate the world.
                var worldTick = command.StartWorldTick + i;
                var tickInput = new TickInput {
                    WorldTick      = (uint)worldTick,
                    RemoteViewTick = (uint)(worldTick - command.ClientWorldTickDeltas[i]),
                    Player         = player,
                    Inputs         = command.Inputs[i],
                };
                queue.Enqueue(tickInput, worldTick);

                // Store the latest input in case the simulation needs to repeat missed frames.
                latestPlayerInput[player.Id] = tickInput;
            }
        }
        else
        {
            staleInputs++;
        }
    }
示例#2
0
 public bool TryGetLatestInput(byte playerId, out TickInput ret)
 {
     return(latestPlayerInput.TryGetValue(playerId, out ret));
 }