X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnet%2FConnectionHandler.hpp;h=be01d10add35ab3b597c4cec5c5efa5d8d17f4c5;hb=c256dca7c6ca2c7f8eeffae53c02fe62bd892198;hp=942826b4329349a9b58f8bd1dad2cccf93ed17be;hpb=8dc262b12992c7cd8d4bee0fa4114ee3fb6dcd87;p=blank.git diff --git a/src/net/ConnectionHandler.hpp b/src/net/ConnectionHandler.hpp index 942826b..be01d10 100644 --- a/src/net/ConnectionHandler.hpp +++ b/src/net/ConnectionHandler.hpp @@ -13,8 +13,12 @@ class ConnectionHandler { public: ConnectionHandler(); + /// packet loss as factor float PacketLoss() const noexcept { return packet_loss; } + /// smooth average round trip time in milliseconds + float RoundTripTime() const noexcept { return rtt; } + void PacketSent(std::uint16_t); void PacketLost(std::uint16_t); void PacketReceived(std::uint16_t); @@ -24,6 +28,9 @@ public: private: void UpdatePacketLoss() noexcept; + void UpdateRTT(std::uint16_t) noexcept; + bool SamplePacket(std::uint16_t) const noexcept; + int HeadDiff(std::uint16_t) const noexcept; // called as soon as the remote end ack'd given packet virtual void OnPacketReceived(std::uint16_t) { } @@ -41,12 +48,19 @@ private: virtual void On(const Packet::PlayerCorrection &) { } virtual void On(const Packet::ChunkBegin &) { } virtual void On(const Packet::ChunkData &) { } + virtual void On(const Packet::BlockUpdate &) { } + virtual void On(const Packet::Message &) { } private: unsigned int packets_lost; unsigned int packets_received; float packet_loss; + Uint32 stamps[16]; + std::size_t stamp_cursor; + std::uint16_t stamp_last; + float rtt; + }; }