This commit is contained in:
miwarnec 2024-10-31 17:50:11 +01:00
parent 4bebec8173
commit bf4f0b5acb

View File

@ -225,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)
{
@ -333,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.
@ -938,7 +944,8 @@ internal static bool IsDirty(ulong mask, int index)
internal void SerializeServer(bool initialState, NetworkWriter ownerWriter, NetworkWriter observersWriter)
{
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample($"NetworkIdentity({name}): SerializeServer"); // TODO nonalloc
Profiler.BeginSample($"NetworkIdentity: Serialize {name}"); // TODO nonalloc
// ensure NetworkBehaviours are valid before usage
ValidateComponents();
NetworkBehaviour[] components = NetworkBehaviours;
@ -1015,7 +1022,7 @@ internal void SerializeServer(bool initialState, NetworkWriter ownerWriter, Netw
internal void SerializeClient(NetworkWriter writer)
{
// profiling marker for shallow profiling to show more than "UpdateFunction.Invoke
Profiler.BeginSample($"NetworkIdentity({name}): SerializeClient"); // TODO nonalloc
Profiler.BeginSample($"NetworkIdentity: Serialize {name}"); // TODO nonalloc
// ensure NetworkBehaviours are valid before usage
ValidateComponents();