mirror of https://github.com/OpenRCT2/OpenRCT2.git
Move storage into Formatter class and refactor usage
This commit is contained in:
parent
1982e8491b
commit
2639349925
|
@ -467,10 +467,10 @@ static void widget_groupbox_draw(rct_drawpixelinfo* dpi, rct_window* w, rct_widg
|
|||
colour |= COLOUR_FLAG_INSET;
|
||||
|
||||
utf8 buffer[512] = { 0 };
|
||||
uint8_t args[sizeof(uintptr_t)] = { 0 };
|
||||
format_string(buffer, sizeof(buffer), stringId, formatArgs);
|
||||
Formatter(args).Add<utf8*>(buffer);
|
||||
gfx_draw_string_left(dpi, STR_STRING, args, colour, { l, t });
|
||||
Formatter ft;
|
||||
ft.Add<utf8*>(buffer);
|
||||
gfx_draw_string_left(dpi, STR_STRING, ft.Data(), colour, { l, t });
|
||||
textRight = l + gfx_get_string_width(buffer) + 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1139,11 +1139,10 @@ static void window_editor_objective_options_rides_scrollpaint(rct_window* w, rct
|
|||
}
|
||||
|
||||
// Ride name
|
||||
uint8_t args[32]{};
|
||||
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
ride->FormatNameTo(ft);
|
||||
gfx_draw_string_left(dpi, stringId, args, COLOUR_BLACK, { 15, y });
|
||||
gfx_draw_string_left(dpi, stringId, ft.Data(), COLOUR_BLACK, { 15, y });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1066,11 +1066,10 @@ static bool guest_should_be_visible(Peep* peep)
|
|||
if (_window_guest_list_filter_name[0] != '\0')
|
||||
{
|
||||
char name[256]{};
|
||||
uint8_t args[32]{};
|
||||
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
peep->FormatNameTo(ft);
|
||||
format_string(name, sizeof(name), STR_STRINGID, args);
|
||||
format_string(name, sizeof(name), STR_STRINGID, ft.Data());
|
||||
if (strcasestr(name, _window_guest_list_filter_name) == nullptr)
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -111,14 +111,13 @@ private:
|
|||
else
|
||||
{
|
||||
char str_downloading_objects[256]{};
|
||||
uint8_t args[32]{};
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
if (_downloadStatusInfo.Source.empty())
|
||||
{
|
||||
ft.Add<int16_t>(static_cast<int16_t>(_downloadStatusInfo.Count));
|
||||
ft.Add<int16_t>(static_cast<int16_t>(_downloadStatusInfo.Total));
|
||||
ft.Add<char*>(_downloadStatusInfo.Name.c_str());
|
||||
format_string(str_downloading_objects, sizeof(str_downloading_objects), STR_DOWNLOADING_OBJECTS, args);
|
||||
format_string(str_downloading_objects, sizeof(str_downloading_objects), STR_DOWNLOADING_OBJECTS, ft.Data());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -126,7 +125,8 @@ private:
|
|||
ft.Add<char*>(_downloadStatusInfo.Source.c_str());
|
||||
ft.Add<int16_t>(static_cast<int16_t>(_downloadStatusInfo.Count));
|
||||
ft.Add<int16_t>(static_cast<int16_t>(_downloadStatusInfo.Total));
|
||||
format_string(str_downloading_objects, sizeof(str_downloading_objects), STR_DOWNLOADING_OBJECTS_FROM, args);
|
||||
format_string(
|
||||
str_downloading_objects, sizeof(str_downloading_objects), STR_DOWNLOADING_OBJECTS_FROM, ft.Data());
|
||||
}
|
||||
|
||||
auto intent = Intent(WC_NETWORK_STATUS);
|
||||
|
|
|
@ -2085,11 +2085,10 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
|||
auto banner = tileElement->AsWall()->GetBanner();
|
||||
if (banner != nullptr && !banner->IsNull())
|
||||
{
|
||||
uint8_t args[32]{};
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
banner->FormatTextTo(ft);
|
||||
gfx_draw_string_left(
|
||||
dpi, STR_TILE_INSPECTOR_ENTRY_BANNER_TEXT, args, COLOUR_WHITE,
|
||||
dpi, STR_TILE_INSPECTOR_ENTRY_BANNER_TEXT, ft.Data(), COLOUR_WHITE,
|
||||
screenCoords + ScreenCoordsXY{ 0, 11 });
|
||||
}
|
||||
}
|
||||
|
@ -2152,11 +2151,10 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
|||
auto banner = sceneryElement->GetBanner();
|
||||
if (banner != nullptr && !banner->IsNull())
|
||||
{
|
||||
uint8_t args[32]{};
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
banner->FormatTextTo(ft);
|
||||
gfx_draw_string_left(
|
||||
dpi, STR_TILE_INSPECTOR_ENTRY_BANNER_TEXT, args, COLOUR_WHITE,
|
||||
dpi, STR_TILE_INSPECTOR_ENTRY_BANNER_TEXT, ft.Data(), COLOUR_WHITE,
|
||||
screenCoords + ScreenCoordsXY{ 0, 22 });
|
||||
}
|
||||
}
|
||||
|
@ -2186,10 +2184,9 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
|||
auto banner = tileElement->AsBanner()->GetBanner();
|
||||
if (banner != nullptr && !banner->IsNull())
|
||||
{
|
||||
uint8_t args[32]{};
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
banner->FormatTextTo(ft);
|
||||
gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_ENTRY_BANNER_TEXT, args, COLOUR_WHITE, screenCoords);
|
||||
gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_ENTRY_BANNER_TEXT, ft.Data(), COLOUR_WHITE, screenCoords);
|
||||
}
|
||||
|
||||
// Properties
|
||||
|
|
|
@ -619,8 +619,7 @@ static void window_title_command_editor_tool_down(
|
|||
if (peep != nullptr)
|
||||
{
|
||||
validSprite = true;
|
||||
uint8_t formatArgs[32]{};
|
||||
Formatter ft(formatArgs);
|
||||
Formatter ft;
|
||||
peep->FormatNameTo(ft);
|
||||
format_string(command.SpriteName, USER_STRING_MAX_LENGTH, STR_STRINGID, &peep->Id);
|
||||
}
|
||||
|
@ -631,10 +630,9 @@ static void window_title_command_editor_tool_down(
|
|||
auto ride = vehicle->GetRide();
|
||||
if (ride != nullptr)
|
||||
{
|
||||
uint8_t formatArgs[32]{};
|
||||
Formatter ft(formatArgs);
|
||||
Formatter ft;
|
||||
ride->FormatNameTo(ft);
|
||||
format_string(command.SpriteName, USER_STRING_MAX_LENGTH, STR_STRINGID, formatArgs);
|
||||
format_string(command.SpriteName, USER_STRING_MAX_LENGTH, STR_STRINGID, ft.Data());
|
||||
}
|
||||
}
|
||||
else if (litter != nullptr)
|
||||
|
|
|
@ -128,22 +128,14 @@ void DrawTextBasic(
|
|||
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, rct_string_id format, const Formatter& ft, colour_t colour,
|
||||
TextAlignment alignment, bool underline)
|
||||
{
|
||||
return DrawTextBasic(dpi, coords, format, ft.GetStartBuf(), colour, alignment, underline);
|
||||
return DrawTextBasic(dpi, coords, format, ft.Data(), colour, alignment, underline);
|
||||
}
|
||||
|
||||
void DrawTextEllipsised(
|
||||
rct_drawpixelinfo* dpi, const ScreenCoordsXY& coords, int32_t width, rct_string_id format, const Formatter& ft,
|
||||
colour_t colour, TextAlignment alignment, bool underline)
|
||||
{
|
||||
const void* args = ft.GetStartBuf();
|
||||
TextPaint textPaint = { colour, FONT_SPRITE_BASE_MEDIUM, underline, alignment };
|
||||
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
||||
|
||||
utf8 buffer[512];
|
||||
format_string(buffer, sizeof(buffer), format, args);
|
||||
gfx_clip_string(buffer, width);
|
||||
|
||||
DrawText(dpi, coords, textPaint, buffer);
|
||||
return DrawTextEllipsised(dpi, coords, width, format, ft.Data(), colour, alignment, underline);
|
||||
}
|
||||
|
||||
void gfx_draw_string(rct_drawpixelinfo* dpi, const_utf8string buffer, uint8_t colour, const ScreenCoordsXY& coords)
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "Language.h"
|
||||
#include "StringIds.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
|
@ -82,24 +83,32 @@ extern const rct_string_id DateGameShortMonthNames[MONTH_COUNT];
|
|||
|
||||
class Formatter
|
||||
{
|
||||
const uint8_t* StartBuf;
|
||||
uint8_t* CurrentBuf;
|
||||
std::array<uint8_t, 80> Buffer{};
|
||||
uint8_t* StartBuf{};
|
||||
uint8_t* CurrentBuf{};
|
||||
|
||||
public:
|
||||
explicit Formatter(uint8_t* buf)
|
||||
Formatter(uint8_t* buf)
|
||||
: StartBuf(buf)
|
||||
, CurrentBuf(buf)
|
||||
{
|
||||
}
|
||||
|
||||
Formatter()
|
||||
: Buffer{}
|
||||
, StartBuf(Buffer.data())
|
||||
, CurrentBuf(StartBuf)
|
||||
{
|
||||
}
|
||||
|
||||
static Formatter Common()
|
||||
{
|
||||
return Formatter(gCommonFormatArgs);
|
||||
return Formatter{ gCommonFormatArgs };
|
||||
}
|
||||
|
||||
static Formatter MapTooltip()
|
||||
{
|
||||
return Formatter(gMapTooltipFormatArgs);
|
||||
return Formatter{ gMapTooltipFormatArgs };
|
||||
}
|
||||
|
||||
auto Buf()
|
||||
|
@ -107,7 +116,7 @@ public:
|
|||
return CurrentBuf;
|
||||
}
|
||||
|
||||
auto GetStartBuf() const
|
||||
auto Data() const
|
||||
{
|
||||
return StartBuf;
|
||||
}
|
||||
|
|
|
@ -2443,11 +2443,11 @@ void NetworkBase::Client_Handle_GAMESTATE(NetworkConnection& connection, Network
|
|||
{
|
||||
log_info("Wrote desync report to '%s'", outputFile.c_str());
|
||||
|
||||
uint8_t args[32]{};
|
||||
Formatter(args).Add<char*>(uniqueFileName);
|
||||
Formatter ft;
|
||||
ft.Add<char*>(uniqueFileName);
|
||||
|
||||
char str_desync[1024];
|
||||
format_string(str_desync, sizeof(str_desync), STR_DESYNC_REPORT, args);
|
||||
format_string(str_desync, sizeof(str_desync), STR_DESYNC_REPORT, ft.Data());
|
||||
|
||||
auto intent = Intent(WC_NETWORK_STATUS);
|
||||
intent.putExtra(INTENT_EXTRA_MESSAGE, std::string{ str_desync });
|
||||
|
|
|
@ -536,12 +536,11 @@ void Guest::UpdateEasterEggInteractions()
|
|||
|
||||
int32_t Guest::GetEasterEggNameId() const
|
||||
{
|
||||
uint8_t args[32]{};
|
||||
char buffer[256]{};
|
||||
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
FormatNameTo(ft);
|
||||
format_string(buffer, sizeof(buffer), STR_STRINGID, args);
|
||||
format_string(buffer, sizeof(buffer), STR_STRINGID, ft.Data());
|
||||
|
||||
for (uint32_t i = 0; i < std::size(gPeepEasterEggNames); i++)
|
||||
if (_stricmp(buffer, gPeepEasterEggNames[i]) == 0)
|
||||
|
@ -684,12 +683,11 @@ void Guest::HandleEasterEggName()
|
|||
*/
|
||||
int32_t Guest::CheckEasterEggName(int32_t index) const
|
||||
{
|
||||
uint8_t args[32]{};
|
||||
char buffer[256]{};
|
||||
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
FormatNameTo(ft);
|
||||
format_string(buffer, sizeof(buffer), STR_STRINGID, args);
|
||||
format_string(buffer, sizeof(buffer), STR_STRINGID, ft.Data());
|
||||
|
||||
return _stricmp(buffer, gPeepEasterEggNames[index]) == 0;
|
||||
}
|
||||
|
|
|
@ -1967,11 +1967,9 @@ void Peep::FormatNameTo(Formatter& ft) const
|
|||
|
||||
std::string Peep::GetName() const
|
||||
{
|
||||
uint8_t args[32]{};
|
||||
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
FormatNameTo(ft);
|
||||
return format_string(STR_STRINGID, args);
|
||||
return format_string(STR_STRINGID, ft.Data());
|
||||
}
|
||||
|
||||
bool Peep::SetName(const std::string_view& value)
|
||||
|
@ -3230,17 +3228,15 @@ int32_t peep_compare(const uint16_t sprite_index_a, const uint16_t sprite_index_
|
|||
}
|
||||
|
||||
// Compare their names as strings
|
||||
uint8_t args[32]{};
|
||||
|
||||
char nameA[256]{};
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
peep_a->FormatNameTo(ft);
|
||||
format_string(nameA, sizeof(nameA), STR_STRINGID, args);
|
||||
format_string(nameA, sizeof(nameA), STR_STRINGID, ft.Data());
|
||||
|
||||
char nameB[256]{};
|
||||
ft = Formatter(args);
|
||||
ft.Rewind();
|
||||
peep_b->FormatNameTo(ft);
|
||||
format_string(nameB, sizeof(nameB), STR_STRINGID, args);
|
||||
format_string(nameB, sizeof(nameB), STR_STRINGID, ft.Data());
|
||||
return strlogicalcmp(nameA, nameB);
|
||||
}
|
||||
|
||||
|
|
|
@ -5498,15 +5498,13 @@ static bool ride_with_colour_config_exists(uint8_t ride_type, const TrackColour*
|
|||
bool Ride::NameExists(const std::string_view& name, ride_id_t excludeRideId)
|
||||
{
|
||||
char buffer[256]{};
|
||||
uint8_t formatArgs[32]{};
|
||||
|
||||
for (auto& ride : GetRideManager())
|
||||
{
|
||||
if (ride.id != excludeRideId)
|
||||
{
|
||||
Formatter ft(formatArgs);
|
||||
Formatter ft;
|
||||
ride.FormatNameTo(ft);
|
||||
format_string(buffer, 256, STR_STRINGID, formatArgs);
|
||||
format_string(buffer, 256, STR_STRINGID, ft.Data());
|
||||
if (std::string_view(buffer) == name && ride_has_any_track_elements(&ride))
|
||||
{
|
||||
return true;
|
||||
|
@ -5590,7 +5588,6 @@ money32 ride_get_common_price(Ride* forRide)
|
|||
void Ride::SetNameToDefault()
|
||||
{
|
||||
char rideNameBuffer[256]{};
|
||||
uint8_t rideNameArgs[32]{};
|
||||
|
||||
// Increment default name number until we find a unique name
|
||||
custom_name = {};
|
||||
|
@ -5598,9 +5595,9 @@ void Ride::SetNameToDefault()
|
|||
do
|
||||
{
|
||||
default_name_number++;
|
||||
Formatter ft(rideNameArgs);
|
||||
Formatter ft;
|
||||
FormatNameTo(ft);
|
||||
format_string(rideNameBuffer, 256, STR_STRINGID, &rideNameArgs);
|
||||
format_string(rideNameBuffer, 256, STR_STRINGID, ft.Data());
|
||||
} while (Ride::NameExists(rideNameBuffer, id));
|
||||
}
|
||||
|
||||
|
@ -7565,11 +7562,9 @@ void ride_clear_leftover_entrances(Ride* ride)
|
|||
|
||||
std::string Ride::GetName() const
|
||||
{
|
||||
uint8_t args[32]{};
|
||||
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
FormatNameTo(ft);
|
||||
return format_string(STR_STRINGID, args);
|
||||
return format_string(STR_STRINGID, ft.Data());
|
||||
}
|
||||
|
||||
void Ride::FormatNameTo(Formatter& ft) const
|
||||
|
|
|
@ -59,10 +59,9 @@ static constexpr CodePointToUtf8<FORMAT_COLOUR_CODE_START, FORMAT_COLOUR_CODE_EN
|
|||
|
||||
std::string Banner::GetText() const
|
||||
{
|
||||
uint8_t args[32]{};
|
||||
Formatter ft(args);
|
||||
Formatter ft;
|
||||
FormatTextTo(ft);
|
||||
return format_string(STR_STRINGID, args);
|
||||
return format_string(STR_STRINGID, ft.Data());
|
||||
}
|
||||
|
||||
void Banner::FormatTextTo(Formatter& ft, bool addColour) const
|
||||
|
@ -79,7 +78,7 @@ void Banner::FormatTextTo(Formatter& ft) const
|
|||
{
|
||||
if (flags & BANNER_FLAG_NO_ENTRY)
|
||||
{
|
||||
ft.Add<rct_string_id>(STR_NO_ENTRY).NumBytes();
|
||||
ft.Add<rct_string_id>(STR_NO_ENTRY);
|
||||
}
|
||||
else if (flags & BANNER_FLAG_LINKED_TO_RIDE)
|
||||
{
|
||||
|
@ -90,16 +89,16 @@ void Banner::FormatTextTo(Formatter& ft) const
|
|||
}
|
||||
else
|
||||
{
|
||||
ft.Add<rct_string_id>(STR_DEFAULT_SIGN).NumBytes();
|
||||
ft.Add<rct_string_id>(STR_DEFAULT_SIGN);
|
||||
}
|
||||
}
|
||||
else if (text.empty())
|
||||
{
|
||||
ft.Add<rct_string_id>(STR_DEFAULT_SIGN).NumBytes();
|
||||
ft.Add<rct_string_id>(STR_DEFAULT_SIGN);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft.Add<rct_string_id>(STR_STRING).Add<const char*>(text.c_str()).NumBytes();
|
||||
ft.Add<rct_string_id>(STR_STRING).Add<const char*>(text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue