server->client half as deltas

This commit is contained in:
mischa 2024-10-28 11:44:41 +01:00
parent 60106c6e06
commit 6791add189

View File

@ -381,7 +381,10 @@ void RpcServerToClientDelta_PositionRotation(byte baselineTick, Half x, Half y,
if (IsClientWithAuthority) return;
// Half: +-65k with 0.0001 precision is enough for deltas
Vector3 position = new Vector3((float)x, (float)y, (float)z);
Vector3 positionDelta = new Vector3((float)x, (float)y, (float)z);
// reconstruct full position from delta + baseline
Vector3 position = lastDeserializedBaselinePosition + positionDelta;
OnServerToClientDeltaSync(baselineTick, position, rotation);//, scale);
}
@ -395,7 +398,10 @@ void RpcServerToClientDelta_Position(byte baselineTick, Half x, Half y, Half z)
if (IsClientWithAuthority) return;
// Half: +-65k with 0.0001 precision is enough for deltas
Vector3 position = new Vector3((float)x, (float)y, (float)z);
Vector3 positionDelta = new Vector3((float)x, (float)y, (float)z);
// reconstruct full position from delta + baseline
Vector3 position = lastDeserializedBaselinePosition + positionDelta;
OnServerToClientDeltaSync(baselineTick, position, Quaternion.identity);//, scale);
}
@ -582,11 +588,15 @@ void UpdateServerDelta(double localTime)
// TransformSnapshot snapshot = ConstructSnapshot();
target.GetLocalPositionAndRotation(out Vector3 position, out Quaternion rotation);
// send the delta since last baseline, not the full position.
// TODO rotation delta too?
Vector3 positionDelta = position - lastSerializedBaselinePosition;
// Half: +-65k with 0.0001 precision is enough for deltas.
// and this cuts position sync bandwidth in half.
Half x = (Half)position.x;
Half y = (Half)position.y;
Half z = (Half)position.z;
Half x = (Half)positionDelta.x;
Half y = (Half)positionDelta.y;
Half z = (Half)positionDelta.z;
// save bandwidth by only transmitting what is needed.
// -> ArraySegment with random data is slower since byte[] copying