Skip to content

Commit 7b41720

Browse files
committed
refactor
1 parent d69b7e1 commit 7b41720

File tree

14 files changed

+561
-550
lines changed

14 files changed

+561
-550
lines changed

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using System.Runtime.CompilerServices;
1717
using FishNet.Managing;
1818
using UnityEngine;
19-
using UnityEngine.Profiling;
19+
using Unity.Profiling;
2020
using TimeManagerCls = FishNet.Managing.Timing.TimeManager;
2121

2222
namespace FishNet.Component.Animating
@@ -274,6 +274,18 @@ public ParameterDetail(AnimatorControllerParameter controllerParameter, byte typ
274274
}
275275
#endregion
276276

277+
#region Private
278+
279+
#region Private Profiler Markers
280+
281+
private static readonly ProfilerMarker PM_OnPreTick = new ProfilerMarker("NetworkAnimator.TimeManager_OnPreTick()");
282+
private static readonly ProfilerMarker PM_OnPostTick = new ProfilerMarker("NetworkAnimator.TimeManager_OnPostTick()");
283+
private static readonly ProfilerMarker PM_OnUpdate = new ProfilerMarker("NetworkAnimator.TimeManager_OnUpdate()");
284+
285+
#endregion
286+
287+
#endregion
288+
277289
#region Public.
278290
/// <summary>
279291
/// Parameters which will not be synchronized.
@@ -569,14 +581,14 @@ private void ChangeTickSubscription(bool subscribe)
569581
/// </summary>
570582
private void TimeManager_OnPreTick()
571583
{
572-
Profiler.BeginSample("NetworkAnimator.TimeManager_OnPreTick()");
573-
try
584+
using (PM_OnPreTick.Auto())
574585
{
575586
if (!_canSynchronizeAnimator)
576587
{
577588
_fromServerBuffer.Clear();
578589
return;
579590
}
591+
580592
//Disabled/cannot start.
581593
if (_startTick == 0)
582594
return;
@@ -586,6 +598,7 @@ private void TimeManager_OnPreTick()
586598
_startTick = 0;
587599
return;
588600
}
601+
589602
//Not enough time has passed to start queue.
590603
if (TimeManager.LocalTick < _startTick)
591604
return;
@@ -595,10 +608,6 @@ private void TimeManager_OnPreTick()
595608
ApplyParametersUpdated(ref segment);
596609
rd.Dispose();
597610
}
598-
finally
599-
{
600-
Profiler.EndSample();
601-
}
602611
}
603612

604613
/* Use post tick values are checked after
@@ -608,8 +617,7 @@ private void TimeManager_OnPreTick()
608617
/// </summary>
609618
private void TimeManager_OnPostTick()
610619
{
611-
Profiler.BeginSample("NetworkAnimator.TimeManager_OnPostTick()");
612-
try
620+
using (PM_OnPostTick.Auto())
613621
{
614622
//One check rather than per each method.
615623
if (!_canSynchronizeAnimator)
@@ -618,27 +626,18 @@ private void TimeManager_OnPostTick()
618626
CheckSendToServer();
619627
CheckSendToClients();
620628
}
621-
finally
622-
{
623-
Profiler.EndSample();
624-
}
625629
}
626630

627631
private void TimeManager_OnUpdate()
628632
{
629-
Profiler.BeginSample("NetworkAnimator.TimeManager_OnUpdate()");
630-
try
633+
using (PM_OnUpdate.Auto())
631634
{
632635
if (!_canSynchronizeAnimator)
633636
return;
634637

635638
if (IsClientStarted)
636639
SmoothFloats();
637640
}
638-
finally
639-
{
640-
Profiler.EndSample();
641-
}
642641
}
643642

644643
/// <summary>
@@ -675,6 +674,12 @@ private void InitializeOnce()
675674
foreach (AnimatorControllerParameter item in _animator.parameters)
676675
{
677676
bool process = !_animator.IsParameterControlledByCurve(item.name);
677+
//PROSTART
678+
/* This is done in a weird way for processing
679+
* to work with the pro tool stripper. */
680+
if (IgnoredParameters.Contains(item.name))
681+
process = false;
682+
//PROEND
678683
if (process)
679684
{
680685
//Over 250 parameters; who would do this!?

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

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using System.Collections.Generic;
1515
using FishNet.Managing.Timing;
1616
using UnityEngine;
17-
using UnityEngine.Profiling;
17+
using Unity.Profiling;
1818
using UnityEngine.Scripting;
1919
using static FishNet.Object.NetworkObject;
2020

@@ -371,13 +371,13 @@ public void InitializeState() { }
371371
Rotation = AutoPackType.Packed,
372372
Scale = AutoPackType.Unpacked
373373
};
374-
/// <summary>
375374
/// True to use scaled deltaTime when smoothing.
376375
/// </summary>
377376
[Tooltip("True to use scaled deltaTime when smoothing.")]
378377
[SerializeField]
379378
private bool _useScaledTime = true;
380379
/// <summary>
380+
/// <summary>
381381
/// How many ticks to interpolate.
382382
/// </summary>
383383
[Tooltip("How many ticks to interpolate.")]
@@ -536,6 +536,14 @@ public void SetSendToOwner(bool value)
536536
#endregion
537537

