Compare commits

...

3 Commits

Author SHA1 Message Date
mischa
32d0796052
Merge 3df73ea9f1 into 1e04c9833b 2024-11-11 21:19:33 +08:00
JesusLuvsYooh
1e04c9833b
Updated Server/Client attribute help text. (#3942)
Some checks are pending
Main / Run Unity Tests (push) Waiting to run
Main / Semantic Release (push) Blocked by required conditions
Main / Delete Old Workflow Runs (push) Waiting to run
Hopefully adds additional support in preventing confusion.
2024-11-11 13:06:29 +01:00
miwarnec
3df73ea9f1 feat(Profiling): NetworkLoop sampling instead of "UpdateFunction.Invoke" 2024-11-05 15:58:59 +01:00
4 changed files with 62 additions and 6 deletions

View File

@ -48,28 +48,28 @@ public class TargetRpcAttribute : Attribute
} }
/// <summary> /// <summary>
/// Prevents clients from running this method. /// Only an active server will run this method.
/// <para>Prints a warning if a client tries to execute this method.</para> /// <para>Prints a warning if a client or in-active server tries to execute this method.</para>
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Method)]
public class ServerAttribute : Attribute {} public class ServerAttribute : Attribute {}
/// <summary> /// <summary>
/// Prevents clients from running this method. /// Only an active server will run this method.
/// <para>No warning is thrown.</para> /// <para>No warning is thrown.</para>
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Method)]
public class ServerCallbackAttribute : Attribute {} public class ServerCallbackAttribute : Attribute {}
/// <summary> /// <summary>
/// Prevents the server from running this method. /// Only an active client will run this method.
/// <para>Prints a warning if the server tries to execute this method.</para> /// <para>Prints a warning if the server or in-active client tries to execute this method.</para>
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Method)]
public class ClientAttribute : Attribute {} public class ClientAttribute : Attribute {}
/// <summary> /// <summary>
/// Prevents the server from running this method. /// Only an active client will run this method.
/// <para>No warning is printed.</para> /// <para>No warning is printed.</para>
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Method)] [AttributeUsage(AttributeTargets.Method)]

View File

@ -3,6 +3,7 @@
using System.Linq; using System.Linq;
using Mirror.RemoteCalls; using Mirror.RemoteCalls;
using UnityEngine; using UnityEngine;
using UnityEngine.Profiling;
namespace Mirror namespace Mirror
{ {
@ -1500,8 +1501,11 @@ internal static void ChangeOwner(NetworkIdentity identity, ChangeOwnerMessage me
internal static void NetworkEarlyUpdate() internal static void NetworkEarlyUpdate()
{ {
// process all incoming messages first before updating the world // process all incoming messages first before updating the world
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("NetworkClient: Transport Processing");
if (Transport.active != null) if (Transport.active != null)
Transport.active.ClientEarlyUpdate(); Transport.active.ClientEarlyUpdate();
Profiler.EndSample();
// time snapshot interpolation // time snapshot interpolation
UpdateTimeInterpolation(); UpdateTimeInterpolation();
@ -1532,7 +1536,10 @@ internal static void NetworkLateUpdate()
bool sendIntervalElapsed = AccurateInterval.Elapsed(NetworkTime.localTime, sendInterval, ref lastSendTime); bool sendIntervalElapsed = AccurateInterval.Elapsed(NetworkTime.localTime, sendInterval, ref lastSendTime);
if (!Application.isPlaying || sendIntervalElapsed) if (!Application.isPlaying || sendIntervalElapsed)
{ {
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("NetworkClient: Broadcast");
Broadcast(); Broadcast();
Profiler.EndSample();
} }
UpdateConnectionQuality(); UpdateConnectionQuality();
@ -1589,8 +1596,11 @@ void UpdateConnectionQuality()
} }
// process all outgoing messages after updating the world // process all outgoing messages after updating the world
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("NetworkClient: Transport Flush");
if (Transport.active != null) if (Transport.active != null)
Transport.active.ClientLateUpdate(); Transport.active.ClientLateUpdate();
Profiler.EndSample();
} }
// broadcast /////////////////////////////////////////////////////////// // broadcast ///////////////////////////////////////////////////////////
@ -1628,7 +1638,11 @@ static void BroadcastToServer()
{ {
// get serialization for this entity viewed by this connection // get serialization for this entity viewed by this connection
// (if anything was serialized this time) // (if anything was serialized this time)
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("BroadcastToServer: SerializeClient");
identity.SerializeClient(writer); identity.SerializeClient(writer);
Profiler.EndSample();
if (writer.Position > 0) if (writer.Position > 0)
{ {
// send state update message // send state update message
@ -1637,7 +1651,11 @@ static void BroadcastToServer()
netId = identity.netId, netId = identity.netId,
payload = writer.ToArraySegment() payload = writer.ToArraySegment()
}; };
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("BroadcastToServer: Flush");
Send(message); Send(message);
Profiler.EndSample();
} }
} }
} }

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();
} }
} }
} }

