Skip to content

Commit be40aa3

Browse files
committed
Readonly, missing MessageTypes, replace quat...
1 parent ff2e26a commit be40aa3

5 files changed

Lines changed: 26 additions & 31 deletions

File tree

com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,7 @@ internal NetworkTransformState ApplyLocalNetworkState()
21022102
/// </summary>
21032103
internal bool ApplyTransformToNetworkState(ref NetworkTransformState networkState, double dirtyTime, Transform transformToUse)
21042104
{
2105-
CachedTransform = transformToUse;
2105+
m_CachedTransform = transformToUse;
21062106
m_CachedNetworkManager = NetworkManager;
21072107
// Apply the interpolate and PostionDeltaCompression flags, otherwise we get false positives whether something changed or not.
21082108
networkState.FlagStates.UseInterpolation = Interpolate;

com.unity.netcode.gameobjects/Runtime/Components/QuaternionCompressor.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ public static class QuaternionCompressor
4242
private const ushort k_True = 1;
4343
private const ushort k_False = 0;
4444

45-
// Used to store the absolute value of the 4 quaternion elements
46-
private static Quaternion s_QuatAbsValues = Quaternion.identity;
47-
#if UNITY_EDITOR
48-
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
49-
private static void ResetStaticsOnLoad() => s_QuatAbsValues = Quaternion.identity;
50-
#endif
51-
5245
/// <summary>
5346
/// Compresses a Quaternion into an unsigned integer
5447
/// </summary>
@@ -58,38 +51,31 @@ public static class QuaternionCompressor
5851
public static uint CompressQuaternion(ref Quaternion quaternion)
5952
{
6053
// Store off the absolute value for each Quaternion element
61-
s_QuatAbsValues[0] = Mathf.Abs(quaternion[0]);
62-
s_QuatAbsValues[1] = Mathf.Abs(quaternion[1]);
63-
s_QuatAbsValues[2] = Mathf.Abs(quaternion[2]);
64-
s_QuatAbsValues[3] = Mathf.Abs(quaternion[3]);
54+
var quatAbsValue0 = Mathf.Abs(quaternion[0]);
55+
var quatAbsValue1 = Mathf.Abs(quaternion[1]);
56+
var quatAbsValue2 = Mathf.Abs(quaternion[2]);
57+
var quatAbsValue3 = Mathf.Abs(quaternion[3]);
6558

6659
// Get the largest element value of the quaternion to know what the remaining "Smallest Three" values are
67-
var quatMax = Mathf.Max(s_QuatAbsValues[0], s_QuatAbsValues[1], s_QuatAbsValues[2], s_QuatAbsValues[3]);
60+
var quatMax = Mathf.Max(quatAbsValue0, quatAbsValue1, quatAbsValue2, quatAbsValue3);
6861

6962
// Find the index of the largest element so we can skip that element while compressing and decompressing
70-
var indexToSkip = (ushort)(s_QuatAbsValues[0] == quatMax ? 0 : s_QuatAbsValues[1] == quatMax ? 1 : s_QuatAbsValues[2] == quatMax ? 2 : 3);
63+
var indexToSkip = (ushort)(quatAbsValue0 == quatMax ? 0 : quatAbsValue1 == quatMax ? 1 : quatAbsValue2 == quatMax ? 2 : 3);
7164

7265
// Get the sign of the largest element which is all that is needed when calculating the sum of squares of a normalized quaternion.
73-
7466
var quatMaxSign = (quaternion[indexToSkip] < 0 ? k_True : k_False);
7567

7668
// Start with the index to skip which will be shifted to the highest two bits
7769
var compressed = (uint)indexToSkip;
7870

79-
// Step 1: Start with the first element
80-
var currentIndex = 0;
81-
8271
// Step 2: If we are on the index to skip preserve the current compressed value, otherwise proceed to step 3 and 4
8372
// Step 3: Get the sign of the element we are processing. If it is the not the same as the largest value's sign bit then we set the bit
8473
// Step 4: Get the compressed and encoded value by multiplying the absolute value of the current element by k_CompressionEcodingMask and round that result up
85-
compressed = currentIndex != indexToSkip ? (compressed << 10) | (uint)((quaternion[currentIndex] < 0 ? k_True : k_False) != quatMaxSign ? k_True : k_False) << k_ShiftNegativeBit | (ushort)Mathf.Round(k_CompressionEcodingMask * s_QuatAbsValues[currentIndex]) : compressed;
86-
currentIndex++;
74+
compressed = 0 != indexToSkip ? (compressed << 10) | (uint)((quaternion[0] < 0 ? k_True : k_False) != quatMaxSign ? k_True : k_False) << k_ShiftNegativeBit | (ushort)Mathf.Round(k_CompressionEcodingMask * quatAbsValue0) : compressed;
8775
// Repeat the last 3 steps for the remaining elements
88-
compressed = currentIndex != indexToSkip ? (compressed << 10) | (uint)((quaternion[currentIndex] < 0 ? k_True : k_False) != quatMaxSign ? k_True : k_False) << k_ShiftNegativeBit | (ushort)Mathf.Round(k_CompressionEcodingMask * s_QuatAbsValues[currentIndex]) : compressed;
89-
currentIndex++;
90-
compressed = currentIndex != indexToSkip ? (compressed << 10) | (uint)((quaternion[currentIndex] < 0 ? k_True : k_False) != quatMaxSign ? k_True : k_False) << k_ShiftNegativeBit | (ushort)Mathf.Round(k_CompressionEcodingMask * s_QuatAbsValues[currentIndex]) : compressed;
91-
currentIndex++;
92-
compressed = currentIndex != indexToSkip ? (compressed << 10) | (uint)((quaternion[currentIndex] < 0 ? k_True : k_False) != quatMaxSign ? k_True : k_False) << k_ShiftNegativeBit | (ushort)Mathf.Round(k_CompressionEcodingMask * s_QuatAbsValues[currentIndex]) : compressed;
76+
compressed = 1 != indexToSkip ? (compressed << 10) | (uint)((quaternion[1] < 0 ? k_True : k_False) != quatMaxSign ? k_True : k_False) << k_ShiftNegativeBit | (ushort)Mathf.Round(k_CompressionEcodingMask * quatAbsValue1) : compressed;
77+
compressed = 2 != indexToSkip ? (compressed << 10) | (uint)((quaternion[2] < 0 ? k_True : k_False) != quatMaxSign ? k_True : k_False) << k_ShiftNegativeBit | (ushort)Mathf.Round(k_CompressionEcodingMask * quatAbsValue2) : compressed;
78+
compressed = 3 != indexToSkip ? (compressed << 10) | (uint)((quaternion[3] < 0 ? k_True : k_False) != quatMaxSign ? k_True : k_False) << k_ShiftNegativeBit | (ushort)Mathf.Round(k_CompressionEcodingMask * quatAbsValue3) : compressed;
9379

9480
// Return the compress quaternion
9581
return compressed;

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ internal abstract class NetcodeAnalytics
18121812

18131813

18141814
/// <summary>
1815-
/// This is called by the Unity Editor reset button. See "OnNetworkManagerReset" from "NetworkManagerHelper.cs" file.
1815+
/// This is called by the Unity Editor reset button. See <see cref="OnNetworkManagerReset"/> which is handled in "NetworkManagerHelper.cs".
18161816
/// </summary>
18171817
private void Reset()
18181818
{

com.unity.netcode.gameobjects/Runtime/Messaging/MessageDelivery.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ private static void UpdateMessageTypes()
5959
MessageDeliveryType<ConnectionApprovedMessage>.Initialize();
6060
MessageDeliveryType<CreateObjectMessage>.Initialize();
6161
MessageDeliveryType<DestroyObjectMessage>.Initialize();
62+
MessageDeliveryType<DisconnectReasonMessage>.Initialize();
63+
MessageDeliveryType<NamedMessage>.Initialize();
64+
MessageDeliveryType<UnnamedMessage>.Initialize();
6265
MessageDeliveryType<NetworkTransformMessage>.Initialize();
6366
MessageDeliveryType<NetworkVariableDeltaMessage>.Initialize();
6467
MessageDeliveryType<ParentSyncMessage>.Initialize();
68+
MessageDeliveryType<ProxyMessage>.Initialize();
6569
// RpcMessage.cs
6670
{
6771
MessageDeliveryType<RpcMessage>.Initialize();

com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ namespace Unity.Netcode
1111
internal class NetworkMetrics : INetworkMetrics
1212
{
1313
private const ulong k_MaxMetricsPerFrame = 1000L;
14-
private readonly static Dictionary<uint, string> s_SceneEventTypeNames;
15-
private static ProfilerMarker s_FrameDispatch = new ProfilerMarker($"{nameof(NetworkMetrics)}.DispatchFrame");
14+
private static readonly Dictionary<uint, string> k_SceneEventTypeNames;
15+
private static ProfilerMarker s_FrameDispatch;
16+
#if UNITY_EDITOR
17+
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
18+
private static void ResetStaticsOnLoad() => s_FrameDispatch = new ProfilerMarker($"{nameof(NetworkMetrics)}.DispatchFrame");
19+
#endif
1620

1721
static NetworkMetrics()
1822
{
19-
s_SceneEventTypeNames = new Dictionary<uint, string>();
23+
k_SceneEventTypeNames = new Dictionary<uint, string>();
2024
foreach (SceneEventType type in Enum.GetValues(typeof(SceneEventType)))
2125
{
22-
s_SceneEventTypeNames[(uint)type] = type.ToString();
26+
k_SceneEventTypeNames[(uint)type] = type.ToString();
2327
}
28+
s_FrameDispatch = new ProfilerMarker($"{nameof(NetworkMetrics)}.DispatchFrame");
2429
}
2530

2631
private static string GetSceneEventTypeName(uint typeCode)
2732
{
28-
return s_SceneEventTypeNames.GetValueOrDefault(typeCode, "Unknown");
33+
return k_SceneEventTypeNames.GetValueOrDefault(typeCode, "Unknown");
2934
}
3035

3136
private readonly Counter m_TransportBytesSent = new Counter(NetworkMetricTypes.TotalBytesSent.Id)

0 commit comments

Comments
 (0)