538538
#region Private.
539+
540+
#region Private Profiler Markers
541+
542+
private static readonly ProfilerMarker PM_OnUpdate = new ProfilerMarker("NetworkTransform.TimeManager_OnUpdate()");
543+
private static readonly ProfilerMarker PM_OnPostTick = new ProfilerMarker("NetworkTransform.TimeManager_OnPostTick()");
544+
545+
#endregion
546+
539547
/// <summary>
540548
/// Packing data with all values set to uncompressed.
541549
/// </summary>
@@ -768,16 +776,11 @@ private void TryClearGoalDatas_OwnershipChange(NetworkConnection prevOwner, bool
768776

769777
private void TimeManager_OnUpdate()
770778
{
771-
Profiler.BeginSample("NetworkTransform.TimeManager_OnUpdate()");
772-
try
779+
using (PM_OnUpdate.Auto())
773780
{
774781
float deltaTime = _useScaledTime ? Time.deltaTime : Time.unscaledDeltaTime;
775782
MoveToTarget(deltaTime);
776783
}
777-
finally
778-
{
779-
Profiler.EndSample();
780-
}
781784
}
782785

783786
/// <summary>
@@ -909,8 +912,7 @@ bool CanMakeKinematic()
909912
/// </summary>
910913
private void TimeManager_OnPostTick()
911914
{
912-
Profiler.BeginSample("NetworkTransform.TimeManager_OnPostTick()");
913-
try
915+
using (PM_OnPostTick.Auto())
914916
{
915917
//If to force send via tick delay do so and reset force send tick.
916918
if (_forceSendTick != TimeManager.UNSET_TICK && _timeManager.LocalTick > _forceSendTick)
@@ -966,10 +968,6 @@ private void TimeManager_OnPostTick()
966968
if (isClientInitialized)
967969
SendToServer(_lastSentTransformData);
968970
}
969-
finally
970-
{
971-
Profiler.EndSample();
972-
}
973971
}
974972

975973
/// <summary>
@@ -1704,15 +1702,39 @@ private void MoveToTarget(float delta)
17041702
//No more in buffer, see if can extrapolate.
17051703
else
17061704
{
1707-
/* If everything matches up then end queue.
1705+
//PROSTART
1706+
//Can extrapolate.
1707+
if (td.ExtrapolationState == TransformData.ExtrapolateState.Available)
1708+
{
1709+
rd.TimeRemaining = (float)(_extrapolation * _timeManager.TickDelta);
1710+
td.ExtrapolationState = TransformData.ExtrapolateState.Active;
1711+
if (leftOver > 0f)
1712+
MoveToTarget(leftOver);
1713+
}
1714+
//Ran out of extrapolate.
1715+
else if (td.ExtrapolationState == TransformData.ExtrapolateState.Active)
1716+
{
1717+
rd.TimeRemaining = (float)(_extrapolation * _timeManager.TickDelta);
1718+
td.ExtrapolationState = TransformData.ExtrapolateState.Disabled;
1719+
if (leftOver > 0f)
1720+
MoveToTarget(leftOver);
1721+
}
1722+
//Extrapolation has ended or was never enabled.
1723+
else
1724+
{
1725+
//PROEND
1726+
/* If everything matches up then end queue.
17081727
* Otherwise let it play out until stuff
17091728
* aligns. Generally the time remaining is enough
17101729
* but every once in awhile something goes funky
17111730
* and it's thrown off. */
17121731
if (!HasChanged(td))
17131732
_currentGoalData = null;
17141733
OnInterpolationComplete?.Invoke();
1715-
}
1734+
//PROSTART
1735+
}
1736+
//PROEND
1737+
}
17161738
}
17171739
}
17181740

