From 6c896c2ef79c1740d7dea6fae95518c768de8931 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:35:36 +1100 Subject: Make ping updates more accurate --- source/game/StarWorldClient.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source/game/StarWorldClient.cpp') diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index b1ad698..3b8f1a3 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -403,6 +403,10 @@ RectI WorldClient::clientWindow() const { return m_clientState.window(); } +WorldClientState& WorldClient::clientState() { + return m_clientState; +} + void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) { if (!m_lightingThread && m_asyncLighting) m_lightingThread = Thread::invoke("WorldClient::lightingMain", mem_fn(&WorldClient::lightingMain), this); @@ -1038,7 +1042,9 @@ void WorldClient::handleIncomingPackets(List const& packets) { m_worldTemplate->setWorldParameters(netLoadVisitableWorldParameters(worldParametersUpdate->parametersData)); } else if (auto pongPacket = as(packet)) { - if (m_pingTime) + if (pongPacket->time) + m_latency = Time::monotonicMilliseconds() - pongPacket->time; + else if (m_pingTime) m_latency = Time::monotonicMilliseconds() - m_pingTime.take(); } else { @@ -1203,10 +1209,11 @@ void WorldClient::update(float dt) { queueUpdatePackets(m_entityUpdateTimer.wrapTick(dt)); - if (m_pingTime.isNothing()) { + if ((!m_clientState.legacy() && m_currentStep % 3 == 0) || m_pingTime.isNothing()) { m_pingTime = Time::monotonicMilliseconds(); - m_outgoingPackets.append(make_shared()); + m_outgoingPackets.append(make_shared(*m_pingTime)); } + LogMap::set("client_ping", m_latency); // Remove active sectors that are outside of the current monitoring region -- cgit v1.2.3