feat(Profiling): NetworkLoop sampling instead of "UpdateFunction.Invoke"

This commit is contained in:
miwarnec 2024-10-31 16:58:17 +01:00
parent e7b3aa77df
commit 2a992e6902

View File

@ -28,6 +28,7 @@
using UnityEngine; using UnityEngine;
using UnityEngine.LowLevel; using UnityEngine.LowLevel;
using UnityEngine.PlayerLoop; using UnityEngine.PlayerLoop;
using UnityEngine.Profiling;
namespace Mirror namespace Mirror
{ {
@ -187,12 +188,17 @@ static void NetworkEarlyUpdate()
// however, we only want to call NetworkServer/Client in play mode. // however, we only want to call NetworkServer/Client in play mode.
if (!Application.isPlaying) return; if (!Application.isPlaying) return;
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke"
Profiler.BeginSample("NetworkEarlyUpdate");
NetworkTime.EarlyUpdate(); NetworkTime.EarlyUpdate();
//Debug.Log($"NetworkEarlyUpdate {Time.time}"); //Debug.Log($"NetworkEarlyUpdate {Time.time}");
NetworkServer.NetworkEarlyUpdate(); NetworkServer.NetworkEarlyUpdate();
NetworkClient.NetworkEarlyUpdate(); NetworkClient.NetworkEarlyUpdate();
// invoke event after mirror has done it's early updating. // invoke event after mirror has done it's early updating.
OnEarlyUpdate?.Invoke(); OnEarlyUpdate?.Invoke();
Profiler.EndSample();
} }
static void NetworkLateUpdate() static void NetworkLateUpdate()
@ -201,11 +207,16 @@ static void NetworkLateUpdate()
// however, we only want to call NetworkServer/Client in play mode. // however, we only want to call NetworkServer/Client in play mode.
if (!Application.isPlaying) return; if (!Application.isPlaying) return;
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke"
Profiler.BeginSample("NetworkLateUpdate");
//Debug.Log($"NetworkLateUpdate {Time.time}"); //Debug.Log($"NetworkLateUpdate {Time.time}");
// invoke event before mirror does its final late updating. // invoke event before mirror does its final late updating.
OnLateUpdate?.Invoke(); OnLateUpdate?.Invoke();
NetworkServer.NetworkLateUpdate(); NetworkServer.NetworkLateUpdate();
NetworkClient.NetworkLateUpdate(); NetworkClient.NetworkLateUpdate();
Profiler.EndSample();
} }
} }
} }