Update FishNet

This commit is contained in:
2026-04-07 03:11:52 +07:00
parent 9675b7b31d
commit ba7513d478
869 changed files with 3675 additions and 2764 deletions
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Authenticating/Authenticator.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Broadcast/Helping/BroadcastHelpers.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Broadcast/IBroadcast.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/CodeGenerating/Attributes.cs
uploadId: 866910
uploadId: 892096
+2 -2
View File
@@ -9,6 +9,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Config.json
uploadId: 866910
uploadId: 892096
+27 -8
View File
@@ -53,6 +53,7 @@ namespace FishNet.Connection
if (Data != null)
ByteArrayPool.Store(Data);
Data = null;
Reset();
}
/// <summary>
@@ -137,7 +138,7 @@ namespace FishNet.Connection
internal PacketBundle(NetworkManager manager, int mtu, int reserve = 0, DataOrderType orderType = DataOrderType.Default)
{
_isSendLastBundle = orderType == DataOrderType.Last;
// If this is not the send last packetbundle then make a new one.
// If this is not the send last packetBundle then make a new one.
if (!_isSendLastBundle)
_sendLastBundle = new(manager, mtu, reserve, DataOrderType.Last);
@@ -215,16 +216,34 @@ namespace FishNet.Connection
return;
}
/* A buffer is added during initialization, so one
* will always be present. */
ByteBuffer ba = _buffers[_bufferIndex];
/* Make a new buffer if...
* forcing a new buffer and data has already been written to the current.
* or---
* segment.Count is more than what is remaining in the buffer. */
bool useNewBuffer = (forceNewBuffer && ba.Length > _reserve) || segment.Count > ba.Remaining;
if (useNewBuffer)
//True if nothing has been written to the buffer.
bool isBufferEmpty = ba.Length == _reserve;
/* If nothing has been written yet there
* is no reason to force a new buffer. */
if (isBufferEmpty)
{
forceNewBuffer = false;
}
else
{
if (!forceNewBuffer)
{
bool canBufferHoldSegmentCount = segment.Count <= ba.Remaining;
if (!canBufferHoldSegmentCount)
forceNewBuffer = true;
}
}
if (forceNewBuffer)
{
_bufferIndex++;
// If need to make a new buffer then do so.
if (_buffers.Count <= _bufferIndex)
{
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Connection/Buffer.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Connection/EstimatedTick.cs
uploadId: 866910
uploadId: 892096
@@ -6,6 +6,7 @@ using FishNet.Object;
using FishNet.Transporting;
using System;
using System.Collections.Generic;
using GameKit.Dependencies.Utilities;
using UnityEngine;
namespace FishNet.Connection
@@ -21,6 +22,10 @@ namespace FishNet.Connection
/// True if this object has been dirtied.
/// </summary>
private bool _serverDirtied;
/// <summary>
/// SplitReader being used as-needed.
/// </summary>
private SplitReader _splitReader;
#endregion
/// <summary>
@@ -35,6 +40,36 @@ namespace FishNet.Connection
}
}
/// <summary>
/// Gets the current SplitReader.
/// </summary>
/// <returns></returns>
internal bool TryGetSplitReader(int expectedMessages, out SplitReader splitReader)
{
if (_splitReader == null)
{
if (NetworkManager is null)
{
NetworkManagerExtensions.LogError($"SplitReader cannot be returned because the NetworkManager reference is null.");
splitReader = null;
return false;
}
_splitReader = ResettableObjectCaches<SplitReader>.Retrieve();
_splitReader.Initialize(NetworkManager, NetworkManager.TransportManager.MaximumClientPacketSize, isSenderClient: true, expectedMessages);
}
splitReader = _splitReader;
return true;
}
/// <summary>
/// Stores the current SpitReader on this connection.
/// </summary>
internal void StoreSplitReader() => ResettableObjectCaches<SplitReader>.StoreAndDefault(ref _splitReader);
/// <summary>
/// Sends a broadcast to this connection.
/// </summary>
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Connection/NetworkConnection.Buffer.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Connection/NetworkConnection.Observers.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Connection/NetworkConnection.PingPong.cs
uploadId: 866910
uploadId: 892096
@@ -34,11 +34,11 @@ namespace FishNet.Connection
/// <param name = "data"></param>
internal void WriteState(PooledWriter data)
{
#if !DEVELOPMENT
#if !DEVELOPMENT
// Do not send states to clientHost.
if (IsLocalClient)
return;
#endif
#endif
TimeManager timeManager = NetworkManager.TimeManager;
TransportManager transportManager = NetworkManager.TransportManager;
@@ -51,21 +51,25 @@ namespace FishNet.Connection
int mtu = transportManager.GetLowestMTU((byte)Channel.Unreliable);
PooledWriter stateWriter;
int writerCount = PredictionStateWriters.Count;
/* Conditions to create a new writer are:
* - writer does not exist yet.
* - data length + currentWriter length > mtu */
Channel channel = Channel.Unreliable;
if (writerCount > 0)
transportManager.CheckSetReliableChannel(data.Length + PredictionStateWriters[writerCount - 1].Length, ref channel);
/* If no writers or if channel would be forced reliable.
*
* By checking if channel would be reliable this is
* essentially asking if (current written + new data) would
* exceed mtu. When it would get a new writer to try
* and favor unreliable. Emphasis on try, because if some
* really unlikely chance the data was really large it would
* still send on reliable down the line. */
if (writerCount == 0 || channel == Channel.Reliable)
//If there are no writers then get a new writer.
if (writerCount == 0 || data.Length > mtu)
{
AddNewStateWriter();
}
/* If a current writer exist and
* if the data length + existing written data will exceed
* MTU then get a new writer. */
else
{
int lengthInCurrentWriter = PredictionStateWriters[writerCount - 1].Length;
int totalLength = lengthInCurrentWriter + data.Length;
if (totalLength > mtu)
AddNewStateWriter();
}
void AddNewStateWriter()
{
stateWriter = WriterPool.Retrieve(mtu);
PredictionStateWriters.Add(stateWriter);
@@ -73,12 +77,11 @@ namespace FishNet.Connection
/// 2 PacketId.
/// 4 Last replicate tick run for connection.
/// 4 Length unpacked.
}
else
{
stateWriter = PredictionStateWriters[writerCount - 1];
writerCount++;
}
stateWriter = PredictionStateWriters[writerCount - 1];
stateWriter.WriteArraySegment(data.GetArraySegment());
}
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Connection/NetworkConnection.Prediction.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Connection/NetworkConnection.QOL.cs
uploadId: 866910
uploadId: 892096
@@ -7,6 +7,7 @@ using GameKit.Dependencies.Utilities;
using System;
using System.Collections.Generic;
using FishNet.Broadcast;
using FishNet.Managing.Transporting;
using FishNet.Transporting;
using UnityEngine.SceneManagement;
using static FishNet.Managing.Timing.EstimatedTick;
@@ -462,6 +463,8 @@ namespace FishNet.Connection
foreach (PacketBundle p in _toClientBundles)
p.Dispose();
_toClientBundles.Clear();
StoreSplitReader();
ServerConnectionTick = 0;
PacketTick.Reset();
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Connection/NetworkConnection.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Connection/OldTickOption.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Documenting/Attributes.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/BuildIdentifier.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/CodeStripping.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/BetaModeMenu.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/ConfigurationData.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/ConfigurationEditor.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/Configuring.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/DelayedEditorTasks.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/EditorCloning/CloneChecker.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/EditorCloning/EditorCloneType.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/FIshNetGettingStartedEditor.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/ReserializeNetworkObjectsEditor.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/ReviewReminderEditor.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Configuring/SettingsProvider.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Constants.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/DefaultPrefabsFinder.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Finding.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/ForceInstallPreventor.cs
uploadId: 866910
uploadId: 892096
@@ -0,0 +1,66 @@
using System.Collections.Generic;
using FishNet.Managing;
using FishNet.Managing.Statistic;
using FishNet.Transporting;
using GameKit.Dependencies.Utilities;
using UnityEngine;
namespace FishNet.Editing.NetworkProfiler
{
/// <summary>
/// Used to store Inbound and Outbound traffic details.
/// </summary>
public class BidirectionalNetworkTraffic : IResettable
{
/// <summary>
/// Received traffic.
/// </summary>
internal NetworkTraffic InboundTraffic;
/// <summary>
/// Sent traffic.
/// </summary>
internal NetworkTraffic OutboundTraffic;
/// <summary>
/// Creates a clone of this class using cache.
/// </summary>
/// <returns></returns>
public BidirectionalNetworkTraffic CloneUsingCache()
{
if (InboundTraffic == null)
{
NetworkManagerExtensions.LogError($"One or more NetworkTraffic values is null. {nameof(BidirectionalNetworkTraffic)} cannot be cloned.");
return null;
}
BidirectionalNetworkTraffic traffic = ResettableObjectCaches<BidirectionalNetworkTraffic>.Retrieve();
traffic.InboundTraffic = InboundTraffic;
traffic.OutboundTraffic = OutboundTraffic;
return traffic;
}
/// <summary>
/// Re-initializes by calling ResetState, then InitializeState.
/// </summary>
public void Reinitialize()
{
ResetState();
InitializeState();
}
public void ResetState()
{
ResettableObjectCaches<NetworkTraffic>.StoreAndDefault(ref InboundTraffic);
ResettableObjectCaches<NetworkTraffic>.StoreAndDefault(ref OutboundTraffic);
}
public void InitializeState()
{
InboundTraffic = ResettableObjectCaches<NetworkTraffic>.Retrieve();
OutboundTraffic = ResettableObjectCaches<NetworkTraffic>.Retrieve();
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 785b3b8173586e8429ac05c83e552200
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/NetworkProfiler/BidirectionNetworkTraffic.cs
uploadId: 892096
@@ -1 +1 @@
//
//
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/NetworkProfiler/NetworkProfilerWindow.cs
uploadId: 866910
uploadId: 892096
@@ -0,0 +1,77 @@
using System.Collections.Generic;
using FishNet.Managing.Statistic;
using FishNet.Transporting;
using GameKit.Dependencies.Utilities;
using UnityEngine;
namespace FishNet.Editing.NetworkProfiler
{
internal class NetworkTraffic : IResettable
{
/// <summary>
/// PacketGroup for each PacketId processed.
/// </summary>
private Dictionary<PacketId, PacketGroup> _packetGroups;
/// <summary>
/// Total bytes for all packets.
/// </summary>
public ulong Bytes;
/// <summary>
/// Adds traffic from a specified packetId.
/// </summary>
public void AddPacketIdData(PacketId packetId, string details, ulong bytes, GameObject gameObject) => LAddPacketId(packetId, details, bytes, gameObject);
/// <summary>
/// Adds traffic from a specified packetId.
/// </summary>
public void AddSocketData(ulong bytes)
{
LAddPacketId(NetworkTrafficStatistics.UNSPECIFIED_PACKETID, details: string.Empty, bytes, gameObject: null);
Bytes += bytes;
}
/// <summary>
/// Adds traffic to a PackerGroup.
/// </summary>
private void LAddPacketId(PacketId packetId, string details, ulong bytes, GameObject gameObject)
{
if (!_packetGroups.TryGetValue(packetId, out PacketGroup packetGroup))
{
packetGroup = ResettableObjectCaches<PacketGroup>.Retrieve();
packetGroup.Initialize(packetId);
_packetGroups[packetId] = packetGroup;
}
packetGroup.AddPacket(details, bytes, gameObject);
}
/// <summary>
/// Calculates and sets Percentage value on each PacketGroup.
/// </summary>
/// <remarks>This should only be called after all PacketGroup entries have been created.</remarks>
public void SetPacketGroupPercentages()
{
//Field would probably get cached at runtime during iteration but let's be certain.
ulong bytes = Bytes;
foreach (PacketGroup pg in _packetGroups.Values)
pg.SetPercent(bytes);
}
public void ResetState()
{
Bytes = 0;
ResettableT2CollectionCaches<PacketId, PacketGroup>.StoreAndDefault(ref _packetGroups);
}
public void InitializeState()
{
_packetGroups = ResettableT2CollectionCaches<PacketId, PacketGroup>.RetrieveDictionary();
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: e4cbde918bea7114f9f2a588ad4ee7f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/NetworkProfiler/NetworkTraffic.cs
uploadId: 892096
@@ -0,0 +1,38 @@
using UnityEngine;
namespace FishNet.Editing.NetworkProfiler
{
/// <summary>
/// Information about a single packet.
/// </summary>
public struct Packet
{
/// <summary>
/// Details about the packet, such as method or class name.
/// </summary>
/// <remarks>This may be empty.</remarks>
public string Details;
/// <summary>
/// Bytes used.
/// </summary>
public ulong Bytes;
/// <summary>
/// Originating GameObject.
/// </summary>
/// <remarks>GameObject is used rather than a script reference because we do not want to risk unintentionally holding a script in memory. Unity will automatically clean up GameObjects, so they are safe to reference.</remarks>
public GameObject GameObject;
public Packet(ulong bytes) : this(details: string.Empty, bytes, gameObject: null) { }
public Packet(string details, ulong bytes) : this(details, bytes, gameObject: null) { }
public Packet(ulong bytes, GameObject gameObject) : this(details: string.Empty, bytes, gameObject) { }
public Packet(string details, ulong bytes, GameObject gameObject)
{
Details = details;
Bytes = bytes;
GameObject = gameObject;
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 1627b8515051d874499946a603f1dad8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/NetworkProfiler/Packet.cs
uploadId: 892096
@@ -0,0 +1,73 @@
using System.Collections.Generic;
using FishNet.Managing.Statistic;
using FishNet.Transporting;
using GameKit.Dependencies.Utilities;
using UnityEngine;
namespace FishNet.Editing.NetworkProfiler
{
/// <summary>
/// Container for multiple Packets of the same type.
/// </summary>
public class PacketGroup : IResettable
{
/// <summary>
/// PacketId of this metric.
/// </summary>
public PacketId PacketId { get; private set; } = PacketId.Unset;
/// <summary>
/// Bytes of all packets using PacketId.
/// </summary>
public ulong Bytes { get; private set; }
/// <summary>
/// Percent Bytes is when compared against Bytes of other PacketMetrics.
/// </summary>
/// <remarks>This can only be completed after all Packet entries for each PacketId are added.</remarks>
public float Percent { get; private set; }
/// <summary>
/// True if PacketId is for unspecified packets.
/// </summary>
public bool IsUnspecifiedPacketId => PacketId == NetworkTrafficStatistics.UNSPECIFIED_PACKETID;
/// <summary>
/// Currently added packets.
/// </summary>
private List<Packet> _packets = new();
public void Initialize(PacketId packetId)
{
PacketId = packetId;
}
/// <summary>
/// Adds traffic from a specified packetId.
/// </summary>
public void AddPacket(string details, ulong bytes, GameObject gameObject)
{
Bytes += bytes;
_packets.Add(new(details, bytes, gameObject));
}
/// <summary>
/// Sets Percent using Bytes against allPacketGroupBytes.
/// </summary>
public void SetPercent(ulong allPacketGroupBytes)
{
//Prevent divide by 0.
if (Bytes == 0)
Percent = 0;
else
Percent = (float)Bytes / allPacketGroupBytes;
}
public void ResetState()
{
PacketId = PacketId.Unset;
Bytes = 0;
Percent = 0f;
_packets.Clear();
}
public void InitializeState() { }
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: ef191f8bce876e345839e0989dcb86a4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/NetworkProfiler/PacketGroup.cs
uploadId: 892096
@@ -0,0 +1,50 @@
using FishNet.Managing.Timing;
using GameKit.Dependencies.Utilities;
namespace FishNet.Editing.NetworkProfiler
{
/// <summary>
/// Data for a profiled tick.
/// </summary>
internal class ProfiledTickData : IResettable
{
/// <summary>
/// Tick this is for.
/// </summary>
public uint Tick;
/// <summary>
/// Traffic collection for the server.
/// </summary>
public BidirectionalNetworkTraffic ServerTraffic;
/// <summary>
/// Traffic collection for the client.
/// </summary>
public BidirectionalNetworkTraffic ClientTraffic;
/// <summary>
/// Initializes and returns if successful.
/// </summary>
public bool TryInitialize(uint tick, BidirectionalNetworkTraffic serverTraffic, BidirectionalNetworkTraffic clientTraffic)
{
Tick = tick;
ServerTraffic = serverTraffic.CloneUsingCache();
ClientTraffic = clientTraffic.CloneUsingCache();
return ServerTraffic != null && ClientTraffic != null;
}
/// <summary>
/// Resets all values and stores to caches as needed.
/// </summary>
public void ResetState()
{
Tick = TimeManager.UNSET_TICK;
ResettableObjectCaches<BidirectionalNetworkTraffic>.StoreAndDefault(ref ServerTraffic);
ResettableObjectCaches<BidirectionalNetworkTraffic>.StoreAndDefault(ref ClientTraffic);
}
public void InitializeState() { }
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c77264c7e46d6694caaa14c5446a6fd5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/NetworkProfiler/ProfiledTickData.cs
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/NewNetworkBehaviour/CreateNewNetworkBehaviour.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/NewNetworkBehaviour/SettingsProvider.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/PlayModeTracker.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/PrefabCollectionGenerator/Generator.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/PrefabCollectionGenerator/SettingsProvider.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/ScriptingDefines.cs
uploadId: 866910
uploadId: 892096
@@ -94,6 +94,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Textures/Icon/fishnet_light.png
uploadId: 866910
uploadId: 892096
@@ -137,6 +137,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Textures/UI/Client_Text.png
uploadId: 866910
uploadId: 892096
@@ -137,6 +137,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Textures/UI/FishNet_Text.png
uploadId: 866910
uploadId: 892096
@@ -137,6 +137,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Textures/UI/Logo_With_Text.png
uploadId: 866910
uploadId: 892096
@@ -137,6 +137,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Textures/UI/Server_Text.png
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Editor/Upgrading/UpgradeFromV3ToV4Menu.cs
uploadId: 866910
uploadId: 892096
@@ -9,6 +9,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/FishNet.Runtime.asmdef
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/NetworkAnimator/Editor/NetworkAnimatorEditor.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/NetworkAnimator/NetworkAnimator.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/NetworkTransform/Editor/NetworkTransformEditor.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/NetworkTransform/NetworkTransform.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/NetworkTransform/SynchronizedProperty.cs
uploadId: 866910
uploadId: 892096
@@ -1,10 +1,6 @@
using FishNet.Object;
using GameKit.Dependencies.Utilities;
using GameKit.Dependencies.Utilities.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine;
using TimeManagerCls = FishNet.Managing.Timing.TimeManager;
@@ -15,15 +11,15 @@ namespace FishNet.Component.Prediction
/// <summary>
/// Called when another collider enters this collider.
/// </summary>
public event Action<Collider> OnEnter;
public event Action<Collider, uint> OnEnter;
/// <summary>
/// Called when another collider stays in this collider.
/// </summary>
public event Action<Collider> OnStay;
public event Action<Collider, uint> OnStay;
/// <summary>
/// Called when another collider exits this collider.
/// </summary>
public event Action<Collider> OnExit;
public event Action<Collider, uint> OnExit;
/// <summary>
/// The colliders on this object.
/// </summary>
@@ -33,66 +29,82 @@ namespace FishNet.Component.Prediction
/// </summary>
private Collider[] _hits;
/// <summary>
/// The history of collider data.
/// Colliders which are entered for a tick, be it stay or for the first time.
/// </summary>
private Dictionary<Collider, CollisionData> _enteredColliders;
private Dictionary<uint, HashSet<Collider>> _enteredColliders;
protected override void Awake()
{
base.Awake();
_enteredColliders = CollectionCaches<Collider, CollisionData>.RetrieveDictionary();
_enteredColliders = CollectionCaches<uint, HashSet<Collider>>.RetrieveDictionary();
_hits = CollectionCaches<Collider>.RetrieveArray();
if (_hits.Length < MaximumSimultaneousHits)
_hits = new Collider[MaximumSimultaneousHits];
}
private void OnDestroy()
public override void OnStopNetwork()
{
CollectionCaches<Collider, CollisionData>.StoreAndDefault(ref _enteredColliders);
base.OnStopNetwork();
StoreEnteredColliders(keepDictionary: true);
_enteredColliders?.Clear();
}
protected override void OnDestroy()
{
base.OnDestroy();
StoreEnteredColliders(keepDictionary: false);
CollectionCaches<Collider>.StoreAndDefault(ref _hits, _hits.Length);
}
/// <summary>
/// Called by the PredictionManager immediately before a reconcile begins.
/// </summary>
protected override void PredictionManager_OnPreReconcile(uint clientTick, uint serverTick)
protected override void PredictionManager_OnPostPhysicsTransformSync(uint clientTick, uint serverTick)
{
/* Remove entries older than the reconcile clientTick, if
* the entry is exited - as in the collider is no longer occupied. */
if (_enteredColliders.Count > 0)
{
List<Collider> entriesToRemove = CollectionCaches<Collider>.RetrieveList();
if (IsStopping)
return;
foreach (KeyValuePair<Collider, CollisionData> kvp in _enteredColliders)
if (clientTick > 0)
{
List<uint> keysToRemove = CollectionCaches<uint>.RetrieveList();
uint maximumTick = clientTick - 2;
foreach (uint enteredTick in _enteredColliders.Keys)
{
uint exitTick = kvp.Value.ExitTick;
if (exitTick != TimeManagerCls.UNSET_TICK && exitTick < clientTick)
entriesToRemove.Add(kvp.Key);
if (enteredTick < maximumTick)
keysToRemove.Add(enteredTick);
}
foreach (Collider entry in entriesToRemove)
_enteredColliders.Remove(entry);
foreach (uint tick in keysToRemove)
{
HashSet<Collider> colliders = _enteredColliders[tick];
CollectionCaches<Collider>.Store(colliders);
CollectionCaches<Collider>.Store(entriesToRemove);
_enteredColliders.Remove(tick);
}
CollectionCaches<uint>.Store(keysToRemove);
}
/* Call base only after removing old entries. This ensures old entries are removed
* before CheckColliders is called. */
base.PredictionManager_OnPreReconcile(clientTick, serverTick);
base.PredictionManager_OnPostPhysicsTransformSync(clientTick, serverTick);
}
/// <summary>
/// Checks for any collider changes;
/// </summary>
protected override void CheckColliders(uint clientTick)
protected override void CheckColliders(uint localTick)
{
// Initial checks failed.
if (!TryPrepareColliderCheck(clientTick))
if (!TryPrepareColliderCheck(localTick))
return;
HashSet<Collider> current = CollectionCaches<Collider>.RetrieveHashSet();
Dictionary<Collider, CollisionData> entered = _enteredColliders;
/* Previous may not be set here if there were
* no collisions during the previous tick. */
@@ -127,79 +139,78 @@ namespace FishNet.Component.Prediction
continue;
current.Add(hit);
}
// Already entered.
if (entered.TryGetValueIL2CPP(hit, out CollisionData collisionData))
/* If the colliders already exist then the tick is being
* run again, which would indicate this is being run during a reconcile.
*
* Since this key will have its data replaced with current, store the prior collection.*/
if (_enteredColliders.TryGetValueIL2CPP(localTick, out HashSet<Collider> enteredColliders))
{
CollectionCaches<Collider>.Store(enteredColliders);
_enteredColliders.Remove(localTick);
}
const uint unsetLastTick = uint.MaxValue;
uint lastTick = localTick > 1 ? localTick - 1 : unsetLastTick;
_enteredColliders.TryGetValueIL2CPP(lastTick, out HashSet<Collider> lastEnteredColliders);
/* If there are entered colliders then
* update enteredColliders for the tick. */
if (current.Count > 0)
{
_enteredColliders[localTick] = current;
/* If there were no colliders last tick
* then without a doubt enter should be called since
* the collider could not possibly be present already. */
if (lastEnteredColliders == null)
{
/* If entered tick is beyond the tick being checked then
* that means the collider entered at a later time, and something
* is not aligning. Invoke OnExit and OnEnter again. */
if (collisionData.EnterTick >= clientTick || collisionData.ExitTick != TimeManagerCls.UNSET_TICK)
//Invoke OnEnter for every collider in current.
foreach (Collider c in current)
OnEnter?.Invoke(c, localTick);
}
/* If the last collection is found then
* check to invoke Enter or Stay. */
else
{
foreach (Collider c in current)
{
OnExit?.Invoke(hit);
OnEnter?.Invoke(hit);
// Also update position in collection.
entered[hit] = new(clientTick);
if (lastEnteredColliders.Contains(c))
OnStay?.Invoke(c, localTick);
else
OnEnter?.Invoke(c, localTick);
}
}
// Not yet in entered state.
else
{
OnEnter?.Invoke(hit);
// Also update position in collection.
entered[hit] = new(clientTick);
}
// Always invoke OnStay when collider hits.
OnStay?.Invoke(hit);
}
List<Collider> collidersExited = CollectionCaches<Collider>.RetrieveList();
/* Check to invoke exit on any colliders which are no longer
* in the entered state. */
foreach (Collider c in entered.Keys)
//If current is empty the collection can be stored.
else
{
// Collider was still entered, no need to check exit.
if (current.Contains(c))
continue;
/* Entered tick will be the same as tick if first
* entering for this tick. It's not possible for Unity physics
* to invoke Enter/Exit on the same tick, as it doesn't make sense
* to anyway. When the same tick, continue. */
if (entered[c].EnterTick == clientTick)
continue;
collidersExited.Add(c);
CollectionCaches<Collider>.Store(current);
}
// Invoke for exited and remove from entered.
foreach (Collider c in collidersExited)
/* Check to invoke OnExit. */
if (lastEnteredColliders != null)
{
/* If here then the entered collider was not hit
* this trace. Invoke exit and remove from entered. */
OnExit?.Invoke(c);
if (IsServerStarted)
/* If current does not have the colliders from
* the last tick, then an exit has occurred. */
foreach (Collider c in lastEnteredColliders)
{
entered.Remove(c);
if (!current.Contains(c))
OnExit?.Invoke(c, localTick);
}
else
{
/* Only re-add if the entered tick is beyond
* the current tick; this would indicate a new enter.
* Otherwise, we are at an exit only. */
uint enteredTick = entered[c].EnterTick;
if (enteredTick > clientTick)
entered[c] = new(entered[c].EnterTick, clientTick);
else
entered.Remove(c);
}
}
CollectionCaches<Collider>.Store(collidersExited);
/* If the server is started the lastEnteredColliders can
* be discarded since the server will never reconcile, and
* will never need to check them again. */
if (IsServerStarted)
{
if (lastTick is not unsetLastTick)
_enteredColliders.Remove(lastTick);
}
}
CollectionCaches<Collider>.Store(current);
}
/// <summary>
@@ -274,18 +285,34 @@ namespace FishNet.Component.Prediction
* to get the proper tick to invoke. */
if (invokeOnExit)
{
foreach (KeyValuePair<Collider, CollisionData> kvp in _enteredColliders)
uint largestTick = 0;
foreach (uint tick in _enteredColliders.Keys)
largestTick = Math.Max(tick, largestTick);
if (_enteredColliders.TryGetValueIL2CPP(largestTick, out HashSet<Collider> colliders))
{
/* This indicates an exit has not yet invoked.
* It's possible for an item to invoked an exit and still
* have its state cached for properly executing events during
* a reconcile. */
if (kvp.Value.ExitTick == TimeManagerCls.UNSET_TICK)
OnExit?.Invoke(kvp.Key);
if (colliders != null)
{
foreach (Collider c in colliders)
OnExit?.Invoke(c, TimeManagerCls.UNSET_TICK);
}
}
}
StoreEnteredColliders(keepDictionary: true);
_enteredColliders.Clear();
}
/// <summary>
/// Stores each Collider HashSet within EnteredColliders.
/// </summary>
private void StoreEnteredColliders(bool keepDictionary)
{
foreach (HashSet<Collider> colliders in _enteredColliders.Values)
CollectionCaches<Collider>.Store(colliders);
if (!keepDictionary)
CollectionCaches<uint, HashSet<Collider>>.Store(_enteredColliders);
}
}
}
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollider.cs
uploadId: 866910
uploadId: 892096
@@ -1,10 +1,6 @@
using FishNet.Managing;
using FishNet.Object;
using GameKit.Dependencies.Utilities;
using GameKit.Dependencies.Utilities.Types;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using TimeManagerCls = FishNet.Managing.Timing.TimeManager;
@@ -15,15 +11,15 @@ namespace FishNet.Component.Prediction
/// <summary>
/// Called when another collider enters this collider.
/// </summary>
public event Action<Collider2D> OnEnter;
public event Action<Collider2D, uint> OnEnter;
/// <summary>
/// Called when another collider stays in this collider.
/// </summary>
public event Action<Collider2D> OnStay;
public event Action<Collider2D, uint> OnStay;
/// <summary>
/// Called when another collider exits this collider.
/// </summary>
public event Action<Collider2D> OnExit;
public event Action<Collider2D, uint> OnExit;
/// <summary>
/// The colliders on this object.
/// </summary>
@@ -33,66 +29,82 @@ namespace FishNet.Component.Prediction
/// </summary>
private Collider2D[] _hits;
/// <summary>
/// The history of collider data.
/// Colliders which are entered for a tick, be it stay or for the first time.
/// </summary>
private Dictionary<Collider2D, CollisionData> _enteredColliders;
private Dictionary<uint, HashSet<Collider2D>> _enteredColliders;
protected override void Awake()
{
base.Awake();
_enteredColliders = CollectionCaches<Collider2D, CollisionData>.RetrieveDictionary();
_enteredColliders = CollectionCaches<uint, HashSet<Collider2D>>.RetrieveDictionary();
_hits = CollectionCaches<Collider2D>.RetrieveArray();
if (_hits.Length < MaximumSimultaneousHits)
_hits = new Collider2D[MaximumSimultaneousHits];
}
private void OnDestroy()
public override void OnStopNetwork()
{
CollectionCaches<Collider2D, CollisionData>.StoreAndDefault(ref _enteredColliders);
base.OnStopNetwork();
StoreEnteredColliders(keepDictionary: true);
_enteredColliders?.Clear();
}
protected override void OnDestroy()
{
base.OnDestroy();
CollectionCaches<uint, HashSet<Collider2D>>.StoreAndDefault(ref _enteredColliders);
CollectionCaches<Collider2D>.StoreAndDefault(ref _hits, _hits.Length);
}
/// <summary>
/// Called by the PredictionManager immediately before a reconcile begins.
/// </summary>
protected override void PredictionManager_OnPreReconcile(uint clientTick, uint serverTick)
protected override void PredictionManager_OnPostPhysicsTransformSync(uint clientTick, uint serverTick)
{
/* Remove entries older than the reconcile clientTick, if
* the entry is exited - as in the collider is no longer occupied. */
if (_enteredColliders.Count > 0)
{
List<Collider2D> entriesToRemove = CollectionCaches<Collider2D>.RetrieveList();
if (IsStopping)
return;
foreach (KeyValuePair<Collider2D, CollisionData> kvp in _enteredColliders)
if (clientTick > 0)
{
List<uint> keysToRemove = CollectionCaches<uint>.RetrieveList();
uint maximumTick = clientTick - 2;
foreach (uint enteredTick in _enteredColliders.Keys)
{
uint exitTick = kvp.Value.ExitTick;
if (exitTick != TimeManagerCls.UNSET_TICK && exitTick < clientTick)
entriesToRemove.Add(kvp.Key);
if (enteredTick < maximumTick)
keysToRemove.Add(enteredTick);
}
foreach (Collider2D entry in entriesToRemove)
_enteredColliders.Remove(entry);
foreach (uint tick in keysToRemove)
{
HashSet<Collider2D> colliders = _enteredColliders[tick];
CollectionCaches<Collider2D>.Store(colliders);
CollectionCaches<Collider2D>.Store(entriesToRemove);
_enteredColliders.Remove(tick);
}
CollectionCaches<uint>.Store(keysToRemove);
}
/* Call base only after removing old entries. This ensures old entries are removed
* before CheckColliders is called. */
base.PredictionManager_OnPreReconcile(clientTick, serverTick);
base.PredictionManager_OnPostPhysicsTransformSync(clientTick, serverTick);
}
/// <summary>
/// Checks for any collider changes;
/// </summary>
protected override void CheckColliders(uint clientTick)
protected override void CheckColliders(uint localTick)
{
// Initial checks failed.
if (!TryPrepareColliderCheck(clientTick))
// Initial checks failed.
if (!TryPrepareColliderCheck(localTick))
return;
HashSet<Collider2D> current = CollectionCaches<Collider2D>.RetrieveHashSet();
Dictionary<Collider2D, CollisionData> entered = _enteredColliders;
/* Previous may not be set here if there were
* no collisions during the previous tick. */
@@ -108,6 +120,7 @@ namespace FishNet.Component.Prediction
if (IsTrigger != col.isTrigger)
continue;
// Number of hits from the checks.
// Number of hits from the checks.
int hits;
if (col is CircleCollider2D circleCollider)
@@ -125,78 +138,78 @@ namespace FishNet.Component.Prediction
continue;
current.Add(hit);
}
// Already entered.
if (entered.TryGetValueIL2CPP(hit, out CollisionData collisionData))
/* If the colliders already exist then the tick is being
* run again, which would indicate this is being run during a reconcile.
*
* Since this key will have its data replaced with current, store the prior collection.*/
if (_enteredColliders.TryGetValueIL2CPP(localTick, out HashSet<Collider2D> enteredColliders))
{
CollectionCaches<Collider2D>.Store(enteredColliders);
_enteredColliders.Remove(localTick);
}
const uint unsetLastTick = uint.MaxValue;
uint lastTick = localTick > 1 ? localTick - 1 : unsetLastTick;
_enteredColliders.TryGetValueIL2CPP(lastTick, out HashSet<Collider2D> lastEnteredColliders);
/* If there are entered colliders then
* update enteredColliders for the tick. */
if (current.Count > 0)
{
_enteredColliders[localTick] = current;
/* If there were no colliders last tick
* then without a doubt enter should be called since
* the collider could not possibly be present already. */
if (lastEnteredColliders == null)
{
/* If entered tick is beyond the tick being checked then
* that means the collider entered at a later time, and something
* is not aligning. Invoke OnExit and OnEnter again. */
if (collisionData.EnterTick >= clientTick || collisionData.ExitTick != TimeManagerCls.UNSET_TICK)
//Invoke OnEnter for every collider in current.
foreach (Collider2D c in current)
OnEnter?.Invoke(c, localTick);
}
/* If the last collection is found then
* check to invoke Enter or Stay. */
else
{
foreach (Collider2D c in current)
{
OnExit?.Invoke(hit);
OnEnter?.Invoke(hit);
// Also update position in collection.
entered[hit] = new(clientTick);
if (lastEnteredColliders.Contains(c))
OnStay?.Invoke(c, localTick);
else
OnEnter?.Invoke(c, localTick);
}
}
// Not yet in entered state.
else
{
OnEnter?.Invoke(hit);
// Also update position in collection.
entered[hit] = new(clientTick);
}
// Always invoke OnStay when collider hits.
OnStay?.Invoke(hit);
}
//If current is empty the collection can be stored.
else
{
CollectionCaches<Collider2D>.Store(current);
}
List<Collider2D> collidersExited = CollectionCaches<Collider2D>.RetrieveList();
/* Check to invoke exit on any colliders which are no longer
* in the entered state. */
foreach (Collider2D c in entered.Keys)
/* Check to invoke OnExit. */
if (lastEnteredColliders != null)
{
// Collider was still entered, no need to check exit.
if (current.Contains(c))
continue;
/* Entered tick will be the same as tick if first
* entering for this tick. It's not possible for Unity physics
* to invoke Enter/Exit on the same tick, as it doesn't make sense
* to anyway. When the same tick, continue. */
if (entered[c].EnterTick == clientTick)
continue;
collidersExited.Add(c);
/* If current does not have the colliders from
* the last tick, then an exit has occurred. */
foreach (Collider2D c in lastEnteredColliders)
{
if (!current.Contains(c))
OnExit?.Invoke(c, localTick);
}
}
// Invoke for exited and remove from entered.
foreach (Collider2D c in collidersExited)
/* If the server is started the lastEnteredColliders can
* be discarded since the server will never reconcile, and
* will never need to check them again. */
if (IsServerStarted)
{
/* If here then the entered collider was not hit
* this trace. Invoke exit and remove from entered. */
OnExit?.Invoke(c);
if (IsServerStarted)
{
entered.Remove(c);
}
else
{
/* Only re-add if the entered tick is beyond
* the current tick; this would indicate a new enter.
* Otherwise, we are at an exit only. */
uint enteredTick = entered[c].EnterTick;
if (enteredTick > clientTick)
entered[c] = new(entered[c].EnterTick, clientTick);
else
entered.Remove(c);
}
// entered.Remove(c);
if (lastTick is not unsetLastTick)
_enteredColliders.Remove(lastTick);
}
}
CollectionCaches<Collider2D>.Store(current);
}
/// <summary>
@@ -260,18 +273,34 @@ namespace FishNet.Component.Prediction
* to get the proper tick to invoke. */
if (invokeOnExit)
{
foreach (KeyValuePair<Collider2D, CollisionData> kvp in _enteredColliders)
uint largestTick = 0;
foreach (uint tick in _enteredColliders.Keys)
largestTick = Math.Max(tick, largestTick);
if (_enteredColliders.TryGetValueIL2CPP(largestTick, out HashSet<Collider2D> colliders))
{
/* This indicates an exit has not yet invoked.
* It's possible for an item to invoked an exit and still
* have its state cached for properly executing events during
* a reconcile. */
if (kvp.Value.ExitTick == TimeManagerCls.UNSET_TICK)
OnExit?.Invoke(kvp.Key);
if (colliders != null)
{
foreach (Collider2D c in colliders)
OnExit?.Invoke(c, TimeManagerCls.UNSET_TICK);
}
}
}
StoreEnteredColliders(keepDictionary: true);
_enteredColliders.Clear();
}
/// <summary>
/// Stores each Collider HashSet within EnteredColliders.
/// </summary>
private void StoreEnteredColliders(bool keepDictionary)
{
foreach (HashSet<Collider2D> colliders in _enteredColliders.Values)
CollectionCaches<Collider2D>.Store(colliders);
if (!keepDictionary)
CollectionCaches<uint, HashSet<Collider2D>>.Store(_enteredColliders);
}
}
}
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollider2D.cs
uploadId: 866910
uploadId: 892096
@@ -9,32 +9,6 @@ namespace FishNet.Component.Prediction
{
public abstract class NetworkColliderBase : NetworkBehaviour
{
#region Types.
protected struct CollisionData
{
/// <summary>
/// Tick when entering collision.
/// </summary>
public uint EnterTick;
/// <summary>
/// Tick when exiting collision.
/// </summary>
public uint ExitTick;
public CollisionData(uint enterTick) : this()
{
EnterTick = enterTick;
ExitTick = Managing.Timing.TimeManager.UNSET_TICK;
}
public CollisionData(uint enterTick, uint exitTick) : this()
{
EnterTick = enterTick;
ExitTick = exitTick;
}
}
#endregion
/// <summary>
/// True to run collisions for colliders which are triggers, false to run collisions for colliders which are not triggers.
/// </summary>
@@ -76,15 +50,21 @@ namespace FishNet.Component.Prediction
/// </summary>
[HideInInspector]
protected int InteractableLayers;
/// <summary>
/// True if stopping or destroying.
/// </summary>
[HideInInspector]
protected bool IsStopping;
protected virtual void Awake()
{
TryFindColliders(force: true);
;
}
public override void OnStartNetwork()
{
IsStopping = false;
// Events needed by server and client.
TimeManager.OnPostPhysicsSimulation += TimeManager_OnPostPhysicsSimulation;
}
@@ -92,24 +72,33 @@ namespace FishNet.Component.Prediction
public override void OnStartClient()
{
// Events only needed by the client.
PredictionManager.OnPostReconcileSyncTransforms += PredictionManager_OnPreReconcile;
PredictionManager.OnPostPhysicsTransformSync += PredictionManager_OnPostPhysicsTransformSync;
}
public override void OnStopClient()
{
// Events only needed by the client.
PredictionManager.OnPostReconcileSyncTransforms -= PredictionManager_OnPreReconcile;
PredictionManager.OnPostPhysicsTransformSync -= PredictionManager_OnPostPhysicsTransformSync;
}
public override void OnStopNetwork()
{
IsStopping = true;
TimeManager.OnPostPhysicsSimulation -= TimeManager_OnPostPhysicsSimulation;
}
/// <summary>
/// Called by the PredictionManager immediately before a reconcile begins.
/// </summary>
protected virtual void PredictionManager_OnPreReconcile(uint clientTick, uint serverTick)
protected virtual void OnDestroy()
{
IsStopping = true;
if (TimeManager != null)
TimeManager.OnPostPhysicsSimulation -= TimeManager_OnPostPhysicsSimulation;
if (PredictionManager != null)
PredictionManager.OnPostPhysicsTransformSync -= PredictionManager_OnPostPhysicsTransformSync;
}
protected virtual void PredictionManager_OnPostPhysicsTransformSync(uint clientTick, uint serverTick)
{
CheckColliders(clientTick);
}
@@ -120,7 +109,7 @@ namespace FishNet.Component.Prediction
/// This may be useful if you wish to run physics differently for stacked scenes.
private void TimeManager_OnPostPhysicsSimulation(float delta)
{
uint tick = PredictionManager.IsReconciling && !IsServerStarted ? PredictionManager.ClientReplayTick : TimeManager.LocalTick;
uint tick = IsServerStarted || !PredictionManager.IsReconciling ? TimeManager.LocalTick : PredictionManager.ClientReplayTick;
CheckColliders(tick);
}
@@ -130,6 +119,9 @@ namespace FishNet.Component.Prediction
/// <returns>True if collision checking should proceed, false if not.</returns>
protected bool TryPrepareColliderCheck(uint tick)
{
if (IsStopping)
return false;
// Should not be possible as tick always starts on 1.
if (tick == TimeManagerCls.UNSET_TICK)
return false;
@@ -159,7 +151,7 @@ namespace FishNet.Component.Prediction
/// <summary>
/// Implement collider checking logic within this method.
/// </summary>
protected abstract void CheckColliders(uint clientTick);
protected abstract void CheckColliders(uint localTick);
/// <summary>
/// Clears stored collider states.
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkColliderBase.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollision.cs
uploadId: 866910
uploadId: 892096
@@ -1,13 +1,13 @@
using UnityEngine;
namespace FishNet.Component.Prediction
{
public sealed class NetworkCollision2D : NetworkCollider2D
{
protected override void Awake()
{
IsTrigger = false;
base.Awake();
}
}
}
// using UnityEngine;
//
// namespace FishNet.Component.Prediction
// {
// public sealed class NetworkCollision2D : NetworkCollider2D
// {
// protected override void Awake()
// {
// IsTrigger = false;
// base.Awake();
// }
// }
// }
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollision2D.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkTrigger.cs
uploadId: 866910
uploadId: 892096
@@ -1,11 +1,11 @@
namespace FishNet.Component.Prediction
{
public sealed class NetworkTrigger2D : NetworkCollider2D
{
protected override void Awake()
{
IsTrigger = true;
base.Awake();
}
}
}
// namespace FishNet.Component.Prediction
// {
// public sealed class NetworkTrigger2D : NetworkCollider2D
// {
// protected override void Awake()
// {
// IsTrigger = true;
// base.Awake();
// }
// }
// }
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkTrigger2D.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/OfflineRigidbody.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/RigidbodyPauser.cs
uploadId: 866910
uploadId: 892096
@@ -19,8 +19,8 @@ namespace FishNet.Component.Prediction
public RigidbodyState(Rigidbody rb, AutoPackType rotationPacking = AutoPackType.Packed)
{
Position = rb.transform.position;
Rotation = rb.transform.rotation;
Position = rb.transform.localPosition;
Rotation = rb.transform.localRotation;
IsKinematic = rb.isKinematic;
#if UNITY_6000_1_OR_NEWER
@@ -49,8 +49,8 @@ namespace FishNet.Component.Prediction
public Rigidbody2DState(Rigidbody2D rb, AutoPackType rotationPacking = AutoPackType.Packed)
{
Position = rb.transform.position;
Rotation = rb.transform.rotation;
Position = rb.transform.localPosition;
Rotation = rb.transform.localRotation;
RotationPacking = rotationPacking;
#if UNITY_6000_1_OR_NEWER
@@ -176,8 +176,8 @@ namespace FishNet.Component.Prediction
public static void SetState(this Rigidbody rb, RigidbodyState state)
{
Transform t = rb.transform;
t.position = state.Position;
t.rotation = state.Rotation;
t.localPosition = state.Position;
t.localRotation = state.Rotation;
rb.isKinematic = state.IsKinematic;
if (!state.IsKinematic)
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/RigidbodyState.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Prediction/RigidbodyType.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Spawning/PlayerSpawner.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/Spawning/ServerSpawner.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TakeOwnership/PredictedOwner.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TakeOwnership/PredictedSpawn.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/AdaptiveInterpolationType.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/Editor/MovementSettingsDrawer.Threaded.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/Editor/MovementSettingsDrawer.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/Editor/NetworkTickSmootherEditor.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/Editor/OfflineTickSmootherEditor.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/InitializationSettings.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/MovementSettings.Threaded.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/MovementSettings.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/NetworkTickSmoother.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/OfflineTickSmoother.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/TickSmootherController.Threaded.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/TickSmootherController.cs
uploadId: 866910
uploadId: 892096
@@ -13,6 +13,6 @@ AssetOrigin:
serializedVersion: 1
productId: 207815
packageName: 'FishNet: Networking Evolved'
packageVersion: 4.6.22R
packageVersion: 4.7.1R
assetPath: Assets/FishNet/Runtime/Generated/Component/TickSmoothing/TickSmoothingManager.Types.cs
uploadId: 866910
uploadId: 892096

Some files were not shown because too many files have changed in this diff Show More