Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -565,28 +569,36 @@ private void ChangeTickSubscription(bool subscribe)
/// </summary>
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<byte> 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<byte> segment = rd.GetArraySegment();
ApplyParametersUpdated(ref segment);
rd.Dispose();
}

/* Use post tick values are checked after
Expand All @@ -596,21 +608,37 @@ private void TimeManager_OnPreTick()
/// </summary>
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();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}

/// <summary>
Expand Down Expand Up @@ -900,59 +909,67 @@ bool CanMakeKinematic()
/// </summary>
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);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using FishNet.Object;
using GameKit.Dependencies.Utilities;
using UnityEngine;
using UnityEngine.Profiling;

namespace FishNet.Component.Transforming.Beta
{
Expand Down Expand Up @@ -140,21 +141,45 @@ 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();
}
}

/// <summary>
/// Called after a tick completes.
/// </summary>
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using FishNet.Utility.Extension;
using GameKit.Dependencies.Utilities;
using UnityEngine;
using UnityEngine.Profiling;

namespace FishNet.Component.Transforming
{
Expand Down Expand Up @@ -170,18 +171,26 @@ private void Update()
/// </summary>
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();
}
}

/// <summary>
Expand Down
Loading