From c08541efc762ce14318e0f3f03f0ae08087f9a5f Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 13 Jul 2024 13:25:55 +0200 Subject: [PATCH] Remove gCommonStringFormatBuffer, CommonTextBufferSize --- src/openrct2-ui/scripting/CustomListView.cpp | 5 +++-- src/openrct2-ui/windows/EditorObjectSelection.cpp | 7 ++++--- src/openrct2-ui/windows/ScenarioSelect.cpp | 2 +- src/openrct2/drawing/Drawing.String.cpp | 2 +- src/openrct2/localisation/Localisation.cpp | 2 -- src/openrct2/localisation/Localisation.h | 4 ---- src/openrct2/paint/tile_element/Paint.Path.cpp | 9 +++++---- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/openrct2-ui/scripting/CustomListView.cpp b/src/openrct2-ui/scripting/CustomListView.cpp index ff08ff2694..788847e205 100644 --- a/src/openrct2-ui/scripting/CustomListView.cpp +++ b/src/openrct2-ui/scripting/CustomListView.cpp @@ -715,8 +715,9 @@ void CustomListView::PaintSeperator( DrawTextBasic(dpi, { centreX, pos.y }, STR_STRING, ft, { baseColour, TextAlignment::CENTRE }); // Get string dimensions - FormatStringLegacy(gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), STR_STRING, ft.Data()); - int32_t categoryStringHalfWidth = (GfxGetStringWidth(gCommonStringFormatBuffer, FontStyle::Medium) / 2) + 4; + utf8 stringBuffer[512]{}; + FormatStringLegacy(stringBuffer, sizeof(stringBuffer), STR_STRING, ft.Data()); + int32_t categoryStringHalfWidth = (GfxGetStringWidth(stringBuffer, FontStyle::Medium) / 2) + 4; int32_t strLeft = centreX - categoryStringHalfWidth; int32_t strRight = centreX + categoryStringHalfWidth; diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 8c3c90212f..dad44cdb2a 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -760,7 +760,8 @@ static std::vector _window_editor_object_selection_widgets = { screenCoords.x = gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER ? 0 : 15; - auto bufferWithColour = strcpy(gCommonStringFormatBuffer, highlighted ? "{WINDOW_COLOUR_2}" : "{BLACK}"); + utf8 itemBuffer[512]{}; + auto bufferWithColour = strcpy(itemBuffer, highlighted ? "{WINDOW_COLOUR_2}" : "{BLACK}"); auto buffer = strchr(bufferWithColour, '\0'); colour_t colour = COLOUR_BLACK; @@ -780,7 +781,7 @@ static std::vector _window_editor_object_selection_widgets = { StringId rideTypeStringId = GetRideTypeStringId(listItem.repositoryItem); SafeStrCpy(buffer, LanguageGetString(rideTypeStringId), 256 - (buffer - bufferWithColour)); auto ft = Formatter(); - ft.Add(gCommonStringFormatBuffer); + ft.Add(itemBuffer); DrawTextEllipsised( dpi, screenCoords, width_limit - 15, STR_STRING, ft, { colour, FontStyle::Medium, darkness }); screenCoords.x = widgets[WIDX_LIST_SORT_RIDE].left - widgets[WIDX_LIST].left; @@ -796,7 +797,7 @@ static std::vector _window_editor_object_selection_widgets = { *buffer = 0; } auto ft = Formatter(); - ft.Add(gCommonStringFormatBuffer); + ft.Add(itemBuffer); DrawTextEllipsised(dpi, screenCoords, width_limit, STR_STRING, ft, { colour, FontStyle::Medium, darkness }); } screenCoords.y += kScrollableRowHeight; diff --git a/src/openrct2-ui/windows/ScenarioSelect.cpp b/src/openrct2-ui/windows/ScenarioSelect.cpp index 62d47abde6..be1ac138ef 100644 --- a/src/openrct2-ui/windows/ScenarioSelect.cpp +++ b/src/openrct2-ui/windows/ScenarioSelect.cpp @@ -500,7 +500,7 @@ static Widget _scenarioSelectWidgets[] = { DrawTextBasic(dpi, { centreX, y }, stringId, {}, { baseColour, TextAlignment::CENTRE }); // Get string dimensions - utf8 buffer[CommonTextBufferSize]; + utf8 buffer[512]; auto bufferPtr = buffer; OpenRCT2::FormatStringLegacy(bufferPtr, sizeof(buffer), stringId, nullptr); int32_t categoryStringHalfWidth = (GfxGetStringWidth(bufferPtr, FontStyle::Medium) / 2) + 4; diff --git a/src/openrct2/drawing/Drawing.String.cpp b/src/openrct2/drawing/Drawing.String.cpp index ceb37d1bb6..a1ebd6f89a 100644 --- a/src/openrct2/drawing/Drawing.String.cpp +++ b/src/openrct2/drawing/Drawing.String.cpp @@ -261,7 +261,7 @@ int32_t GfxWrapString(u8string_view text, int32_t width, FontStyle fontStyle, u8 void GfxDrawStringLeftCentred( DrawPixelInfo& dpi, StringId format, void* args, ColourWithFlags colour, const ScreenCoordsXY& coords) { - char buffer[CommonTextBufferSize]; + char buffer[512]; auto bufferPtr = buffer; FormatStringLegacy(bufferPtr, sizeof(buffer), format, args); int32_t height = StringGetHeightRaw(bufferPtr, FontStyle::Medium); diff --git a/src/openrct2/localisation/Localisation.cpp b/src/openrct2/localisation/Localisation.cpp index f026292d48..a0f549b9bc 100644 --- a/src/openrct2/localisation/Localisation.cpp +++ b/src/openrct2/localisation/Localisation.cpp @@ -25,8 +25,6 @@ using namespace OpenRCT2; -thread_local char gCommonStringFormatBuffer[CommonTextBufferSize]; - std::string FormatStringIDLegacy(StringId format, const void* args) { std::string buffer(256, 0); diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h index 1ff44520d9..b6fe1952b8 100644 --- a/src/openrct2/localisation/Localisation.h +++ b/src/openrct2/localisation/Localisation.h @@ -17,7 +17,3 @@ 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; - -constexpr size_t CommonTextBufferSize = 512; - -extern thread_local char gCommonStringFormatBuffer[CommonTextBufferSize]; diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index cab866af85..6bf3f01a08 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -162,17 +162,18 @@ static void PathPaintQueueBanner( { ft.Add(STR_RIDE_ENTRANCE_CLOSED); } + + utf8 bannerBuffer[512]{}; if (Config::Get().general.UpperCaseBanners) { - FormatStringToUpper( - gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), STR_BANNER_TEXT_FORMAT, ft.Data()); + FormatStringToUpper(bannerBuffer, sizeof(bannerBuffer), STR_BANNER_TEXT_FORMAT, ft.Data()); } else { - FormatStringLegacy(gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), STR_BANNER_TEXT_FORMAT, ft.Data()); + FormatStringLegacy(bannerBuffer, sizeof(bannerBuffer), STR_BANNER_TEXT_FORMAT, ft.Data()); } - uint16_t stringWidth = GfxGetStringWidth(gCommonStringFormatBuffer, FontStyle::Tiny); + uint16_t stringWidth = GfxGetStringWidth(bannerBuffer, FontStyle::Tiny); uint16_t scroll = stringWidth > 0 ? (GetGameState().CurrentTicks / 2) % stringWidth : 0; PaintAddImageAsChild(