Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Spawner/ProtocolZero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@
#include <IPXManagerClass.h>

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<unsigned char>::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();
Expand All @@ -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
Expand All @@ -65,7 +71,7 @@ void ProtocolZero::SendResponseTime2()
}
else
{
++NextSendFrame;
++ProtocolZero::NextSendFrame;
}
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Spawner/ProtocolZero.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/Spawner/Spawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading