perf: PredictedRigidbody RecordState only grabs count once

This commit is contained in:
mischa 2024-03-14 15:07:46 +08:00 committed by MrGadget
parent 2ecafaa634
commit 0657da87ea

View File

@ -508,9 +508,10 @@ void RecordState()
Vector3 velocityDelta = Vector3.zero; Vector3 velocityDelta = Vector3.zero;
Vector3 angularVelocityDelta = Vector3.zero; Vector3 angularVelocityDelta = Vector3.zero;
Quaternion rotationDelta = Quaternion.identity; Quaternion rotationDelta = Quaternion.identity;
if (stateHistory.Count > 0) int stateHistoryCount = stateHistory.Count; // perf: only grab .Count once
if (stateHistoryCount > 0)
{ {
RigidbodyState last = stateHistory.Values[stateHistory.Count - 1]; RigidbodyState last = stateHistory.Values[stateHistoryCount - 1];
positionDelta = currentPosition - last.position; positionDelta = currentPosition - last.position;
velocityDelta = currentVelocity - last.velocity; velocityDelta = currentVelocity - last.velocity;
// Quaternions always need to be normalized in order to be valid rotations after operations // Quaternions always need to be normalized in order to be valid rotations after operations