aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLee Salzman <[email protected]>2020-03-03 15:34:06 -0500
committerLee Salzman <[email protected]>2020-03-03 15:34:06 -0500
commit6537dc81f36ff9c8d5c5a0f53950e4d39b374475 (patch)
tree27312d33865d0cd9633616455bf5a2737db3b7c5
parent0eaf48eeb0d94a18d079378d8b76d588832ce838 (diff)
downloadenet-6537dc81f36ff9c8d5c5a0f53950e4d39b374475.tar.gz
enet-6537dc81f36ff9c8d5c5a0f53950e4d39b374475.zip
make RTT calculations more TCP-like (contributed by Vladimir 'virtul' Ivannikov)
-rw-r--r--protocol.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/protocol.c b/protocol.c
index eee7f88..afdef99 100644
--- a/protocol.c
+++ b/protocol.c
@@ -851,24 +851,39 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
if (ENET_TIME_LESS (host -> serviceTime, receivedSentTime))
return 0;
- peer -> lastReceiveTime = host -> serviceTime;
- peer -> earliestTimeout = 0;
-
roundTripTime = ENET_TIME_DIFFERENCE (host -> serviceTime, receivedSentTime);
enet_peer_throttle (peer, roundTripTime);
- peer -> roundTripTimeVariance -= peer -> roundTripTimeVariance / 4;
-
- if (roundTripTime >= peer -> roundTripTime)
+ if (peer -> lastReceiveTime > 0)
{
- peer -> roundTripTime += (roundTripTime - peer -> roundTripTime) / 8;
- peer -> roundTripTimeVariance += (roundTripTime - peer -> roundTripTime) / 4;
+ if (roundTripTime >= peer -> roundTripTime)
+ {
+ enet_uint32 diff = roundTripTime - peer -> roundTripTime;
+ peer -> roundTripTimeVariance -= peer -> roundTripTimeVariance / 4;
+ peer -> roundTripTimeVariance += diff / 4;
+ peer -> roundTripTime += diff / 8;
+ }
+ else
+ {
+ enet_uint32 diff = peer -> roundTripTime - roundTripTime;
+ if (diff <= peer -> roundTripTimeVariance)
+ {
+ peer -> roundTripTimeVariance -= peer -> roundTripTimeVariance / 4;
+ peer -> roundTripTimeVariance += diff / 4;
+ }
+ else
+ {
+ peer -> roundTripTimeVariance -= peer -> roundTripTimeVariance / 32;
+ peer -> roundTripTimeVariance += diff / 32;
+ }
+ peer -> roundTripTime -= diff / 8;
+ }
}
else
{
- peer -> roundTripTime -= (peer -> roundTripTime - roundTripTime) / 8;
- peer -> roundTripTimeVariance += (peer -> roundTripTime - roundTripTime) / 4;
+ peer -> roundTripTime = roundTripTime;
+ peer -> roundTripTimeVariance = roundTripTime / 2;
}
if (peer -> roundTripTime < peer -> lowestRoundTripTime)
@@ -887,6 +902,9 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
peer -> packetThrottleEpoch = host -> serviceTime;
}
+ peer -> lastReceiveTime = ENET_MAX (host -> serviceTime, 1);
+ peer -> earliestTimeout = 0;
+
receivedReliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> acknowledge.receivedReliableSequenceNumber);
commandNumber = enet_protocol_remove_sent_reliable_command (peer, receivedReliableSequenceNumber, command -> header.channelID);