fix(NetworkTransform): Separate ResetState (#3738)

We should not have hijacked Unity's callback for runtime resets.
This commit is contained in:
MrGadget 2024-01-19 12:23:35 -05:00 committed by GitHub
parent ac050a804d
commit b885db3703
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 11 deletions

View File

@ -311,9 +311,9 @@ public void RpcTeleport(Vector3 destination, Quaternion rotation)
} }
[ClientRpc] [ClientRpc]
void RpcReset() void RpcResetState()
{ {
Reset(); ResetState();
} }
// common Teleport code for client->server and server->client // common Teleport code for client->server and server->client
@ -367,7 +367,7 @@ protected virtual void OnTeleport(Vector3 destination, Quaternion rotation)
// -> maybe add destination as first entry? // -> maybe add destination as first entry?
} }
public virtual void Reset() public virtual void ResetState()
{ {
// disabled objects aren't updated anymore. // disabled objects aren't updated anymore.
// so let's clear the buffers. // so let's clear the buffers.
@ -375,9 +375,14 @@ public virtual void Reset()
clientSnapshots.Clear(); clientSnapshots.Clear();
} }
public virtual void Reset()
{
ResetState();
}
protected virtual void OnEnable() protected virtual void OnEnable()
{ {
Reset(); ResetState();
if (NetworkServer.active) if (NetworkServer.active)
NetworkIdentity.clientAuthorityCallback += OnClientAuthorityChanged; NetworkIdentity.clientAuthorityCallback += OnClientAuthorityChanged;
@ -385,7 +390,7 @@ protected virtual void OnEnable()
protected virtual void OnDisable() protected virtual void OnDisable()
{ {
Reset(); ResetState();
if (NetworkServer.active) if (NetworkServer.active)
NetworkIdentity.clientAuthorityCallback -= OnClientAuthorityChanged; NetworkIdentity.clientAuthorityCallback -= OnClientAuthorityChanged;
@ -403,8 +408,8 @@ void OnClientAuthorityChanged(NetworkConnectionToClient conn, NetworkIdentity id
if (syncDirection == SyncDirection.ClientToServer) if (syncDirection == SyncDirection.ClientToServer)
{ {
Reset(); ResetState();
RpcReset(); RpcResetState();
} }
} }

View File

@ -402,9 +402,9 @@ static void RewriteHistory(
// reset state for next session. // reset state for next session.
// do not ever call this during a session (i.e. after teleport). // do not ever call this during a session (i.e. after teleport).
// calling this will break delta compression. // calling this will break delta compression.
public override void Reset() public override void ResetState()
{ {
base.Reset(); base.ResetState();
// reset delta // reset delta
lastSerializedPosition = Vector3Long.zero; lastSerializedPosition = Vector3Long.zero;

View File

@ -346,7 +346,7 @@ protected virtual void OnClientToServerSync(Vector3? position, Quaternion? rotat
double timeIntervalCheck = bufferResetMultiplier * sendIntervalMultiplier * NetworkClient.sendInterval; double timeIntervalCheck = bufferResetMultiplier * sendIntervalMultiplier * NetworkClient.sendInterval;
if (serverSnapshots.Count > 0 && serverSnapshots.Values[serverSnapshots.Count - 1].remoteTime + timeIntervalCheck < timestamp) if (serverSnapshots.Count > 0 && serverSnapshots.Values[serverSnapshots.Count - 1].remoteTime + timeIntervalCheck < timestamp)
Reset(); ResetState();
} }
AddSnapshot(serverSnapshots, connectionToClient.remoteTimeStamp + timeStampAdjustment + offset, position, rotation, scale); AddSnapshot(serverSnapshots, connectionToClient.remoteTimeStamp + timeStampAdjustment + offset, position, rotation, scale);
@ -401,7 +401,7 @@ protected virtual void OnServerToClientSync(Vector3? position, Quaternion? rotat
double timeIntervalCheck = bufferResetMultiplier * sendIntervalMultiplier * NetworkServer.sendInterval; double timeIntervalCheck = bufferResetMultiplier * sendIntervalMultiplier * NetworkServer.sendInterval;
if (clientSnapshots.Count > 0 && clientSnapshots.Values[clientSnapshots.Count - 1].remoteTime + timeIntervalCheck < timestamp) if (clientSnapshots.Count > 0 && clientSnapshots.Values[clientSnapshots.Count - 1].remoteTime + timeIntervalCheck < timestamp)
Reset(); ResetState();
} }
AddSnapshot(clientSnapshots, NetworkClient.connection.remoteTimeStamp + timeStampAdjustment + offset, position, rotation, scale); AddSnapshot(clientSnapshots, NetworkClient.connection.remoteTimeStamp + timeStampAdjustment + offset, position, rotation, scale);