Skip to content

Commit d69b7e1

Browse files
committed
feat: add profiler markers
1 parent 1d17590 commit d69b7e1

File tree

10 files changed

+592
-164
lines changed

10 files changed

+592
-164
lines changed

Assets/FishNet/Runtime/Generated/Component/NetworkAnimator/NetworkAnimator.cs

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Runtime.CompilerServices;
1717
using FishNet.Managing;
1818
using UnityEngine;
19+
using UnityEngine.Profiling;
1920
using TimeManagerCls = FishNet.Managing.Timing.TimeManager;
2021

2122
namespace FishNet.Component.Animating
@@ -333,6 +334,9 @@ public bool ClientAuthoritative
333334
[Tooltip("True to synchronize server results back to owner. Typically used when you are changing animations on the server and are relying on the server response to update the clients animations.")]
334335
[SerializeField]
335336
private bool _sendToOwner;
337+
338+
public bool SendToOwner => _sendToOwner;
339+
336340
#endregion
337341

338342
#region Private.
@@ -565,28 +569,36 @@ private void ChangeTickSubscription(bool subscribe)
565569
/// </summary>
566570
private void TimeManager_OnPreTick()
567571
{
568-
if (!_canSynchronizeAnimator)
572+
Profiler.BeginSample("NetworkAnimator.TimeManager_OnPreTick()");
573+
try
569574
{
570-
_fromServerBuffer.Clear();
571-
return;
575+
if (!_canSynchronizeAnimator)
576+
{
577+
_fromServerBuffer.Clear();
578+
return;
579+
}
580+
//Disabled/cannot start.
581+
if (_startTick == 0)
582+
return;
583+
//Nothing in queue.
584+
if (_fromServerBuffer.Count == 0)
585+
{
586+
_startTick = 0;
587+
return;
588+
}
589+
//Not enough time has passed to start queue.
590+
if (TimeManager.LocalTick < _startTick)
591+
return;
592+
593+
ReceivedServerData rd = _fromServerBuffer.Dequeue();
594+
ArraySegment<byte> segment = rd.GetArraySegment();
595+
ApplyParametersUpdated(ref segment);
596+
rd.Dispose();
572597
}
573-
//Disabled/cannot start.
574-
if (_startTick == 0)
575-
return;
576-
//Nothing in queue.
577-
if (_fromServerBuffer.Count == 0)
598+
finally
578599
{
579-
_startTick = 0;
580-
return;
600+
Profiler.EndSample();
581601
}
582-
//Not enough time has passed to start queue.
583-
if (TimeManager.LocalTick < _startTick)
584-
return;
585-
586-
ReceivedServerData rd = _fromServerBuffer.Dequeue();
587-
ArraySegment<byte> segment = rd.GetArraySegment();
588-
ApplyParametersUpdated(ref segment);
589-
rd.Dispose();
590602
}
591603

