diff --git a/src/Spawner/ProtocolZero.cpp b/src/Spawner/ProtocolZero.cpp index 63b2e97c..92932113 100644 --- a/src/Spawner/ProtocolZero.cpp +++ b/src/Spawner/ProtocolZero.cpp @@ -28,18 +28,24 @@ #include bool ProtocolZero::Enable = false; -int ProtocolZero::WorstMaxAhead = 24; -unsigned char ProtocolZero::MaxLatencyLevel = 0xff; +int ProtocolZero::NextSendFrame = -1; +int ProtocolZero::WorstMaxAhead = LatencyLevel::GetMaxAhead(LatencyLevelEnum::LATENCY_LEVEL_6); +unsigned char ProtocolZero::MaxLatencyLevel = std::numeric_limits::max(); void ProtocolZero::SendResponseTime2() { if (SessionClass::IsSingleplayer()) return; - static int NextSendFrame = 6 * SendResponseTimeInterval; int currentFrame = Unsorted::CurrentFrame; - if (NextSendFrame >= currentFrame) + if (ProtocolZero::NextSendFrame < 0) + { + ProtocolZero::NextSendFrame = currentFrame + Game::Network::FrameSendRate + ProtocolZero::SendResponseTimeFrame; + return; + } + + if (ProtocolZero::NextSendFrame >= currentFrame) return; const int ipxResponseTime = IPXManagerClass::Instance.ResponseTime(); @@ -55,7 +61,7 @@ void ProtocolZero::SendResponseTime2() if (event.AddEvent()) { - NextSendFrame = currentFrame + SendResponseTimeInterval; + ProtocolZero::NextSendFrame = currentFrame + ProtocolZero::SendResponseTimeInterval; Debug::Log("[Spawner] Player %d sending response time of %d, LatencyMode = %d, Frame = %d\n" , event.HouseIndex , event.ResponseTime2.MaxAhead @@ -65,7 +71,7 @@ void ProtocolZero::SendResponseTime2() } else { - ++NextSendFrame; + ++ProtocolZero::NextSendFrame; } } @@ -94,7 +100,7 @@ void ProtocolZero::HandleResponseTime2(EventExt* event) for (char i = 0; i < (char)std::size(PlayerMaxAheads); ++i) { - if (Unsorted::CurrentFrame >= (PlayerLastTimingFrame[i] + (SendResponseTimeInterval * 4))) + if (Unsorted::CurrentFrame >= (PlayerLastTimingFrame[i] + (ProtocolZero::SendResponseTimeFrame / 2))) { PlayerMaxAheads[i] = 0; PlayerLatencyMode[i] = 0; diff --git a/src/Spawner/ProtocolZero.h b/src/Spawner/ProtocolZero.h index 24c6bc11..b2d7dc19 100644 --- a/src/Spawner/ProtocolZero.h +++ b/src/Spawner/ProtocolZero.h @@ -25,11 +25,13 @@ class ProtocolZero { private: static constexpr int SendResponseTimeInterval = 30; + static constexpr int SendResponseTimeFrame = 8 * SendResponseTimeInterval; public: static bool Enable; static unsigned char MaxLatencyLevel; static int WorstMaxAhead; + static int NextSendFrame; static void SendResponseTime2(); static void HandleResponseTime2(EventExt* event); diff --git a/src/Spawner/Spawner.cpp b/src/Spawner/Spawner.cpp index 73d1702b..186e5a51 100644 --- a/src/Spawner/Spawner.cpp +++ b/src/Spawner/Spawner.cpp @@ -393,6 +393,10 @@ void Spawner::InitNetwork() { Game::Network::FrameSendRate = 2; Game::Network::PreCalcMaxAhead = pSpawnerConfig->PreCalcMaxAhead; + + ProtocolZero::NextSendFrame = -1; + ProtocolZero::WorstMaxAhead = LatencyLevel::GetMaxAhead(LatencyLevelEnum::LATENCY_LEVEL_6); + ProtocolZero::MaxLatencyLevel = std::clamp( pSpawnerConfig->MaxLatencyLevel, (byte)LatencyLevelEnum::LATENCY_LEVEL_1,