Skip to content

Commit

Permalink
fix: Prediction.CorrectHistory now adjusts afterIndex after removals/…
Browse files Browse the repository at this point in the history
…insertions
  • Loading branch information
miwarnec committed Mar 18, 2024
1 parent af35e86 commit a84b786
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Assets/Mirror/Core/Prediction/Prediction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,21 @@ public static class Prediction
T corrected, // corrected state with timestamp
T before, // state in history before the correction
T after, // state in history after the correction
int afterIndex) // index of the 'after' value so we don't need to find it again here
int afterIndex) // index of the 'after' value so we don't need to find it again here
where T: PredictedState
{
// respect the limit
// TODO unit test to check if it respects max size
if (history.Count >= stateHistoryLimit)
{
history.RemoveAt(0);
afterIndex -= 1; // we removed the first value so all indices are off by one now
}

// insert the corrected state into the history, or overwrite if already exists
// SortedList insertions are O(N)!
history[corrected.timestamp] = corrected;
afterIndex += 1; // we inserted the corrected value before the previous index

// the entry behind the inserted one still has the delta from (before, after).
// we need to correct it to (corrected, after).
Expand Down

0 comments on commit a84b786

Please sign in to comment.