diff --git a/Assets/FishNet/Runtime/Generated/Component/NetworkAnimator/NetworkAnimator.cs b/Assets/FishNet/Runtime/Generated/Component/NetworkAnimator/NetworkAnimator.cs index 78977cb4..183f42ff 100644 --- a/Assets/FishNet/Runtime/Generated/Component/NetworkAnimator/NetworkAnimator.cs +++ b/Assets/FishNet/Runtime/Generated/Component/NetworkAnimator/NetworkAnimator.cs @@ -16,6 +16,7 @@ using System.Runtime.CompilerServices; using FishNet.Managing; using UnityEngine; +using UnityEngine.Profiling; using TimeManagerCls = FishNet.Managing.Timing.TimeManager; namespace FishNet.Component.Animating @@ -333,6 +334,9 @@ public bool ClientAuthoritative [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.")] [SerializeField] private bool _sendToOwner; + + public bool SendToOwner => _sendToOwner; + #endregion #region Private. @@ -565,28 +569,36 @@ private void ChangeTickSubscription(bool subscribe) /// private void TimeManager_OnPreTick() { - if (!_canSynchronizeAnimator) + Profiler.BeginSample("NetworkAnimator.TimeManager_OnPreTick()"); + try { - _fromServerBuffer.Clear(); - return; + if (!_canSynchronizeAnimator) + { + _fromServerBuffer.Clear(); + return; + } + //Disabled/cannot start. + if (_startTick == 0) + return; + //Nothing in queue. + if (_fromServerBuffer.Count == 0) + { + _startTick = 0; + return; + } + //Not enough time has passed to start queue. + if (TimeManager.LocalTick < _startTick) + return; + + ReceivedServerData rd = _fromServerBuffer.Dequeue(); + ArraySegment segment = rd.GetArraySegment(); + ApplyParametersUpdated(ref segment); + rd.Dispose(); } - //Disabled/cannot start. - if (_startTick == 0) - return; - //Nothing in queue. - if (_fromServerBuffer.Count == 0) + finally { - _startTick = 0; - return; + Profiler.EndSample(); } - //Not enough time has passed to start queue. - if (TimeManager.LocalTick < _startTick) - return; - - ReceivedServerData rd = _fromServerBuffer.Dequeue(); - ArraySegment segment = rd.GetArraySegment(); - ApplyParametersUpdated(ref segment); - rd.Dispose(); } /* Use post tick values are checked after @@ -596,21 +608,37 @@ private void TimeManager_OnPreTick() /// private void TimeManager_OnPostTick() { - //One check rather than per each method. - if (!_canSynchronizeAnimator) - return; + Profiler.BeginSample("NetworkAnimator.TimeManager_OnPostTick()"); + try + { + //One check rather than per each method. + if (!_canSynchronizeAnimator) + return; - CheckSendToServer(); - CheckSendToClients(); + CheckSendToServer(); + CheckSendToClients(); + } + finally + { + Profiler.EndSample(); + } } private void TimeManager_OnUpdate() { - if (!_canSynchronizeAnimator) - return; + Profiler.BeginSample("NetworkAnimator.TimeManager_OnUpdate()"); + try + { + if (!_canSynchronizeAnimator) + return; - if (IsClientStarted) - SmoothFloats(); + if (IsClientStarted) + SmoothFloats(); + } + finally + { + Profiler.EndSample(); + } } /// diff --git a/Assets/FishNet/Runtime/Generated/Component/NetworkTransform/NetworkTransform.cs b/Assets/FishNet/Runtime/Generated/Component/NetworkTransform/NetworkTransform.cs index 7e1cd494..1e5b1601 100644 --- a/Assets/FishNet/Runtime/Generated/Component/NetworkTransform/NetworkTransform.cs +++ b/Assets/FishNet/Runtime/Generated/Component/NetworkTransform/NetworkTransform.cs @@ -14,6 +14,7 @@ using System.Collections.Generic; using FishNet.Managing.Timing; using UnityEngine; +using UnityEngine.Profiling; using UnityEngine.Scripting; using static FishNet.Object.NetworkObject; @@ -767,8 +768,16 @@ private void TryClearGoalDatas_OwnershipChange(NetworkConnection prevOwner, bool private void TimeManager_OnUpdate() { - float deltaTime = _useScaledTime ? Time.deltaTime : Time.unscaledDeltaTime; - MoveToTarget(deltaTime); + Profiler.BeginSample("NetworkTransform.TimeManager_OnUpdate()"); + try + { + float deltaTime = _useScaledTime ? Time.deltaTime : Time.unscaledDeltaTime; + MoveToTarget(deltaTime); + } + finally + { + Profiler.EndSample(); + } } /// @@ -900,59 +909,67 @@ bool CanMakeKinematic() /// private void TimeManager_OnPostTick() { - //If to force send via tick delay do so and reset force send tick. - if (_forceSendTick != TimeManager.UNSET_TICK && _timeManager.LocalTick > _forceSendTick) + Profiler.BeginSample("NetworkTransform.TimeManager_OnPostTick()"); + try { - _forceSendTick = TimeManager.UNSET_TICK; - ForceSend(); - } + //If to force send via tick delay do so and reset force send tick. + if (_forceSendTick != TimeManager.UNSET_TICK && _timeManager.LocalTick > _forceSendTick) + { + _forceSendTick = TimeManager.UNSET_TICK; + ForceSend(); + } - UpdateParentBehaviour(); + UpdateParentBehaviour(); - /* Intervals remaining is only used when the interval value - * is set higher than 1. An interval of 1 indicates to send - * every tick. Only check to wait more ticks if interval - * is larger than 1. */ - if (_interval > 1) - { - /* If intervalsRemaining is unset then that means the transform - * did not change last tick. See if transform changed and if so then - * update remaining to _interval. */ - if (_intervalsRemaining == -1) + /* Intervals remaining is only used when the interval value + * is set higher than 1. An interval of 1 indicates to send + * every tick. Only check to wait more ticks if interval + * is larger than 1. */ + if (_interval > 1) { - //Transform didn't change, no reason to start remaining. - if (!_cachedTransform.hasChanged) + /* If intervalsRemaining is unset then that means the transform + * did not change last tick. See if transform changed and if so then + * update remaining to _interval. */ + if (_intervalsRemaining == -1) + { + //Transform didn't change, no reason to start remaining. + if (!_cachedTransform.hasChanged) + return; + + _intervalsRemaining = _interval; + } + + //If here then intervalsRemaining can be deducted. + _intervalsRemaining--; + //Interval not met yet. + if (_intervalsRemaining > 0) return; - _intervalsRemaining = _interval; + //Intervals remainin is met. Reset to -1 to await new change. + _intervalsRemaining = -1; } - //If here then intervalsRemaining can be deducted. - _intervalsRemaining--; - //Interval not met yet. - if (_intervalsRemaining > 0) - return; - - //Intervals remainin is met. Reset to -1 to await new change. - _intervalsRemaining = -1; - } + bool isServerInitialized = IsServerInitialized; + bool isClientInitialized = IsClientInitialized; - bool isServerInitialized = IsServerInitialized; - bool isClientInitialized = IsClientInitialized; + if (isServerInitialized) + { + /* If client is not initialized then + * call a move to targe ton post tick to ensure + * anything with instant rates gets moved. */ + if (!isClientInitialized) + MoveToTarget((float)_timeManager.TickDelta); + // + SendToClients(); + } - if (isServerInitialized) + if (isClientInitialized) + SendToServer(_lastSentTransformData); + } + finally { - /* If client is not initialized then - * call a move to targe ton post tick to ensure - * anything with instant rates gets moved. */ - if (!isClientInitialized) - MoveToTarget((float)_timeManager.TickDelta); - // - SendToClients(); + Profiler.EndSample(); } - - if (isClientInitialized) - SendToServer(_lastSentTransformData); } /// diff --git a/Assets/FishNet/Runtime/Generated/Component/TickSmoothing/TickSmootherController.cs b/Assets/FishNet/Runtime/Generated/Component/TickSmoothing/TickSmootherController.cs index 517e2a06..265a13d7 100644 --- a/Assets/FishNet/Runtime/Generated/Component/TickSmoothing/TickSmootherController.cs +++ b/Assets/FishNet/Runtime/Generated/Component/TickSmoothing/TickSmootherController.cs @@ -3,6 +3,7 @@ using FishNet.Object; using GameKit.Dependencies.Utilities; using UnityEngine; +using UnityEngine.Profiling; namespace FishNet.Component.Transforming.Beta { @@ -140,12 +141,28 @@ void StopOnline() public void TimeManager_OnUpdate() { - UniversalSmoother.OnUpdate(Time.deltaTime); + Profiler.BeginSample("TickSmootherController.TimeManager_OnUpdate()"); + try + { + UniversalSmoother.OnUpdate(Time.deltaTime); + } + finally + { + Profiler.EndSample(); + } } public void TimeManager_OnPreTick() { - UniversalSmoother.OnPreTick(); + Profiler.BeginSample("TickSmootherController.TimeManager_OnPreTick()"); + try + { + UniversalSmoother.OnPreTick(); + } + finally + { + Profiler.EndSample(); + } } /// @@ -153,8 +170,16 @@ public void TimeManager_OnPreTick() /// public void TimeManager_OnPostTick() { - if (_timeManager != null) - UniversalSmoother.OnPostTick(_timeManager.LocalTick); + Profiler.BeginSample("TickSmootherController.TimeManager_OnPostTick()"); + try + { + if (_timeManager != null) + UniversalSmoother.OnPostTick(_timeManager.LocalTick); + } + finally + { + Profiler.EndSample(); + } } private void PredictionManager_OnPostReplicateReplay(uint clientTick, uint serverTick) diff --git a/Assets/FishNet/Runtime/Generated/Component/Utility/DetachableNetworkTickSmoother.cs b/Assets/FishNet/Runtime/Generated/Component/Utility/DetachableNetworkTickSmoother.cs index a757007d..a6d1ba11 100644 --- a/Assets/FishNet/Runtime/Generated/Component/Utility/DetachableNetworkTickSmoother.cs +++ b/Assets/FishNet/Runtime/Generated/Component/Utility/DetachableNetworkTickSmoother.cs @@ -6,6 +6,7 @@ using FishNet.Utility.Extension; using GameKit.Dependencies.Utilities; using UnityEngine; +using UnityEngine.Profiling; namespace FishNet.Component.Transforming { @@ -170,18 +171,26 @@ private void Update() /// private void _timeManager_OnPostTick() { - if (!_initialized) - return; - - _postTickFollowObjectWorldProperties.Update(_followObject); - // Unset values if not following the transform property. - if (!_synchronizePosition) - _postTickFollowObjectWorldProperties.Position = transform.position; - if (!_synchronizeRotation) - _postTickFollowObjectWorldProperties.Rotation = transform.rotation; - if (!_synchronizeScale) - _postTickFollowObjectWorldProperties.Scale = transform.localScale; - SetMoveRates(); + Profiler.BeginSample("DetachableNetworkTickSmoother._timeManager_OnPostTick()"); + try + { + if (!_initialized) + return; + + _postTickFollowObjectWorldProperties.Update(_followObject); + // Unset values if not following the transform property. + if (!_synchronizePosition) + _postTickFollowObjectWorldProperties.Position = transform.position; + if (!_synchronizeRotation) + _postTickFollowObjectWorldProperties.Rotation = transform.rotation; + if (!_synchronizeScale) + _postTickFollowObjectWorldProperties.Scale = transform.localScale; + SetMoveRates(); + } + finally + { + Profiler.EndSample(); + } } /// diff --git a/Assets/FishNet/Runtime/Generated/Component/Utility/MonoTickSmoother.cs b/Assets/FishNet/Runtime/Generated/Component/Utility/MonoTickSmoother.cs index 87283d66..ea99bdcf 100644 --- a/Assets/FishNet/Runtime/Generated/Component/Utility/MonoTickSmoother.cs +++ b/Assets/FishNet/Runtime/Generated/Component/Utility/MonoTickSmoother.cs @@ -4,6 +4,7 @@ using FishNet.Object.Prediction; using GameKit.Dependencies.Utilities; using UnityEngine; +using UnityEngine.Profiling; #pragma warning disable CS0618 // Type or member is obsolete @@ -136,7 +137,15 @@ private void ChangeSubscription(bool subscribe) /// private void _timeManager_OnPreTick() { - _tickSmoother.OnPreTick(); + Profiler.BeginSample("MonoTickSmoother._timeManager_OnPreTick()"); + try + { + _tickSmoother.OnPreTick(); + } + finally + { + Profiler.EndSample(); + } } /// @@ -144,7 +153,15 @@ private void _timeManager_OnPreTick() /// private void _timeManager_OnPostTick() { - _tickSmoother.OnPostTick(); + Profiler.BeginSample("MonoTickSmoother._timeManager_OnPostTick()"); + try + { + _tickSmoother.OnPostTick(); + } + finally + { + Profiler.EndSample(); + } } } } \ No newline at end of file diff --git a/Assets/FishNet/Runtime/Managing/Client/ClientManager.cs b/Assets/FishNet/Runtime/Managing/Client/ClientManager.cs index f3900b0f..ada05e7f 100644 --- a/Assets/FishNet/Runtime/Managing/Client/ClientManager.cs +++ b/Assets/FishNet/Runtime/Managing/Client/ClientManager.cs @@ -15,6 +15,7 @@ using System.Collections.Generic; using FishNet.Managing.Statistic; using UnityEngine; +using UnityEngine.Profiling; namespace FishNet.Managing.Client { @@ -142,7 +143,7 @@ public void SetFrameRate(ushort value) private SplitReader _splitReader = new(); /// /// - private NetworkTrafficStatistics _networkTrafficStatistics; + [NonSerialized] private NetworkTrafficStatistics _networkTrafficStatistics; #endregion private void OnDestroy() @@ -670,7 +671,15 @@ private void ParseAuthenticated(PooledReader reader) /// private void TimeManager_OnPostTick() { - CheckServerTimeout(); + Profiler.BeginSample("ClientManager.TimeManager_OnPostTick()"); + try + { + CheckServerTimeout(); + } + finally + { + Profiler.EndSample(); + } } /// diff --git a/Assets/FishNet/Runtime/Managing/Prediction/PredictionManager.cs b/Assets/FishNet/Runtime/Managing/Prediction/PredictionManager.cs index 8a26bbe1..bb670151 100644 --- a/Assets/FishNet/Runtime/Managing/Prediction/PredictionManager.cs +++ b/Assets/FishNet/Runtime/Managing/Prediction/PredictionManager.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using FishNet.Managing.Statistic; using UnityEngine; +using UnityEngine.Profiling; using UnityEngine.Serialization; namespace FishNet.Managing.Predicting @@ -539,15 +540,23 @@ private void SubscribeToTimeManager(bool subscribe, bool asServer) /// private void TimeManager_OnLateUpdate() { - /* Do not throttle nor count frames if scene manager has performed actions recently. */ - if (_networkManager.SceneManager.HasProcessedScenesRecently(timeFrame: 2f)) + Profiler.BeginSample("PredictionManager.TimeManager_OnLateUpdate()"); + try { - _clientReconcileThrottler.ResetState(); - return; - } + /* Do not throttle nor count frames if scene manager has performed actions recently. */ + if (_networkManager.SceneManager.HasProcessedScenesRecently(timeFrame: 2f)) + { + _clientReconcileThrottler.ResetState(); + return; + } - if (_reduceReconcilesWithFramerate) - _clientReconcileThrottler.AddFrame(Time.unscaledDeltaTime); + if (_reduceReconcilesWithFramerate) + _clientReconcileThrottler.AddFrame(Time.unscaledDeltaTime); + } + finally + { + Profiler.EndSample(); + } } /// @@ -662,18 +671,81 @@ bool ConditionsMet(StatePacket spChecked) bool timeManagerPhysics = tm.PhysicsMode == PhysicsMode.TimeManager; float tickDelta = (float)tm.TickDelta * _networkManager.TimeManager.GetPhysicsTimeScale(); - OnPreReconcile?.Invoke(ClientStateTick, ServerStateTick); - OnReconcile?.Invoke(ClientStateTick, ServerStateTick); + + Profiler.BeginSample("PredictionManager.OnPreReconcile(uint, uint)"); + try + { + OnPreReconcile?.Invoke(ClientStateTick, ServerStateTick); + } + finally + { + Profiler.EndSample(); + } + + Profiler.BeginSample("PredictionManager.OnReconcile(uint, uint)"); + try + { + + OnReconcile?.Invoke(ClientStateTick, ServerStateTick); + } + finally + { + Profiler.EndSample(); + } if (timeManagerPhysics) { - OnPrePhysicsTransformSync?.Invoke(ClientStateTick, ServerStateTick); - Physics.SyncTransforms(); - Physics2D.SyncTransforms(); - OnPostPhysicsTransformSync?.Invoke(ClientStateTick, ServerStateTick); + Profiler.BeginSample("PredictionManager.OnPrePhysicsTransformSync(uint, uint)"); + try + { + OnPreReconcile?.Invoke(ClientStateTick, ServerStateTick); + } + finally + { + Profiler.EndSample(); + } + + Profiler.BeginSample("PredictionManager.Physics.SyncTransforms()"); + try + { + Physics.SyncTransforms(); + } + finally + { + Profiler.EndSample(); + } + + Profiler.BeginSample("PredictionManager.Physics2D.SyncTransforms()"); + try + { + Physics2D.SyncTransforms(); + } + finally + { + Profiler.EndSample(); + } + + Profiler.BeginSample("PredictionManager.OnPostPhysicsTransformSync(uint, uint)"); + try + { + OnPostPhysicsTransformSync?.Invoke(ClientStateTick, ServerStateTick); + } + finally + { + Profiler.EndSample(); + } } - OnPostReconcileSyncTransforms?.Invoke(ClientStateTick, ServerStateTick); + Profiler.BeginSample("PredictionManager.OnPostReconcileSyncTransforms(uint, uint)"); + try + { + OnPostReconcileSyncTransforms?.Invoke(ClientStateTick, ServerStateTick); + } + finally + { + Profiler.EndSample(); + } + /* Set first replicate to be the 1 tick * after reconcile. This is because reconcile calcs * should be performed after replicate has run. @@ -694,19 +766,72 @@ bool ConditionsMet(StatePacket spChecked) * will fire for 100. */ while (ClientReplayTick < localTick) { - OnPreReplicateReplay?.Invoke(ClientReplayTick, ServerReplayTick); - OnReplicateReplay?.Invoke(ClientReplayTick, ServerReplayTick); + Profiler.BeginSample("PredictionManager.OnPreReplicateReplay(uint, uint)"); + try + { + OnPreReplicateReplay?.Invoke(ClientReplayTick, ServerReplayTick); + } + finally + { + Profiler.EndSample(); + } + + Profiler.BeginSample("PredictionManager.OnReplicateReplay(uint, uint)"); + try + { + OnReplicateReplay?.Invoke(ClientReplayTick, ServerReplayTick); + } + finally + { + Profiler.EndSample(); + } + if (timeManagerPhysics && tickDelta > 0f) { - Physics.Simulate(tickDelta); - Physics2D.Simulate(tickDelta); + Profiler.BeginSample("PredictionManager.Physics.Simulate(float)"); + try + { + Physics.Simulate(tickDelta); + } + finally + { + Profiler.EndSample(); + } + + Profiler.BeginSample("PredictionManager.Physics2D.Simulate(float)"); + try + { + Physics2D.Simulate(tickDelta); + } + finally + { + Profiler.EndSample(); + } } - OnPostReplicateReplay?.Invoke(ClientReplayTick, ServerReplayTick); + + Profiler.BeginSample("PredictionManager.OnPostReplicateReplay(uint, uint)"); + try + { + OnPostReplicateReplay?.Invoke(ClientReplayTick, ServerReplayTick); + } + finally + { + Profiler.EndSample(); + } + ClientReplayTick++; ServerReplayTick++; } - - OnPostReconcile?.Invoke(ClientStateTick, ServerStateTick); + + Profiler.BeginSample("PredictionManager.OnPostReconcile(uint, uint)"); + try + { + OnPostReconcile?.Invoke(ClientStateTick, ServerStateTick); + } + finally + { + Profiler.EndSample(); + } // ClientStateTick = TimeManager.UNSET_TICK; // ServerStateTick = TimeManager.UNSET_TICK; diff --git a/Assets/FishNet/Runtime/Managing/Server/ServerManager.cs b/Assets/FishNet/Runtime/Managing/Server/ServerManager.cs index 3d2fa15c..c14fd0f3 100644 --- a/Assets/FishNet/Runtime/Managing/Server/ServerManager.cs +++ b/Assets/FishNet/Runtime/Managing/Server/ServerManager.cs @@ -21,6 +21,7 @@ using System.Text; using FishNet.Managing.Statistic; using UnityEngine; +using UnityEngine.Profiling; namespace FishNet.Managing.Server { @@ -221,7 +222,7 @@ public void SetFrameRate(ushort value) private SplitReader _splitReader = new(); /// /// - private NetworkTrafficStatistics _networkTrafficStatistics; + [NonSerialized] private NetworkTrafficStatistics _networkTrafficStatistics; #if DEVELOPMENT /// /// Logs data about parser to help debug. @@ -438,7 +439,15 @@ private void CheckClientTimeout() /// private void TimeManager_OnPostTick() { - CheckClientTimeout(); + Profiler.BeginSample("ServerManager.TimeManager_OnPostTick()"); + try + { + CheckClientTimeout(); + } + finally + { + Profiler.EndSample(); + } } /// diff --git a/Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs b/Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs index f918eec5..3e4b576f 100644 --- a/Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs +++ b/Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs @@ -9,6 +9,7 @@ using System.Runtime.CompilerServices; using FishNet.Managing.Statistic; using UnityEngine; +using UnityEngine.Profiling; using SystemStopwatch = System.Diagnostics.Stopwatch; namespace FishNet.Managing.Timing @@ -283,7 +284,7 @@ public void SetPhysicsTimeScale(float value) /// /// - private NetworkTrafficStatistics _networkTrafficStatistics; + [NonSerialized] private NetworkTrafficStatistics _networkTrafficStatistics; #endregion #region Const. @@ -318,7 +319,16 @@ private void OnDisable() /// internal void TickFixedUpdate() { - OnFixedUpdate?.Invoke(); + Profiler.BeginSample("TimeManager.OnFixedUpdate()"); + try + { + OnFixedUpdate?.Invoke(); + } + finally + { + Profiler.EndSample(); + } + /* Invoke onsimulation if using Unity time. * Otherwise let the tick cycling part invoke. */ if (PhysicsMode == PhysicsMode.Unity) @@ -329,10 +339,28 @@ internal void TickFixedUpdate() * This can only happen if a FixedUpdate occurs * multiple times per frame. */ if (_fixedUpdateTimeStep) - OnPostPhysicsSimulation?.Invoke(Time.fixedDeltaTime); + { + Profiler.BeginSample("TimeManager.OnPostPhysicsSimulation(float)"); + try + { + OnPostPhysicsSimulation?.Invoke(Time.fixedDeltaTime); + } + finally + { + Profiler.EndSample(); + } + } _fixedUpdateTimeStep = true; - OnPrePhysicsSimulation?.Invoke(Time.fixedDeltaTime); + Profiler.BeginSample("TimeManager.OnPrePhysicsSimulation(float)"); + try + { + OnPrePhysicsSimulation?.Invoke(Time.fixedDeltaTime); + } + finally + { + Profiler.EndSample(); + } } } @@ -349,13 +377,30 @@ internal void TickUpdate() bool beforeTick = _updateOrder == UpdateOrder.BeforeTick; if (beforeTick) { - OnUpdate?.Invoke(); + Profiler.BeginSample("TimeManager.OnUpdate()"); + try + { + OnUpdate?.Invoke(); + } + finally + { + Profiler.EndSample(); + } + MethodLogic(); } else { MethodLogic(); - OnUpdate?.Invoke(); + Profiler.BeginSample("TimeManager.OnUpdate()"); + try + { + OnUpdate?.Invoke(); + } + finally + { + Profiler.EndSample(); + } } void MethodLogic() @@ -366,7 +411,15 @@ void MethodLogic() if (PhysicsMode == PhysicsMode.Unity && _fixedUpdateTimeStep) { _fixedUpdateTimeStep = false; - OnPostPhysicsSimulation?.Invoke(Time.fixedDeltaTime); + Profiler.BeginSample("TimeManager.OnPostPhysicsSimulation(float)"); + try + { + OnPostPhysicsSimulation?.Invoke(Time.fixedDeltaTime); + } + finally + { + Profiler.EndSample(); + } } } } @@ -376,7 +429,15 @@ void MethodLogic() /// internal void TickLateUpdate() { - OnLateUpdate?.Invoke(); + Profiler.BeginSample("TimeManager.OnLateUpdate(float)"); + try + { + OnLateUpdate?.Invoke(); + } + finally + { + Profiler.EndSample(); + } } /// @@ -578,7 +639,15 @@ internal void ModifyPing(uint clientTick) RoundTripTime = (long)Math.Round(averageInTime); _receivedPong = true; - OnRoundTripTimeUpdated?.Invoke(RoundTripTime); + Profiler.BeginSample("TimeManager.OnRoundTripTimeUpdated(float)"); + try + { + OnRoundTripTimeUpdated?.Invoke(RoundTripTime); + } + finally + { + Profiler.EndSample(); + } } /// @@ -687,7 +756,17 @@ private void IncreaseTick() do { if (frameTicked) - OnPreTick?.Invoke(); + { + Profiler.BeginSample("TimeManager.OnPreTick()"); + try + { + OnPreTick?.Invoke(); + } + finally + { + Profiler.EndSample(); + } + } /* This has to be called inside the loop because * OnPreTick promises data hasn't been read yet. @@ -700,17 +779,69 @@ private void IncreaseTick() { // Tell predicted objecs to reconcile before OnTick. NetworkManager.PredictionManager.ReconcileToStates(); - OnTick?.Invoke(); + Profiler.BeginSample("TimeManager.OnTick()"); + try + { + OnTick?.Invoke(); + } + finally + { + Profiler.EndSample(); + } if (PhysicsMode == PhysicsMode.TimeManager && tickDelta > 0f) { - OnPrePhysicsSimulation?.Invoke(tickDelta); - Physics.Simulate(tickDelta); - Physics2D.Simulate(tickDelta); - OnPostPhysicsSimulation?.Invoke(tickDelta); + Profiler.BeginSample("TimeManager.OnPrePhysicsSimulation(float)"); + try + { + OnPrePhysicsSimulation?.Invoke(tickDelta); + } + finally + { + Profiler.EndSample(); + } + + Profiler.BeginSample("TimeManager.Physics.Simulate(float)"); + try + { + Physics.Simulate(tickDelta); + } + finally + { + Profiler.EndSample(); + } + + Profiler.BeginSample("TimeManager.Physics2D.Simulate(float)"); + try + { + Physics2D.Simulate(tickDelta); + } + finally + { + Profiler.EndSample(); + } + + Profiler.BeginSample("TimeManager.OnPostPhysicsSimulation(float)"); + try + { + OnPostPhysicsSimulation?.Invoke(tickDelta); + } + finally + { + Profiler.EndSample(); + } } - - OnPostTick?.Invoke(); + + Profiler.BeginSample("TimeManager.OnPostTick()"); + try + { + OnPostTick?.Invoke(); + } + finally + { + Profiler.EndSample(); + } + // After post tick send states. NetworkManager.PredictionManager.SendStateUpdate(); diff --git a/Assets/FishNet/Runtime/Object/NetworkObject/NetworkObject.Prediction.cs b/Assets/FishNet/Runtime/Object/NetworkObject/NetworkObject.Prediction.cs index fb378c31..c147b54f 100644 --- a/Assets/FishNet/Runtime/Object/NetworkObject/NetworkObject.Prediction.cs +++ b/Assets/FishNet/Runtime/Object/NetworkObject/NetworkObject.Prediction.cs @@ -7,9 +7,11 @@ using FishNet.Object.Prediction; using GameKit.Dependencies.Utilities; using System.Collections.Generic; +using FishNet.Component.Transforming.Beta; using FishNet.Connection; using FishNet.Managing.Server; using UnityEngine; +using UnityEngine.Profiling; #pragma warning disable CS0618 // Type or member is obsolete @@ -317,66 +319,122 @@ private void InvokeStopCallbacks_Prediction(bool asServer) private void TimeManager_OnPreTick() { - if (PredictionSmoother != null) - PredictionSmoother.OnPreTick(); + Profiler.BeginSample("NetworkObject.TimeManager_OnPreTick()"); + try + { + if (PredictionSmoother != null) + PredictionSmoother.OnPreTick(); + } + finally + { + Profiler.EndSample(); + } } private void PredictionManager_OnPostReplicateReplay(uint clientTick, uint serverTick) { - if (PredictionSmoother != null) - PredictionSmoother.OnPostReplicateReplay(clientTick); + Profiler.BeginSample("NetworkObject.PredictionManager_OnPostReplicateReplay(uint, uint)"); + try + { + if (PredictionSmoother != null) + PredictionSmoother.OnPostReplicateReplay(clientTick); + } + finally + { + Profiler.EndSample(); + } } private void TimeManager_OnPostTick() { - if (PredictionSmoother != null) - PredictionSmoother.OnPostTick(NetworkManager.TimeManager.LocalTick); + Profiler.BeginSample("NetworkObject.TimeManager_OnPostTick()"); + try + { + if (PredictionSmoother != null) + PredictionSmoother.OnPostTick(NetworkManager.TimeManager.LocalTick); + } + finally + { + Profiler.EndSample(); + } } private void PredictionManager_OnPreReconcile(uint clientTick, uint serverTick) { - if (PredictionSmoother != null) - PredictionSmoother.OnPreReconcile(); + Profiler.BeginSample("NetworkObject.PredictionManager_OnPreReconcile(uint, uint)"); + try + { + if (PredictionSmoother != null) + PredictionSmoother.OnPreReconcile(); + } + finally + { + Profiler.EndSample(); + } } private void PredictionManager_OnReconcile(uint clientReconcileTick, uint serverReconcileTick) { - /* Tell all prediction behaviours to set/validate their - * reconcile data now. This will use reconciles from the server - * whenever possible, and local reconciles if a server reconcile - * is not available. */ - for (int i = 0; i < _predictionBehaviours.Count; i++) - _predictionBehaviours[i].Reconcile_Client_Start(); - - /* If still not reconciling then pause rigidbody. - * This shouldn't happen unless the user is not calling - * reconcile at all. */ - if (!IsObjectReconciling) + Profiler.BeginSample("NetworkObject.PredictionManager_OnReconcile(uint, uint)"); + try { - if (_rigidbodyPauser != null) - _rigidbodyPauser.Pause(); + /* Tell all prediction behaviours to set/validate their + * reconcile data now. This will use reconciles from the server + * whenever possible, and local reconciles if a server reconcile + * is not available. */ + for (int i = 0; i < _predictionBehaviours.Count; i++) + _predictionBehaviours[i].Reconcile_Client_Start(); + + /* If still not reconciling then pause rigidbody. + * This shouldn't happen unless the user is not calling + * reconcile at all. */ + if (!IsObjectReconciling) + { + if (_rigidbodyPauser != null) + _rigidbodyPauser.Pause(); + } + } + finally + { + Profiler.EndSample(); } } private void PredictionManager_OnPostReconcile(uint clientReconcileTick, uint serverReconcileTick) { - for (int i = 0; i < _predictionBehaviours.Count; i++) - _predictionBehaviours[i].Reconcile_Client_End(); - - /* Unpause rigidbody pauser. It's okay to do that here rather - * than per NB, where the pausing occurs, because once here - * the entire object is out of the replay cycle so there's - * no reason to try and unpause per NB. */ - if (_rigidbodyPauser != null) - _rigidbodyPauser.Unpause(); - IsObjectReconciling = false; + Profiler.BeginSample("NetworkObject.PredictionManager_OnPostReconcile(uint, uint)"); + try + { + for (int i = 0; i < _predictionBehaviours.Count; i++) + _predictionBehaviours[i].Reconcile_Client_End(); + + /* Unpause rigidbody pauser. It's okay to do that here rather + * than per NB, where the pausing occurs, because once here + * the entire object is out of the replay cycle so there's + * no reason to try and unpause per NB. */ + if (_rigidbodyPauser != null) + _rigidbodyPauser.Unpause(); + IsObjectReconciling = false; + } + finally + { + Profiler.EndSample(); + } } private void PredictionManager_OnReplicateReplay(uint clientTick, uint serverTick) { - uint replayTick = IsOwner ? clientTick : serverTick; - for (int i = 0; i < _predictionBehaviours.Count; i++) - _predictionBehaviours[i].Replicate_Replay_Start(replayTick); + Profiler.BeginSample("NetworkObject.PredictionManager_OnReplicateReplay(uint, uint)"); + try + { + uint replayTick = IsOwner ? clientTick : serverTick; + for (int i = 0; i < _predictionBehaviours.Count; i++) + _predictionBehaviours[i].Replicate_Replay_Start(replayTick); + } + finally + { + Profiler.EndSample(); + } } ///