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