Skip to content

Commit

Permalink
4.5.5
Browse files Browse the repository at this point in the history
- Fixed DistanceCondition.MaximumDistance not applying properly when set at runtime (#809).
- Obsoleted DistanceCondition.MaximumDistance.
- Added DistanceCondition.Get/SetMaximumDistance.
- Fixed predicted spawners not becoming an observer of the object they spawned.
- Fixed internals trying to call prediction methods on NetworkBehaviours when they do not utilize prediction when at least one NetworkBehaviour for the NetworkObject does.
- Fixed SyncTimers finishing immediately on clientsOnly when using timer.Update without arguments. (#807).
- Added TickNetworkBehaviour.SetTickCallbacks to set callbacks at runtime.
  • Loading branch information
FirstGearGames committed Nov 8, 2024
1 parent 22b9588 commit 2fa3d62
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Assets/FishNet/Runtime/Managing/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static IReadOnlyList<NetworkManager> Instances
/// <summary>
/// Version of this release.
/// </summary>
public const string FISHNET_VERSION = "4.5.4hf0";
public const string FISHNET_VERSION = "4.5.5";
/// <summary>
/// Maximum framerate allowed.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void UpdateTimedObservers()

/* Try to iterate all timed observers every half a second.
* This value will increase as there's more observers or timed conditions. */
float timeMultiplier = 1f + (float)((base.NetworkManager.ServerManager.Clients.Count * 0.005f) + (_timedNetworkObservers.Count * 0.0005f));
float timeMultiplier = 1f + ((base.NetworkManager.ServerManager.Clients.Count * 0.005f) + (_timedNetworkObservers.Count * 0.0005f));
//Check cap this way for readability.
float completionTime = Mathf.Min((0.5f * timeMultiplier), base.NetworkManager.ObserverManager.MaximumTimedObserversDuration);
uint completionTicks = base.NetworkManager.TimeManager.TimeToTicks(completionTime, TickRounding.RoundUp);
Expand Down Expand Up @@ -174,7 +174,7 @@ private List<NetworkObject> GetSpawnedNetworkObjects()
{
List<NetworkObject> cache = CollectionCaches<NetworkObject>.RetrieveList();
Spawned.ValuesToList(ref cache);

return cache;
}

Expand All @@ -194,7 +194,7 @@ internal List<NetworkObject> SortRootAndNestedByInitializeOrder(List<NetworkObje

sortedRootCache.AddOrdered(item);
}

/* After all root are ordered check
* their nested. Order nested in segments
* of each root then insert after the root.
Expand Down Expand Up @@ -414,7 +414,12 @@ internal void RebuildObservers(NetworkObject nob, NetworkConnection conn, List<N
ObserverStateChange osc = nob.RebuildObservers(conn, timedOnly);
if (osc == ObserverStateChange.Added)
{
WriteSpawn(nob, _writer, conn);
/* Only write spawn if not predicted spawned, or if
* conn is not predicted spawner. There is no need to send spawn
* to predicted spawner given they spawned the object locally. */
NetworkConnection predictedSpawner = nob.PredictedSpawner;
if (!predictedSpawner.IsActive || predictedSpawner != conn)
WriteSpawn(nob, _writer, conn);
addedNobs.Add(nob);
}
else if (osc == ObserverStateChange.Removed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,6 @@ internal void ReadSpawn(PooledReader reader, NetworkConnection conn)


List<NetworkConnection> conns = RetrieveAuthenticatedConnections();
conns.Remove(conn);

RebuildObservers(spawnedNobs, conns);
CollectionCaches<NetworkObject>.Store(spawnedNobs);
Expand Down
6 changes: 0 additions & 6 deletions Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,6 @@ private void IncreaseTick()
NetworkManagerExtensions.LogWarning($"Simulation delta cannot be 0. Network timing will not continue.");
return;
}
////If client needs to slow down then increase delta very slightly.
//if (!isServer && NetworkManager.PredictionManager.ReduceClientTiming)
//{
// Debug.LogWarning($"Slowing down.");
// timePerSimulation *= 1.05f;
//}

double time = Time.unscaledDeltaTime;

Expand Down
17 changes: 9 additions & 8 deletions Assets/FishNet/Runtime/Object/NetworkBehaviour.Prediction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ int FindIndexBruteForce(out DataPlacementResult result)
public abstract partial class NetworkBehaviour : MonoBehaviour
{
#region Public.
// /// <summary>
// /// True if this Networkbehaviour implements prediction methods.
// /// </summary>
// [APIExclude]
// [MakePublic]
// protected internal bool UsesPrediction;
/// <summary>
/// True if this NetworkBehaviour is reconciling.
/// If this NetworkBehaviour does not implemnent prediction methods this value will always be false.
Expand Down Expand Up @@ -240,6 +234,11 @@ public abstract partial class NetworkBehaviour : MonoBehaviour
/// Last values when checking for transform changes since previous tick.
/// </summary>
private Vector3 _lastTransformScale;
/// <summary>
/// True if this Networkbehaviour implements prediction methods.
/// </summary>
[APIExclude]
private bool _usesPrediction;
#endregion

#region Consts.
Expand Down Expand Up @@ -286,6 +285,8 @@ internal void OnDestroy_Prediction()
[MakePublic]
internal void RegisterReplicateRpc(uint hash, ReplicateRpcDelegate del)
{
_usesPrediction = true;

if (_replicateRpcDelegates == null)
_replicateRpcDelegates = CollectionCaches<uint, ReplicateRpcDelegate>.RetrieveDictionary();
_replicateRpcDelegates[hash] = del;
Expand Down Expand Up @@ -359,7 +360,7 @@ internal void ResetState_Prediction(bool asServer)
/// Clears cached replicates for server and client. This can be useful to call on server and client after teleporting.
/// </summary>
public virtual void ClearReplicateCache() { }

/// <summary>
/// Clears cached replicates and histories.
/// </summary>
Expand Down Expand Up @@ -1204,7 +1205,7 @@ public void Reconcile_Server<T>(uint methodHash, ref T lastReconcileData, T data
}

/// <summary>
/// This is called when the networkbehaviour should perform a reconcile.
/// This is called when the NetworkBehaviour should perform a reconcile.
/// Codegen overrides this calling Reconcile_Client with the needed data.
/// </summary>
[MakePublic]
Expand Down
2 changes: 1 addition & 1 deletion Assets/FishNet/Runtime/Object/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ internal void Preinitialize_Internal(NetworkObject nob, bool asServer)
}
else
{
if (!_initializedOnceClient && nob.EnablePrediction)
if (!_initializedOnceClient && nob.EnablePrediction && _usesPrediction)
nob.RegisterPredictionBehaviourOnce(this);

_initializedOnceClient = true;
Expand Down
9 changes: 2 additions & 7 deletions Assets/FishNet/Runtime/Object/Synchronizing/Beta/SyncTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,10 @@ protected internal override void Read(PooledReader reader, bool asServer)

if (canModifyValues)
{
SetUpdateTime();
Paused = false;
Remaining = next;
Duration = duration;

SetUpdateTime();
}

if (newChangeId)
Expand Down Expand Up @@ -356,12 +355,8 @@ void UpdatePauseState(SyncTimerOperation op)
}

Paused = newPauseState;

if (!Paused && Remaining > 0f)
{
if (!Paused)
SetUpdateTime();
}

if (newChangeId)
InvokeOnChange(op, prev, next, asServer);
}
Expand Down
14 changes: 8 additions & 6 deletions Assets/FishNet/Runtime/Object/TransformPropertiesFlag.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
namespace FishNet.Object
using GameKit.Dependencies.Utilities;

namespace FishNet.Object
{
[System.Flags]
public enum TransformPropertiesFlag : byte
public enum TransformPropertiesFlag : uint
{
Unset = 0,
Position = 1,
Rotation = 2,
LocalScale = 4,
Everything = ~(-1 << 8),
Position = (1 << 0),
Rotation = (1 << 1),
LocalScale = (1 << 2),
Everything = Enums.SHIFT_EVERYTHING_UINT,
}

public static class TransformPropertiesOptionExtensions
Expand Down
38 changes: 26 additions & 12 deletions Assets/FishNet/Runtime/Observing/Conditions/DistanceCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,31 @@ public class DistanceCondition : ObserverCondition
/// <summary>
/// Maximum distance a client must be within this object to see it.
/// </summary>
public float MaximumDistance { get => _maximumDistance; set => SetMaximumDistance(value); }
[Obsolete("Use Get/SetMaximumDistance.")]
public float MaximumDistance
{
get => GetMaximumDistance();
set => SetMaximumDistance(value);
}

/// <summary>
/// Maximum distance a client must be within this object to see it.
/// </summary>
/// <returns></returns>
public float GetMaximumDistance() => _maximumDistance;
/// <summary>
/// Sets the maximum distance value.
/// </summary>
/// <param name="value">New value.</param>
public void SetMaximumDistance(float value)
{
_maximumDistance = value;
_sqrMaximumDistance = (_maximumDistance * _maximumDistance);

float maxDistanceHide = (_maximumDistance * (1f + _hideDistancePercent));
_sqrHideMaximumDistance = (maxDistanceHide * maxDistanceHide);
}

/// <summary>
/// Additional percent of distance client must be until this object is hidden. For example, if distance was 100f and percent was 0.5f the client must be 150f units away before this object is hidden again. This can be useful for keeping objects from regularly appearing and disappearing.
/// </summary>
Expand All @@ -49,22 +73,12 @@ private void Awake()
SetMaximumDistance(_maximumDistance);
}

private void SetMaximumDistance(float value)
{
_maximumDistance = value;
_sqrMaximumDistance = (_maximumDistance * _maximumDistance);

float maxDistanceHide = (_maximumDistance * (1f + _hideDistancePercent));
_sqrHideMaximumDistance = (maxDistanceHide * maxDistanceHide);
}

/// <summary>
/// Returns if the object which this condition resides should be visible to connection.
/// </summary>
/// <param name="connection">Connection which the condition is being checked for.</param>
/// <param name="currentlyAdded">True if the connection currently has visibility of this object.</param>
/// <param name="notProcessed">True if the condition was not processed. This can be used to skip processing for performance. While output as true this condition result assumes the previous ConditionMet value.</param>

public override bool ConditionMet(NetworkConnection connection, bool currentlyAdded, out bool notProcessed)
{
//If here then checks are being processed.
Expand All @@ -89,4 +103,4 @@ public override bool ConditionMet(NetworkConnection connection, bool currentlyAd
/// <returns></returns>
public override ObserverConditionType GetConditionType() => ObserverConditionType.Timed;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace GameKit.Dependencies.Utilities

public static class Enums
{
public const int SHIFT_EVERYTHING_INT = ~0;
public const uint SHIFT_EVERYTHING_UINT = ~0u;
//65535
/// <summary>
/// Determine an enum value from a given string. This can be an expensive function.
/// </summary>
Expand Down
26 changes: 19 additions & 7 deletions Assets/FishNet/Runtime/Utility/Template/TickNetworkBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FishNet.Managing.Timing;
using FishNet.Object;
using GameKit.Dependencies.Utilities;
using UnityEngine;

namespace FishNet.Utility.Template
Expand All @@ -12,15 +13,15 @@ public abstract class TickNetworkBehaviour : NetworkBehaviour
#region Types.
[System.Flags]
[System.Serializable]
private enum TickCallback : int
public enum TickCallback : uint
{
None = 0,
PreTick = 1,
Tick = 2,
PostTick = 4,
Update = 8,
LateUpdate = 16,
All = ~0,
PreTick = (1 << 0),
Tick = (1 << 1),
PostTick = (1 << 2),
Update = (1 << 3),
LateUpdate = (1 << 4),
Everything = Enums.SHIFT_EVERYTHING_UINT,
}
#endregion

Expand Down Expand Up @@ -48,6 +49,17 @@ internal override void OnStopNetwork_Internal()
ChangeSubscriptions(false);
}

/// <summary>
/// Updates callbacks to use and changes subscriptions accordingly.
/// </summary>
/// <param name="value">Next value.</param>
public void SetTickCallbacks(TickCallback value)
{
ChangeSubscriptions(subscribe: false);
_tickCallbacks = value;
ChangeSubscriptions(subscribe: true);
}

private void ChangeSubscriptions(bool subscribe)
{
TimeManager tm = base.TimeManager;
Expand Down
2 changes: 1 addition & 1 deletion Assets/FishNet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.firstgeargames.fishnet",
"version": "4.5.4hf0",
"version": "4.5.5",
"displayName": "FishNet: Networking Evolved",
"description": "A feature-rich Unity networking solution aimed towards reliability, ease of use, efficiency, and flexibility.",
"unity": "2021.3",
Expand Down

0 comments on commit 2fa3d62

Please sign in to comment.