592604
/* Use post tick values are checked after
@@ -596,21 +608,37 @@ private void TimeManager_OnPreTick()
596608
/// </summary>
597609
private void TimeManager_OnPostTick()
598610
{
599-
//One check rather than per each method.
600-
if (!_canSynchronizeAnimator)
601-
return;
611+
Profiler.BeginSample("NetworkAnimator.TimeManager_OnPostTick()");
612+
try
613+
{
614+
//One check rather than per each method.
615+
if (!_canSynchronizeAnimator)
616+
return;
602617

603-
CheckSendToServer();
604-
CheckSendToClients();
618+
CheckSendToServer();
619+
CheckSendToClients();
620+
}
621+
finally
622+
{
623+
Profiler.EndSample();
624+
}
605625
}
606626

607627
private void TimeManager_OnUpdate()
608628
{
609-
if (!_canSynchronizeAnimator)
610-
return;
629+
Profiler.BeginSample("NetworkAnimator.TimeManager_OnUpdate()");
630+
try
631+
{
632+
if (!_canSynchronizeAnimator)
633+
return;
611634

612-
if (IsClientStarted)
613-
SmoothFloats();
635+
if (IsClientStarted)
636+
SmoothFloats();
637+
}
638+
finally
639+
{
640+
Profiler.EndSample();
641+
}
614642
}
615643

616644
/// <summary>

Assets/FishNet/Runtime/Generated/Component/NetworkTransform/NetworkTransform.cs

Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Collections.Generic;
1515
using FishNet.Managing.Timing;
1616
using UnityEngine;
17+
using UnityEngine.Profiling;
1718
using UnityEngine.Scripting;
1819
using static FishNet.Object.NetworkObject;
1920

@@ -767,8 +768,16 @@ private void TryClearGoalDatas_OwnershipChange(NetworkConnection prevOwner, bool
767768

768769
private void TimeManager_OnUpdate()
769770
{
770-
float deltaTime = _useScaledTime ? Time.deltaTime : Time.unscaledDeltaTime;
771-
MoveToTarget(deltaTime);
771+
Profiler.BeginSample("NetworkTransform.TimeManager_OnUpdate()");
772+
try
773+
{
774+
float deltaTime = _useScaledTime ? Time.deltaTime : Time.unscaledDeltaTime;
775+
MoveToTarget(deltaTime);
776+
}
777+
finally
778+
{
779+
Profiler.EndSample();
780+
}
772781
}
773782

774783
/// <summary>
@@ -900,59 +909,67 @@ bool CanMakeKinematic()
900909
/// </summary>
901910
private void TimeManager_OnPostTick()
902911
{
903-
//If to force send via tick delay do so and reset force send tick.
904-
if (_forceSendTick != TimeManager.UNSET_TICK && _timeManager.LocalTick > _forceSendTick)
912+
Profiler.BeginSample("NetworkTransform.TimeManager_OnPostTick()");
913+
try
905914
{
906-
_forceSendTick = TimeManager.UNSET_TICK;
907-
ForceSend();
908-
}
915+
//If to force send via tick delay do so and reset force send tick.
916+
if (_forceSendTick != TimeManager.UNSET_TICK && _timeManager.LocalTick > _forceSendTick)
917+
{
918+
_forceSendTick = TimeManager.UNSET_TICK;
919+
ForceSend();
920+
}
909921

910-
UpdateParentBehaviour();
922+
UpdateParentBehaviour();
911923

912-
/* Intervals remaining is only used when the interval value
913-
* is set higher than 1. An interval of 1 indicates to send
914-
* every tick. Only check to wait more ticks if interval
915-
* is larger than 1. */
916-
if (_interval > 1)
917-
{
918-
/* If intervalsRemaining is unset then that means the transform
919-
* did not change last tick. See if transform changed and if so then
920-
* update remaining to _interval. */
921-
if (_intervalsRemaining == -1)
924+
/* Intervals remaining is only used when the interval value
925+
* is set higher than 1. An interval of 1 indicates to send
926+
* every tick. Only check to wait more ticks if interval
927+
* is larger than 1. */
928+
if (_interval > 1)
922929
{
923-
//Transform didn't change, no reason to start remaining.
924-
if (!_cachedTransform.hasChanged)
930+
/* If intervalsRemaining is unset then that means the transform
931+
* did not change last tick. See if transform changed and if so then
932+
* update remaining to _interval. */
933+
if (_intervalsRemaining == -1)
934+
{
935+
//Transform didn't change, no reason to start remaining.
936+
if (!_cachedTransform.hasChanged)
937+
return;
938+
939+
_intervalsRemaining = _interval;
940+
}
941+
942+
//If here then intervalsRemaining can be deducted.
943+
_intervalsRemaining--;
944+
//Interval not met yet.
945+
if (_intervalsRemaining > 0)
925946
return;
926947

927-
_intervalsRemaining = _interval;
948+
//Intervals remainin is met. Reset to -1 to await new change.
949+
_intervalsRemaining = -1;
928950
}
929951

930-
//If here then intervalsRemaining can be deducted.
931-
_intervalsRemaining--;
932-
//Interval not met yet.
933-
if (_intervalsRemaining > 0)
934-
return;
935-
936-
//Intervals remainin is met. Reset to -1 to await new change.
937-
_intervalsRemaining = -1;
938-
}
952+
bool isServerInitialized = IsServerInitialized;
953+
bool isClientInitialized = IsClientInitialized;
939954

940-
bool isServerInitialized = IsServerInitialized;
941-
bool isClientInitialized = IsClientInitialized;
955+
if (isServerInitialized)
956+
{
957+
/* If client is not initialized then
958+
* call a move to targe ton post tick to ensure
959+
* anything with instant rates gets moved. */
960+
if (!isClientInitialized)
961+
MoveToTarget((float)_timeManager.TickDelta);
962+
//
963+
SendToClients();
964+
}
942965