@@ -2222,7 +2244,16 @@ private void SetExtrapolatedData(TransformData prev, TransformData next, Channel
22222244
//Default value.
22232245
next.ExtrapolationState = TransformData.ExtrapolateState.Disabled;
22242246

2225-
}
2247+
//PROSTART
2248+
//Teleports cannot extrapolate.
2249+
if (_extrapolation == 0 || !_synchronizePosition || channel == Channel.Reliable || next.Position == prev.Position)
2250+
return;
2251+
2252+
Vector3 offet = (next.Position - prev.Position) * _extrapolation;
2253+
next.ExtrapolatedPosition = next.Position + offet;
2254+
next.ExtrapolationState = TransformData.ExtrapolateState.Available;
2255+
//PROEND
2256+
}
22262257

22272258
/// <summary>
22282259
/// Updates a client with transform data.

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

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

88
namespace FishNet.Component.Transforming.Beta
99
{
@@ -21,6 +21,15 @@ public class TickSmootherController : IResettable
2121
#endregion
2222

2323
#region Private.
24+
25+
#region Private Profiler Markers
26+
27+
private static readonly ProfilerMarker PM_OnUpdate = new ProfilerMarker("TickSmootherController.TimeManager_OnUpdate()");
28+
private static readonly ProfilerMarker PM_OnPreTick = new ProfilerMarker("TickSmootherController.TimeManager_OnPreTick()");
29+
private static readonly ProfilerMarker PM_OnPostTick = new ProfilerMarker("TickSmootherController.TimeManager_OnPostTick()");
30+
31+
#endregion
32+
2433
/// <summary>
2534
/// </summary>
2635
private InitializationSettings _initializationSettings = new();
@@ -141,45 +150,30 @@ void StopOnline()
141150

142151
public void TimeManager_OnUpdate()
143152
{
144-
Profiler.BeginSample("TickSmootherController.TimeManager_OnUpdate()");
145-
try
153+
using (PM_OnUpdate.Auto())
146154
{
147155
UniversalSmoother.OnUpdate(Time.deltaTime);
148156
}
149-
finally
150-
{
151-
Profiler.EndSample();
152-
}
153157
}
154158

155159
public void TimeManager_OnPreTick()
156160
{
157-
Profiler.BeginSample("TickSmootherController.TimeManager_OnPreTick()");
158-
try
161+
using (PM_OnPreTick.Auto())
159162
{
160163
UniversalSmoother.OnPreTick();
161164
}
162-
finally
163-
{
164-
Profiler.EndSample();
165-
}
166165
}
167166

168167
/// <summary>
169168
/// Called after a tick completes.
170169
/// </summary>
171170
public void TimeManager_OnPostTick()
172171
{
173-
Profiler.BeginSample("TickSmootherController.TimeManager_OnPostTick()");
174-
try
172+
using (PM_OnPostTick.Auto())
175173
{
176174
if (_timeManager != null)
177175
UniversalSmoother.OnPostTick(_timeManager.LocalTick);
178176
}
179-
finally
180-
{
181-
Profiler.EndSample();
182-
}
183177
}
184178

185179
private void PredictionManager_OnPostReplicateReplay(uint clientTick, uint serverTick)

0 commit comments

Comments
 (0)