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]
void RpcReset()
void RpcResetState()
{
Reset();
ResetState();
}
// 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?
}
public virtual void Reset()
public virtual void ResetState()
{
// disabled objects aren't updated anymore.
// so let's clear the buffers.
@ -375,9 +375,14 @@ public virtual void Reset()
clientSnapshots.Clear();
}
public virtual void Reset()
{
ResetState();
}
protected virtual void OnEnable()
{
Reset();
ResetState();
if (NetworkServer.active)
NetworkIdentity.clientAuthorityCallback += OnClientAuthorityChanged;
@ -385,7 +390,7 @@ protected virtual void OnEnable()
protected virtual void OnDisable()
{
Reset();
ResetState();
if (NetworkServer.active)
NetworkIdentity.clientAuthorityCallback -= OnClientAuthorityChanged;
@ -403,8 +408,8 @@ void OnClientAuthorityChanged(NetworkConnectionToClient conn, NetworkIdentity id
if (syncDirection == SyncDirection.ClientToServer)
{
Reset();
RpcReset();
ResetState();
RpcResetState();
}
}

View File

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

View File

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