File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 2626use function array_push ;
2727use function assert ;
2828use function count ;
29+ use function microtime ;
2930use function str_split ;
3031use function strlen ;
31- use function time ;
3232
3333final class SendReliabilityLayer{
3434 private const DATAGRAM_MTU_OVERHEAD = 36 + Datagram::HEADER_SIZE ; //IP header (20 bytes) + UDP header (8 bytes) + RakNet weird (8 bytes) = 36
3535 private const MIN_POSSIBLE_PACKET_SIZE_LIMIT = Session::MIN_MTU_SIZE - self ::DATAGRAM_MTU_OVERHEAD ;
36+ /**
37+ * Delay in seconds before an unacked packet is retransmitted.
38+ * TODO: Replace this with dynamic calculation based on roundtrip times (that's a complex task for another time)
39+ */
40+ private const UNACKED_RETRANSMIT_DELAY = 2.0 ;
3641
3742 /** @var EncapsulatedPacket[] */
3843 private array $ sendQueue = [];
@@ -255,8 +260,9 @@ public function needsUpdate() : bool{
255260 }
256261
257262 public function update () : void {
263+ $ retransmitOlderThan = microtime (true ) - self ::UNACKED_RETRANSMIT_DELAY ;
258264 foreach ($ this ->reliableCache as $ seq => $ pk ){
259- if ($ pk ->getTimestamp () < ( time () - 8 ) ){
265+ if ($ pk ->getTimestamp () < $ retransmitOlderThan ){
260266 //behave as if a NACK was received
261267 array_push ($ this ->resendQueue , ...$ pk ->getPackets ());
262268 unset($ this ->reliableCache [$ seq ]);
You can’t perform that action at this time.
0 commit comments