Vixen
02b45cc4
csharp
public sealed class InputLog<T> where T : struct, IPredictedInput<T>

What a client has done recently, and what it has not been told arrived.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Two jobs, and they are the same log. It is what goes on the wire, and it is what a rollback replays: reconciling means restoring the server's state for tick T and simulating T+1 to now again, which needs the inputs that were used the first time. A design with a send buffer and a replay buffer would be two copies of one truth.

Every packet carries the last several ticks, not just the newest. A lost input is not a lost update — it is a tick the server simulates differently from the client that predicted it, and the divergence is permanent rather than corrected by the next packet. So inputs are sent redundantly, which costs a few bytes and removes the failure entirely for any loss shorter than the redundancy. It is the oldest trick in netcode and it is worth spelling out, because the obvious implementation — send this tick's input, it is unreliable, the next one will fix it — is wrong in a way that only shows up on a bad connection.

Trimmed by acknowledgement, not by age. The server says which tick it has everything up to; anything at or below that has been consumed and cannot be needed again, by either job. Trimming by age instead would throw away the inputs a slow acknowledgement still needs for the replay.

Fields and properties (8)

  • public int Redundancy

    How many past ticks ride along with the newest one.

  • public int Capacity

    The most inputs the log will hold before it starts forgetting the oldest.

  • public Tick Newest

    The newest tick recorded.

  • public bool HasAny

    Whether anything has been recorded.

  • public int Count

    How many inputs are held.

  • public Tick Acknowledged

    The newest tick the server has said it has.

  • public bool HasAcknowledged

    Whether the server has acknowledged anything.

  • public long OverflowCount

    Inputs dropped because the log was full, which is a connection that has gone quiet.

Methods (5)

  • public void Record(Tick tick, in T input)

    Records what the local player did on a tick.

  • public bool TryGet(Tick tick, out T input)

    Finds what was done on a tick, for replaying it.

  • public bool TryWrite(Span<byte> buffer, out ReadOnlySpan<byte> payload)

    Writes the newest input and the few before it.

  • public void Acknowledge(Tick tick)

    Takes the server's word for what it has.

  • public void Clear()

    Forgets everything, for a client that is reconnecting.

Used by (4)

  • ClientPredictionVixen.Net
  • ClientPredictionTestsVixen.Net.Tests
  • PredictedInputTestsVixen.Net.Tests
  • PredictedPlayerMovementTestsVixen.Net.Physics.Tests