mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Reduce usage of gCommonStringFormatBuffer
This commit is contained in:
committed by
GitHub
parent
8439499004
commit
96284123e7
@@ -653,9 +653,10 @@ static void DrawCategoryHeading(
|
||||
DrawTextBasic(dpi, { centreX, y }, stringId, {}, { baseColour, TextAlignment::CENTRE });
|
||||
|
||||
// Get string dimensions
|
||||
utf8* buffer = gCommonStringFormatBuffer;
|
||||
format_string(buffer, 256, stringId, nullptr);
|
||||
int32_t categoryStringHalfWidth = (gfx_get_string_width(buffer, FontStyle::Medium) / 2) + 4;
|
||||
utf8 buffer[CommonTextBufferSize];
|
||||
auto bufferPtr = buffer;
|
||||
format_string(bufferPtr, sizeof(buffer), stringId, nullptr);
|
||||
int32_t categoryStringHalfWidth = (gfx_get_string_width(bufferPtr, FontStyle::Medium) / 2) + 4;
|
||||
int32_t strLeft = centreX - categoryStringHalfWidth;
|
||||
int32_t strRight = centreX + categoryStringHalfWidth;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ static rct_widget window_tooltip_widgets[] = {
|
||||
class TooltipWindow final : public Window
|
||||
{
|
||||
private:
|
||||
utf8 _tooltipText[sizeof(gCommonStringFormatBuffer)]{};
|
||||
utf8 _tooltipText[CommonTextBufferSize]{};
|
||||
int16_t _tooltipNumLines = 1;
|
||||
|
||||
public:
|
||||
@@ -106,7 +106,7 @@ private:
|
||||
// Returns the width of the new tooltip text
|
||||
int32_t FormatTextForTooltip(const OpenRCT2String& message)
|
||||
{
|
||||
utf8 tempBuffer[sizeof(gCommonStringFormatBuffer)];
|
||||
utf8 tempBuffer[CommonTextBufferSize];
|
||||
format_string(tempBuffer, sizeof(tempBuffer), message.str, message.args.Data());
|
||||
|
||||
OpenRCT2String formattedMessage{ STR_STRING_TOOLTIP, Formatter() };
|
||||
|
||||
@@ -272,10 +272,11 @@ int32_t gfx_wrap_string(utf8* text, int32_t width, FontStyle fontStyle, int32_t*
|
||||
void gfx_draw_string_left_centred(
|
||||
rct_drawpixelinfo* dpi, StringId format, void* args, colour_t colour, const ScreenCoordsXY& coords)
|
||||
{
|
||||
char* buffer = gCommonStringFormatBuffer;
|
||||
format_string(buffer, 256, format, args);
|
||||
int32_t height = string_get_height_raw(buffer, FontStyle::Medium);
|
||||
gfx_draw_string(dpi, coords - ScreenCoordsXY{ 0, (height / 2) }, buffer, { colour });
|
||||
char buffer[CommonTextBufferSize];
|
||||
auto bufferPtr = buffer;
|
||||
format_string(bufferPtr, sizeof(buffer), format, args);
|
||||
int32_t height = string_get_height_raw(bufferPtr, FontStyle::Medium);
|
||||
gfx_draw_string(dpi, coords - ScreenCoordsXY{ 0, (height / 2) }, bufferPtr, { colour });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -274,11 +274,12 @@ static void chat_clear_input()
|
||||
static int32_t chat_history_draw_string(
|
||||
rct_drawpixelinfo* dpi, const char* text, const ScreenCoordsXY& screenCoords, int32_t width)
|
||||
{
|
||||
auto buffer = gCommonStringFormatBuffer;
|
||||
FormatStringToBuffer(gCommonStringFormatBuffer, sizeof(gCommonStringFormatBuffer), "{OUTLINE}{WHITE}{STRING}", text);
|
||||
char buffer[CommonTextBufferSize];
|
||||
auto bufferPtr = buffer;
|
||||
FormatStringToBuffer(buffer, sizeof(buffer), "{OUTLINE}{WHITE}{STRING}", text);
|
||||
|
||||
int32_t numLines;
|
||||
gfx_wrap_string(buffer, width, FontStyle::Medium, &numLines);
|
||||
gfx_wrap_string(bufferPtr, width, FontStyle::Medium, &numLines);
|
||||
auto lineHeight = font_get_line_height(FontStyle::Medium);
|
||||
|
||||
int32_t expectedY = screenCoords.y - (numLines * lineHeight);
|
||||
@@ -290,8 +291,8 @@ static int32_t chat_history_draw_string(
|
||||
auto lineY = screenCoords.y;
|
||||
for (int32_t line = 0; line <= numLines; ++line)
|
||||
{
|
||||
gfx_draw_string(dpi, { screenCoords.x, lineY - (numLines * lineHeight) }, buffer, { TEXT_COLOUR_254 });
|
||||
buffer = get_string_end(buffer) + 1;
|
||||
gfx_draw_string(dpi, { screenCoords.x, lineY - (numLines * lineHeight) }, bufferPtr, { TEXT_COLOUR_254 });
|
||||
bufferPtr = get_string_end(bufferPtr) + 1;
|
||||
lineY += lineHeight;
|
||||
}
|
||||
return lineY - screenCoords.y;
|
||||
@@ -301,17 +302,18 @@ static int32_t chat_history_draw_string(
|
||||
// Almost the same as gfx_draw_string_left_wrapped
|
||||
int32_t chat_string_wrapped_get_height(void* args, int32_t width)
|
||||
{
|
||||
char* buffer = gCommonStringFormatBuffer;
|
||||
format_string(buffer, 256, STR_STRING, args);
|
||||
char buffer[CommonTextBufferSize];
|
||||
auto bufferPtr = buffer;
|
||||
format_string(bufferPtr, 256, STR_STRING, args);
|
||||
|
||||
int32_t numLines;
|
||||
gfx_wrap_string(buffer, width, FontStyle::Medium, &numLines);
|
||||
gfx_wrap_string(bufferPtr, width, FontStyle::Medium, &numLines);
|
||||
int32_t lineHeight = font_get_line_height(FontStyle::Medium);
|
||||
|
||||
int32_t lineY = 0;
|
||||
for (int32_t line = 0; line <= numLines; ++line)
|
||||
{
|
||||
buffer = get_string_end(buffer) + 1;
|
||||
bufferPtr = get_string_end(bufferPtr) + 1;
|
||||
lineY += lineHeight;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <iterator>
|
||||
#include <limits.h>
|
||||
|
||||
thread_local char gCommonStringFormatBuffer[512];
|
||||
thread_local char gCommonStringFormatBuffer[CommonTextBufferSize];
|
||||
|
||||
#ifdef DEBUG
|
||||
// Set to true before a string format call to see details of the formatting.
|
||||
|
||||
@@ -51,11 +51,13 @@ bool is_user_string_id(StringId stringId);
|
||||
#define REAL_NAME_START 0xA000
|
||||
#define REAL_NAME_END 0xDFFF
|
||||
|
||||
constexpr const size_t CommonTextBufferSize = 512;
|
||||
|
||||
// Real name data
|
||||
extern const char real_name_initials[16];
|
||||
extern const char* real_names[1024];
|
||||
|
||||
extern thread_local char gCommonStringFormatBuffer[512];
|
||||
extern thread_local char gCommonStringFormatBuffer[CommonTextBufferSize];
|
||||
extern bool gDebugStringFormatting;
|
||||
|
||||
extern const StringId SpeedNames[5];
|
||||
|
||||
Reference in New Issue
Block a user