Skip to content

Commit

Permalink
Switch to single-precision floats for networking since double-precisi…
Browse files Browse the repository at this point in the history
…on floats are redundant and waste bandwidth
  • Loading branch information
RedBigz committed Dec 23, 2024
1 parent 0a22a52 commit 790c9db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 4 additions & 2 deletions TABGVR.Server/Patches/NetworkEventPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static bool Prefix(ServerClient __instance, ServerPackage networkEvent)
return false;
}

if (networkEvent.Buffer.Length != 8 * 18) // drop malformed packets and kick the responsible player
if (networkEvent.Buffer.Length !=
sizeof(float) * 3 * 6) // drop malformed packets and kick the responsible player
{
PlayerKickCommand.Run(player,
__instance, KickReason.Invalid);
Expand All @@ -44,7 +45,8 @@ public static bool Prefix(ServerClient __instance, ServerPackage networkEvent)

byte[] message = [player.PlayerIndex, ..networkEvent.Buffer];

var recipients = from watcher in ServerChunks.Instance.GetWatchers(player.ChunkData) select watcher.PlayerIndex;
var recipients = from watcher in ServerChunks.Instance.GetWatchers(player.ChunkData)
select watcher.PlayerIndex;

__instance.SendMessageToClients(networkEvent.Code, message, recipients.ToArray(), true);

Expand Down
6 changes: 3 additions & 3 deletions TABGVR/Patches/Interactions/KinematicsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ private static void FixedUpdatePostfix(Holding __instance)
{
void WriteVector(Vector3 vector)
{
writer.Write((double)vector.x);
writer.Write((double)vector.y);
writer.Write((double)vector.z);
writer.Write(vector.x);
writer.Write(vector.y);
writer.Write(vector.z);
}

var heldObject = Grenades.SelectedGrenade?.GetComponent<HoldableObject>() ?? __instance.heldObject;
Expand Down
3 changes: 1 addition & 2 deletions TABGVR/Patches/Networking/NetworkEventPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public static bool Prefix(ClientPackage clientPackage)

var store = NetworkStoreList.NetworkStores[playerIndex];

Vector3 ReadVector() => new((float)reader.ReadDouble(), (float)reader.ReadDouble(),
(float)reader.ReadDouble());
Vector3 ReadVector() => new(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

store.HmdPosition = ReadVector();
store.HmdRotation = ReadVector();
Expand Down

0 comments on commit 790c9db

Please sign in to comment.