mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Fix GameStateProcessor skipping over necessary game states in some extrapolation cases.
Fixes #1246
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user