This commit is contained in:
mischa 2024-04-04 19:26:53 +08:00
parent d656239476
commit 84ec18f61d
2 changed files with 17 additions and 34 deletions

View File

@ -209,11 +209,17 @@ protected virtual bool IsMoving() =>
predictedRigidbody.velocity.sqrMagnitude >= velocitySensitivitySqr || predictedRigidbody.velocity.sqrMagnitude >= velocitySensitivitySqr ||
predictedRigidbody.angularVelocity.sqrMagnitude >= angularVelocitySensitivitySqr; predictedRigidbody.angularVelocity.sqrMagnitude >= angularVelocitySensitivitySqr;
// when using Fast mode, we don't create any ghosts. void Update()
// but we still want to check IsMoving() in order to support the same
// user callbacks.
void UpdateClient()
{ {
if (isServer) UpdateServer();
}
// Prediction always has a Rigidbody.
// position changes should always happen in FixedUpdate, even while kinematic.
// improves benchmark performance from 600 -> 870 FPS.
void FixedUpdateClient()
{
// PREDICTING checks state, which happens in update()
if (state == ForecastState.PREDICTING) if (state == ForecastState.PREDICTING)
{ {
// we want to predict until the first server state came in. // we want to predict until the first server state came in.
@ -230,32 +236,6 @@ void UpdateClient()
} }
} }
else if (state == ForecastState.BLENDING) else if (state == ForecastState.BLENDING)
{
// BLENDING sets Rigidbody which happens in FixedUpdate()!
}
else if (state == ForecastState.FOLLOWING)
{
// hard set position & rotation.
// TODO snapshot interpolation
tf.SetPositionAndRotation(lastReceivedState.position, lastReceivedState.rotation);
}
}
void Update()
{
if (isServer) UpdateServer();
if (isClientOnly) UpdateClient();
}
void FixedUpdateClient()
{
// physics movements need to be done in FixedUpdate.
// PREDICTING checks state, which happens in update()
// if (state == ForecastState.PREDICTING)
// {
// }
if (state == ForecastState.BLENDING)
{ {
// TODO snapshot interpolation // TODO snapshot interpolation
@ -315,9 +295,12 @@ void FixedUpdateClient()
} }
} }
// FOLLOWING sets Transform, which happens in Update(). // FOLLOWING sets Transform, which happens in Update().
// else if (state == ForecastState.FOLLOWING) else if (state == ForecastState.FOLLOWING)
// { {
// } // hard set position & rotation.
// TODO snapshot interpolation
tf.SetPositionAndRotation(lastReceivedState.position, lastReceivedState.rotation);
}
} }
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: 580 FPS Client, 1700 FPS Server // Forecasting & hand-off 2024-04-04: 870 FPS Client, 1700 FPS Server // Forecasting & hand-off