Skip to content

Commit

Permalink
perf: Added Compress / Decompress Quaternion to Experimental Network …
Browse files Browse the repository at this point in the history
…Transform
  • Loading branch information
MrGadget1024 committed Nov 28, 2020
1 parent fde07de commit 1616f57
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Assets/Mirror/Components/Experimental/NetworkTransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void FixedUpdate()

void ServerUpdate()
{
RpcMove(targetTransform.localPosition, targetTransform.localRotation, targetTransform.localScale);
RpcMove(targetTransform.localPosition, Compression.CompressQuaternion(targetTransform.localRotation), targetTransform.localScale);
}

void ClientAuthorityUpdate()
Expand All @@ -148,7 +148,7 @@ void ClientAuthorityUpdate()
// serialize
// local position/rotation for VR support
// send to server
CmdClientToServerSync(targetTransform.localPosition, targetTransform.localRotation, targetTransform.localScale);
CmdClientToServerSync(targetTransform.localPosition, Compression.CompressQuaternion(targetTransform.localRotation), targetTransform.localScale);
}
}

Expand Down Expand Up @@ -213,29 +213,29 @@ bool NeedsTeleport()

// local authority client sends sync message to server for broadcasting
[Command]
void CmdClientToServerSync(Vector3 position, Quaternion rotation, Vector3 scale)
void CmdClientToServerSync(Vector3 position, uint packedRotation, Vector3 scale)
{
// Ignore messages from client if not in client authority mode
if (!clientAuthority)
return;

// deserialize payload
SetGoal(position, rotation, scale);
SetGoal(position, Compression.DecompressQuaternion(packedRotation), scale);

// server-only mode does no interpolation to save computations, but let's set the position directly
if (isServer && !isClient)
ApplyPositionRotationScale(goal.localPosition, goal.localRotation, goal.localScale);

RpcMove(position, rotation, scale);
RpcMove(position, packedRotation, scale);
}

[ClientRpc]
void RpcMove(Vector3 position, Quaternion rotation, Vector3 scale)
void RpcMove(Vector3 position, uint packedRotation, Vector3 scale)
{
if (hasAuthority && excludeOwnerUpdate) return;

if (!isServer)
SetGoal(position, rotation, scale);
SetGoal(position, Compression.DecompressQuaternion(packedRotation), scale);
}

// serialization is needed by OnSerialize and by manual sending from authority
Expand Down Expand Up @@ -440,7 +440,7 @@ public void ServerTeleport(Vector3 localPosition, Quaternion localRotation)
DoTeleport(localPosition, localRotation);

// tell all clients about new values
RpcTeleport(localPosition, localRotation, clientAuthorityBeforeTeleport);
RpcTeleport(localPosition, Compression.CompressQuaternion(localRotation), clientAuthorityBeforeTeleport);
}

void DoTeleport(Vector3 newLocalPosition, Quaternion newLocalRotation)
Expand All @@ -457,9 +457,9 @@ void DoTeleport(Vector3 newLocalPosition, Quaternion newLocalRotation)
}

[ClientRpc]
void RpcTeleport(Vector3 newPosition, Quaternion newRotation, bool isClientAuthority)
void RpcTeleport(Vector3 newPosition, uint newPackedRotation, bool isClientAuthority)
{
DoTeleport(newPosition, newRotation);
DoTeleport(newPosition, Compression.DecompressQuaternion(newPackedRotation));

// only send finished if is owner and is ClientAuthority on server
if (hasAuthority && isClientAuthority)
Expand Down

0 comments on commit 1616f57

Please sign in to comment.