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

Changed internal representation of time in a bunch of places from float to double

This commit is contained in:
lidgren
2015-01-17 16:35:01 +00:00
parent c15e4cb2c8
commit 999e113d65
7 changed files with 35 additions and 35 deletions

View File

@@ -4,10 +4,10 @@ namespace Lidgren.Network
{
public partial class NetConnection
{
private float m_sentPingTime;
private double m_sentPingTime;
private int m_sentPingNumber;
private float m_averageRoundtripTime;
private float m_timeoutDeadline = float.MaxValue;
private double m_averageRoundtripTime;
private double m_timeoutDeadline = double.MaxValue;
// local time value + m_remoteTimeOffset = remote time value
internal double m_remoteTimeOffset;
@@ -15,7 +15,7 @@ namespace Lidgren.Network
/// <summary>
/// Gets the current average roundtrip time in seconds
/// </summary>
public float AverageRoundtripTime { get { return m_averageRoundtripTime; } }
public float AverageRoundtripTime { get { return (float)m_averageRoundtripTime; } }
/// <summary>
/// Time offset between this peer and the remote peer
@@ -46,13 +46,13 @@ namespace Lidgren.Network
internal void InitializePing()
{
float now = (float)NetTime.Now;
double now = NetTime.Now;
// randomize ping sent time (0.25 - 1.0 x ping interval)
m_sentPingTime = now;
m_sentPingTime -= (m_peerConfiguration.PingInterval * 0.25f); // delay ping for a little while
m_sentPingTime -= (MWCRandom.Instance.NextSingle() * (m_peerConfiguration.PingInterval * 0.75f));
m_timeoutDeadline = now + (m_peerConfiguration.m_connectionTimeout * 2.0f); // initially allow a little more time
m_timeoutDeadline = now + (m_peerConfiguration.m_connectionTimeout * 2.0); // initially allow a little more time
// make it better, quick :-)
SendPing();
@@ -64,7 +64,7 @@ namespace Lidgren.Network
m_sentPingNumber++;
m_sentPingTime = (float)NetTime.Now;
m_sentPingTime = NetTime.Now;
NetOutgoingMessage om = m_peer.CreateMessage(1);
om.Write((byte)m_sentPingNumber); // truncating to 0-255
om.m_messageType = NetMessageType.Ping;
@@ -95,7 +95,7 @@ namespace Lidgren.Network
m_peer.Recycle(om);
}
internal void ReceivedPong(float now, int pongNumber, float remoteSendTime)
internal void ReceivedPong(double now, int pongNumber, float remoteSendTime)
{
if ((byte)pongNumber != (byte)m_sentPingNumber)
{
@@ -105,7 +105,7 @@ namespace Lidgren.Network
m_timeoutDeadline = now + m_peerConfiguration.m_connectionTimeout;
float rtt = now - m_sentPingTime;
double rtt = now - m_sentPingTime;
NetException.Assert(rtt >= 0);
double diff = (remoteSendTime + (rtt / 2.0)) - now;
@@ -118,14 +118,14 @@ namespace Lidgren.Network
}
else
{
m_averageRoundtripTime = (m_averageRoundtripTime * 0.7f) + (float)(rtt * 0.3f);
m_averageRoundtripTime = (m_averageRoundtripTime * 0.7) + (rtt * 0.3);
m_remoteTimeOffset = ((m_remoteTimeOffset * (double)(m_sentPingNumber - 1)) + diff) / (double)m_sentPingNumber;
m_peer.LogVerbose("Updated average roundtrip time to " + NetTime.ToReadable(m_averageRoundtripTime) + ", remote time to " + (now + m_remoteTimeOffset) + " (ie. diff " + m_remoteTimeOffset + ")");
}
// update resend delay for all channels
float resendDelay = GetResendDelay();
double resendDelay = GetResendDelay();
foreach (var chan in m_sendChannels)
{
var rchan = chan as NetReliableSenderChannel;