diff options
author | Lee Salzman <[email protected]> | 2020-04-04 12:30:54 -0400 |
---|---|---|
committer | Lee Salzman <[email protected]> | 2020-04-04 12:30:54 -0400 |
commit | 6991632abf1af161f332bf38bd8517c7c2834b58 (patch) | |
tree | 9cfb3a997a2ebe2d5ccbfe3d048b6ba7d4334b20 | |
parent | b4c427059aa39ce42ae4c82afcfe617dea255c4d (diff) | |
download | enet-6991632abf1af161f332bf38bd8517c7c2834b58.tar.gz enet-6991632abf1af161f332bf38bd8517c7c2834b58.zip |
accumulate fractional RTT values
-rw-r--r-- | include/enet/enet.h | 11 | ||||
-rw-r--r-- | peer.c | 23 | ||||
-rw-r--r-- | protocol.c | 39 |
3 files changed, 45 insertions, 28 deletions
diff --git a/include/enet/enet.h b/include/enet/enet.h index 4a704ee..174e062 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -216,7 +216,7 @@ enum ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE = 32 * 1024 * 1024, ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA = 32 * 1024 * 1024, - ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500, + ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 350, ENET_PEER_DEFAULT_PACKET_THROTTLE = 32, ENET_PEER_PACKET_THROTTLE_SCALE = 32, ENET_PEER_PACKET_THROTTLE_COUNTER = 7, @@ -250,6 +250,11 @@ typedef struct _ENetChannel ENetList incomingUnreliableCommands; } ENetChannel; +typedef enum _ENetPeerFlag +{ + ENET_PEER_FLAG_NEEDS_DISPATCH = (1 << 0) +} ENetPeerFlag; + /** * An ENet peer which data packets may be sent or received from. * @@ -311,7 +316,9 @@ typedef struct _ENetPeer ENetList outgoingReliableCommands; ENetList outgoingUnreliableCommands; ENetList dispatchedCommands; - int needsDispatch; + enet_uint16 flags; + enet_uint8 roundTripTimeRemainder; + enet_uint8 roundTripTimeVarianceRemainder; enet_uint16 incomingUnsequencedGroup; enet_uint16 outgoingUnsequencedGroup; enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32]; @@ -306,11 +306,11 @@ enet_peer_reset_queues (ENetPeer * peer) { ENetChannel * channel; - if (peer -> needsDispatch) + if (peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH) { enet_list_remove (& peer -> dispatchList); - peer -> needsDispatch = 0; + peer -> flags &= ~ ENET_PEER_FLAG_NEEDS_DISPATCH; } while (! enet_list_empty (& peer -> acknowledgements)) @@ -418,6 +418,9 @@ enet_peer_reset (ENetPeer * peer) peer -> outgoingUnsequencedGroup = 0; peer -> eventData = 0; peer -> totalWaitingData = 0; + peer -> flags = 0; + peer -> roundTripTimeRemainder = 0; + peer -> roundTripTimeVarianceRemainder = 0; memset (peer -> unsequencedWindow, 0, sizeof (peer -> unsequencedWindow)); @@ -724,11 +727,11 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * { enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand)); - if (! peer -> needsDispatch) + if (! (peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH)) { enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList); - peer -> needsDispatch = 1; + peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH; } droppedCommand = currentCommand; @@ -752,11 +755,11 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * { enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand)); - if (! peer -> needsDispatch) + if (! (peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH)) { enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList); - peer -> needsDispatch = 1; + peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH; } } } @@ -768,11 +771,11 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * { enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand)); - if (! peer -> needsDispatch) + if (! (peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH)) { enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList); - peer -> needsDispatch = 1; + peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH; } droppedCommand = currentCommand; @@ -809,11 +812,11 @@ enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * ch enet_list_move (enet_list_end (& peer -> dispatchedCommands), enet_list_begin (& channel -> incomingReliableCommands), enet_list_previous (currentCommand)); - if (! peer -> needsDispatch) + if (! (peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH)) { enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList); - peer -> needsDispatch = 1; + peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH; } if (! enet_list_empty (& channel -> incomingUnreliableCommands)) @@ -48,11 +48,11 @@ enet_protocol_dispatch_state (ENetHost * host, ENetPeer * peer, ENetPeerState st { enet_protocol_change_state (host, peer, state); - if (! peer -> needsDispatch) + if (! (peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH)) { enet_list_insert (enet_list_end (& host -> dispatchQueue), & peer -> dispatchList); - peer -> needsDispatch = 1; + peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH; } } @@ -63,7 +63,7 @@ enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event) { ENetPeer * peer = (ENetPeer *) enet_list_remove (enet_list_begin (& host -> dispatchQueue)); - peer -> needsDispatch = 0; + peer -> flags &= ~ ENET_PEER_FLAG_NEEDS_DISPATCH; switch (peer -> state) { @@ -101,7 +101,7 @@ enet_protocol_dispatch_incoming_commands (ENetHost * host, ENetEvent * event) if (! enet_list_empty (& peer -> dispatchedCommands)) { - peer -> needsDispatch = 1; + peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH; enet_list_insert (enet_list_end (& host -> dispatchQueue), & peer -> dispatchList); } @@ -858,28 +858,35 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer * if (peer -> lastReceiveTime > 0) { - if (roundTripTime >= peer -> roundTripTime) + enet_uint32 accumRoundTripTime = (peer -> roundTripTime << 8) + peer -> roundTripTimeRemainder; + enet_uint32 accumRoundTripTimeVariance = (peer -> roundTripTimeVariance << 8) + peer -> roundTripTimeVarianceRemainder; + roundTripTime <<= 8; + if (roundTripTime >= accumRoundTripTime) { - enet_uint32 diff = roundTripTime - peer -> roundTripTime; - peer -> roundTripTimeVariance -= peer -> roundTripTimeVariance / 4; - peer -> roundTripTimeVariance += diff / 4; - peer -> roundTripTime += diff / 8; + enet_uint32 diff = roundTripTime - accumRoundTripTime; + accumRoundTripTimeVariance -= accumRoundTripTimeVariance / 4; + accumRoundTripTimeVariance += diff / 4; + accumRoundTripTime += diff / 8; } else { - enet_uint32 diff = peer -> roundTripTime - roundTripTime; - if (diff <= peer -> roundTripTimeVariance) + enet_uint32 diff = accumRoundTripTime - roundTripTime; + if (diff <= accumRoundTripTimeVariance) { - peer -> roundTripTimeVariance -= peer -> roundTripTimeVariance / 4; - peer -> roundTripTimeVariance += diff / 4; + accumRoundTripTimeVariance -= accumRoundTripTimeVariance / 4; + accumRoundTripTimeVariance += diff / 4; } else { - peer -> roundTripTimeVariance -= peer -> roundTripTimeVariance / 32; - peer -> roundTripTimeVariance += diff / 32; + accumRoundTripTimeVariance -= accumRoundTripTimeVariance / 32; + accumRoundTripTimeVariance += diff / 32; } - peer -> roundTripTime -= diff / 8; + accumRoundTripTime -= diff / 8; } + peer -> roundTripTime = accumRoundTripTime >> 8; + peer -> roundTripTimeRemainder = accumRoundTripTime & 0xFF; + peer -> roundTripTimeVariance = accumRoundTripTimeVariance >> 8; + peer -> roundTripTimeVarianceRemainder = accumRoundTripTimeVariance & 0xFF; } else { |