+void ConnectionHandler::UpdateRTT(std::uint16_t seq) noexcept {
+ if (!SamplePacket(seq)) return;
+ int diff = HeadDiff(seq);
+ if (diff > 0 || diff < -15) {
+ // packet outside observed time frame
+ return;
+ }
+ int cur_rtt = SDL_GetTicks() - stamps[(stamp_cursor + diff + 16) % 16];
+ rtt += (cur_rtt - rtt) * 0.1f;
+}
+
+bool ConnectionHandler::SamplePacket(std::uint16_t seq) const noexcept {
+ // only sample every eighth packet
+ return seq % 8 == 0;
+}
+
+int ConnectionHandler::HeadDiff(std::uint16_t seq) const noexcept {
+ int16_t diff = int16_t(seq) - int16_t(stamp_last);
+ return diff / 8;
+}
+