diff --git a/src/openrct2-ui/scripting/CustomListView.cpp b/src/openrct2-ui/scripting/CustomListView.cpp index 788847e205..6897741695 100644 --- a/src/openrct2-ui/scripting/CustomListView.cpp +++ b/src/openrct2-ui/scripting/CustomListView.cpp @@ -18,7 +18,6 @@ # include # include # include -# include # include using namespace OpenRCT2::Scripting; diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index 26f3038585..3d2bc6db39 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -25,7 +25,6 @@ # include # include # include -# include # include # include # include diff --git a/src/openrct2-ui/windows/Error.cpp b/src/openrct2-ui/windows/Error.cpp index 252af9c4cc..03ca90a0fb 100644 --- a/src/openrct2-ui/windows/Error.cpp +++ b/src/openrct2-ui/windows/Error.cpp @@ -17,8 +17,7 @@ #include #include #include -#include -#include +#include namespace OpenRCT2::Ui::Windows { diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index 26dd8ad6f3..ccd002c478 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -26,9 +26,8 @@ #include #include #include -#include +#include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/ProgressWindow.cpp b/src/openrct2-ui/windows/ProgressWindow.cpp index 00f6aebfa2..95adab9b1d 100644 --- a/src/openrct2-ui/windows/ProgressWindow.cpp +++ b/src/openrct2-ui/windows/ProgressWindow.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/openrct2-ui/windows/ServerList.cpp b/src/openrct2-ui/windows/ServerList.cpp index 9b3509a96e..4d12ebc013 100644 --- a/src/openrct2-ui/windows/ServerList.cpp +++ b/src/openrct2-ui/windows/ServerList.cpp @@ -21,7 +21,6 @@ # include # include # include -# include # include # include # include diff --git a/src/openrct2-ui/windows/ServerStart.cpp b/src/openrct2-ui/windows/ServerStart.cpp index a796d08941..20286bf1a7 100644 --- a/src/openrct2-ui/windows/ServerStart.cpp +++ b/src/openrct2-ui/windows/ServerStart.cpp @@ -17,7 +17,6 @@ # include # include # include -# include # include # include # include diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index 5e74726f5a..7dcc186370 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/openrct2-ui/windows/Tooltip.cpp b/src/openrct2-ui/windows/Tooltip.cpp index 8417ba037b..bf2a1bfd60 100644 --- a/src/openrct2-ui/windows/Tooltip.cpp +++ b/src/openrct2-ui/windows/Tooltip.cpp @@ -16,7 +16,6 @@ #include #include #include -#include namespace OpenRCT2::Ui::Windows { diff --git a/src/openrct2-ui/windows/TrackList.cpp b/src/openrct2-ui/windows/TrackList.cpp index 65d1c7ace1..4393603346 100644 --- a/src/openrct2-ui/windows/TrackList.cpp +++ b/src/openrct2-ui/windows/TrackList.cpp @@ -17,8 +17,7 @@ #include #include #include -#include -#include +#include #include #include #include diff --git a/src/openrct2/actions/GameActionResult.cpp b/src/openrct2/actions/GameActionResult.cpp index 7bee0864ab..08c0a29503 100644 --- a/src/openrct2/actions/GameActionResult.cpp +++ b/src/openrct2/actions/GameActionResult.cpp @@ -1,9 +1,11 @@ #include "GameActionResult.h" -#include "../localisation/Localisation.h" +#include "../localisation/Formatting.h" #include +using namespace OpenRCT2; + namespace GameActions { Result::Result(GameActions::Status error, StringId title, StringId message, uint8_t* args /*= nullptr*/) diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index f48cedf701..2baa787821 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -22,8 +22,8 @@ #include "../drawing/IDrawingEngine.h" #include "../interface/Window.h" #include "../localisation/Currency.h" +#include "../localisation/Formatting.h" #include "../localisation/Language.h" -#include "../localisation/Localisation.h" #include "../localisation/StringIds.h" #include "../network/network.h" #include "../paint/VirtualFloor.h" diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index cc45fd3c69..ad6e8a1c68 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -14,7 +14,6 @@ #include "../interface/Colour.h" #include "../localisation/Formatter.h" #include "../localisation/Formatting.h" -#include "../localisation/Localisation.h" #include "../localisation/LocalisationService.h" #include "../paint/Paint.h" #include "../sprites.h" diff --git a/src/openrct2/drawing/Text.cpp b/src/openrct2/drawing/Text.cpp index d89e151dc5..a83ed35025 100644 --- a/src/openrct2/drawing/Text.cpp +++ b/src/openrct2/drawing/Text.cpp @@ -12,7 +12,6 @@ #include "../core/UTF8.h" #include "../localisation/Formatter.h" #include "../localisation/Formatting.h" -#include "../localisation/Localisation.h" #include "Drawing.h" class StaticLayout @@ -153,7 +152,7 @@ int32_t DrawTextWrapped( { const void* args = ft.Data(); - StaticLayout layout(FormatStringIDLegacy(format, args), textPaint, width); + StaticLayout layout(OpenRCT2::FormatStringIDLegacy(format, args), textPaint, width); if (textPaint.Alignment == TextAlignment::CENTRE) { diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index f34ac37137..d5d5bfd8a3 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -29,7 +29,6 @@ #include "../interface/Window_internal.h" #include "../localisation/Formatter.h" #include "../localisation/Formatting.h" -#include "../localisation/Localisation.h" #include "../management/Finance.h" #include "../management/Marketing.h" #include "../management/NewsItem.h" diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 8a55b4567b..e91aab7628 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -291,7 +291,6 @@ - @@ -821,7 +820,6 @@ - diff --git a/src/openrct2/localisation/Formatting.cpp b/src/openrct2/localisation/Formatting.cpp index 6290c3abe4..4276ffb11a 100644 --- a/src/openrct2/localisation/Formatting.cpp +++ b/src/openrct2/localisation/Formatting.cpp @@ -9,6 +9,7 @@ #include "Formatting.h" +#include "../Diagnostic.h" #include "../config/Config.h" #include "../peep/RealNames.h" #include "../util/Util.h" @@ -813,15 +814,6 @@ namespace OpenRCT2 } } - size_t FormatStringLegacy(char* buffer, size_t bufferLen, StringId id, const void* args) - { - thread_local std::vector anyArgs; - anyArgs.clear(); - auto fmt = GetFmtStringById(id); - BuildAnyArgListFromLegacyArgBuffer(fmt, anyArgs, args); - return FormatStringAny(buffer, bufferLen, fmt, anyArgs); - } - static void FormatMonthYear(FormatBuffer& ss, int32_t month, int32_t year) { thread_local std::vector tempArgs; @@ -837,4 +829,67 @@ namespace OpenRCT2 FormatStringAny(ss, fmt, tempArgs, argIndex); } + size_t FormatStringLegacy(char* buffer, size_t bufferLen, StringId id, const void* args) + { + thread_local std::vector anyArgs; + anyArgs.clear(); + auto fmt = GetFmtStringById(id); + BuildAnyArgListFromLegacyArgBuffer(fmt, anyArgs, args); + return FormatStringAny(buffer, bufferLen, fmt, anyArgs); + } + + std::string FormatStringIDLegacy(StringId format, const void* args) + { + std::string buffer(256, 0); + size_t len{}; + for (;;) + { + FormatStringLegacy(buffer.data(), buffer.size(), format, args); + len = buffer.find('\0'); + if (len == std::string::npos) + { + len = buffer.size(); + } + if (len >= buffer.size() - 1) + { + // Null terminator to close to end of buffer, grow buffer and try again + buffer.resize(buffer.size() * 2); + } + else + { + buffer.resize(len); + break; + } + } + return buffer; + } + + /** + * Writes a formatted string to a buffer and converts it to upper case. + * rct2: 0x006C2538 + * dest (edi) + * format (ax) + * args (ecx) + */ + void FormatStringToUpper(utf8* dest, size_t size, StringId format, const void* args) + { + if (size == 0) + { + return; + } + + FormatStringLegacy(dest, size, format, args); + + std::string upperString = String::ToUpper(dest); + + if (upperString.size() + 1 >= size) + { + upperString.resize(size - 1); + dest[size - 1] = '\0'; + LOG_WARNING("Truncating formatted string \"%s\" to %d bytes.", dest, size); + } + + upperString.copy(dest, upperString.size()); + dest[upperString.size()] = '\0'; + } } // namespace OpenRCT2 diff --git a/src/openrct2/localisation/Formatting.h b/src/openrct2/localisation/Formatting.h index ccf59bc84b..b60bb586d7 100644 --- a/src/openrct2/localisation/Formatting.h +++ b/src/openrct2/localisation/Formatting.h @@ -23,6 +23,9 @@ namespace OpenRCT2 { + // TODO: find a better spot for this (RCT12.h?) + constexpr size_t kUserStringMaxLength = 32; + template> class FormatBufferBase { T _storage[StackSize]; @@ -304,5 +307,9 @@ namespace OpenRCT2 std::string FormatStringAny(const FmtString& fmt, const std::vector& args); size_t FormatStringAny(char* buffer, size_t bufferLen, const FmtString& fmt, const std::vector& args); + + // TODO: the following three functions should not be used in new code. size_t FormatStringLegacy(char* buffer, size_t bufferLen, StringId id, const void* args); + std::string FormatStringIDLegacy(StringId format, const void* args); + void FormatStringToUpper(char* dest, size_t size, StringId format, const void* args); } // namespace OpenRCT2 diff --git a/src/openrct2/localisation/Localisation.cpp b/src/openrct2/localisation/Localisation.cpp deleted file mode 100644 index a0f549b9bc..0000000000 --- a/src/openrct2/localisation/Localisation.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2024 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#include "Localisation.h" - -#include "../Diagnostic.h" -#include "../Game.h" -#include "../config/Config.h" -#include "../core/Guard.hpp" -#include "../core/String.hpp" -#include "../ride/Ride.h" -#include "../util/Util.h" -#include "Currency.h" -#include "FormatCodes.h" -#include "Formatting.h" -#include "Localisation.Date.h" - -#include - -using namespace OpenRCT2; - -std::string FormatStringIDLegacy(StringId format, const void* args) -{ - std::string buffer(256, 0); - size_t len{}; - for (;;) - { - OpenRCT2::FormatStringLegacy(buffer.data(), buffer.size(), format, args); - len = buffer.find('\0'); - if (len == std::string::npos) - { - len = buffer.size(); - } - if (len >= buffer.size() - 1) - { - // Null terminator to close to end of buffer, grow buffer and try again - buffer.resize(buffer.size() * 2); - } - else - { - buffer.resize(len); - break; - } - } - return buffer; -} - -/** - * Writes a formatted string to a buffer and converts it to upper case. - * rct2: 0x006C2538 - * dest (edi) - * format (ax) - * args (ecx) - */ -void FormatStringToUpper(utf8* dest, size_t size, StringId format, const void* args) -{ - if (size == 0) - { - return; - } - - OpenRCT2::FormatStringLegacy(dest, size, format, args); - - std::string upperString = String::ToUpper(dest); - - if (upperString.size() + 1 >= size) - { - upperString.resize(size - 1); - dest[size - 1] = '\0'; - LOG_WARNING("Truncating formatted string \"%s\" to %d bytes.", dest, size); - } - - upperString.copy(dest, upperString.size()); - dest[upperString.size()] = '\0'; -} diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h deleted file mode 100644 index b6fe1952b8..0000000000 --- a/src/openrct2/localisation/Localisation.h +++ /dev/null @@ -1,19 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2024 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#pragma once - -#include "StringIdType.h" - -#include - -std::string FormatStringIDLegacy(StringId format, const void* args); -void FormatStringToUpper(char* dest, size_t size, StringId format, const void* args); - -constexpr size_t kUserStringMaxLength = 32; diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 591d33e0c7..f880110f06 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -79,7 +79,6 @@ static constexpr uint32_t MaxPacketsPerUpdate = 100; # include "../interface/Chat.h" # include "../interface/Window.h" # include "../localisation/Localisation.Date.h" -# include "../localisation/Localisation.h" # include "../object/ObjectManager.h" # include "../object/ObjectRepository.h" # include "../scenario/Scenario.h" diff --git a/src/openrct2/network/NetworkConnection.cpp b/src/openrct2/network/NetworkConnection.cpp index 2ed2a0e34f..77fc4ea87b 100644 --- a/src/openrct2/network/NetworkConnection.cpp +++ b/src/openrct2/network/NetworkConnection.cpp @@ -13,7 +13,6 @@ # include "../core/String.hpp" # include "../localisation/Formatting.h" -# include "../localisation/Localisation.h" # include "../platform/Platform.h" # include "Socket.h" # include "network.h" diff --git a/src/openrct2/network/NetworkPlayer.cpp b/src/openrct2/network/NetworkPlayer.cpp index 27f7a8a9e7..ef221ddbf8 100644 --- a/src/openrct2/network/NetworkPlayer.cpp +++ b/src/openrct2/network/NetworkPlayer.cpp @@ -12,7 +12,6 @@ # include "NetworkPlayer.h" # include "../interface/Window.h" -# include "../localisation/Localisation.h" # include "NetworkPacket.h" void NetworkPlayer::SetName(std::string_view name) diff --git a/src/openrct2/paint/tile_element/Paint.Banner.cpp b/src/openrct2/paint/tile_element/Paint.Banner.cpp index f6b22ec944..d76360a3de 100644 --- a/src/openrct2/paint/tile_element/Paint.Banner.cpp +++ b/src/openrct2/paint/tile_element/Paint.Banner.cpp @@ -15,7 +15,6 @@ #include "../../interface/Viewport.h" #include "../../localisation/Formatter.h" #include "../../localisation/Formatting.h" -#include "../../localisation/Localisation.h" #include "../../localisation/StringIds.h" #include "../../object/BannerObject.h" #include "../../object/ObjectEntryManager.h" diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index a737543380..39cf0831b2 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -17,7 +17,6 @@ #include "../../interface/Viewport.h" #include "../../localisation/Formatter.h" #include "../../localisation/Formatting.h" -#include "../../localisation/Localisation.h" #include "../../object/EntranceObject.h" #include "../../object/ObjectManager.h" #include "../../object/StationObject.h" diff --git a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp index 158e4cd541..c0370ea6b0 100644 --- a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp @@ -17,7 +17,6 @@ #include "../../core/UTF8.h" #include "../../interface/Viewport.h" #include "../../localisation/Formatting.h" -#include "../../localisation/Localisation.h" #include "../../localisation/StringIds.h" #include "../../object/LargeSceneryObject.h" #include "../../profiling/Profiling.h" diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 6bf3f01a08..a1397aaa1b 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -18,7 +18,6 @@ #include "../../interface/Viewport.h" #include "../../localisation/Formatter.h" #include "../../localisation/Formatting.h" -#include "../../localisation/Localisation.h" #include "../../localisation/StringIds.h" #include "../../object/FootpathObject.h" #include "../../object/FootpathRailingsObject.h" diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index d5b39bc1db..5f091e477a 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -16,7 +16,6 @@ #include "../../interface/Colour.h" #include "../../interface/Viewport.h" #include "../../localisation/Formatting.h" -#include "../../localisation/Localisation.h" #include "../../localisation/StringIds.h" #include "../../object/WallSceneryEntry.h" #include "../../profiling/Profiling.h" diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 16f08dae89..dd87c66a24 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -37,8 +37,8 @@ #include "../entity/Peep.h" #include "../entity/Staff.h" #include "../interface/Window.h" +#include "../localisation/Formatting.h" #include "../localisation/Localisation.Date.h" -#include "../localisation/Localisation.h" #include "../management/Award.h" #include "../management/Finance.h" #include "../management/Marketing.h" diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 6c1c7d5793..8b43059a21 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -35,8 +35,8 @@ #include "../entity/PatrolArea.h" #include "../entity/Staff.h" #include "../interface/Viewport.h" +#include "../localisation/Formatting.h" #include "../localisation/Localisation.Date.h" -#include "../localisation/Localisation.h" #include "../management/Award.h" #include "../management/Finance.h" #include "../management/Marketing.h" diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index ced7c75419..a8716c2ecf 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -35,7 +35,6 @@ #include "../localisation/Formatter.h" #include "../localisation/Formatting.h" #include "../localisation/Localisation.Date.h" -#include "../localisation/Localisation.h" #include "../management/Finance.h" #include "../management/Marketing.h" #include "../management/NewsItem.h" diff --git a/src/openrct2/scenes/title/Command/FollowEntity.h b/src/openrct2/scenes/title/Command/FollowEntity.h index 0cc98a18a9..ff8e36b547 100644 --- a/src/openrct2/scenes/title/Command/FollowEntity.h +++ b/src/openrct2/scenes/title/Command/FollowEntity.h @@ -11,7 +11,7 @@ #include "../../../Identifiers.h" #include "../../../core/String.hpp" -#include "../../../localisation/Localisation.h" +#include "../../../localisation/Formatting.h" #include diff --git a/src/openrct2/scenes/title/TitleScene.cpp b/src/openrct2/scenes/title/TitleScene.cpp index a7afb7da3b..99a1b61afd 100644 --- a/src/openrct2/scenes/title/TitleScene.cpp +++ b/src/openrct2/scenes/title/TitleScene.cpp @@ -23,7 +23,6 @@ #include "../../interface/Screenshot.h" #include "../../interface/Viewport.h" #include "../../interface/Window.h" -#include "../../localisation/Localisation.h" #include "../../network/NetworkBase.h" #include "../../network/network.h" #include "../../scenario/Scenario.h" diff --git a/src/openrct2/scripting/bindings/entity/ScGuest.cpp b/src/openrct2/scripting/bindings/entity/ScGuest.cpp index bde8fd4b48..ac86f9d32b 100644 --- a/src/openrct2/scripting/bindings/entity/ScGuest.cpp +++ b/src/openrct2/scripting/bindings/entity/ScGuest.cpp @@ -13,7 +13,7 @@ # include "../../../GameState.h" # include "../../../entity/Guest.h" -# include "../../../localisation/Localisation.h" +# include "../../../localisation/Formatting.h" # include "../../../peep/PeepAnimationData.h" # include "../../../ride/RideEntry.h" diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index 9f5ae48928..39185532d7 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -16,9 +16,8 @@ #include "../core/Memory.hpp" #include "../core/String.hpp" #include "../interface/Window.h" -#include "../localisation/FormatCodes.h" #include "../localisation/Formatter.h" -#include "../localisation/Localisation.h" +#include "../localisation/Formatting.h" #include "../management/Finance.h" #include "../network/network.h" #include "../object/BannerSceneryEntry.h" diff --git a/test/tests/FormattingTests.cpp b/test/tests/FormattingTests.cpp index 899adfb126..449cf1eb93 100644 --- a/test/tests/FormattingTests.cpp +++ b/test/tests/FormattingTests.cpp @@ -7,8 +7,6 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include "openrct2/localisation/Formatting.h" - #include #include #include @@ -16,7 +14,7 @@ #include #include #include -#include +#include #include #include #include