perf(PredictedRigidbody): OnSerialize faster

This commit is contained in:
mischa 2024-02-05 20:59:47 +01:00
parent 8e21a2101c
commit 1bd84f06d1

View File

@ -637,10 +637,14 @@ public override void OnSerialize(NetworkWriter writer, bool initialState)
// server is technically supposed to be at a fixed frame rate, but this can vary.
// sending server's current deltaTime is the safest option.
// client then applies it on top of remoteTimestamp.
// FAST VERSION: this shows in profiler a lot, so cache EVERYTHING!
tf.GetPositionAndRotation(out Vector3 position, out Quaternion rotation); // faster than tf.position + tf.rotation. server's rigidbody is on the same transform.
writer.WriteFloat(Time.deltaTime);
writer.WriteVector3(rb.position); // own rigidbody on server, it's never moved to physics copy
writer.WriteQuaternion(rb.rotation); // own rigidbody on server, it's never moved to physics copy
writer.WriteVector3(rb.velocity); // own rigidbody on server, it's never moved to physics copy
writer.WriteVector3(position);
writer.WriteQuaternion(rotation);
writer.WriteVector3(rb.velocity); // own rigidbody on server, it's never moved to physics copy
}
// read the server's state, compare with client state & correct if necessary.