From 0ea0be0a5d160827d342a364eb2212a3e2d5ee40 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 10 Jul 2026 17:18:35 +0100 Subject: [PATCH] System: move float3/float4/Matrix44f str() out of line str() was defined inline in the headers, which forced onto every translation unit that includes float3.h - i.e. most of the engine, plus vendored targets (lua, luasocket) that pull it in transitively. That is a lot of compile-time cost for a debug-only helper, and it means any target touching float3.h must have the formatting library's headers available. Move the three str() bodies into their .cpp files and drop from the headers (float3.h keeps for the declaration). Now only the three math .cpp files need . Add the direct include to the two other live std::format users that were relying on the transitive pull (UnsyncedGameCommands.cpp, DumpHistory.cpp). --- rts/Game/UnsyncedGameCommands.cpp | 1 + rts/System/Matrix44f.cpp | 8 ++++++++ rts/System/Matrix44f.h | 6 +----- rts/System/Sync/DumpHistory.cpp | 2 ++ rts/System/float3.cpp | 6 ++++++ rts/System/float3.h | 6 ++---- rts/System/float4.cpp | 7 +++++++ rts/System/float4.h | 4 +--- 8 files changed, 28 insertions(+), 12 deletions(-) diff --git a/rts/Game/UnsyncedGameCommands.cpp b/rts/Game/UnsyncedGameCommands.cpp index d5b80f5f44f..c49edc0a6a7 100644 --- a/rts/Game/UnsyncedGameCommands.cpp +++ b/rts/Game/UnsyncedGameCommands.cpp @@ -1,5 +1,6 @@ /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ #include +#include #include #include diff --git a/rts/System/Matrix44f.cpp b/rts/System/Matrix44f.cpp index 6368561aca2..4c1328880dd 100644 --- a/rts/System/Matrix44f.cpp +++ b/rts/System/Matrix44f.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "System/simd_compat.h" @@ -18,6 +19,13 @@ CR_BIND(CMatrix44f, ) CR_REG_METADATA(CMatrix44f, CR_MEMBER(m)) static_assert(alignof(CMatrix44f) == 64); + +std::string CMatrix44f::str() const +{ + return std::format( + "m44(\n{:.3f} {:.3f} {:.3f} {:.3f}\n{:.3f} {:.3f} {:.3f} {:.3f}\n{:.3f} {:.3f} {:.3f} {:.3f}\n{:.3f} {:.3f} {:.3f} {:.3f})", + m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[13], m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]); +} CMatrix44f::CMatrix44f(const CMatrix44f& mat) { memcpy(&m[0], &mat.m[0], sizeof(CMatrix44f)); diff --git a/rts/System/Matrix44f.h b/rts/System/Matrix44f.h index bd5e6d1fc5b..f8061e659d7 100644 --- a/rts/System/Matrix44f.h +++ b/rts/System/Matrix44f.h @@ -176,11 +176,7 @@ class CMatrix44f float4 col[4]; }; - std::string str() const { - return std::format( - "m44(\n{:.3f} {:.3f} {:.3f} {:.3f}\n{:.3f} {:.3f} {:.3f} {:.3f}\n{:.3f} {:.3f} {:.3f} {:.3f}\n{:.3f} {:.3f} {:.3f} {:.3f})", - m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[13], m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]); - } + std::string str() const; }; diff --git a/rts/System/Sync/DumpHistory.cpp b/rts/System/Sync/DumpHistory.cpp index 8280888df87..724352a6855 100644 --- a/rts/System/Sync/DumpHistory.cpp +++ b/rts/System/Sync/DumpHistory.cpp @@ -1,5 +1,7 @@ /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ +#include + #include "DumpHistory.h" #include "SyncChecker.h" diff --git a/rts/System/float3.cpp b/rts/System/float3.cpp index 370f53e32a8..6189708d086 100644 --- a/rts/System/float3.cpp +++ b/rts/System/float3.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "System/creg/creg_cond.h" #include "System/SpringMath.h" @@ -15,6 +16,11 @@ CR_REG_METADATA(float3, (CR_MEMBER(x), CR_MEMBER(y), CR_MEMBER(z))) float float3::maxxpos = -1.0f; float float3::maxzpos = -1.0f; +std::string float3::str() const +{ + return std::format("float3({:.3f}, {:.3f}, {:.3f})", x, y, z); +} + float3 float3::PickNonParallel() const { // https://math.stackexchange.com/questions/3122010/how-to-deterministically-pick-a-vector-that-is-guaranteed-to-be-non-parallel-to diff --git a/rts/System/float3.h b/rts/System/float3.h index bf47dd90c2a..e827f2c0b73 100644 --- a/rts/System/float3.h +++ b/rts/System/float3.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include "System/BranchPrediction.h" #include "System/creg/creg_cond.h" @@ -838,9 +838,7 @@ class float3 static constexpr float cmp_eps() { return 1e-04f; } static constexpr float nrm_eps() { return 1e-12f; } - std::string str() const { - return std::format("float3({:.3f}, {:.3f}, {:.3f})", x, y, z); - } + std::string str() const; /** * @brief max x pos diff --git a/rts/System/float4.cpp b/rts/System/float4.cpp index 8fcdfb597b6..d6bf6971115 100644 --- a/rts/System/float4.cpp +++ b/rts/System/float4.cpp @@ -4,9 +4,16 @@ #include "System/creg/creg_cond.h" #include "System/SpringMath.h" +#include + CR_BIND(float4, ) CR_REG_METADATA(float4, (CR_MEMBER(x), CR_MEMBER(y), CR_MEMBER(z), CR_MEMBER(w))) +std::string float4::str() const +{ + return std::format("float4({:.3f}, {:.3f}, {:.3f}, {:.3f})", x, y, z, w); +} + // ensure that we use a continuous block of memory // (required for passing to gl functions) static_assert(sizeof(float4) == 4 * sizeof(float), ""); diff --git a/rts/System/float4.h b/rts/System/float4.h index 347f0d2e822..7381701184b 100644 --- a/rts/System/float4.h +++ b/rts/System/float4.h @@ -108,9 +108,7 @@ struct float4 : public float3 return (x * f.x) + (y * f.y) + (z * f.z) + (w * f.w); } - std::string str() const { - return std::format("float4({:.3f}, {:.3f}, {:.3f}, {:.3f})", x, y, z, w); - } + std::string str() const; /// Allows implicit conversion to float* (for passing to gl functions)