Fix GameStateProcessor skipping over necessary game states in some extrapolation cases.

Fixes #1246
This commit is contained in:
Pieter-Jan Briers
2020-08-26 13:45:15 +02:00
parent cd5115fa85
commit 3f0e2fa429
5 changed files with 113 additions and 9 deletions

View File

@@ -153,6 +153,84 @@ namespace Robust.UnitTesting.Client.GameStates
Assert.That(nextState, Is.Null);
}
/// <summary>
/// There is a hole in the state buffer, we have a future state but their FromSequence is too high!
/// In this case we stop and wait for the server to get us the missing link.
/// </summary>
[Test]
public void Hole()
{
var (timing, processor) = SetupProcessorFactory();
processor.AddNewState(GameStateFactory(4, 5));
processor.LastProcessedRealState = new GameTick(3);
timing.CurTick = new GameTick(4);
var result = processor.ProcessTickStates(timing.CurTick, out _, out _);
Assert.That(result, Is.False);
}
/// <summary>
/// Test that the game state manager goes into extrapolation mode *temporarily*,
/// if we are missing the curState, but we have a future state that we can apply to skip it.
/// </summary>
[Test]
public void ExtrapolateAdvanceWithFutureState()
{
var (timing, processor) = SetupProcessorFactory();
processor.Interpolation = true;
timing.CurTick = new GameTick(4);
processor.LastProcessedRealState = new GameTick(3);
processor.AddNewState(GameStateFactory(3, 5));
// We're missing the state for this tick so go into extrap.
var result = processor.ProcessTickStates(timing.CurTick, out var curState, out _);
Assert.That(result, Is.True);
Assert.That(curState, Is.Not.Null);
Assert.That(curState!.Extrapolated, Is.True);
timing.CurTick = new GameTick(5);
// But we DO have the state for the tick after so apply away!
result = processor.ProcessTickStates(timing.CurTick, out curState, out _);
Assert.That(result, Is.True);
Assert.That(curState, Is.Not.Null);
Assert.That(curState!.Extrapolated, Is.False);
}
/// <summary>
/// The client started extrapolating and now received the state it needs to "continue as normal".
/// In this scenario the CurTick passed to the game state processor
/// is higher than the real next tick to apply, IF it went into extrapolation.
/// The processor needs to go back to the next REAL tick.
/// </summary>
[Test, Ignore("Extrapolation is currently non functional anyways")]
public void UndoExtrapolation()
{
var (timing, processor) = SetupProcessorFactory();
processor.Extrapolation = true;
processor.AddNewState(GameStateFactory(4, 5));
processor.AddNewState(GameStateFactory(3, 4));
processor.LastProcessedRealState = new GameTick(3);
timing.CurTick = new GameTick(5);
var result = processor.ProcessTickStates(timing.CurTick, out var curState, out _);
Assert.That(result, Is.True);
Assert.That(curState, Is.Not.Null);
Assert.That(curState!.ToSequence, Is.EqualTo(new GameTick(4)));
}
/// <summary>
/// Creates a new empty GameState with the given to and from properties.
/// </summary>