Prediction: RingBuffer perf comments

This commit is contained in:
mischa 2024-03-15 13:44:46 +08:00
parent 52d00aa3e3
commit 4d6ac92b62
2 changed files with 3 additions and 1 deletions

View File

@ -48,7 +48,7 @@ public class PredictedRigidbody : NetworkBehaviour
// client keeps state history for correction & reconciliation. // client keeps state history for correction & reconciliation.
// this needs to be a SortedList because we need to be able to insert inbetween. // this needs to be a SortedList because we need to be able to insert inbetween.
// RingBuffer would be faster iteration, but can't do insertions. // => RingBuffer: see prediction_ringbuffer_2 branch, but it's slower!
[Header("State History")] [Header("State History")]
public int stateHistoryLimit = 32; // 32 x 50 ms = 1.6 seconds is definitely enough public int stateHistoryLimit = 32; // 32 x 50 ms = 1.6 seconds is definitely enough
readonly SortedList<double, RigidbodyState> stateHistory = new SortedList<double, RigidbodyState>(); readonly SortedList<double, RigidbodyState> stateHistory = new SortedList<double, RigidbodyState>();

View File

@ -28,6 +28,7 @@ public static class Prediction
{ {
// get the two states closest to a given timestamp. // get the two states closest to a given timestamp.
// those can be used to interpolate the exact state at that time. // those can be used to interpolate the exact state at that time.
// => RingBuffer: see prediction_ringbuffer_2 branch, but it's slower!
public static bool Sample<T>( public static bool Sample<T>(
SortedList<double, T> history, SortedList<double, T> history,
double timestamp, // current server time double timestamp, // current server time
@ -98,6 +99,7 @@ public static bool Sample<T>(
// inserts a server state into the client's history. // inserts a server state into the client's history.
// readjust the deltas of the states after the inserted one. // readjust the deltas of the states after the inserted one.
// returns the corrected final position. // returns the corrected final position.
// => RingBuffer: see prediction_ringbuffer_2 branch, but it's slower!
public static T CorrectHistory<T>( public static T CorrectHistory<T>(
SortedList<double, T> history, SortedList<double, T> history,
int stateHistoryLimit, int stateHistoryLimit,