micro optimizations

This commit is contained in:
mischa 2024-04-04 18:58:19 +08:00
parent 141b9e9a76
commit 592a41d065
2 changed files with 15 additions and 15 deletions

View File

@ -156,7 +156,6 @@ protected void BeginPredicting()
} }
double blendingStartTime; double blendingStartTime;
float BlendingElapsedTime() => (float)(NetworkTime.time - blendingStartTime);
protected void BeginBlending() protected void BeginBlending()
{ {
state = ForecastState.BLENDING; state = ForecastState.BLENDING;
@ -252,11 +251,11 @@ void FixedUpdateClient()
{ {
// physics movements need to be done in FixedUpdate. // physics movements need to be done in FixedUpdate.
if (state == ForecastState.PREDICTING) // PREDICTING checks state, which happens in update()
{ // if (state == ForecastState.PREDICTING)
// PREDICTING checks state, which happens in update() // {
} // }
else if (state == ForecastState.BLENDING) if (state == ForecastState.BLENDING)
{ {
// TODO snapshot interpolation // TODO snapshot interpolation
@ -268,14 +267,15 @@ void FixedUpdateClient()
} }
// sample the blending curve to find out how much to blend right now // sample the blending curve to find out how much to blend right now
float blendingElapsed = BlendingElapsedTime();
float blendingElapsed = (float)(NetworkTime.time - blendingStartTime);
float relativeElapsed = blendingElapsed / blendingTime; float relativeElapsed = blendingElapsed / blendingTime;
float p = blendingCurve.Evaluate(relativeElapsed); float p = blendingCurve.Evaluate(relativeElapsed);
// Debug.Log($"{name} BLENDING @ {blendingElapsed:F2} / {blendingTime:F2} => {(p*100):F0}%"); // Debug.Log($"{name} BLENDING @ {blendingElapsed:F2} / {blendingTime:F2} => {(p*100):F0}%");
// blend local position to remote position // blend local position to remote position.
Vector3 currentPosition = predictedRigidbody.position; // getting both at once is fastest.
Quaternion currentRotation = predictedRigidbody.rotation; tf.GetPositionAndRotation(out Vector3 currentPosition, out Quaternion currentRotation);
// smoothly interpolate to the target position. // smoothly interpolate to the target position.
// speed relative to how far away we are. // speed relative to how far away we are.
@ -305,10 +305,10 @@ void FixedUpdateClient()
BeginFollowing(); BeginFollowing();
} }
} }
else if (state == ForecastState.FOLLOWING) // FOLLOWING sets Transform, which happens in Update().
{ // else if (state == ForecastState.FOLLOWING)
// FOLLOWING sets Transform, which happens in Update(). // {
} // }
} }
void FixedUpdate() void FixedUpdate()

View File

@ -22,4 +22,4 @@ Predicted:
2024-03-15: 625 FPS Client, 1700 FPS Server // Vector3.MoveTowardsCustom() 2024-03-15: 625 FPS Client, 1700 FPS Server // Vector3.MoveTowardsCustom()
2024-03-18: 628 FPS Client, 1700 FPS Server // removed O(N) insertion from CorrectHistory() 2024-03-18: 628 FPS Client, 1700 FPS Server // removed O(N) insertion from CorrectHistory()
2024-03-28: 800 FPS Client, 1700 FPS Server // FAST mode prediction 2024-03-28: 800 FPS Client, 1700 FPS Server // FAST mode prediction
2024-04-04: 570 FPS Client, 1700 FPS Server // Forecasting & hand-off 2024-04-04: 580 FPS Client, 1700 FPS Server // Forecasting & hand-off