Skip to content

Commit 2fa3d62

Browse files
author
FirstGearGames
committed
4.5.5
- 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.
1 parent 22b9588 commit 2fa3d62

12 files changed

Lines changed: 79 additions & 54 deletions

File tree

Assets/FishNet/Runtime/Managing/NetworkManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static IReadOnlyList<NetworkManager> Instances
212212
/// <summary>
213213
/// Version of this release.
214214
/// </summary>
215-
public const string FISHNET_VERSION = "4.5.4hf0";
215+
public const string FISHNET_VERSION = "4.5.5";
216216
/// <summary>
217217
/// Maximum framerate allowed.
218218
/// </summary>

Assets/FishNet/Runtime/Managing/Server/Object/ServerObjects.Observers.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private void UpdateTimedObservers()
6161

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

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

195195
sortedRootCache.AddOrdered(item);
196196
}
197-
197+
198198
/* After all root are ordered check
199199
* their nested. Order nested in segments
200200
* of each root then insert after the root.
@@ -414,7 +414,12 @@ internal void RebuildObservers(NetworkObject nob, NetworkConnection conn, List<N
414414
ObserverStateChange osc = nob.RebuildObservers(conn, timedOnly);
415415
if (osc == ObserverStateChange.Added)
416416
{
417-
WriteSpawn(nob, _writer, conn);
417+
/* Only write spawn if not predicted spawned, or if
418+
* conn is not predicted spawner. There is no need to send spawn
419+
* to predicted spawner given they spawned the object locally. */
420+
NetworkConnection predictedSpawner = nob.PredictedSpawner;
421+
if (!predictedSpawner.IsActive || predictedSpawner != conn)
422+
WriteSpawn(nob, _writer, conn);
418423
addedNobs.Add(nob);
419424
}
420425
else if (osc == ObserverStateChange.Removed)

Assets/FishNet/Runtime/Managing/Server/Object/ServerObjects.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,6 @@ internal void ReadSpawn(PooledReader reader, NetworkConnection conn)
735735

736736

737737
List<NetworkConnection> conns = RetrieveAuthenticatedConnections();
738-
conns.Remove(conn);
739738

740739
RebuildObservers(spawnedNobs, conns);
741740
CollectionCaches<NetworkObject>.Store(spawnedNobs);

Assets/FishNet/Runtime/Managing/Timing/TimeManager.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,6 @@ private void IncreaseTick()
664664
NetworkManagerExtensions.LogWarning($"Simulation delta cannot be 0. Network timing will not continue.");
665665
return;
666666
}
667-
////If client needs to slow down then increase delta very slightly.
668-
//if (!isServer && NetworkManager.PredictionManager.ReduceClientTiming)
669-
//{
670-
// Debug.LogWarning($"Slowing down.");
671-
// timePerSimulation *= 1.05f;
672-
//}
673667

674668
double time = Time.unscaledDeltaTime;
675669

Assets/FishNet/Runtime/Object/NetworkBehaviour.Prediction.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,6 @@ int FindIndexBruteForce(out DataPlacementResult result)
162162
public abstract partial class NetworkBehaviour : MonoBehaviour
163163
{
164164
#region Public.
165-
// /// <summary>
166-
// /// True if this Networkbehaviour implements prediction methods.
167-
// /// </summary>
168-
// [APIExclude]
169-
// [MakePublic]
170-
// protected internal bool UsesPrediction;
171165
/// <summary>
172166
/// True if this NetworkBehaviour is reconciling.
173167
/// If this NetworkBehaviour does not implemnent prediction methods this value will always be false.
@@ -240,6 +234,11 @@ public abstract partial class NetworkBehaviour : MonoBehaviour
240234
/// Last values when checking for transform changes since previous tick.
241235
/// </summary>
242236
private Vector3 _lastTransformScale;
237+
/// <summary>
238+
/// True if this Networkbehaviour implements prediction methods.
239+
/// </summary>
240+
[APIExclude]
241+
private bool _usesPrediction;
243242
#endregion
244243

245244
#region Consts.
@@ -286,6 +285,8 @@ internal void OnDestroy_Prediction()
286285
[MakePublic]
287286
internal void RegisterReplicateRpc(uint hash, ReplicateRpcDelegate del)
288287
{
288+
_usesPrediction = true;
289+
289290
if (_replicateRpcDelegates == null)
290291
_replicateRpcDelegates = CollectionCaches<uint, ReplicateRpcDelegate>.RetrieveDictionary();
291292
_replicateRpcDelegates[hash] = del;
@@ -359,7 +360,7 @@ internal void ResetState_Prediction(bool asServer)
359360
/// Clears cached replicates for server and client. This can be useful to call on server and client after teleporting.
360361
/// </summary>
361362
public virtual void ClearReplicateCache() { }
362-
363+
363364
/// <summary>
364365
/// Clears cached replicates and histories.
365366
/// </summary>
@@ -1204,7 +1205,7 @@ public void Reconcile_Server<T>(uint methodHash, ref T lastReconcileData, T data
12041205
}
12051206

12061207
/// <summary>
1207-
/// This is called when the networkbehaviour should perform a reconcile.
1208+
/// This is called when the NetworkBehaviour should perform a reconcile.
12081209
/// Codegen overrides this calling Reconcile_Client with the needed data.
12091210
/// </summary>
12101211
[MakePublic]

Assets/FishNet/Runtime/Object/NetworkBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ internal void Preinitialize_Internal(NetworkObject nob, bool asServer)
107107
}
108108
else
109109
{
110-
if (!_initializedOnceClient && nob.EnablePrediction)
110+
if (!_initializedOnceClient && nob.EnablePrediction && _usesPrediction)
111111
nob.RegisterPredictionBehaviourOnce(this);
112112

113113
_initializedOnceClient = true;

Assets/FishNet/Runtime/Object/Synchronizing/Beta/SyncTimer.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,10 @@ protected internal override void Read(PooledReader reader, bool asServer)
288288

289289
if (canModifyValues)
290290
{
291+
SetUpdateTime();
291292
Paused = false;
292293
Remaining = next;
293294
Duration = duration;
294-
295-
SetUpdateTime();
296295
}
297296

298297
if (newChangeId)
@@ -356,12 +355,8 @@ void UpdatePauseState(SyncTimerOperation op)
356355
}
357356

358357
Paused = newPauseState;
359-
360-
if (!Paused && Remaining > 0f)
361-
{
358+
if (!Paused)
362359
SetUpdateTime();
363-
}
364-
365360
if (newChangeId)
366361
InvokeOnChange(op, prev, next, asServer);
367362
}

