fix: Prediction.CorrectHistory now adjusts afterIndex after removals/insertions

This commit is contained in:
mischa 2024-03-18 15:52:24 +08:00 committed by MrGadget
parent 39338b413d
commit 1d004dcd21

View File

@ -112,11 +112,15 @@ public static T CorrectHistory<T>(
// 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).