1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-15 22:56:30 +09:00

major update; gen 3.5

This commit is contained in:
lidgren
2010-10-19 17:45:55 +00:00
parent baaa5926f8
commit 609bc1afe2
167 changed files with 4065 additions and 9640 deletions

View File

@@ -23,6 +23,9 @@ using System.Diagnostics;
namespace Lidgren.Network
{
/// <summary>
/// Statistics for a NetConnection instance
/// </summary>
public sealed class NetConnectionStatistics
{
private readonly NetConnection m_connection;
@@ -77,23 +80,12 @@ namespace Lidgren.Network
/// </summary>
public int ResentMessages { get { return m_resentMessages; } }
public double LastSendRespondedTo { get { return m_connection.m_lastSendRespondedTo; } }
public int MostSends
{
get
{
int most = 0;
foreach (var a in m_connection.m_unackedSends)
if (a.NumSends > most)
most = a.NumSends;
return most;
}
}
// public double LastSendRespondedTo { get { return m_connection.m_lastSendRespondedTo; } }
[Conditional("DEBUG")]
internal void PacketSent(int numBytes, int numMessages)
{
NetException.Assert(numBytes > 0 && numMessages > 0);
m_sentPackets++;
m_sentBytes += numBytes;
m_sentMessages += numMessages;
@@ -102,6 +94,7 @@ namespace Lidgren.Network
[Conditional("DEBUG")]
internal void PacketReceived(int numBytes, int numMessages)
{
NetException.Assert(numBytes > 0 && numMessages > 0);
m_receivedPackets++;
m_receivedBytes += numBytes;
m_receivedMessages += numMessages;
@@ -116,24 +109,47 @@ namespace Lidgren.Network
public override string ToString()
{
StringBuilder bdr = new StringBuilder();
bdr.AppendLine("Average roundtrip time: " + NetTime.ToReadable(m_connection.m_averageRoundtripTime));
//bdr.AppendLine("Average roundtrip time: " + NetTime.ToReadable(m_connection.m_averageRoundtripTime));
bdr.AppendLine("Sent " + m_sentBytes + " bytes in " + m_sentMessages + " messages in " + m_sentPackets + " packets");
bdr.AppendLine("Received " + m_receivedBytes + " bytes in " + m_receivedMessages + " messages in " + m_receivedPackets + " packets");
if (m_resentMessages > 0)
bdr.AppendLine("Resent messages: " + m_resentMessages);
int numUnsent = m_connection.m_unsentMessages.Count;
if (numUnsent > 0)
bdr.AppendLine("Unsent messages: " + numUnsent);
int numStored = m_connection.GetStoredMessagesCount();
if (numStored > 0)
bdr.AppendLine("Stored messages: " + numStored);
int numWithheld = m_connection.GetWithheldMessagesCount();
if (numWithheld > 0)
bdr.AppendLine("Withheld messages: " + numWithheld);
int numUnsent = 0;
int numStored = 0;
foreach (NetSenderChannelBase sendChan in m_connection.m_sendChannels)
{
if (sendChan == null)
continue;
numUnsent += sendChan.m_queuedSends.Count;
var relSendChan = sendChan as NetReliableSenderChannel;
if (relSendChan != null)
{
for (int i = 0; i < relSendChan.m_storedMessages.Length; i++)
if (relSendChan.m_storedMessages[i].Message != null)
numStored++;
}
}
int numWithheld = 0;
foreach (NetReceiverChannelBase recChan in m_connection.m_receiveChannels)
{
var relRecChan = recChan as NetReliableOrderedReceiver;
if (relRecChan != null)
{
for (int i = 0; i < relRecChan.m_withheldMessages.Length; i++)
if (relRecChan.m_withheldMessages[i] != null)
numWithheld++;
}
}
bdr.AppendLine("Unsent messages: " + numUnsent);
bdr.AppendLine("Stored messages: " + numStored);
bdr.AppendLine("Withheld messages: " + numWithheld);
return bdr.ToString();
}
}
}
}