Skip to content

Commit 7bbe9a3

Browse files
committed
Fixed headersize calculation in NetworkProfiler
1 parent d0aeae0 commit 7bbe9a3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,13 @@ private void Update()
681681
{
682682
if((NetworkTime - lastSendTickTime >= (1f / NetworkConfig.SendTickrate)) || NetworkConfig.SendTickrate <= 0)
683683
{
684-
NetworkProfiler.StartTick(TickType.Send);
685684
foreach (KeyValuePair<uint, NetworkedClient> pair in connectedClients)
686685
{
687686
byte error;
688687
NetworkConfig.NetworkTransport.SendQueue(pair.Key, out error);
689688
if (LogHelper.CurrentLogLevel <= LogLevel.Developer) LogHelper.LogInfo("Send Pending Queue: " + pair.Key);
690689
}
691690
lastSendTickTime = NetworkTime;
692-
NetworkProfiler.EndTick();
693691
}
694692
if((NetworkTime - lastReceiveTickTime >= (1f / NetworkConfig.ReceiveTickrate)) || NetworkConfig.ReceiveTickrate <= 0)
695693
{
@@ -838,8 +836,16 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId, uint
838836
else if (isPassthrough && !isServer)
839837
passthroughOrigin = reader.ReadUInt();
840838

841-
byte headerSize = 0; //TODO
842-
NetworkProfiler.StartEvent(TickType.Receive, totalSize - headerSize, channelId, messageType);
839+
long headerBitSize = BitWriter.GetBitCount(messageType) + BitWriter.GetBitCount(targeted);
840+
if (targeted) headerBitSize += BitWriter.GetBitCount(targetNetworkId) + BitWriter.GetBitCount(networkOrderId);
841+
headerBitSize += BitWriter.GetBitCount(isPassthrough);
842+
if (isPassthrough && isServer)
843+
headerBitSize += BitWriter.GetBitCount(passthroughTarget);
844+
else if (isPassthrough && !isServer)
845+
headerBitSize += BitWriter.GetBitCount(passthroughOrigin);
846+
847+
uint headerByteSize = (uint)Math.Ceiling(headerBitSize / 8d);
848+
NetworkProfiler.StartEvent(TickType.Receive, totalSize - headerByteSize, channelId, messageType);
843849

844850
if (LogHelper.CurrentLogLevel <= LogLevel.Developer) LogHelper.LogInfo("Data Header" +
845851
":messageHeader=" + messageType +

MLAPI/NetworkingManagerComponents/Binary/BitWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ private static Type GetUnsignedType(Type t) =>
359359
t == typeof(long) ? typeof(ulong) :
360360
null;
361361

362-
private static ulong ZigZagEncode(long d, int bytes) => (ulong)(((d >> (bytes * 8 - 1))&1) | (d << 1));
362+
public static ulong ZigZagEncode(long d, int bytes) => (ulong)(((d >> (bytes * 8 - 1))&1) | (d << 1));
363363

364-
private static long GetBitCount<T>(T t)
364+
public static long GetBitCount<T>(T t)
365365
{
366366
Type type = t.GetType();
367367
long count = 0;

0 commit comments

Comments
 (0)