mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Compare commits
11 Commits
bfb8998846
...
0d1787b0f4
Author | SHA1 | Date | |
---|---|---|---|
|
0d1787b0f4 | ||
|
ed58604205 | ||
|
bf4f0b5acb | ||
|
4bebec8173 | ||
|
69d9aa2ff0 | ||
|
b31fe9ec92 | ||
|
aefde5cd66 | ||
|
0b165ff348 | ||
|
62ba66847d | ||
|
4ec274458f | ||
|
2a992e6902 |
@ -3,6 +3,7 @@
|
||||
using System.Linq;
|
||||
using Mirror.RemoteCalls;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
@ -1500,8 +1501,11 @@ internal static void ChangeOwner(NetworkIdentity identity, ChangeOwnerMessage me
|
||||
internal static void NetworkEarlyUpdate()
|
||||
{
|
||||
// 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)
|
||||
Transport.active.ClientEarlyUpdate();
|
||||
Profiler.EndSample();
|
||||
|
||||
// time snapshot interpolation
|
||||
UpdateTimeInterpolation();
|
||||
@ -1532,7 +1536,10 @@ internal static void NetworkLateUpdate()
|
||||
bool sendIntervalElapsed = AccurateInterval.Elapsed(NetworkTime.localTime, sendInterval, ref lastSendTime);
|
||||
if (!Application.isPlaying || sendIntervalElapsed)
|
||||
{
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
|
||||
Profiler.BeginSample("NetworkClient: Broadcast");
|
||||
Broadcast();
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
UpdateConnectionQuality();
|
||||
@ -1589,8 +1596,11 @@ void UpdateConnectionQuality()
|
||||
}
|
||||
|
||||
// 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)
|
||||
Transport.active.ClientLateUpdate();
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
// broadcast ///////////////////////////////////////////////////////////
|
||||
@ -1628,7 +1638,11 @@ static void BroadcastToServer()
|
||||
{
|
||||
// get serialization for this entity viewed by this connection
|
||||
// (if anything was serialized this time)
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
|
||||
Profiler.BeginSample("BroadcastToServer: SerializeClient");
|
||||
identity.SerializeClient(writer);
|
||||
Profiler.EndSample();
|
||||
|
||||
if (writer.Position > 0)
|
||||
{
|
||||
// send state update message
|
||||
@ -1637,7 +1651,11 @@ static void BroadcastToServer()
|
||||
netId = identity.netId,
|
||||
payload = writer.ToArraySegment()
|
||||
};
|
||||
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
|
||||
Profiler.BeginSample("BroadcastToServer: Flush");
|
||||
Send(message);
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Mirror.RemoteCalls;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
@ -224,6 +225,9 @@ internal set
|
||||
static readonly Dictionary<ulong, NetworkIdentity> sceneIds =
|
||||
new Dictionary<ulong, NetworkIdentity>();
|
||||
|
||||
// profiling: cache the serialization string to avoid runtime allocations
|
||||
string profilingSerializationTag = $"NetworkIdentity: Serialize"; // set to {name} in Awake
|
||||
|
||||
// Helper function to handle Command/Rpc
|
||||
internal void HandleRemoteCall(byte componentIndex, ushort functionHash, RemoteCallType remoteCallType, NetworkReader reader, NetworkConnectionToClient senderConnection = null)
|
||||
{
|
||||
@ -332,6 +336,9 @@ void ValidateComponents()
|
||||
// internal so we can call it during unit tests too.
|
||||
internal void Awake()
|
||||
{
|
||||
// cache profiling string to avoid runtime allocations
|
||||
profilingSerializationTag = $"NetworkIdentity: Serialize {name}";
|
||||
|
||||
// initialize NetworkBehaviour components.
|
||||
// Awake() is called immediately after initialization.
|
||||
// no one can overwrite it because NetworkIdentity is sealed.
|
||||
@ -936,6 +943,9 @@ internal static bool IsDirty(ulong mask, int index)
|
||||
// check ownerWritten/observersWritten to know if anything was written
|
||||
internal void SerializeServer(bool initialState, NetworkWriter ownerWriter, NetworkWriter observersWriter)
|
||||
{
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
|
||||
Profiler.BeginSample($"NetworkIdentity: Serialize {name}"); // TODO nonalloc
|
||||
|
||||
// ensure NetworkBehaviours are valid before usage
|
||||
ValidateComponents();
|
||||
NetworkBehaviour[] components = NetworkBehaviours;
|
||||
@ -1004,11 +1014,16 @@ internal void SerializeServer(bool initialState, NetworkWriter ownerWriter, Netw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
// serialize components into writer on the client.
|
||||
internal void SerializeClient(NetworkWriter writer)
|
||||
{
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
|
||||
Profiler.BeginSample($"NetworkIdentity: Serialize {name}"); // TODO nonalloc
|
||||
|
||||
// ensure NetworkBehaviours are valid before usage
|
||||
ValidateComponents();
|
||||
NetworkBehaviour[] components = NetworkBehaviours;
|
||||
@ -1061,6 +1076,8 @@ internal void SerializeClient(NetworkWriter writer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
// deserialize components from the client on the server.
|
||||
|
@ -28,6 +28,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.LowLevel;
|
||||
using UnityEngine.PlayerLoop;
|
||||
using UnityEngine.Profiling;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
@ -187,12 +188,17 @@ static void NetworkEarlyUpdate()
|
||||
// however, we only want to call NetworkServer/Client in play mode.
|
||||
if (!Application.isPlaying) return;
|
||||
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke"
|
||||
Profiler.BeginSample("NetworkEarlyUpdate");
|
||||
|
||||
NetworkTime.EarlyUpdate();
|
||||
//Debug.Log($"NetworkEarlyUpdate {Time.time}");
|
||||
NetworkServer.NetworkEarlyUpdate();
|
||||
NetworkClient.NetworkEarlyUpdate();
|
||||
// invoke event after mirror has done it's early updating.
|
||||
OnEarlyUpdate?.Invoke();
|
||||
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
static void NetworkLateUpdate()
|
||||
@ -201,11 +207,16 @@ static void NetworkLateUpdate()
|
||||
// however, we only want to call NetworkServer/Client in play mode.
|
||||
if (!Application.isPlaying) return;
|
||||
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke"
|
||||
Profiler.BeginSample("NetworkLateUpdate");
|
||||
|
||||
//Debug.Log($"NetworkLateUpdate {Time.time}");
|
||||
// invoke event before mirror does its final late updating.
|
||||
OnLateUpdate?.Invoke();
|
||||
NetworkServer.NetworkLateUpdate();
|
||||
NetworkClient.NetworkLateUpdate();
|
||||
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
using System.Linq;
|
||||
using Mirror.RemoteCalls;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
@ -1928,7 +1929,11 @@ static void BroadcastToConnection(NetworkConnectionToClient connection)
|
||||
{
|
||||
// get serialization for this entity viewed by this connection
|
||||
// (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);
|
||||
Profiler.EndSample();
|
||||
|
||||
if (serialization != null)
|
||||
{
|
||||
EntityStateMessage message = new EntityStateMessage
|
||||
@ -1936,7 +1941,11 @@ static void BroadcastToConnection(NetworkConnectionToClient connection)
|
||||
netId = identity.netId,
|
||||
payload = serialization.ToArraySegment()
|
||||
};
|
||||
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
|
||||
Profiler.BeginSample("BroadcastToConnection: Send");
|
||||
connection.Send(message);
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
// spawned list should have no null entries because we
|
||||
@ -2017,7 +2026,10 @@ static void Broadcast()
|
||||
}
|
||||
|
||||
// update connection to flush out batched messages
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
|
||||
Profiler.BeginSample("Broadcast: Flush");
|
||||
connection.Update();
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2034,12 +2046,19 @@ internal static void NetworkEarlyUpdate()
|
||||
}
|
||||
|
||||
// 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)
|
||||
Transport.active.ServerEarlyUpdate();
|
||||
Profiler.EndSample();
|
||||
|
||||
|
||||
// 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)
|
||||
connection.UpdateTimeInterpolation();
|
||||
Profiler.EndSample();
|
||||
|
||||
if (active) earlyUpdateDuration.End();
|
||||
}
|
||||
@ -2068,13 +2087,21 @@ internal static void NetworkLateUpdate()
|
||||
// Unity 2019 doesn't have Time.timeAsDouble yet
|
||||
bool sendIntervalElapsed = AccurateInterval.Elapsed(NetworkTime.localTime, sendInterval, ref lastSendTime);
|
||||
if (!Application.isPlaying || sendIntervalElapsed)
|
||||
{
|
||||
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
|
||||
Profiler.BeginSample("NetworkServer: Broadcast");
|
||||
Broadcast();
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
// process all outgoing messages after updating the world
|
||||
// (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)
|
||||
Transport.active.ServerLateUpdate();
|
||||
Profiler.EndSample();
|
||||
|
||||
// measure actual tick rate every second.
|
||||
if (active)
|
||||
|
Loading…
Reference in New Issue
Block a user