Skip to content

Commit

Permalink
4.5.0
Browse files Browse the repository at this point in the history
- Added IOrderable.
- Added lst.AddOrdered().
- Added ObserverCondition.AddOrder.
- Added Observer conditions can now be checked in a preferred order. This can be useful for prioritizing the fastest checks first.
- Added TimeManager.GetTickElapsedAsDouble.
- Fixed NetworkTransform deinitialize capable of corrupting packet (#786).
- Fixed harmless message, server timed out a client, on a ghost connection (#782).
- Fixed SyncTimer Start callback not working on clientOnly when object spawned with timer active (#768).
- Fixed SyncTimer Finished callback not working on clientOnly when timer duration expired on the same tick timer was started (#768).
- Improved Obsolete message on SyncVars to alleviate confusion.
- Fixed beta SyncType collections incorrectly being cleared when clientHost lost visibility (#651).
- Fixed harmless 'method not supported' error on Multipass (#455).
- Added beta PredictionManager.CreateLocalStates.
- Changed NetworkObject inspector layout.
- Added NetworkTransform component configuration now occurs on ownership change as well.
- Added PlayerSpawner.SetPlayerPrefab.
- Fixed several clientHost destroy race conditions with rapid despawns.
- Improved performance on despawning objects with timed observer conditions.
- Added Tugboat.SetTimeout.
- Fixed server incorrectly sending clientAuth NetworkTransform updates as reliable, resulting in stutter on observers (#787).
- Added notice when Fish-Networking code stripping is enabled when building.
- Fixed Resettable/RingBuffer foreach iteration error when Count is 0.
- Fixed NetworkObject.Deinitialize running asServer: false multiple times when using predicted spawning.
- Fixed potential for clientHost renderers to stay hidden on an object after removing a pre-existing renderer.
- Fixed sceneIds sometimes not being set on NetworkObjects newly added to scenes.
- Obsoleted NetworkObject.IsSpawnable.
- Added NetworkObject.Get/SetIsSpawnable.
- Added TimeManager.GetTickElapsedAsDouble.
- Fixed SceneIds sometimes not being set on objects newly added to scenes.
- Fixed possible race condition with users accessing SyncTypes from awake before scene objects are initialized.
- Obsoleted NetworkObject.IsNetworked.
- Added NetworkObject.GetIsNetworked; SetIsNetworked already existed.
- Obsoleted NetworkBehaviour.IsNetworked.
- Added Networkbehaviour.Get/SetIsNetworked.
  • Loading branch information
FirstGearGames committed Oct 8, 2024
1 parent 230444a commit 1aa96ec
Show file tree
Hide file tree
Showing 50 changed files with 2,171 additions and 686 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ public override bool ImportReferences()

foreach (MethodInfo mi in networkBehaviourType.GetMethods((BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)))
{
if (mi.Name == nameof(NetworkBehaviour.GetIsNetworked))
IsNetworked_MethodRef = base.ImportReference(mi);
//CreateDelegates.
if (mi.Name == nameof(NetworkBehaviour.RegisterServerRpc))
else if (mi.Name == nameof(NetworkBehaviour.RegisterServerRpc))
RegisterServerRpc_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.RegisterObserversRpc))
RegisterObserversRpc_MethodRef = base.ImportReference(mi);
Expand Down Expand Up @@ -152,8 +154,6 @@ public override bool ImportReferences()
IsHost_MethodRef = base.ImportReference(pi.GetMethod);
else if (pi.Name == nameof(NetworkBehaviour.IsOwner))
IsOwner_MethodRef = base.ImportReference(pi.GetMethod);
else if (pi.Name == nameof(NetworkBehaviour.IsNetworked))
IsNetworked_MethodRef = base.ImportReference(pi.GetMethod);
//Owner.
else if (pi.Name == nameof(NetworkBehaviour.Owner))
Owner_MethodRef = base.ImportReference(pi.GetMethod);
Expand Down
2 changes: 2 additions & 0 deletions Assets/FishNet/CodeGenerating/ILCore/FishNetILPP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
if (!session.Initialize(assemblyDef.MainModule))
return null;



bool modified = false;

bool fnAssembly = IsFishNetAssembly(compiledAssembly);
Expand Down
3 changes: 2 additions & 1 deletion Assets/FishNet/Runtime/Connection/NetworkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ public bool LoadedStartScenes(bool asServer)
/// <summary>
/// TransportIndex this connection is on.
/// For security reasons this value will be unset on clients if this is not their connection.
/// This is not yet used.
/// </summary>
public int TransportIndex { get; internal set; } = -1;
public int TransportIndex { get; private set; } = -1;
/// <summary>
/// True if this connection is authenticated. Only available to server.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ private static void OnPostprocessAllAssets(string[] importedAssets, string[] del
/// </summary>
private static bool CanAddNetworkObject(NetworkObject networkObject, PrefabGeneratorConfigurations settings)
{
return networkObject != null && (networkObject.IsSpawnable || !settings.SpawnableOnly);
return networkObject != null && (networkObject.GetIsSpawnable() || !settings.SpawnableOnly);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using GameKit.Dependencies.Utilities;
using System;
using System.Collections.Generic;
using FishNet.Managing.Timing;
using UnityEngine;
using UnityEngine.Scripting;
using static FishNet.Object.NetworkObject;
Expand Down Expand Up @@ -46,19 +47,24 @@ private struct ReceivedClientData
/// Channel the current data arrived on.
/// </summary>
public Channel Channel;
/// <summary>
/// LocalTick of the side receiving this update, typically the server.
/// </summary>
public uint LocalTick;

/// <summary>
/// Updates current values.
/// </summary>
/// <param name="updateHasData">True to set all HasData to true.</param>
public void Update(ArraySegment<byte> data, Channel channel, bool updateHasData)
public void Update(ArraySegment<byte> data, Channel channel, bool updateHasData, uint localTick)
{
if (Writer == null)
Writer = WriterPool.Retrieve();

Writer.Reset();
Writer.WriteArraySegment(data);
Channel = channel;
LocalTick = localTick;

if (updateHasData)
HasData = true;
Expand Down Expand Up @@ -576,14 +582,10 @@ public void SetSendToOwner(bool value)
/// Number of intervals remaining before synchronization.
/// </summary>
private short _intervalsRemaining;

/// <summary>
/// Last sent transform data.
/// </summary>
private TransformData _lastSentTransformData;

private TransformData _ll;

/// <summary>
/// Writers for changed data.
/// </summary>
Expand Down Expand Up @@ -681,6 +683,7 @@ public override void OnOwnershipServer(NetworkConnection prevOwner)

public override void OnOwnershipClient(NetworkConnection prevOwner)
{
ConfigureComponents();
_intervalsRemaining = 0;

/* If newOwner is self then client
Expand Down Expand Up @@ -1500,9 +1503,9 @@ private void MoveToTarget(float delta)

float multiplier = 1f;
int queueCount = _goalDataQueue.Count;
//For every entry past interpolation increase move rate.
//Increase move rate slightly if over queue count.
if (queueCount > (_interpolation + 1))
multiplier += (0.05f * queueCount);
multiplier += 0.05f;

//Rate to update. Changes per property.
float rate;
Expand Down Expand Up @@ -1590,23 +1593,30 @@ private void SendToClients()
* If owner is clientHost just send current server values. */
if (clientAuthoritativeWithOwner && !base.Owner.IsLocalClient)
{
//Check to set hasData if does not, and hasn't sent reliably yet.
/* If there is not new data yet and the last received was not reliable
* then a packet maybe did not arrive when expected. See if we need
* to force a reliable with the last data based on ticks passed since
* last update.*/
if (!_authoritativeClientData.HasData && _authoritativeClientData.Channel != Channel.Reliable)
_authoritativeClientData.SendReliably();
{
/* If ticks have passed beyond interpolation then force
* to send reliably. */
uint maxPassedTicks = (uint)(1 + _interpolation + _extrapolation);
uint localTick = base.TimeManager.LocalTick;
if ((localTick - _authoritativeClientData.LocalTick) > maxPassedTicks)
_authoritativeClientData.SendReliably();
//Not enough time to send reliably, just don't need update.
else
return;
}

if (_authoritativeClientData.HasData)
{
_changedSinceStart = true;
//Resend data from clients.
ObserversUpdateClientAuthoritativeTransform(_authoritativeClientData.Writer.GetArraySegment(), _authoritativeClientData.Channel);

/* If has not yet sent reliably then make it so
* for the next send. If new data comes in this will be
* overwritten with whatever channel is used on the new data. */
if (_authoritativeClientData.Channel != Channel.Reliable)
_authoritativeClientData.SendReliably();
else
_authoritativeClientData.HasData = false;
//Now being sent data can unset.
_authoritativeClientData.HasData = false;
}
}
//Sending server transform state.
Expand Down Expand Up @@ -1645,7 +1655,7 @@ private void SendToClients()
lastSentData.Update(0, t.localPosition, t.localRotation, t.localScale, t.localPosition, ParentBehaviour);
SerializeChanged(changed, writer);
}

ObserversUpdateClientAuthoritativeTransform(writer.GetArraySegment(), channel);
}
}
Expand Down Expand Up @@ -2020,7 +2030,7 @@ private void SetCalculatedRates(TransformData prevTd, RateData prevRd, GoalData
}

rd.Update(positionRate, rotationRate, scaleRate, unalteredPositionRate, tickDifference, timePassed);

//Returns if whole contains part.
bool ChangedFullContains(ChangedFull whole, ChangedFull part)
{
Expand Down Expand Up @@ -2138,13 +2148,14 @@ private void ServerUpdateTransform(ArraySegment<byte> data, Channel channel)
return;
}

TimeManager tm = base.TimeManager;
//Not new data.
uint lastPacketTick = base.TimeManager.LastPacketTick.LastRemoteTick;
uint lastPacketTick = tm.LastPacketTick.LastRemoteTick;
if (lastPacketTick <= _lastServerRpcTick)
return;
_lastServerRpcTick = lastPacketTick;

_authoritativeClientData.Update(data, channel, true);
_authoritativeClientData.Update(data, channel, true, tm.LocalTick);
DataReceived(data, channel, true);
}

Expand All @@ -2163,7 +2174,7 @@ private void DataReceived(ArraySegment<byte> data, Channel channel, bool asServe
GoalData nextGd = ResettableObjectCaches<GoalData>.Retrieve();
TransformData nextTd = nextGd.Transforms;
UpdateTransformData(data, prevTd, nextTd, ref changedFull);

OnDataReceived?.Invoke(prevTd, nextTd);
SetExtrapolation(prevTd, nextTd, channel);

Expand Down Expand Up @@ -2384,11 +2395,7 @@ private void ResetState()

ObjectCaches<PooledWriter>.StoreAndDefault(ref _authoritativeClientData.Writer);

if (_toClientChangedWriter != null)
{
WriterPool.Store(_toClientChangedWriter);
ObjectCaches<PooledWriter>.StoreAndDefault(ref _toClientChangedWriter);
}
WriterPool.StoreAndDefault(ref _toClientChangedWriter);

ObjectCaches<bool>.StoreAndDefault(ref _authoritativeClientData.HasData);
ObjectCaches<ChangedDelta>.StoreAndDefault(ref _serverChangedSinceReliable);
Expand All @@ -2409,8 +2416,7 @@ private void ResetState()
private void ResetState_OnDestroy()
{
ResettableObjectCaches<TransformData>.StoreAndDefault(ref _lastSentTransformData);
if (_toClientChangedWriter != null)
WriterPool.Store(_toClientChangedWriter);
WriterPool.StoreAndDefault(ref _toClientChangedWriter);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class PlayerSpawner : MonoBehaviour
[SerializeField]
private NetworkObject _playerPrefab;
/// <summary>
/// Sets the PlayerPrefab to use.
/// </summary>
/// <param name="nob"></param>
public void SetPlayerPrefab(NetworkObject nob) => _playerPrefab = nob;
/// <summary>
/// True to add player to the active scene when no global scenes are specified through the SceneManager.
/// </summary>
[Tooltip("True to add player to the active scene when no global scenes are specified through the SceneManager.")]
Expand Down
3 changes: 2 additions & 1 deletion Assets/FishNet/Runtime/Managing/Client/ClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ public bool StartConnection()
/// </summary>
public bool StartConnection(string address)
{
return StartConnection(address, NetworkManager.TransportManager.Transport.GetPort());
NetworkManager.TransportManager.Transport.SetClientAddress(address);
return StartConnection();
}
/// <summary>
/// Sets the transport address and port, and starts the local client connection.
Expand Down
15 changes: 9 additions & 6 deletions Assets/FishNet/Runtime/Managing/Client/Object/ClientObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ internal void OnClientConnectionState(ClientConnectionStateArgs args)
{
foreach (NetworkObject n in Spawned.Values)
{
if (!n.CanDeinitialize(asServer: false))
continue;

n.InvokeStopCallbacks(false, true);
n.SetInitializedStatus(false, false);
}
Expand Down Expand Up @@ -174,7 +177,7 @@ internal void PredictedSpawn(NetworkObject networkObject, NetworkConnection owne
}
else
{
networkObject.Deinitialize(false);
networkObject.Deinitialize(asServer: false);
NetworkManager.StorePooledInstantiated(networkObject, false);
}

Expand All @@ -191,8 +194,8 @@ internal void PredictedDespawn(NetworkObject networkObject)
base.NetworkManager.TransportManager.SendToServer((byte)Channel.Reliable, writer.GetArraySegment());
writer.Store();

networkObject.Deinitialize(false);
NetworkManager.StorePooledInstantiated(networkObject, false);
networkObject.Deinitialize(asServer: false);
NetworkManager.StorePooledInstantiated(networkObject, asServer: false);
}

/// <summary>
Expand Down Expand Up @@ -233,9 +236,9 @@ private void RegisterAndDespawnSceneObjects(Scene s)

//Only set initialized values if not server, as server would have already done so.
if (!isServerStarted)
nob.SetInitializedValues(null);
nob.SetInitializedValues(parentNob: null);

if (nob.IsNetworked)
if (nob.GetIsNetworked())
{
base.AddToSceneObjects(nob);
//Only run if not also server, as this already ran on server.
Expand Down Expand Up @@ -333,7 +336,7 @@ internal void ParsePredictedSpawnResult(PooledReader reader)
{
if (Spawned.TryGetValueIL2CPP(usedObjectId, out NetworkObject nob))
{
nob.Deinitialize(false);
nob.Deinitialize(asServer: false);
NetworkManager.StorePooledInstantiated(nob, false);
}
}
Expand Down
8 changes: 4 additions & 4 deletions 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.4.7";
public const string FISHNET_VERSION = "4.5.0";
/// <summary>
/// Maximum framerate allowed.
/// </summary>
Expand Down Expand Up @@ -322,7 +322,7 @@ internal void UpdateFramerate()
{
bool clientStarted = ClientManager.Started;
bool serverStarted = ServerManager.Started;

int frameRate = 0;
//If both client and server are started then use whichever framerate is higher.
if (clientStarted && serverStarted)
Expand All @@ -335,8 +335,8 @@ internal void UpdateFramerate()
/* Make sure framerate isn't set to max on server.
* If it is then default to tick rate. If framerate is
* less than tickrate then also set to tickrate. */
#if UNITY_SERVER
ushort minimumServerFramerate = (ushort)(TimeManager.TickRate + 1);
#if UNITY_SERVER && !UNITY_EDITOR
ushort minimumServerFramerate = (ushort)(TimeManager.TickRate + 15);
if (frameRate == MAXIMUM_FRAMERATE)
frameRate = minimumServerFramerate;
else if (frameRate < TimeManager.TickRate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace FishNet.Managing.Predicting.Editing
{


[CustomEditor(typeof(PredictionManager), true)]
[CanEditMultipleObjects]
public class PredictionManagerEditor : Editor
Expand All @@ -14,6 +12,7 @@ public class PredictionManagerEditor : Editor
private SerializedProperty _dropExcessiveReplicates;
private SerializedProperty _maximumServerReplicates;
private SerializedProperty _maximumConsumeCount;
private SerializedProperty _createLocalStates;
private SerializedProperty _stateInterpolation;
private SerializedProperty _stateOrder;

Expand All @@ -22,6 +21,7 @@ protected virtual void OnEnable()
_dropExcessiveReplicates = serializedObject.FindProperty(nameof(_dropExcessiveReplicates));
_maximumServerReplicates = serializedObject.FindProperty(nameof(_maximumServerReplicates));
_maximumConsumeCount = serializedObject.FindProperty(nameof(_maximumConsumeCount));
_createLocalStates = serializedObject.FindProperty(nameof(_createLocalStates));
_stateInterpolation = serializedObject.FindProperty(nameof(_stateInterpolation));
_stateOrder = serializedObject.FindProperty(nameof(_stateOrder));
}
Expand All @@ -37,6 +37,9 @@ public override void OnInspectorGUI()

EditorGUILayout.LabelField("Client", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
#if !FISHNET_STABLE_MODE
EditorGUILayout.PropertyField(_createLocalStates);
#endif
if (_stateInterpolation.intValue == 0)
EditorGUILayout.HelpBox($"With interpolation set at 0 states will run as they are received, rather than create an interpolation buffer. Using 0 interpolation drastically increases the chance of Created states arriving out of order.", MessageType.Warning);
EditorGUILayout.PropertyField(_stateInterpolation);
Expand All @@ -60,8 +63,6 @@ public override void OnInspectorGUI()

serializedObject.ApplyModifiedProperties();
}

}
}
#endif

#endif
Loading

0 comments on commit 1aa96ec

Please sign in to comment.