From f73cb3ce03c35770605ce83a49906cc4825c00a6 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:32:23 +1000 Subject: [PATCH] improve WorldServer debug logging is now consistent with WorldServerThread's use of the world id, which is generally more appropriate --- source/game/StarSystemWorldServerThread.cpp | 2 +- source/game/StarWorldServer.cpp | 21 +++++++++++++++------ source/game/StarWorldServer.hpp | 5 +++++ source/game/StarWorldServerThread.cpp | 7 +++++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/source/game/StarSystemWorldServerThread.cpp b/source/game/StarSystemWorldServerThread.cpp index dd9b9b8..8035975 100644 --- a/source/game/StarSystemWorldServerThread.cpp +++ b/source/game/StarSystemWorldServerThread.cpp @@ -52,7 +52,7 @@ void SystemWorldServerThread::run() { TickRateApproacher tickApproacher(1.0 / SystemWorldTimestep, 0.5); while (!m_stop) { - LogMap::set(strf("system_{}_update_fps", m_systemLocation), tickApproacher.rate()); + LogMap::set(strf("system_{}_update_rate", m_systemLocation), strf("{:4.2f}Hz", tickApproacher.rate())); update(); diff --git a/source/game/StarWorldServer.cpp b/source/game/StarWorldServer.cpp index dffe057..ebd853a 100644 --- a/source/game/StarWorldServer.cpp +++ b/source/game/StarWorldServer.cpp @@ -40,6 +40,7 @@ WorldServer::WorldServer(WorldTemplatePtr const& worldTemplate, IODevicePtr stor m_respawnInWorld = false; m_tileProtectionEnabled = true; m_universeSettings = make_shared(); + m_worldId = worldTemplate->worldName(); init(true); writeMetadata(); @@ -52,6 +53,7 @@ WorldServer::WorldServer(IODevicePtr const& storage) { m_worldStorage = make_shared(storage, make_shared(this)); m_tileProtectionEnabled = true; m_universeSettings = make_shared(); + m_worldId = "Nowhere"; readMetadata(); init(false); @@ -61,6 +63,7 @@ WorldServer::WorldServer(WorldChunks const& chunks) { m_worldStorage = make_shared(chunks, make_shared(this)); m_tileProtectionEnabled = true; m_universeSettings = make_shared(); + m_worldId = "Nowhere"; readMetadata(); init(false); @@ -72,6 +75,14 @@ WorldServer::~WorldServer() { m_worldStorage->unloadAll(true); } +void WorldServer::setWorldId(String worldId) { + m_worldId = move(worldId); +} + +String const& WorldServer::worldId() const { + return m_worldId; +} + void WorldServer::setUniverseSettings(UniverseSettingsPtr universeSettings) { m_universeSettings = move(universeSettings); } @@ -616,12 +627,10 @@ void WorldServer::update() { for (auto& pair : m_clientInfo) pair.second->pendingForward = false; - LogMap::set(strf("server_{}_entities", m_worldTemplate->worldSeed()), m_entityMap->size()); - LogMap::set(strf("server_{}_sectors", m_worldTemplate->worldSeed()), strf("{}", m_tileArray->loadedSectorCount())); - LogMap::set(strf("server_{}_world_time", m_worldTemplate->worldSeed()), epochTime()); - LogMap::set(strf("server_{}_active_liquid", m_worldTemplate->worldSeed()), m_liquidEngine->activeCells()); - LogMap::set(strf("server_{}_day_time", m_worldTemplate->worldSeed()), timeOfDay() / dayLength()); - LogMap::set(strf("server_{}_lua_mem", m_worldTemplate->worldSeed()), m_luaRoot->luaMemoryUsage()); + LogMap::set(strf("server_{}_entities", m_worldId), strf("{} in {} sectors", m_entityMap->size(), m_tileArray->loadedSectorCount())); + LogMap::set(strf("server_{}_time", m_worldId), strf("age = {:4.2f}, day = {:4.2f}/{:4.2f}s", epochTime(), timeOfDay(), dayLength())); + LogMap::set(strf("server_{}_active_liquid", m_worldId), m_liquidEngine->activeCells()); + LogMap::set(strf("server_{}_lua_mem", m_worldId), m_luaRoot->luaMemoryUsage()); } WorldGeometry WorldServer::geometry() const { diff --git a/source/game/StarWorldServer.hpp b/source/game/StarWorldServer.hpp index 7609cdc..40dd7c1 100644 --- a/source/game/StarWorldServer.hpp +++ b/source/game/StarWorldServer.hpp @@ -57,6 +57,9 @@ public: // Load an existing world from an in-memory representation ~WorldServer(); + void setWorldId(String worldId); + String const& worldId() const; + void setUniverseSettings(UniverseSettingsPtr universeSettings); UniverseSettingsPtr universeSettings() const; @@ -374,6 +377,8 @@ private: HashMap>>> m_entityMessageResponses; List m_forceRegions; + + String m_worldId; }; } diff --git a/source/game/StarWorldServerThread.cpp b/source/game/StarWorldServerThread.cpp index d3bcbc4..c31ae84 100644 --- a/source/game/StarWorldServerThread.cpp +++ b/source/game/StarWorldServerThread.cpp @@ -13,7 +13,10 @@ WorldServerThread::WorldServerThread(WorldServerPtr server, WorldId worldId) m_worldServer(move(server)), m_worldId(move(worldId)), m_stop(false), - m_errorOccurred(false) {} + m_errorOccurred(false) { + if (m_worldServer) + m_worldServer->setWorldId(printWorldId(m_worldId)); +} WorldServerThread::~WorldServerThread() { m_stop = true; @@ -195,7 +198,7 @@ void WorldServerThread::run() { while (!m_stop && !m_errorOccurred) { auto fidelity = lockedFidelity.value(automaticFidelity); LogMap::set(strf("server_{}_fidelity", m_worldId), WorldServerFidelityNames.getRight(fidelity)); - LogMap::set(strf("server_{}_update_fps", m_worldId), tickApproacher.rate()); + LogMap::set(strf("server_{}_update", m_worldId), strf("{:4.2f}Hz", tickApproacher.rate())); update(fidelity); tickApproacher.tick();