perf: PredictedRigidbody syncs a blittable struct once instead of doing 5 separate reads/writes

This commit is contained in:
mischa 2024-03-14 11:50:54 +08:00 committed by MrGadget
parent 9497121c45
commit 0789d41798
2 changed files with 3 additions and 13 deletions

View File

@ -39,23 +39,12 @@ public static class PredictedSyncDataReadWrite
{ {
public static void WritePredictedSyncData(this NetworkWriter writer, PredictedSyncData data) public static void WritePredictedSyncData(this NetworkWriter writer, PredictedSyncData data)
{ {
writer.WriteFloat(data.deltaTime); writer.WriteBlittable(data);
writer.WriteVector3(data.position);
writer.WriteQuaternion(data.rotation);
writer.WriteVector3(data.velocity);
writer.WriteVector3(data.angularVelocity);
} }
public static PredictedSyncData ReadPredictedSyncData(this NetworkReader reader) public static PredictedSyncData ReadPredictedSyncData(this NetworkReader reader)
{ {
return new PredictedSyncData return reader.ReadBlittable<PredictedSyncData>();
{
deltaTime = reader.ReadFloat(),
position = reader.ReadVector3(),
rotation = reader.ReadQuaternion(),
velocity = reader.ReadVector3(),
angularVelocity = reader.ReadVector3()
};
} }
} }
} }

View File

@ -10,3 +10,4 @@
[assembly: InternalsVisibleTo("Mirror.Tests.Performance.Editor")] [assembly: InternalsVisibleTo("Mirror.Tests.Performance.Editor")]
[assembly: InternalsVisibleTo("Mirror.Tests.Performance.Runtime")] [assembly: InternalsVisibleTo("Mirror.Tests.Performance.Runtime")]
[assembly: InternalsVisibleTo("Mirror.Editor")] [assembly: InternalsVisibleTo("Mirror.Editor")]
[assembly: InternalsVisibleTo("Mirror.Components")]