From c9522fb740200ccef6230cec452c48efb31e5394 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 11 May 2023 22:05:17 +0200 Subject: Removed all Printf-family functions from StringUtils. Replaced them with fmt::format calls, including changes to the format strings. Also changed the format strings to use FMT_STRING, so that the format is checked compile-time against the arguments. Also fixed code-style violations already present in the code. --- src/Generating/Caves.cpp | 4 ++-- src/Generating/DistortedHeightmap.cpp | 2 +- src/Generating/FinishGen.cpp | 6 +++--- src/Generating/PieceStructuresGen.cpp | 6 +++--- src/Generating/PrefabPiecePool.cpp | 14 +++++++------- src/Generating/Ravines.cpp | 25 ++++++++++++------------- src/Generating/SinglePieceStructuresGen.cpp | 6 +++--- src/Generating/StructGen.cpp | 2 +- src/Generating/VillageGen.cpp | 4 ++-- 9 files changed, 34 insertions(+), 35 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp index fcad9032c..27978dd75 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -558,11 +558,11 @@ AString cCaveTunnel::ExportAsSVG(int a_Color, int a_OffsetX, int a_OffsetZ) cons { AString SVG; SVG.reserve(m_Points.size() * 20 + 200); - AppendPrintf(SVG, "m_BlockX, a_OffsetZ + itr->m_BlockZ); + SVG.append(fmt::format(FMT_STRING("{} {}, {} "), Prefix, a_OffsetX + itr->m_BlockX, a_OffsetZ + itr->m_BlockZ)); Prefix = 'L'; } SVG.append("\"/>\n"); diff --git a/src/Generating/DistortedHeightmap.cpp b/src/Generating/DistortedHeightmap.cpp index a0732287b..32b1a3a18 100644 --- a/src/Generating/DistortedHeightmap.cpp +++ b/src/Generating/DistortedHeightmap.cpp @@ -222,7 +222,7 @@ void cDistortedHeightmap::GenerateHeightArray(void) m_DistortedHeightmap, INTERPOL_X, INTERPOL_Y, INTERPOL_Z ); - // DEBUG: Debug3DNoise(m_DistortedHeightmap, 17, 257, 17, Printf("DistortedHeightmap_%d_%d", m_CurChunkX, m_CurChunkZ)); + // DEBUG: Debug3DNoise(m_DistortedHeightmap, 17, 257, 17, fmt::format(FMT_STRING("DistortedHeightmap_{}_{}"), m_CurChunkX, m_CurChunkZ)); } diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 0ce48f90c..0cf65d1f6 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1858,10 +1858,10 @@ AString cFinishGenOres::OreInfosToString(const cFinishGenOres::OreInfos & a_OreI { res.append(" | "); } - AppendPrintf(res, "%s:%d:%d:%d:%d", - ItemTypeToString(ore.m_BlockType).c_str(), ore.m_BlockMeta, + res.append(fmt::format(FMT_STRING("{}:{}:{}:{}:{}"), + ItemTypeToString(ore.m_BlockType), ore.m_BlockMeta, ore.m_MaxHeight, ore.m_NumNests, ore.m_NestSize - ); + )); } // for ore - a_OreInfos[] return res; } diff --git a/src/Generating/PieceStructuresGen.cpp b/src/Generating/PieceStructuresGen.cpp index 56890597a..a0c30a538 100644 --- a/src/Generating/PieceStructuresGen.cpp +++ b/src/Generating/PieceStructuresGen.cpp @@ -135,13 +135,13 @@ bool cPieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel, auto Structures = StringSplitAndTrim(a_Prefabs, "|"); for (const auto & Structure : Structures) { - auto FileName = Printf("Prefabs%cPieceStructures%c%s.cubeset", cFile::PathSeparator(), cFile::PathSeparator(), Structure.c_str()); + auto FileName = fmt::format(FMT_STRING("Prefabs{0}PieceStructures{0}{1}.cubeset"), cFile::PathSeparator(), Structure); if (!cFile::IsFile(FileName)) { FileName.append(".gz"); if (!cFile::IsFile(FileName)) { - LOGWARNING("Cannot load PieceStructures cubeset file %s", FileName.c_str()); + LOGWARNING("Cannot load PieceStructures cubeset file %s", FileName); continue; } } @@ -155,7 +155,7 @@ bool cPieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel, // Report a warning if no generators available: if (m_Gens.empty()) { - LOGWARNING("The PieceStructures generator was asked to generate \"%s\", but none of the prefabs are valid.", a_Prefabs.c_str()); + LOGWARNING("The PieceStructures generator was asked to generate \"%s\", but none of the prefabs are valid.", a_Prefabs); return false; } return true; diff --git a/src/Generating/PrefabPiecePool.cpp b/src/Generating/PrefabPiecePool.cpp index 4deee38ef..4293f38aa 100644 --- a/src/Generating/PrefabPiecePool.cpp +++ b/src/Generating/PrefabPiecePool.cpp @@ -112,7 +112,7 @@ void cPrefabPiecePool::AddStartingPieceDefs( ) { ASSERT(a_StartingPieceDefs != nullptr); - auto verticalStrategy = CreateVerticalStrategyFromString(Printf("Fixed|%d", a_DefaultPieceHeight), false); + auto verticalStrategy = CreateVerticalStrategyFromString(fmt::format(FMT_STRING("Fixed|{}"), a_DefaultPieceHeight), false); for (size_t i = 0; i < a_NumStartingPieceDefs; i++) { cPrefab * Prefab = new cPrefab(a_StartingPieceDefs[i]); @@ -186,7 +186,7 @@ bool cPrefabPiecePool::LoadFromString(const AString & a_Contents, const AString bool cPrefabPiecePool::LoadFromCubeset(const AString & a_Contents, const AString & a_FileName, bool a_LogWarnings) { // Load the file in the Lua interpreter: - cLuaState Lua(Printf("LoadablePiecePool %s", a_FileName.c_str())); + cLuaState Lua(fmt::format(FMT_STRING("LoadablePiecePool {}"), a_FileName)); Lua.Create(); cLuaState::cLock lock(Lua); if (!Lua.LoadString(a_Contents, a_FileName, a_LogWarnings)) @@ -199,7 +199,7 @@ bool cPrefabPiecePool::LoadFromCubeset(const AString & a_Contents, const AString int Version = 0; if (!Lua.GetNamedGlobal("Cubeset.Metadata.CubesetFormatVersion", Version)) { - CONDWARNING(a_LogWarnings, "Cannot load cubeset %s, it doesn't contain version information.", a_FileName.c_str()); + CONDWARNING(a_LogWarnings, "Cannot load cubeset %s, it doesn't contain version information.", a_FileName); return false; } @@ -210,7 +210,7 @@ bool cPrefabPiecePool::LoadFromCubeset(const AString & a_Contents, const AString } // Unknown version: - CONDWARNING(a_LogWarnings, "Cannot load cubeset %s, version (%d) not supported.", a_FileName.c_str(), Version); + CONDWARNING(a_LogWarnings, "Cannot load cubeset %s, version (%d) not supported.", a_FileName, Version); return false; } @@ -280,7 +280,7 @@ bool cPrefabPiecePool::LoadCubesetPieceVer1(const AString & a_FileName, cLuaStat AString PieceName; if (!a_LuaState.GetNamedValue("OriginData.ExportName", PieceName)) { - Printf(PieceName, "Piece #%d", a_PieceIndex); + PieceName = fmt::format(FMT_STRING("Piece #{}"), a_PieceIndex); } // Read the hitbox dimensions: @@ -294,7 +294,7 @@ bool cPrefabPiecePool::LoadCubesetPieceVer1(const AString & a_FileName, cLuaStat !a_LuaState.GetNamedValue("Hitbox.MaxZ", Hitbox.p2.z) ) { - CONDWARNING(a_LogWarnings, "Cannot load piece %s from file %s, it's missing hitbox information", PieceName.c_str(), a_FileName.c_str()); + CONDWARNING(a_LogWarnings, "Cannot load piece %s from file %s, it's missing hitbox information", PieceName, a_FileName); return false; } @@ -331,7 +331,7 @@ bool cPrefabPiecePool::LoadCubesetPieceVer1(const AString & a_FileName, cLuaStat if (prefab->GetVerticalStrategy() == nullptr) { CONDWARNING(a_LogWarnings, "Starting prefab %s in file %s doesn't have its VerticalStrategy set. Setting to Fixed|150.", - PieceName.c_str(), a_FileName.c_str() + PieceName, a_FileName ); VERIFY(prefab->SetVerticalStrategyFromString("Fixed|150", false)); } diff --git a/src/Generating/Ravines.cpp b/src/Generating/Ravines.cpp index 4e5d90770..57c806ba5 100644 --- a/src/Generating/Ravines.cpp +++ b/src/Generating/Ravines.cpp @@ -280,41 +280,40 @@ void cStructGenRavines::cRavine::FinishLinear(void) #ifndef NDEBUG AString cStructGenRavines::cRavine::ExportAsSVG(int a_Color, int a_OffsetX, int a_OffsetZ) const { - AString SVG; - AppendPrintf(SVG, "m_BlockX, a_OffsetZ + itr->m_BlockZ); + SVG.append(fmt::format(FMT_STRING("{} {}, {} "), Prefix, a_OffsetX + itr->m_BlockX, a_OffsetZ + itr->m_BlockZ)); Prefix = 'L'; } SVG.append("\"/>\n"); // Base point highlight: - AppendPrintf(SVG, "\n", + SVG.append(fmt::format(FMT_STRING("\n"), a_OffsetX + m_OriginX - 5, a_OffsetZ + m_OriginZ, a_OffsetX + m_OriginX + 5, a_OffsetZ + m_OriginZ - ); - AppendPrintf(SVG, "\n", + )); + SVG.append(fmt::format(FMT_STRING("\n"), a_OffsetX + m_OriginX, a_OffsetZ + m_OriginZ - 5, a_OffsetX + m_OriginX, a_OffsetZ + m_OriginZ + 5 - ); + )); // A gray line from the base point to the first point of the ravine, for identification: - AppendPrintf(SVG, "\n", + SVG.append(fmt::format(FMT_STRING("\n"), a_OffsetX + m_OriginX, a_OffsetZ + m_OriginZ, a_OffsetX + m_Points.front().m_BlockX, a_OffsetZ + m_Points.front().m_BlockZ - ); + )); // Offset guides: if (a_OffsetX > 0) { - AppendPrintf(SVG, "\n", + SVG.append(fmt::format(FMT_STRING("\n"), a_OffsetX, a_OffsetX - ); + )); } if (a_OffsetZ > 0) { - AppendPrintf(SVG, "\n", + SVG.append(fmt::format(FMT_STRING("\n"), a_OffsetZ, a_OffsetZ - ); + )); } return SVG; } diff --git a/src/Generating/SinglePieceStructuresGen.cpp b/src/Generating/SinglePieceStructuresGen.cpp index fb6dcd67d..375e87fdf 100644 --- a/src/Generating/SinglePieceStructuresGen.cpp +++ b/src/Generating/SinglePieceStructuresGen.cpp @@ -166,13 +166,13 @@ bool cSinglePieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaL auto Structures = StringSplitAndTrim(a_Prefabs, "|"); for (const auto & S: Structures) { - auto FileName = Printf("Prefabs%cSinglePieceStructures%c%s.cubeset", cFile::PathSeparator(), cFile::PathSeparator(), S.c_str()); + auto FileName = fmt::format(FMT_STRING("Prefabs{0}SinglePieceStructures{0}{1}.cubeset"), cFile::PathSeparator(), S); if (!cFile::IsFile(FileName)) { FileName.append(".gz"); if (!cFile::IsFile(FileName)) { - LOGWARNING("Cannot load SinglePieceStructure cubeset file %s", FileName.c_str()); + LOGWARNING("Cannot load SinglePieceStructure cubeset file %s", FileName); continue; } } @@ -187,7 +187,7 @@ bool cSinglePieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaL // Report a warning if no generators available: if (m_Gens.empty()) { - LOGWARNING("The PieceStructures generator was asked to generate \"%s\", but none of the prefabs are valid.", a_Prefabs.c_str()); + LOGWARNING("The PieceStructures generator was asked to generate \"%s\", but none of the prefabs are valid.", a_Prefabs); return false; } return true; diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index 3bdf94d1c..2b497e9a5 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -410,7 +410,7 @@ void cStructGenLakes::CreateLakeImage(int a_ChunkX, int a_ChunkZ, int a_MaxLakeH // TODO: Turn sponge next to lava into stone - // a_Lake.SaveToSchematicFile(Printf("Lake_%d_%d.schematic", a_ChunkX, a_ChunkZ)); + // a_Lake.SaveToSchematicFile(fmt::format(FMT_STRING("Lake_{}_{}.schematic"), a_ChunkX, a_ChunkZ)); } diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp index 6575b2f3a..d7edf688d 100644 --- a/src/Generating/VillageGen.cpp +++ b/src/Generating/VillageGen.cpp @@ -354,13 +354,13 @@ cVillageGen::cVillageGen( for (const auto & toLoad: a_PrefabsToLoad) { auto prefabs = std::make_shared(); - auto fileName = Printf("Prefabs%sVillages%s%s.cubeset", cFile::GetPathSeparator().c_str(), cFile::GetPathSeparator().c_str(), toLoad.c_str()); + auto fileName = fmt::format(FMT_STRING("Prefabs{0}Villages{0}{1}.cubeset"), cFile::GetPathSeparator(), toLoad); if (prefabs->LoadFromFile(fileName, true)) { if (NoCaseCompare(prefabs->GetIntendedUse(), "village") != 0) { LOGWARNING("Village generator: File %s is intended for use in \"%s\", rather than villages. Loading the file, but the generator may behave unexpectedly.", - fileName.c_str(), prefabs->GetIntendedUse().c_str() + fileName, prefabs->GetIntendedUse() ); } prefabs->AssignGens(a_Seed, m_BiomeGen, m_HeightGen, a_SeaLevel); -- cgit v1.2.3