Update FishNet
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user