Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarWorldClient.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-04-04 14:35:36 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-04-04 14:35:36 +1100
commit6c896c2ef79c1740d7dea6fae95518c768de8931 (patch)
treefce5fcd1bb6b9743cee93371b7f7d7b586a455b1 /source/game/StarWorldClient.cpp
parentbe676518f4639250376842db7e48e5aaeaad9424 (diff)
Make ping updates more accurate
Diffstat (limited to 'source/game/StarWorldClient.cpp')
-rw-r--r--source/game/StarWorldClient.cpp13
1 files changed, 10 insertions, 3 deletions
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<PacketPtr> const& packets) {
m_worldTemplate->setWorldParameters(netLoadVisitableWorldParameters(worldParametersUpdate->parametersData));
} else if (auto pongPacket = as<PongPacket>(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<PingPacket>());
+ m_outgoingPackets.append(make_shared<PingPacket>(*m_pingTime));
}
+
LogMap::set("client_ping", m_latency);
// Remove active sectors that are outside of the current monitoring region