Assets/FishNet/Runtime/Object/TransformPropertiesFlag.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
namespace FishNet.Object
1+
using GameKit.Dependencies.Utilities;
2+
3+
namespace FishNet.Object
24
{
35
[System.Flags]
4-
public enum TransformPropertiesFlag : byte
6+
public enum TransformPropertiesFlag : uint
57
{
68
Unset = 0,
7-
Position = 1,
8-
Rotation = 2,
9-
LocalScale = 4,
10-
Everything = ~(-1 << 8),
9+
Position = (1 << 0),
10+
Rotation = (1 << 1),
11+
LocalScale = (1 << 2),
12+
Everything = Enums.SHIFT_EVERYTHING_UINT,
1113
}
1214

1315
public static class TransformPropertiesOptionExtensions

Assets/FishNet/Runtime/Observing/Conditions/DistanceCondition.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,31 @@ public class DistanceCondition : ObserverCondition
2323
/// <summary>
2424
/// Maximum distance a client must be within this object to see it.
2525
/// </summary>
26-
public float MaximumDistance { get => _maximumDistance; set => SetMaximumDistance(value); }
26+
[Obsolete("Use Get/SetMaximumDistance.")]
27+
public float MaximumDistance
28+
{
29+
get => GetMaximumDistance();
30+
set => SetMaximumDistance(value);
31+
}
32+
33+
/// <summary>
34+
/// Maximum distance a client must be within this object to see it.
35+
/// </summary>
36+
/// <returns></returns>
37+
public float GetMaximumDistance() => _maximumDistance;
38+
/// <summary>
39+
/// Sets the maximum distance value.
40+
/// </summary>
41+
/// <param name="value">New value.</param>
42+
public void SetMaximumDistance(float value)
43+
{
44+
_maximumDistance = value;
45+
_sqrMaximumDistance = (_maximumDistance * _maximumDistance);
46+
47+
float maxDistanceHide = (_maximumDistance * (1f + _hideDistancePercent));
48+
_sqrHideMaximumDistance = (maxDistanceHide * maxDistanceHide);
49+
}
50+
2751
/// <summary>
2852
/// 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.
2953
/// </summary>
@@ -49,22 +73,12 @@ private void Awake()
4973
SetMaximumDistance(_maximumDistance);
5074
}
5175

52-
private void SetMaximumDistance(float value)
53-
{
54-
_maximumDistance = value;
55-
_sqrMaximumDistance = (_maximumDistance * _maximumDistance);
56-
57-
float maxDistanceHide = (_maximumDistance * (1f + _hideDistancePercent));
58-
_sqrHideMaximumDistance = (maxDistanceHide * maxDistanceHide);
59-
}
60-
6176
/// <summary>
6277
/// Returns if the object which this condition resides should be visible to connection.
6378
/// </summary>
6479
/// <param name="connection">Connection which the condition is being checked for.</param>
6580
/// <param name="currentlyAdded">True if the connection currently has visibility of this object.</param>
6681
/// <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>
67-
6882
public override bool ConditionMet(NetworkConnection connection, bool currentlyAdded, out bool notProcessed)
6983
{
7084
//If here then checks are being processed.
@@ -89,4 +103,4 @@ public override bool ConditionMet(NetworkConnection connection, bool currentlyAd
89103
/// <returns></returns>
90104
public override ObserverConditionType GetConditionType() => ObserverConditionType.Timed;
91105
}
92-
}
106+
}

Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/Enums.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ namespace GameKit.Dependencies.Utilities
66

77
public static class Enums
88
{
9+
public const int SHIFT_EVERYTHING_INT = ~0;
10+
public const uint SHIFT_EVERYTHING_UINT = ~0u;
11+
//65535
912
/// <summary>
1013
/// Determine an enum value from a given string. This can be an expensive function.
1114
/// </summary>

0 commit comments

Comments
 (0)