mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
dont record more
This commit is contained in:
parent
e7e49985a0
commit
522cf50d9f
@ -492,10 +492,10 @@ void LateUpdate()
|
|||||||
float lastAngularVelocitySqr = 0;
|
float lastAngularVelocitySqr = 0;
|
||||||
RigidbodyState? remoteState = null;
|
RigidbodyState? remoteState = null;
|
||||||
bool remoteResting = false; // perf: only calculate on receive, not every single update()!
|
bool remoteResting = false; // perf: only calculate on receive, not every single update()!
|
||||||
void ClientHoldAtRest()
|
bool ClientHoldAtRest() // returns true when forced to rest
|
||||||
{
|
{
|
||||||
// no state yet? then nothing to do.
|
// no state yet? then nothing to do.
|
||||||
if (remoteState == null) return;
|
if (remoteState == null) return false;
|
||||||
|
|
||||||
// color code for debugging
|
// color code for debugging
|
||||||
if (showRemoteSleeping) rend.material.color = remoteResting ? Color.gray : originalColor;
|
if (showRemoteSleeping) rend.material.color = remoteResting ? Color.gray : originalColor;
|
||||||
@ -503,7 +503,7 @@ void ClientHoldAtRest()
|
|||||||
// try fixing objects coming to rest:
|
// try fixing objects coming to rest:
|
||||||
// if remote is sleeping and we are DECELERATING from a previous move,
|
// if remote is sleeping and we are DECELERATING from a previous move,
|
||||||
// then hold position exactly at remote sleeping position.
|
// then hold position exactly at remote sleeping position.
|
||||||
if (!remoteResting) return;
|
if (!remoteResting) return false;
|
||||||
|
|
||||||
// <= comparison matters so it works while decelearting AND at rest,
|
// <= comparison matters so it works while decelearting AND at rest,
|
||||||
// but stop when accelerating again!
|
// but stop when accelerating again!
|
||||||
@ -512,7 +512,7 @@ void ClientHoldAtRest()
|
|||||||
bool decelerating = currentVelocitySqr <= lastVelocitySqr && currentAngularVelocitySqr <= lastAngularVelocitySqr;
|
bool decelerating = currentVelocitySqr <= lastVelocitySqr && currentAngularVelocitySqr <= lastAngularVelocitySqr;
|
||||||
lastVelocitySqr = currentVelocitySqr;
|
lastVelocitySqr = currentVelocitySqr;
|
||||||
lastAngularVelocitySqr = currentAngularVelocitySqr;
|
lastAngularVelocitySqr = currentAngularVelocitySqr;
|
||||||
if (!decelerating) return;
|
if (!decelerating) return false;
|
||||||
|
|
||||||
// hold in place to avoid fighting at rest
|
// hold in place to avoid fighting at rest
|
||||||
predictedRigidbody.velocity = Vector3.zero;
|
predictedRigidbody.velocity = Vector3.zero;
|
||||||
@ -521,6 +521,9 @@ void ClientHoldAtRest()
|
|||||||
predictedRigidbody.rotation = remoteState.Value.rotation;
|
predictedRigidbody.rotation = remoteState.Value.rotation;
|
||||||
predictedRigidbody.Sleep();
|
predictedRigidbody.Sleep();
|
||||||
stateHistory.Clear();
|
stateHistory.Clear();
|
||||||
|
|
||||||
|
// indicate that it was forced to rest
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
@ -531,7 +534,11 @@ void FixedUpdate()
|
|||||||
|
|
||||||
// holding at rest forces physics position, so it's enough to do this
|
// holding at rest forces physics position, so it's enough to do this
|
||||||
// in FixedUpdate.
|
// in FixedUpdate.
|
||||||
if (holdAtRest) ClientHoldAtRest();
|
if (holdAtRest)
|
||||||
|
{
|
||||||
|
// if forced to rest, don't record anything or do any more work
|
||||||
|
if (ClientHoldAtRest()) return;
|
||||||
|
}
|
||||||
|
|
||||||
// OPTIMIZATION: RecordState() is expensive because it inserts into a SortedList.
|
// OPTIMIZATION: RecordState() is expensive because it inserts into a SortedList.
|
||||||
// only record if state actually changed!
|
// only record if state actually changed!
|
||||||
|
Loading…
Reference in New Issue
Block a user