PredictedRigidbody: OnDeserialize parsing grouped together (syntax change)

This commit is contained in:
mischa 2024-03-14 11:38:09 +08:00 committed by MrGadget
parent c503724b61
commit 597fd933c4

View File

@ -769,10 +769,16 @@ public override void OnDeserialize(NetworkReader reader, bool initialState)
// we want to know the time on the server when this was sent, which is remoteTimestamp. // we want to know the time on the server when this was sent, which is remoteTimestamp.
double timestamp = NetworkClient.connection.remoteTimeStamp; double timestamp = NetworkClient.connection.remoteTimeStamp;
// server send state at the end of the frame. // parse state
double serverDeltaTime = reader.ReadFloat();
Vector3 position = reader.ReadVector3();
Quaternion rotation = reader.ReadQuaternion();
Vector3 velocity = reader.ReadVector3();
Vector3 angularVelocity = reader.ReadVector3();
// server sends state at the end of the frame.
// parse and apply the server's delta time to our timestamp. // parse and apply the server's delta time to our timestamp.
// otherwise we see noticeable resets that seem off by one frame. // otherwise we see noticeable resets that seem off by one frame.
double serverDeltaTime = reader.ReadFloat();
timestamp += serverDeltaTime; timestamp += serverDeltaTime;
// however, adding yet one more frame delay gives much(!) better results. // however, adding yet one more frame delay gives much(!) better results.
@ -781,12 +787,6 @@ public override void OnDeserialize(NetworkReader reader, bool initialState)
// with physics happening at the end of the frame? // with physics happening at the end of the frame?
if (oneFrameAhead) timestamp += serverDeltaTime; if (oneFrameAhead) timestamp += serverDeltaTime;
// parse state
Vector3 position = reader.ReadVector3();
Quaternion rotation = reader.ReadQuaternion();
Vector3 velocity = reader.ReadVector3();
Vector3 angularVelocity = reader.ReadVector3();
// process received state // process received state
OnReceivedState(timestamp, new RigidbodyState(timestamp, Vector3.zero, position, Quaternion.identity, rotation, Vector3.zero, velocity, Vector3.zero, angularVelocity)); OnReceivedState(timestamp, new RigidbodyState(timestamp, Vector3.zero, position, Quaternion.identity, rotation, Vector3.zero, velocity, Vector3.zero, angularVelocity));
} }