From d686708c920cc5b5c7cbdb7bb08daf514672b53e Mon Sep 17 00:00:00 2001 From: phosit Date: Thu, 3 Sep 2026 15:33:30 +0200 Subject: [PATCH] Use fmt::format for LOGMESSAGERENDER The format string can be checked at compile time. It will be easier to transition to `std::format`. --- source/graphics/CameraController.cpp | 14 ++++++++------ source/network/NetClient.cpp | 3 ++- source/network/NetFileTransfer.cpp | 4 ++-- source/ps/CLogger.h | 3 ++- source/ps/ProfileViewer.cpp | 2 +- source/ps/Profiler2.cpp | 2 +- source/ps/SavedGame.cpp | 2 +- source/ps/scripting/JSInterface_Game.cpp | 2 +- source/renderer/Renderer.cpp | 4 ++-- source/simulation2/Simulation2.cpp | 2 +- 10 files changed, 21 insertions(+), 17 deletions(-) diff --git a/source/graphics/CameraController.cpp b/source/graphics/CameraController.cpp index 5ce83fe56b..f79edf9f0d 100644 --- a/source/graphics/CameraController.cpp +++ b/source/graphics/CameraController.cpp @@ -703,39 +703,41 @@ Input::Reaction CCameraController::HandleEvent(const SDL_Event& ev) else if (hotkey == "camera.scroll.speed.increase") { m_ViewScrollSpeed *= m_ViewScrollSpeedModifier; - LOGMESSAGERENDER("Scroll speed increased to %.1f", m_ViewScrollSpeed); + LOGMESSAGERENDER("Scroll speed increased to {:.1f}", m_ViewScrollSpeed); return Input::Reaction::HANDLED; } else if (hotkey == "camera.scroll.speed.decrease") { m_ViewScrollSpeed /= m_ViewScrollSpeedModifier; - LOGMESSAGERENDER("Scroll speed decreased to %.1f", m_ViewScrollSpeed); + LOGMESSAGERENDER("Scroll speed decreased to {:.1f}", m_ViewScrollSpeed); return Input::Reaction::HANDLED; } else if (hotkey == "camera.rotate.speed.increase") { m_ViewRotateXSpeed *= m_ViewRotateSpeedModifier; m_ViewRotateYSpeed *= m_ViewRotateSpeedModifier; - LOGMESSAGERENDER("Rotate speed increased to X=%.3f, Y=%.3f", m_ViewRotateXSpeed, m_ViewRotateYSpeed); + LOGMESSAGERENDER("Rotate speed increased to X={:.3f}, Y={:.3f}", m_ViewRotateXSpeed, + m_ViewRotateYSpeed); return Input::Reaction::HANDLED; } else if (hotkey == "camera.rotate.speed.decrease") { m_ViewRotateXSpeed /= m_ViewRotateSpeedModifier; m_ViewRotateYSpeed /= m_ViewRotateSpeedModifier; - LOGMESSAGERENDER("Rotate speed decreased to X=%.3f, Y=%.3f", m_ViewRotateXSpeed, m_ViewRotateYSpeed); + LOGMESSAGERENDER("Rotate speed decreased to X={:.3f}, Y={:.3f}", m_ViewRotateXSpeed, + m_ViewRotateYSpeed); return Input::Reaction::HANDLED; } else if (hotkey == "camera.zoom.speed.increase") { m_ViewZoomSpeed *= m_ViewZoomSpeedModifier; - LOGMESSAGERENDER("Zoom speed increased to %.1f", m_ViewZoomSpeed); + LOGMESSAGERENDER("Zoom speed increased to {:.1f}", m_ViewZoomSpeed); return Input::Reaction::HANDLED; } else if (hotkey == "camera.zoom.speed.decrease") { m_ViewZoomSpeed /= m_ViewZoomSpeedModifier; - LOGMESSAGERENDER("Zoom speed decreased to %.1f", m_ViewZoomSpeed); + LOGMESSAGERENDER("Zoom speed decreased to {:.1f}", m_ViewZoomSpeed); return Input::Reaction::HANDLED; } return Input::Reaction::PASS; diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index edacf719ab..113d0b3142 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -639,7 +639,8 @@ bool CNetClient::HandleMessage(CNetMessage* message) std::stringstream stream; - LOGMESSAGERENDER("Serializing game at turn %u for rejoining player", m_ClientTurnManager->GetCurrentTurn()); + LOGMESSAGERENDER("Serializing game at turn {} for rejoining player", + m_ClientTurnManager->GetCurrentTurn()); std::uint32_t turn = to_le32(m_ClientTurnManager->GetCurrentTurn()); stream.write((char*)&turn, sizeof(turn)); diff --git a/source/network/NetFileTransfer.cpp b/source/network/NetFileTransfer.cpp index dbd58c9c87..c10745a551 100644 --- a/source/network/NetFileTransfer.cpp +++ b/source/network/NetFileTransfer.cpp @@ -69,7 +69,7 @@ Status CNetFileTransferer::OnFileTransferResponse(const CFileTransferResponseMes task.length = message.m_Length; task.buffer.reserve(message.m_Length); - LOGMESSAGERENDER("Downloading data over network (%lu KiB) - please wait...", task.length / KiB); + LOGMESSAGERENDER("Downloading data over network ({} KiB) - please wait...", task.length / KiB); m_LastProgressReportTime = timer_Time(); return INFO::OK; @@ -117,7 +117,7 @@ Status CNetFileTransferer::OnFileTransferData(const CFileTransferDataMessage& me double t = timer_Time(); if (t > m_LastProgressReportTime + 0.5) { - LOGMESSAGERENDER("Downloading data: %.1f%% of %lu KiB", + LOGMESSAGERENDER("Downloading data: {:.1f}% of {} KiB", 100.f * task.buffer.size() / task.length, task.length / KiB); m_LastProgressReportTime = t; } diff --git a/source/ps/CLogger.h b/source/ps/CLogger.h index 4a73c359e2..c8344a6ec5 100644 --- a/source/ps/CLogger.h +++ b/source/ps/CLogger.h @@ -36,7 +36,8 @@ extern CLogger* g_Logger; #define LOGMESSAGE(fmtstring, ...) g_Logger->WriteMessage( \ fmt::format(FMT_STRING(fmtstring), ## __VA_ARGS__).c_str(), false) -#define LOGMESSAGERENDER(...) g_Logger->WriteMessage(fmt::sprintf(__VA_ARGS__).c_str(), true) +#define LOGMESSAGERENDER(fmtstring, ...) g_Logger->WriteMessage( \ + fmt::format(FMT_STRING(fmtstring), ## __VA_ARGS__).c_str(), true) #define LOGWARNING(...) g_Logger->WriteWarning(fmt::sprintf(__VA_ARGS__).c_str()) #define LOGERROR(...) g_Logger->WriteError (fmt::sprintf(__VA_ARGS__).c_str()) diff --git a/source/ps/ProfileViewer.cpp b/source/ps/ProfileViewer.cpp index c1251ce249..a5fb042cfc 100644 --- a/source/ps/ProfileViewer.cpp +++ b/source/ps/ProfileViewer.cpp @@ -560,7 +560,7 @@ void CProfileViewerInternals::SaveToFile() } else { - LOGMESSAGERENDER("Profiler snapshot saved to '%s'", filePath.string8()); + LOGMESSAGERENDER("Profiler snapshot saved to '{}'", filePath.string8()); } } diff --git a/source/ps/Profiler2.cpp b/source/ps/Profiler2.cpp index e98ce25fa3..f59b3a59a2 100644 --- a/source/ps/Profiler2.cpp +++ b/source/ps/Profiler2.cpp @@ -789,7 +789,7 @@ void CProfiler2::SaveToFile() { OsPath path = psLogDir()/"profile2.jsonp"; debug_printf("Writing profile data to %s \n", path.string8().c_str()); - LOGMESSAGERENDER("Writing profile data to %s \n", path.string8().c_str()); + LOGMESSAGERENDER("Writing profile data to {}\n", path.string8()); std::ofstream stream(OsString(path), std::ofstream::out | std::ofstream::trunc); ENSURE(stream.good()); diff --git a/source/ps/SavedGame.cpp b/source/ps/SavedGame.cpp index f864eb16d6..8750602906 100644 --- a/source/ps/SavedGame.cpp +++ b/source/ps/SavedGame.cpp @@ -166,7 +166,7 @@ Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation OsPath realPath; WARN_RETURN_STATUS_IF_ERR(g_VFS->GetRealPath(filename, realPath)); - LOGMESSAGERENDER("Saved game to '%s'", realPath.string8()); + LOGMESSAGERENDER("Saved game to '{}'", realPath.string8()); debug_printf("Saved game to '%s'\n", realPath.string8().c_str()); return INFO::OK; diff --git a/source/ps/scripting/JSInterface_Game.cpp b/source/ps/scripting/JSInterface_Game.cpp index 1b5cb9790b..46ad82f158 100644 --- a/source/ps/scripting/JSInterface_Game.cpp +++ b/source/ps/scripting/JSInterface_Game.cpp @@ -190,7 +190,7 @@ void DumpTerrainMipmap() g_Game->GetWorld()->GetTerrain().GetHeightMipmap().DumpToDisk(filename); OsPath realPath; g_VFS->GetRealPath(filename, realPath); - LOGMESSAGERENDER("Terrain mipmap written to '%s'", realPath.string8()); + LOGMESSAGERENDER("Terrain mipmap written to '{}'", realPath.string8()); } void RegisterScriptFunctions(const Script::Request& rq) diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index a3e75a4892..51c3b88c83 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -833,7 +833,7 @@ void CRenderer::RenderScreenShot(const bool needsPresent) OsPath realPath; g_VFS->GetRealPath(filename, realPath); - LOGMESSAGERENDER("Screenshot written to '%s'", realPath.string8()); + LOGMESSAGERENDER("Screenshot written to '{}'", realPath.string8()); debug_printf( CStr(g_L10n.Translate("Screenshot written to '%s'") + "\n").c_str(), @@ -971,7 +971,7 @@ void CRenderer::RenderBigScreenShot(const bool needsPresent) OsPath realPath; g_VFS->GetRealPath(filename, realPath); - LOGMESSAGERENDER("Screenshot written to '%s'", realPath.string8()); + LOGMESSAGERENDER("Screenshot written to '{}'", realPath.string8()); debug_printf( CStr(g_L10n.Translate("Screenshot written to '%s'") + "\n").c_str(), diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index 1634d7b8bf..4b9dc9c15b 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -894,7 +894,7 @@ void CSimulation2::ActivateRejoinTest(turn_id_t turn) { if (m->m_RejoinTestTurn.has_value()) return; - LOGMESSAGERENDER("Rejoin test will activate in %d turns", turn - m->m_TurnNumber); + LOGMESSAGERENDER("Rejoin test will activate in {} turns", turn - m->m_TurnNumber); m->m_RejoinTestTurn = turn; }