943-
if (isServerInitialized)
966+
if (isClientInitialized)
967+
SendToServer(_lastSentTransformData);
968+
}
969+
finally
944970
{
945-
/* If client is not initialized then
946-
* call a move to targe ton post tick to ensure
947-
* anything with instant rates gets moved. */
948-
if (!isClientInitialized)
949-
MoveToTarget((float)_timeManager.TickDelta);
950-
//
951-
SendToClients();
971+
Profiler.EndSample();
952972
}
953-
954-
if (isClientInitialized)
955-
SendToServer(_lastSentTransformData);
956973
}
957974

958975
/// <summary>

Assets/FishNet/Runtime/Generated/Component/TickSmoothing/TickSmootherController.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FishNet.Object;
44
using GameKit.Dependencies.Utilities;
55
using UnityEngine;
6+
using UnityEngine.Profiling;
67

78
namespace FishNet.Component.Transforming.Beta
89
{
@@ -140,21 +141,45 @@ void StopOnline()
140141

141142
public void TimeManager_OnUpdate()
142143
{
143-
UniversalSmoother.OnUpdate(Time.deltaTime);
144+
Profiler.BeginSample("TickSmootherController.TimeManager_OnUpdate()");
145+
try
146+
{
147+
UniversalSmoother.OnUpdate(Time.deltaTime);
148+
}
149+
finally
150+
{
151+
Profiler.EndSample();
152+
}
144153
}
145154

146155
public void TimeManager_OnPreTick()
147156
{
148-
UniversalSmoother.OnPreTick();
157+
Profiler.BeginSample("TickSmootherController.TimeManager_OnPreTick()");
158+
try
159+
{
160+
UniversalSmoother.OnPreTick();
161+
}
162+
finally
163+
{
164+
Profiler.EndSample();
165+
}
149166
}
150167

151168
/// <summary>
152169
/// Called after a tick completes.
153170
/// </summary>
154171
public void TimeManager_OnPostTick()
155172
{
156-
if (_timeManager != null)
157-
UniversalSmoother.OnPostTick(_timeManager.LocalTick);
173+
Profiler.BeginSample("TickSmootherController.TimeManager_OnPostTick()");
174+
try
175+
{
176+
if (_timeManager != null)
177+
UniversalSmoother.OnPostTick(_timeManager.LocalTick);
178+
}
179+
finally
180+
{
181+
Profiler.EndSample();
182+
}
158183
}
159184

160185
private void PredictionManager_OnPostReplicateReplay(uint clientTick, uint serverTick)

Assets/FishNet/Runtime/Generated/Component/Utility/DetachableNetworkTickSmoother.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using FishNet.Utility.Extension;
77
using GameKit.Dependencies.Utilities;
88
using UnityEngine;
9+
using UnityEngine.Profiling;
910

1011
namespace FishNet.Component.Transforming
1112
{
@@ -170,18 +171,26 @@ private void Update()
170171
/// </summary>
171172
private void _timeManager_OnPostTick()
172173
{
173-
if (!_initialized)
174-
return;
175-
176-
_postTickFollowObjectWorldProperties.Update(_followObject);
177-
// Unset values if not following the transform property.
178-
if (!_synchronizePosition)
179-
_postTickFollowObjectWorldProperties.Position = transform.position;
180-
if (!_synchronizeRotation)
181-
_postTickFollowObjectWorldProperties.Rotation = transform.rotation;
182-
if (!_synchronizeScale)
183-
_postTickFollowObjectWorldProperties.Scale = transform.localScale;
184-
SetMoveRates();
174+
Profiler.BeginSample("DetachableNetworkTickSmoother._timeManager_OnPostTick()");
175+
try
176+
{
177+
if (!_initialized)
178+
return;
179+
180+
_postTickFollowObjectWorldProperties.Update(_followObject);
181+
// Unset values if not following the transform property.
182+
if (!_synchronizePosition)
183+
_postTickFollowObjectWorldProperties.Position = transform.position;
184+
if (!_synchronizeRotation)
185+
_postTickFollowObjectWorldProperties.Rotation = transform.rotation;
186+
if (!_synchronizeScale)
187+
_postTickFollowObjectWorldProperties.Scale = transform.localScale;
188+
SetMoveRates();
189+
}
190+
finally
191+
{
192+
Profiler.EndSample();
193+
}
185194
}
186195

187196
/// <summary>

0 commit comments

Comments
 (0)