View File

@ -3,6 +3,7 @@
using System.Linq; using System.Linq;
using Mirror.RemoteCalls; using Mirror.RemoteCalls;
using UnityEngine; using UnityEngine;
using UnityEngine.Profiling;
namespace Mirror namespace Mirror
{ {
@ -1928,7 +1929,11 @@ static void BroadcastToConnection(NetworkConnectionToClient connection)
{ {
// get serialization for this entity viewed by this connection // get serialization for this entity viewed by this connection
// (if anything was serialized this time) // (if anything was serialized this time)
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("BroadcastToConnection: SerializeForConnection");
NetworkWriter serialization = SerializeForConnection(identity, connection); NetworkWriter serialization = SerializeForConnection(identity, connection);
Profiler.EndSample();
if (serialization != null) if (serialization != null)
{ {
EntityStateMessage message = new EntityStateMessage EntityStateMessage message = new EntityStateMessage
@ -1936,7 +1941,11 @@ static void BroadcastToConnection(NetworkConnectionToClient connection)
netId = identity.netId, netId = identity.netId,
payload = serialization.ToArraySegment() payload = serialization.ToArraySegment()
}; };
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("BroadcastToConnection: Send");
connection.Send(message); connection.Send(message);
Profiler.EndSample();
} }
} }
// spawned list should have no null entries because we // spawned list should have no null entries because we
@ -2017,7 +2026,10 @@ static void Broadcast()
} }
// update connection to flush out batched messages // update connection to flush out batched messages
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("Broadcast: Flush");
connection.Update(); connection.Update();
Profiler.EndSample();
} }
} }
@ -2034,12 +2046,19 @@ internal static void NetworkEarlyUpdate()
} }
// process all incoming messages first before updating the world // process all incoming messages first before updating the world
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("NetworkServer: Transport Processing");
if (Transport.active != null) if (Transport.active != null)
Transport.active.ServerEarlyUpdate(); Transport.active.ServerEarlyUpdate();
Profiler.EndSample();
// step each connection's local time interpolation in early update. // step each connection's local time interpolation in early update.
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("NetworkServer: Connections Time Update");
foreach (NetworkConnectionToClient connection in connections.Values) foreach (NetworkConnectionToClient connection in connections.Values)
connection.UpdateTimeInterpolation(); connection.UpdateTimeInterpolation();
Profiler.EndSample();
if (active) earlyUpdateDuration.End(); if (active) earlyUpdateDuration.End();
} }
@ -2068,13 +2087,21 @@ internal static void NetworkLateUpdate()
// Unity 2019 doesn't have Time.timeAsDouble yet // Unity 2019 doesn't have Time.timeAsDouble yet
bool sendIntervalElapsed = AccurateInterval.Elapsed(NetworkTime.localTime, sendInterval, ref lastSendTime); bool sendIntervalElapsed = AccurateInterval.Elapsed(NetworkTime.localTime, sendInterval, ref lastSendTime);
if (!Application.isPlaying || sendIntervalElapsed) if (!Application.isPlaying || sendIntervalElapsed)
{
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("NetworkServer: Broadcast");
Broadcast(); Broadcast();
Profiler.EndSample();
}
} }
// process all outgoing messages after updating the world // process all outgoing messages after updating the world
// (even if not active. still want to process disconnects etc.) // (even if not active. still want to process disconnects etc.)
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample("NetworkServer: Transport Flush");
if (Transport.active != null) if (Transport.active != null)
Transport.active.ServerLateUpdate(); Transport.active.ServerLateUpdate();
Profiler.EndSample();
// measure actual tick rate every second. // measure actual tick rate every second.
if (active) if (active)