From 10a5d790c6790e3678a048117c4a4b303813f949 Mon Sep 17 00:00:00 2001 From: Claudio Tiecher Date: Thu, 9 May 2024 13:59:03 +0200 Subject: [PATCH] Part of #21421: replace define with constexpr (#21760) * Part of #21421: refactor TUNNEL_MAX_COUNT * Part of #21421: deleted unused OBJECT_SELECTION_NOT_... * Part of #21421: refactor MAX_SERVER_DESCRIPTION_LENGTH * Part of #21421: refactor EXPENDITURE_TABLE_MONTH_COUNT * Part of #21421: refactor FINANCE_GRAPH_SIZE * Part of #21421: refactor NETWORK_STREAM_VERSION and _ID * Part of #21421: MONEY_STRING_MAXLENGTH * Part of #21421: deleted MAX_USER_STRINGS * Part of #21421: refactor USER_STRING_MAX_LENGTH * Part of #21421: deleted USER_STRING_END * Part of #21421: refactor REAL_NAME_START * Part of #21421: refactor REAL_NAME_END * Part of #21421: deleted FONT(X) and FONT_OPENRCT2_SPRITE * Part of #21421: refactor CURRENCY_SYMBOL_MAX_SIZE * Part of #21421: refactor CURRENCY_RATE_MAX_NUM_DIGITS * Part of #21421: refactor SCROLLABLE_ROW_HEIGHT * Part of #21421: refactor ADD_CLAMP_BODY * Part of #21421: applied clang-format to Util.cpp * Part of #21421: incorporate feedback from #21760 * Part of #21421: revert to nbsp in Currency.cpp * Part of #21421: fix merge conflict * Part of #21421: fix more merge conflict * Part of #21421: apply clang format * Part of #21421: using std::numerics for finding bounds * Part of #21421: fix reference to kAddClampBody * Part of #21421: improved on comments about AddClamp func * Part of #21421: apply correct network stream version number * Part of #21421: apply clang-format --- src/openrct2-ui/windows/AssetPacks.cpp | 2 +- src/openrct2-ui/windows/Cheats.cpp | 10 ++-- src/openrct2-ui/windows/CustomCurrency.cpp | 6 +-- .../windows/EditorInventionsList.cpp | 16 +++--- .../windows/EditorObjectSelection.cpp | 10 ++-- src/openrct2-ui/windows/Finances.cpp | 2 +- src/openrct2-ui/windows/GuestList.cpp | 16 +++--- src/openrct2-ui/windows/LoadSave.cpp | 12 ++--- src/openrct2-ui/windows/Multiplayer.cpp | 22 ++++----- src/openrct2-ui/windows/ObjectLoadError.cpp | 12 ++--- src/openrct2-ui/windows/Park.cpp | 9 ++-- src/openrct2-ui/windows/Ride.cpp | 10 ++-- src/openrct2-ui/windows/RideList.cpp | 10 ++-- src/openrct2-ui/windows/ShortcutKeys.cpp | 14 +++--- src/openrct2-ui/windows/StaffList.cpp | 10 ++-- src/openrct2-ui/windows/TileInspector.cpp | 12 ++--- src/openrct2-ui/windows/TrackList.cpp | 20 ++++---- src/openrct2/GameState.h | 6 +-- src/openrct2/actions/CheatSetAction.cpp | 2 +- src/openrct2/entity/Guest.cpp | 2 +- src/openrct2/entity/Peep.cpp | 2 +- src/openrct2/interface/Fonts.h | 3 -- src/openrct2/interface/Window.h | 2 +- src/openrct2/localisation/Currency.cpp | 2 +- src/openrct2/localisation/Currency.h | 8 +-- src/openrct2/localisation/Formatting.cpp | 4 +- src/openrct2/localisation/Language.h | 2 - src/openrct2/localisation/Localisation.h | 10 ++-- src/openrct2/management/Finance.cpp | 16 +++--- src/openrct2/management/Finance.h | 4 +- src/openrct2/network/NetworkBase.cpp | 7 +-- src/openrct2/object/Object.h | 2 - src/openrct2/paint/Paint.h | 6 +-- .../paint/tile_element/Paint.Surface.cpp | 2 +- .../paint/tile_element/Paint.TileElement.cpp | 4 +- src/openrct2/park/ParkFile.cpp | 4 +- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/ride/CableLift.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 6 +-- src/openrct2/scenario/Scenario.cpp | 2 +- .../scenes/title/Command/FollowEntity.h | 2 +- src/openrct2/scenes/title/TitleSequence.cpp | 2 +- src/openrct2/util/Util.cpp | 49 ------------------- src/openrct2/util/Util.h | 27 +++++++--- src/openrct2/world/Park.cpp | 2 +- src/openrct2/world/Park.h | 2 +- 47 files changed, 168 insertions(+), 211 deletions(-) diff --git a/src/openrct2-ui/windows/AssetPacks.cpp b/src/openrct2-ui/windows/AssetPacks.cpp index 2c425e8172..e69c5d5f87 100644 --- a/src/openrct2-ui/windows/AssetPacks.cpp +++ b/src/openrct2-ui/windows/AssetPacks.cpp @@ -52,7 +52,7 @@ static Widget WindowAssetPacksWidgets[] = { class AssetPacksWindow final : public Window { private: - static constexpr int32_t ItemHeight = SCROLLABLE_ROW_HEIGHT + 1; + static constexpr int32_t ItemHeight = kScrollableRowHeight + 1; static constexpr int32_t ItemCheckBoxSize = ItemHeight - 3; std::optional _highlightedIndex; std::optional _selectedIndex; diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp index 75df3872b8..a7fe4402b8 100644 --- a/src/openrct2-ui/windows/Cheats.cpp +++ b/src/openrct2-ui/windows/Cheats.cpp @@ -358,7 +358,7 @@ static StringId window_cheats_page_titles[] = { class CheatsWindow final : public Window { private: - char _moneySpinnerText[MONEY_STRING_MAXLENGTH]{}; + char _moneySpinnerText[kMoneyStringMaxlength]{}; money64 _moneySpinnerValue = CHEATS_MONEY_DEFAULT; int32_t _parkRatingSpinnerValue{}; int32_t _yearSpinnerValue = 1; @@ -709,13 +709,13 @@ static StringId window_cheats_page_titles[] = { switch (widgetIndex) { case WIDX_MONEY_SPINNER_INCREMENT: - _moneySpinnerValue = AddClamp_money64( + _moneySpinnerValue = AddClamp( CHEATS_MONEY_INCREMENT_DIV * (_moneySpinnerValue / CHEATS_MONEY_INCREMENT_DIV), CHEATS_MONEY_INCREMENT_DIV); InvalidateWidget(WIDX_MONEY_SPINNER); break; case WIDX_MONEY_SPINNER_DECREMENT: - _moneySpinnerValue = AddClamp_money64( + _moneySpinnerValue = AddClamp( CHEATS_MONEY_INCREMENT_DIV * (_moneySpinnerValue / CHEATS_MONEY_INCREMENT_DIV), -CHEATS_MONEY_INCREMENT_DIV); InvalidateWidget(WIDX_MONEY_SPINNER); @@ -789,10 +789,10 @@ static StringId window_cheats_page_titles[] = { CheatsSet(CheatType::NoMoney, GetGameState().Park.Flags & PARK_FLAGS_NO_MONEY ? 0 : 1); break; case WIDX_MONEY_SPINNER: - MoneyToString(_moneySpinnerValue, _moneySpinnerText, MONEY_STRING_MAXLENGTH, false); + MoneyToString(_moneySpinnerValue, _moneySpinnerText, kMoneyStringMaxlength, false); WindowTextInputRawOpen( this, WIDX_MONEY_SPINNER, STR_ENTER_NEW_VALUE, STR_ENTER_NEW_VALUE, {}, _moneySpinnerText, - MONEY_STRING_MAXLENGTH); + kMoneyStringMaxlength); break; case WIDX_SET_MONEY: CheatsSet(CheatType::SetMoney, _moneySpinnerValue); diff --git a/src/openrct2-ui/windows/CustomCurrency.cpp b/src/openrct2-ui/windows/CustomCurrency.cpp index 03cef746b4..9a9c96f818 100644 --- a/src/openrct2-ui/windows/CustomCurrency.cpp +++ b/src/openrct2-ui/windows/CustomCurrency.cpp @@ -110,7 +110,7 @@ static Widget window_custom_currency_widgets[] = { case WIDX_SYMBOL_TEXT: WindowTextInputRawOpen( this, WIDX_SYMBOL_TEXT, STR_CUSTOM_CURRENCY_SYMBOL_INPUT_TITLE, STR_CUSTOM_CURRENCY_SYMBOL_INPUT_DESC, - {}, CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, CURRENCY_SYMBOL_MAX_SIZE); + {}, CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, kCurrencySymbolMaxSize); break; } } @@ -123,7 +123,7 @@ static Widget window_custom_currency_widgets[] = { WindowTextInputOpen( this, WIDX_RATE, STR_RATE_INPUT_TITLE, STR_RATE_INPUT_DESC, {}, STR_FORMAT_INTEGER, static_cast(CurrencyDescriptors[EnumValue(CurrencyType::Custom)].rate), - CURRENCY_RATE_MAX_NUM_DIGITS); + kCurrencyRateMaxNumDigits); break; } } @@ -165,7 +165,7 @@ static Widget window_custom_currency_widgets[] = { case WIDX_SYMBOL_TEXT: SafeStrCpy( CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, std::string(text).c_str(), - CURRENCY_SYMBOL_MAX_SIZE); + kCurrencySymbolMaxSize); gConfigGeneral.CustomCurrencySymbol = CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode; diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 5fde66cf74..beafebca55 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -230,11 +230,11 @@ static Widget _inventionListDragWidgets[] = { ScreenSize size{}; if (scrollIndex == 0) { - size.height = static_cast(gameState.ResearchItemsInvented.size()) * SCROLLABLE_ROW_HEIGHT; + size.height = static_cast(gameState.ResearchItemsInvented.size()) * kScrollableRowHeight; } else { - size.height = static_cast(gameState.ResearchItemsUninvented.size()) * SCROLLABLE_ROW_HEIGHT; + size.height = static_cast(gameState.ResearchItemsUninvented.size()) * kScrollableRowHeight; } return size; } @@ -279,14 +279,14 @@ static Widget _inventionListDragWidgets[] = { GfxClear(dpi, paletteIndex); int16_t boxWidth = widgets[WIDX_RESEARCH_ORDER_SCROLL].width(); - int32_t itemY = -SCROLLABLE_ROW_HEIGHT; + int32_t itemY = -kScrollableRowHeight; auto* dragItem = WindowEditorInventionsListDragGetItem(); const auto& researchList = scrollIndex == 0 ? gameState.ResearchItemsInvented : gameState.ResearchItemsUninvented; for (const auto& researchItem : researchList) { - itemY += SCROLLABLE_ROW_HEIGHT; - if (itemY + SCROLLABLE_ROW_HEIGHT < dpi.y || itemY >= dpi.y + dpi.height) + itemY += kScrollableRowHeight; + if (itemY + kScrollableRowHeight < dpi.y || itemY >= dpi.y + dpi.height) continue; if (_selectedResearchItem == &researchItem) @@ -296,7 +296,7 @@ static Widget _inventionListDragWidgets[] = { { // Highlight top = itemY; - bottom = itemY + SCROLLABLE_ROW_HEIGHT - 1; + bottom = itemY + kScrollableRowHeight - 1; } else { @@ -559,7 +559,7 @@ static Widget _inventionListDragWidgets[] = { auto& researchList = isInvented ? gameState.ResearchItemsInvented : gameState.ResearchItemsUninvented; for (auto& researchItem : researchList) { - y -= SCROLLABLE_ROW_HEIGHT; + y -= kScrollableRowHeight; if (y < 0) { return &researchItem; @@ -575,7 +575,7 @@ static Widget _inventionListDragWidgets[] = { auto& researchList = isInvented ? gameState.ResearchItemsInvented : gameState.ResearchItemsUninvented; for (auto& researchItem : researchList) { - y -= SCROLLABLE_ROW_HEIGHT; + y -= kScrollableRowHeight; if (y < 0) { return &researchItem; diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index b2c945d4f8..3949839cca 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -584,7 +584,7 @@ static std::vector _window_editor_object_selection_widgets = { */ ScreenSize OnScrollGetSize(int32_t scrollIndex) override { - const auto newHeight = static_cast(_listItems.size() * SCROLLABLE_ROW_HEIGHT); + const auto newHeight = static_cast(_listItems.size() * kScrollableRowHeight); return { 0, newHeight }; } @@ -729,7 +729,7 @@ static std::vector _window_editor_object_selection_widgets = { for (size_t i = 0; i < _listItems.size(); i++) { const auto& listItem = _listItems[i]; - if (screenCoords.y + SCROLLABLE_ROW_HEIGHT >= dpi.y && screenCoords.y <= dpi.y + dpi.height) + if (screenCoords.y + kScrollableRowHeight >= dpi.y && screenCoords.y <= dpi.y + dpi.height) { // Draw checkbox if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) && !(*listItem.flags & 0x20)) @@ -741,7 +741,7 @@ static std::vector _window_editor_object_selection_widgets = { && !(*listItem.flags & ObjectSelectionFlags::Flag6); if (highlighted) { - auto bottom = screenCoords.y + (SCROLLABLE_ROW_HEIGHT - 1); + auto bottom = screenCoords.y + (kScrollableRowHeight - 1); GfxFilterRect(dpi, { 0, screenCoords.y, width, bottom }, FilterPaletteID::PaletteDarken1); } @@ -800,7 +800,7 @@ static std::vector _window_editor_object_selection_widgets = { ft.Add(gCommonStringFormatBuffer); DrawTextEllipsised(dpi, screenCoords, width_limit, STR_STRING, ft, { colour, FontStyle::Medium, darkness }); } - screenCoords.y += SCROLLABLE_ROW_HEIGHT; + screenCoords.y += kScrollableRowHeight; } } @@ -1538,7 +1538,7 @@ static std::vector _window_editor_object_selection_widgets = { */ int32_t GetObjectFromObjectSelection(ObjectType object_type, int32_t y) { - int32_t listItemIndex = y / SCROLLABLE_ROW_HEIGHT; + int32_t listItemIndex = y / kScrollableRowHeight; if (listItemIndex < 0 || static_cast(listItemIndex) >= _listItems.size()) return -1; diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index df1f816c91..a1420ca323 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -603,7 +603,7 @@ static Widget _windowFinancesResearchWidgets[] = uint16_t SummaryMaxAvailableMonth() { - return std::min(GetDate().GetMonthsElapsed(), EXPENDITURE_TABLE_MONTH_COUNT - 1); + return std::min(GetDate().GetMonthsElapsed(), kExpenditureTableMonthCount - 1); } #pragma endregion diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index b5c7b4cd25..deb54d58c9 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -129,9 +129,9 @@ static Widget window_guest_list_widgets[] = { char Name[256]; }; - static constexpr uint8_t SUMMARISED_GUEST_ROW_HEIGHT = SCROLLABLE_ROW_HEIGHT + 11; + static constexpr uint8_t SUMMARISED_GUEST_ROW_HEIGHT = kScrollableRowHeight + 11; static constexpr auto GUESTS_PER_PAGE = 2000; - static constexpr const auto GUEST_PAGE_HEIGHT = GUESTS_PER_PAGE * SCROLLABLE_ROW_HEIGHT; + static constexpr const auto GUEST_PAGE_HEIGHT = GUESTS_PER_PAGE * kScrollableRowHeight; static constexpr size_t MaxGroups = 240; TabId _selectedTab{}; @@ -500,7 +500,7 @@ static Widget window_guest_list_widgets[] = { { case TabId::Individual: // Count the number of guests - y = static_cast(_guestList.size()) * SCROLLABLE_ROW_HEIGHT; + y = static_cast(_guestList.size()) * kScrollableRowHeight; _numPages = (_guestList.size() + GUESTS_PER_PAGE - 1) / GUESTS_PER_PAGE; if (_numPages == 0) _selectedPage = 0; @@ -539,7 +539,7 @@ static Widget window_guest_list_widgets[] = { void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - auto i = screenCoords.y / (_selectedTab == TabId::Individual ? SCROLLABLE_ROW_HEIGHT : SUMMARISED_GUEST_ROW_HEIGHT); + auto i = screenCoords.y / (_selectedTab == TabId::Individual ? kScrollableRowHeight : SUMMARISED_GUEST_ROW_HEIGHT); i += static_cast(_selectedPage * GUESTS_PER_PAGE); if (static_cast(i) != _highlightedIndex) { @@ -554,7 +554,7 @@ static Widget window_guest_list_widgets[] = { { case TabId::Individual: { - auto i = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + auto i = screenCoords.y / kScrollableRowHeight; i += static_cast(_selectedPage * GUESTS_PER_PAGE); for (const auto& guestItem : _guestList) { @@ -667,14 +667,14 @@ static Widget window_guest_list_widgets[] = { for (const auto& guestItem : _guestList) { // Check if y is beyond the scroll control - if (y + SCROLLABLE_ROW_HEIGHT + 1 >= -0x7FFF && y + SCROLLABLE_ROW_HEIGHT + 1 > dpi.y && y < 0x7FFF + if (y + kScrollableRowHeight + 1 >= -0x7FFF && y + kScrollableRowHeight + 1 > dpi.y && y < 0x7FFF && y < dpi.y + dpi.height) { // Highlight backcolour and text colour (format) StringId format = STR_BLACK_STRING; if (index == _highlightedIndex) { - GfxFilterRect(dpi, { 0, y, 800, y + SCROLLABLE_ROW_HEIGHT - 1 }, FilterPaletteID::PaletteDarken1); + GfxFilterRect(dpi, { 0, y, 800, y + kScrollableRowHeight - 1 }, FilterPaletteID::PaletteDarken1); format = STR_WINDOW_COLOUR_2_STRINGID; } @@ -722,7 +722,7 @@ static Widget window_guest_list_widgets[] = { break; } } - y += SCROLLABLE_ROW_HEIGHT; + y += kScrollableRowHeight; index++; } } diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 499bb913e4..f155f6773f 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -904,14 +904,14 @@ static Widget window_loadsave_widgets[] = ScreenSize OnScrollGetSize(int32_t scrollIndex) override { - return { 0, no_list_items * SCROLLABLE_ROW_HEIGHT }; + return { 0, no_list_items * kScrollableRowHeight }; } void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { int32_t selectedItem; - selectedItem = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + selectedItem = screenCoords.y / kScrollableRowHeight; if (selectedItem >= no_list_items) return; @@ -924,7 +924,7 @@ static Widget window_loadsave_widgets[] = { int32_t selectedItem; - selectedItem = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + selectedItem = screenCoords.y / kScrollableRowHeight; if (selectedItem >= no_list_items) return; @@ -965,11 +965,11 @@ static Widget window_loadsave_widgets[] = for (int32_t i = 0; i < no_list_items; i++) { - int32_t y = i * SCROLLABLE_ROW_HEIGHT; + int32_t y = i * kScrollableRowHeight; if (y > dpi.y + dpi.height) break; - if (y + SCROLLABLE_ROW_HEIGHT < dpi.y) + if (y + kScrollableRowHeight < dpi.y) continue; StringId stringId = STR_BLACK_STRING; @@ -978,7 +978,7 @@ static Widget window_loadsave_widgets[] = if (i == selected_list_item) { stringId = STR_WINDOW_COLOUR_2_STRINGID; - GfxFilterRect(dpi, { 0, y, listWidth, y + SCROLLABLE_ROW_HEIGHT }, FilterPaletteID::PaletteDarken1); + GfxFilterRect(dpi, { 0, y, listWidth, y + kScrollableRowHeight }, FilterPaletteID::PaletteDarken1); } // display a marker next to the currently loaded game file if (_listItems[i].loaded) diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp index 51e1e02e6d..759692f430 100644 --- a/src/openrct2-ui/windows/Multiplayer.cpp +++ b/src/openrct2-ui/windows/Multiplayer.cpp @@ -569,7 +569,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { Invalidate(); } - screenSize = { 0, NetworkGetNumPlayers() * SCROLLABLE_ROW_HEIGHT }; + screenSize = { 0, NetworkGetNumPlayers() * kScrollableRowHeight }; int32_t i = screenSize.height - window_multiplayer_players_widgets[WIDX_LIST].bottom + window_multiplayer_players_widgets[WIDX_LIST].top + 21; if (i < 0) @@ -590,7 +590,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { Invalidate(); } - screenSize = { 0, NetworkGetNumActions() * SCROLLABLE_ROW_HEIGHT }; + screenSize = { 0, NetworkGetNumActions() * kScrollableRowHeight }; int32_t i = screenSize.height - window_multiplayer_groups_widgets[WIDX_LIST].bottom + window_multiplayer_groups_widgets[WIDX_LIST].top + 21; if (i < 0) @@ -612,7 +612,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { { case WINDOW_MULTIPLAYER_PAGE_PLAYERS: { - int32_t index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + int32_t index = screenCoords.y / kScrollableRowHeight; if (index >= no_list_items) return; @@ -626,7 +626,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { case WINDOW_MULTIPLAYER_PAGE_GROUPS: { - int32_t index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + int32_t index = screenCoords.y / kScrollableRowHeight; if (index >= no_list_items) return; @@ -648,7 +648,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { case WINDOW_MULTIPLAYER_PAGE_PLAYERS: case WINDOW_MULTIPLAYER_PAGE_GROUPS: { - int32_t index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + int32_t index = screenCoords.y / kScrollableRowHeight; if (index >= no_list_items) return; @@ -751,7 +751,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { break; } - if (screenCoords.y + SCROLLABLE_ROW_HEIGHT + 1 >= dpi.y) + if (screenCoords.y + kScrollableRowHeight + 1 >= dpi.y) { thread_local std::string _buffer; _buffer.reserve(512); @@ -762,7 +762,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { if (listPosition == selected_list_item) { GfxFilterRect( - dpi, { 0, screenCoords.y, 800, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1 }, + dpi, { 0, screenCoords.y, 800, screenCoords.y + kScrollableRowHeight - 1 }, FilterPaletteID::PaletteDarken1); _buffer += NetworkGetPlayerName(player); colour = colours[2]; @@ -831,7 +831,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { screenCoords.x = 356; GfxDrawString(dpi, screenCoords, _buffer.c_str(), { colour }); } - screenCoords.y += SCROLLABLE_ROW_HEIGHT; + screenCoords.y += kScrollableRowHeight; listPosition++; } } @@ -893,7 +893,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { if (i == selected_list_item) { GfxFilterRect( - dpi, { 0, screenCoords.y, 800, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1 }, + dpi, { 0, screenCoords.y, 800, screenCoords.y + kScrollableRowHeight - 1 }, FilterPaletteID::PaletteDarken1); } if (screenCoords.y > dpi.y + dpi.height) @@ -901,7 +901,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { break; } - if (screenCoords.y + SCROLLABLE_ROW_HEIGHT + 1 >= dpi.y) + if (screenCoords.y + kScrollableRowHeight + 1 >= dpi.y) { int32_t groupindex = NetworkGetGroupIndex(_selectedGroup); if (groupindex != -1) @@ -918,7 +918,7 @@ static constexpr StringId WindowMultiplayerPageTitles[] = { ft.Add(NetworkGetActionNameStringID(i)); DrawTextBasic(dpi, { 10, screenCoords.y }, STR_WINDOW_COLOUR_2_STRINGID, ft); } - screenCoords.y += SCROLLABLE_ROW_HEIGHT; + screenCoords.y += kScrollableRowHeight; } } diff --git a/src/openrct2-ui/windows/ObjectLoadError.cpp b/src/openrct2-ui/windows/ObjectLoadError.cpp index 3eca21d95e..47fd301eb4 100644 --- a/src/openrct2-ui/windows/ObjectLoadError.cpp +++ b/src/openrct2-ui/windows/ObjectLoadError.cpp @@ -465,19 +465,19 @@ static Widget window_object_load_error_widgets[] = { ScreenSize OnScrollGetSize(const int32_t scrollIndex) override { - return ScreenSize(0, no_list_items * SCROLLABLE_ROW_HEIGHT); + return ScreenSize(0, no_list_items * kScrollableRowHeight); } void OnScrollMouseDown(const int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - const auto selectedItem = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + const auto selectedItem = screenCoords.y / kScrollableRowHeight; SelectObjectFromList(selectedItem); } void OnScrollMouseOver(const int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { // Highlight item that the cursor is over, or remove highlighting if none - const auto selectedItem = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + const auto selectedItem = screenCoords.y / kScrollableRowHeight; if (selectedItem < 0 || selectedItem >= no_list_items) _highlightedIndex = -1; else @@ -513,15 +513,15 @@ static Widget window_object_load_error_widgets[] = { for (int32_t i = 0; i < no_list_items; i++) { ScreenCoordsXY screenCoords; - screenCoords.y = i * SCROLLABLE_ROW_HEIGHT; + screenCoords.y = i * kScrollableRowHeight; if (screenCoords.y > dpi.y + dpi.height) break; - if (screenCoords.y + SCROLLABLE_ROW_HEIGHT < dpi.y) + if (screenCoords.y + kScrollableRowHeight < dpi.y) continue; const auto screenRect = ScreenRect{ { 0, screenCoords.y }, - { listWidth, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1 } }; + { listWidth, screenCoords.y + kScrollableRowHeight - 1 } }; // If hovering over item, change the color and fill the backdrop. if (i == selected_list_item) GfxFillRect(dpi, screenRect, ColourMapA[colours[1]].darker); diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index 7c8d7a554b..02a5bfebf4 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -427,7 +427,7 @@ static constexpr WindowParkAward _parkAwards[] = { { auto& park = OpenRCT2::GetGameState().Park; WindowTextInputRawOpen( - this, WIDX_RENAME, STR_PARK_NAME, STR_ENTER_PARK_NAME, {}, park.Name.c_str(), USER_STRING_MAX_LENGTH); + this, WIDX_RENAME, STR_PARK_NAME, STR_ENTER_PARK_NAME, {}, park.Name.c_str(), kUserStringMaxLength); break; } case WIDX_CLOSE_LIGHT: @@ -853,11 +853,10 @@ static constexpr WindowParkAward _parkAwards[] = { } case WIDX_PRICE: { - utf8 _moneyInputText[MONEY_STRING_MAXLENGTH] = {}; - MoneyToString(Park::GetEntranceFee(), _moneyInputText, MONEY_STRING_MAXLENGTH, false); + utf8 _moneyInputText[kMoneyStringMaxlength] = {}; + MoneyToString(Park::GetEntranceFee(), _moneyInputText, kMoneyStringMaxlength, false); WindowTextInputRawOpen( - this, WIDX_PRICE, STR_ENTER_NEW_VALUE, STR_ENTER_NEW_VALUE, {}, _moneyInputText, - MONEY_STRING_MAXLENGTH); + this, WIDX_PRICE, STR_ENTER_NEW_VALUE, STR_ENTER_NEW_VALUE, {}, _moneyInputText, kMoneyStringMaxlength); } } } diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index e48dca60f9..b904ec1955 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -6110,7 +6110,7 @@ static_assert(std::size(RatingNames) == 6); void IncomeOnMouseUp(WidgetIndex widgetIndex) { - utf8 _moneyInputText[MONEY_STRING_MAXLENGTH] = {}; + utf8 _moneyInputText[kMoneyStringMaxlength] = {}; switch (widgetIndex) { @@ -6137,10 +6137,10 @@ static_assert(std::size(RatingNames) == 6); auto ride = GetRide(rideId); if (ride != nullptr) { - MoneyToString(ride->price[0], _moneyInputText, MONEY_STRING_MAXLENGTH, true); + MoneyToString(ride->price[0], _moneyInputText, kMoneyStringMaxlength, true); WindowTextInputRawOpen( this, WIDX_PRIMARY_PRICE, STR_ENTER_NEW_VALUE, STR_ENTER_NEW_VALUE, {}, _moneyInputText, - MONEY_STRING_MAXLENGTH); + kMoneyStringMaxlength); } break; } @@ -6151,10 +6151,10 @@ static_assert(std::size(RatingNames) == 6); { auto price64 = IncomeGetSecondaryPrice(); - MoneyToString(price64, _moneyInputText, MONEY_STRING_MAXLENGTH, true); + MoneyToString(price64, _moneyInputText, kMoneyStringMaxlength, true); WindowTextInputRawOpen( this, WIDX_SECONDARY_PRICE, STR_ENTER_NEW_VALUE, STR_ENTER_NEW_VALUE, {}, _moneyInputText, - MONEY_STRING_MAXLENGTH); + kMoneyStringMaxlength); } break; case WIDX_SECONDARY_PRICE_SAME_THROUGHOUT_PARK: diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index 73f5ad8f2a..9efda22713 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -385,7 +385,7 @@ static Widget _rideListWidgets[] = { */ ScreenSize OnScrollGetSize(int32_t scrollIndex) override { - const auto newHeight = static_cast(_rideList.size() * SCROLLABLE_ROW_HEIGHT); + const auto newHeight = static_cast(_rideList.size() * kScrollableRowHeight); if (selected_list_item != -1) { selected_list_item = -1; @@ -410,7 +410,7 @@ static Widget _rideListWidgets[] = { */ void OnScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - const auto index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + const auto index = screenCoords.y / kScrollableRowHeight; if (index < 0 || static_cast(index) >= _rideList.size()) return; @@ -436,7 +436,7 @@ static Widget _rideListWidgets[] = { */ void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - const auto index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + const auto index = screenCoords.y / kScrollableRowHeight; if (index < 0 || static_cast(index) >= _rideList.size()) return; @@ -551,7 +551,7 @@ static Widget _rideListWidgets[] = { if (i == static_cast(selected_list_item)) { // Background highlight - GfxFilterRect(dpi, { 0, y, 800, y + SCROLLABLE_ROW_HEIGHT - 1 }, FilterPaletteID::PaletteDarken1); + GfxFilterRect(dpi, { 0, y, 800, y + kScrollableRowHeight - 1 }, FilterPaletteID::PaletteDarken1); format = (_quickDemolishMode ? STR_LIGHTPINK_STRINGID : STR_WINDOW_COLOUR_2_STRINGID); } @@ -741,7 +741,7 @@ static Widget _rideListWidgets[] = { ft.Add(formatSecondary); } DrawTextEllipsised(dpi, { 160, y - 1 }, 157, format, ft); - y += SCROLLABLE_ROW_HEIGHT; + y += kScrollableRowHeight; } } diff --git a/src/openrct2-ui/windows/ShortcutKeys.cpp b/src/openrct2-ui/windows/ShortcutKeys.cpp index cc9f3d7339..084373cb06 100644 --- a/src/openrct2-ui/windows/ShortcutKeys.cpp +++ b/src/openrct2-ui/windows/ShortcutKeys.cpp @@ -263,7 +263,7 @@ static Widget window_shortcut_change_widgets[] = { ScreenSize OnScrollGetSize(int32_t scrollIndex) override { - auto h = static_cast(_list.size() * SCROLLABLE_ROW_HEIGHT); + auto h = static_cast(_list.size() * kScrollableRowHeight); auto bottom = std::max(0, h - widgets[WIDX_SCROLL].bottom + widgets[WIDX_SCROLL].top + 21); if (bottom < scrolls[0].v_top) { @@ -275,7 +275,7 @@ static Widget window_shortcut_change_widgets[] = { void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - auto index = static_cast((screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT); + auto index = static_cast((screenCoords.y - 1) / kScrollableRowHeight); if (static_cast(index) < _list.size()) { _highlightedItem = index; @@ -289,7 +289,7 @@ static Widget window_shortcut_change_widgets[] = { void OnScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - auto selectedItem = static_cast((screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT); + auto selectedItem = static_cast((screenCoords.y - 1) / kScrollableRowHeight); if (selectedItem < _list.size()) { // Is this a separator? @@ -314,13 +314,13 @@ static Widget window_shortcut_change_widgets[] = { for (size_t i = 0; i < _list.size(); ++i) { - auto y = static_cast(1 + i * SCROLLABLE_ROW_HEIGHT); + auto y = static_cast(1 + i * kScrollableRowHeight); if (y > dpi.y + dpi.height) { break; } - if (y + SCROLLABLE_ROW_HEIGHT < dpi.y) + if (y + kScrollableRowHeight < dpi.y) { continue; } @@ -504,7 +504,7 @@ static Widget window_shortcut_change_widgets[] = { void DrawSeparator(DrawPixelInfo& dpi, int32_t y, int32_t scrollWidth) { - const int32_t top = y + (SCROLLABLE_ROW_HEIGHT / 2) - 1; + const int32_t top = y + (kScrollableRowHeight / 2) - 1; GfxFillRect(dpi, { { 0, top }, { scrollWidth, top } }, ColourMapA[colours[0]].mid_dark); GfxFillRect(dpi, { { 0, top + 1 }, { scrollWidth, top + 1 } }, ColourMapA[colours[0]].lightest); } @@ -516,7 +516,7 @@ static Widget window_shortcut_change_widgets[] = { if (isHighlighted) { format = STR_WINDOW_COLOUR_2_STRINGID; - GfxFilterRect(dpi, { 0, y - 1, scrollWidth, y + (SCROLLABLE_ROW_HEIGHT - 2) }, FilterPaletteID::PaletteDarken1); + GfxFilterRect(dpi, { 0, y - 1, scrollWidth, y + (kScrollableRowHeight - 2) }, FilterPaletteID::PaletteDarken1); } auto bindingOffset = (scrollWidth * 2) / 3; diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 33aa616c1b..3ec1d923ea 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -323,7 +323,7 @@ static Widget _staffListWidgets[] = { Invalidate(); } - auto scrollHeight = static_cast(_staffList.size()) * SCROLLABLE_ROW_HEIGHT; + auto scrollHeight = static_cast(_staffList.size()) * kScrollableRowHeight; auto i = scrollHeight - widgets[WIDX_STAFF_LIST_LIST].bottom + widgets[WIDX_STAFF_LIST_LIST].top + 21; if (i < 0) i = 0; @@ -339,7 +339,7 @@ static Widget _staffListWidgets[] = { void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - auto i = static_cast(screenCoords.y / SCROLLABLE_ROW_HEIGHT); + auto i = static_cast(screenCoords.y / kScrollableRowHeight); if (i != _highlightedIndex) { _highlightedIndex = static_cast(i); @@ -349,7 +349,7 @@ static Widget _staffListWidgets[] = { void OnScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - int32_t i = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + int32_t i = screenCoords.y / kScrollableRowHeight; for (const auto& entry : _staffList) { if (i == 0) @@ -409,7 +409,7 @@ static Widget _staffListWidgets[] = { if (i == _highlightedIndex) { - GfxFilterRect(dpi, { 0, y, 800, y + (SCROLLABLE_ROW_HEIGHT - 1) }, FilterPaletteID::PaletteDarken1); + GfxFilterRect(dpi, { 0, y, 800, y + (kScrollableRowHeight - 1) }, FilterPaletteID::PaletteDarken1); format = (_quickFireMode ? STR_LIGHTPINK_STRINGID : STR_WINDOW_COLOUR_2_STRINGID); } @@ -451,7 +451,7 @@ static Widget _staffListWidgets[] = { } } - y += SCROLLABLE_ROW_HEIGHT; + y += kScrollableRowHeight; i++; } } diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 84eb33b92e..767cc7a6a0 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -993,7 +993,7 @@ static uint64_t PageDisabledWidgets[] = { ScreenSize OnScrollGetSize(int32_t scrollIndex) override { - return ScreenSize(WW - 30, windowTileInspectorElementCount * SCROLLABLE_ROW_HEIGHT); + return ScreenSize(WW - 30, windowTileInspectorElementCount * kScrollableRowHeight); } void OnScrollMouseDown(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override @@ -1003,7 +1003,7 @@ static uint64_t PageDisabledWidgets[] = { return; // Because the list items are displayed in reverse order, subtract the calculated index from the amount of elements - const int16_t index = windowTileInspectorElementCount - (screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT - 1; + const int16_t index = windowTileInspectorElementCount - (screenCoords.y - 1) / kScrollableRowHeight - 1; const ScreenRect checkboxColumnRect{ { 2, 0 }, { 15, screenCoords.y } }; if (index >= 0 && checkboxColumnRect.Contains(screenCoords)) { // Checkbox was clicked @@ -1017,7 +1017,7 @@ static uint64_t PageDisabledWidgets[] = { void OnScrollMouseOver(int32_t scrollIndex, const ScreenCoordsXY& screenCoords) override { - int16_t index = windowTileInspectorElementCount - (screenCoords.y - 1) / SCROLLABLE_ROW_HEIGHT - 1; + int16_t index = windowTileInspectorElementCount - (screenCoords.y - 1) / kScrollableRowHeight - 1; if (index < 0 || index >= windowTileInspectorElementCount) _highlightedIndex = -1; else @@ -1584,7 +1584,7 @@ static uint64_t PageDisabledWidgets[] = { } ScreenCoordsXY screenCoords{}; - screenCoords.y = SCROLLABLE_ROW_HEIGHT * (windowTileInspectorElementCount - 1); + screenCoords.y = kScrollableRowHeight * (windowTileInspectorElementCount - 1); int32_t i = 0; char buffer[256]; @@ -1601,7 +1601,7 @@ static uint64_t PageDisabledWidgets[] = { // Draw row background colour auto fillRectangle = ScreenRect{ { 0, screenCoords.y }, - { listWidth, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1 } }; + { listWidth, screenCoords.y + kScrollableRowHeight - 1 } }; if (selectedRow) GfxFillRect(dpi, fillRectangle, ColourMapA[colours[1]].mid_dark); else if (hoveredRow) @@ -1718,7 +1718,7 @@ static uint64_t PageDisabledWidgets[] = { if (last) DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ LastFlagColumnXY.x, 0 }, stringFormat, checkboxFormatter); - screenCoords.y -= SCROLLABLE_ROW_HEIGHT; + screenCoords.y -= kScrollableRowHeight; i++; } while (!(tileElement++)->IsLastForTile()); } diff --git a/src/openrct2-ui/windows/TrackList.cpp b/src/openrct2-ui/windows/TrackList.cpp index 19a050b57e..9ad501a3e7 100644 --- a/src/openrct2-ui/windows/TrackList.cpp +++ b/src/openrct2-ui/windows/TrackList.cpp @@ -74,7 +74,7 @@ static Widget _trackListWidgets[] = { { private: std::vector _trackDesigns; - utf8 _filterString[USER_STRING_MAX_LENGTH]{}; + utf8 _filterString[kUserStringMaxLength]{}; std::vector _filteredTrackIds; uint16_t _loadedTrackDesignIndex; std::unique_ptr _loadedTrackDesign; @@ -172,7 +172,7 @@ static Widget _trackListWidgets[] = { maxItems++; } - int32_t index = screenCoords.y / SCROLLABLE_ROW_HEIGHT; + int32_t index = screenCoords.y / kScrollableRowHeight; if (index < 0 || static_cast(index) >= maxItems) { index = -1; @@ -328,7 +328,7 @@ static Widget _trackListWidgets[] = { // Extra item: custom design numItems++; } - int32_t scrollHeight = static_cast(numItems * SCROLLABLE_ROW_HEIGHT); + int32_t scrollHeight = static_cast(numItems * kScrollableRowHeight); return { width, scrollHeight }; } @@ -519,7 +519,7 @@ static Widget _trackListWidgets[] = { { // Vehicle design not available DrawTextEllipsised(dpi, screenPos, 368, STR_VEHICLE_DESIGN_UNAVAILABLE, {}, { TextAlignment::CENTRE }); - screenPos.y -= SCROLLABLE_ROW_HEIGHT; + screenPos.y -= kScrollableRowHeight; } if (_loadedTrackDesign->track_flags & TRACK_DESIGN_FLAG_SCENERY_UNAVAILABLE) @@ -529,7 +529,7 @@ static Widget _trackListWidgets[] = { // Scenery not available DrawTextEllipsised( dpi, screenPos, 368, STR_DESIGN_INCLUDES_SCENERY_WHICH_IS_UNAVAILABLE, {}, { TextAlignment::CENTRE }); - screenPos.y -= SCROLLABLE_ROW_HEIGHT; + screenPos.y -= kScrollableRowHeight; } } @@ -696,7 +696,7 @@ static Widget _trackListWidgets[] = { { // Highlight GfxFilterRect( - dpi, { screenCoords, { width, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1 } }, + dpi, { screenCoords, { width, screenCoords.y + kScrollableRowHeight - 1 } }, FilterPaletteID::PaletteDarken1); stringId = STR_WINDOW_COLOUR_2_STRINGID; } @@ -708,20 +708,20 @@ static Widget _trackListWidgets[] = { auto ft = Formatter(); ft.Add(STR_BUILD_CUSTOM_DESIGN); DrawTextBasic(dpi, screenCoords - ScreenCoordsXY{ 0, 1 }, stringId, ft); - screenCoords.y += SCROLLABLE_ROW_HEIGHT; + screenCoords.y += kScrollableRowHeight; listIndex++; } for (auto i : _filteredTrackIds) { - if (screenCoords.y + SCROLLABLE_ROW_HEIGHT >= dpi.y && screenCoords.y < dpi.y + dpi.height) + if (screenCoords.y + kScrollableRowHeight >= dpi.y && screenCoords.y < dpi.y + dpi.height) { StringId stringId; if (listIndex == static_cast(selected_list_item)) { // Highlight GfxFilterRect( - dpi, { screenCoords, { width, screenCoords.y + SCROLLABLE_ROW_HEIGHT - 1 } }, + dpi, { screenCoords, { width, screenCoords.y + kScrollableRowHeight - 1 } }, FilterPaletteID::PaletteDarken1); stringId = STR_WINDOW_COLOUR_2_STRINGID; } @@ -737,7 +737,7 @@ static Widget _trackListWidgets[] = { DrawTextBasic(dpi, screenCoords - ScreenCoordsXY{ 0, 1 }, stringId, ft); } - screenCoords.y += SCROLLABLE_ROW_HEIGHT; + screenCoords.y += kScrollableRowHeight; listIndex++; } } diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 564166c58a..8be137ecd6 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -52,7 +52,7 @@ namespace OpenRCT2 ClimateState ClimateNext; uint16_t ClimateUpdateTimer; money64 Cash; - money64 CashHistory[FINANCE_GRAPH_SIZE]; + money64 CashHistory[kFinanceGraphSize]; money64 InitialCash; money64 GuestInitialCash; uint8_t GuestInitialHappiness; @@ -68,7 +68,7 @@ namespace OpenRCT2 money64 TotalIncomeFromAdmissions; money64 TotalRideValueForMoney; uint16_t WeeklyProfitAverageDivisor; - money64 WeeklyProfitHistory[FINANCE_GRAPH_SIZE]; + money64 WeeklyProfitHistory[kFinanceGraphSize]; Objective ScenarioObjective; uint16_t ScenarioParkRatingWarningDays; money64 ScenarioCompletedCompanyValue; @@ -76,7 +76,7 @@ namespace OpenRCT2 money64 BankLoan; uint8_t BankLoanInterestRate; money64 MaxBankLoan; - money64 ExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][EnumValue(ExpenditureType::Count)]; + money64 ExpenditureTable[kExpenditureTableMonthCount][EnumValue(ExpenditureType::Count)]; random_engine_t ScenarioRand; TileCoordsXY MapSize; money64 LandPrice; diff --git a/src/openrct2/actions/CheatSetAction.cpp b/src/openrct2/actions/CheatSetAction.cpp index 194e505e10..98abfd4dbb 100644 --- a/src/openrct2/actions/CheatSetAction.cpp +++ b/src/openrct2/actions/CheatSetAction.cpp @@ -598,7 +598,7 @@ void CheatSetAction::SetMoney(money64 amount) const void CheatSetAction::AddMoney(money64 amount) const { - GetGameState().Cash = AddClamp_money64(GetGameState().Cash, amount); + GetGameState().Cash = AddClamp(GetGameState().Cash, amount); WindowInvalidateByClass(WindowClass::Finances); WindowInvalidateByClass(WindowClass::BottomToolbar); diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index d5446cc109..34b032adcc 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -3850,7 +3850,7 @@ void Guest::UpdateRideFreeVehicleEnterRide(Ride& ride) } else { - ride.total_profit = AddClamp_money64(ride.total_profit, ridePrice); + ride.total_profit = AddClamp(ride.total_profit, ridePrice); ride.window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME; SpendMoney(PaidOnRides, ridePrice, ExpenditureType::ParkRideTickets); } diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index f8ecc38abd..d8c102f8c5 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -2561,7 +2561,7 @@ StringId GetRealNameStringIDFromPeepID(uint32_t id) dx += 0x1000; } dx /= 4; - dx += REAL_NAME_START; + dx += kRealNameStart; return dx; } diff --git a/src/openrct2/interface/Fonts.h b/src/openrct2/interface/Fonts.h index 509ddd35cd..44fe19631f 100644 --- a/src/openrct2/interface/Fonts.h +++ b/src/openrct2/interface/Fonts.h @@ -30,9 +30,6 @@ extern TTFFontSetDescriptor TTFFontNanum; extern TTFFontSetDescriptor TTFFontArial; extern TTFFontSetDescriptor TTFFontArialUnicode; extern TTFFontSetDescriptor TTFFontMicroHei; -# define FONT(x) x -#else -# define FONT(x) FONT_OPENRCT2_SPRITE #endif // NO_TTF void TryLoadFonts(OpenRCT2::Localisation::LocalisationService& localisationService); diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 62d494f2a8..061031569e 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -41,7 +41,7 @@ enum class CloseWindowModifier : uint8_t; constexpr uint8_t CloseButtonWidth = 10; -#define SCROLLABLE_ROW_HEIGHT 12 +constexpr int32_t kScrollableRowHeight = 12; constexpr uint8_t kListRowHeight = 12; constexpr uint8_t kTableCellHeight = 12; constexpr uint8_t kButtonFaceHeight = 12; diff --git a/src/openrct2/localisation/Currency.cpp b/src/openrct2/localisation/Currency.cpp index 88d0560d9b..9a523a2a2a 100644 --- a/src/openrct2/localisation/Currency.cpp +++ b/src/openrct2/localisation/Currency.cpp @@ -44,6 +44,6 @@ void CurrencyLoadCustomCurrencyConfig() { SafeStrCpy( CurrencyDescriptors[EnumValue(CurrencyType::Custom)].symbol_unicode, gConfigGeneral.CustomCurrencySymbol.c_str(), - CURRENCY_SYMBOL_MAX_SIZE); + kCurrencySymbolMaxSize); } } diff --git a/src/openrct2/localisation/Currency.h b/src/openrct2/localisation/Currency.h index 4928dd77fb..2fc85d30c7 100644 --- a/src/openrct2/localisation/Currency.h +++ b/src/openrct2/localisation/Currency.h @@ -14,8 +14,8 @@ #include "../util/Util.h" #include "CurrencyTypes.h" -#define CURRENCY_SYMBOL_MAX_SIZE 8 -#define CURRENCY_RATE_MAX_NUM_DIGITS 9 +constexpr size_t kCurrencySymbolMaxSize = 8; +constexpr size_t kCurrencyRateMaxNumDigits = 9; // Currency format specification - inspired by OpenTTD struct CurrencyDescriptor @@ -24,9 +24,9 @@ struct CurrencyDescriptor // Rate is relative to 0.10 GBP int32_t rate; CurrencyAffix affix_unicode; - utf8 symbol_unicode[CURRENCY_SYMBOL_MAX_SIZE]; + utf8 symbol_unicode[kCurrencySymbolMaxSize]; CurrencyAffix affix_ascii; - char symbol_ascii[CURRENCY_SYMBOL_MAX_SIZE]; + char symbol_ascii[kCurrencySymbolMaxSize]; StringId stringId; }; diff --git a/src/openrct2/localisation/Formatting.cpp b/src/openrct2/localisation/Formatting.cpp index dc304655ea..7ffeabdab4 100644 --- a/src/openrct2/localisation/Formatting.cpp +++ b/src/openrct2/localisation/Formatting.cpp @@ -285,7 +285,7 @@ namespace OpenRCT2 { if (IsRealNameStringId(id)) { - auto realNameIndex = id - REAL_NAME_START; + auto realNameIndex = id - kRealNameStart; ss << real_names[realNameIndex % std::size(real_names)]; ss << ' '; ss << real_name_initials[(realNameIndex >> 10) % std::size(real_name_initials)]; @@ -625,7 +625,7 @@ namespace OpenRCT2 bool IsRealNameStringId(StringId id) { - return id >= REAL_NAME_START && id <= REAL_NAME_END; + return id >= kRealNameStart && id <= kRealNameEnd; } FmtString GetFmtStringById(StringId id) diff --git a/src/openrct2/localisation/Language.h b/src/openrct2/localisation/Language.h index c5f406f3f7..0a2368f3db 100644 --- a/src/openrct2/localisation/Language.h +++ b/src/openrct2/localisation/Language.h @@ -68,8 +68,6 @@ enum class RCT2LanguageId End = 255 }; -#define FONT_OPENRCT2_SPRITE NULL - #include "../interface/FontFamilies.h" struct LanguageDescriptor diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h index d8355669ba..e057f595be 100644 --- a/src/openrct2/localisation/Localisation.h +++ b/src/openrct2/localisation/Localisation.h @@ -34,16 +34,14 @@ utf8* GetStringEnd(const utf8* text); size_t GetStringSize(const utf8* text); // The maximum number of characters allowed for string/money conversions (anything above will risk integer overflow issues) -#define MONEY_STRING_MAXLENGTH 14 +constexpr size_t kMoneyStringMaxlength = 14; money64 StringToMoney(const char* string_to_monetise); void MoneyToString(money64 amount, char* buffer_to_put_value_to, size_t buffer_len, bool forceDecimals); -#define MAX_USER_STRINGS 1024 -#define USER_STRING_MAX_LENGTH 32 +constexpr size_t kUserStringMaxLength = 32; -#define USER_STRING_END 0x8FFF -#define REAL_NAME_START 0xA000 -#define REAL_NAME_END 0xDFFF +constexpr uint16_t kRealNameStart = 0xA000; +constexpr uint16_t kRealNameEnd = 0xDFFF; constexpr size_t CommonTextBufferSize = 512; diff --git a/src/openrct2/management/Finance.cpp b/src/openrct2/management/Finance.cpp index 10d4b113e6..cf3b0de93e 100644 --- a/src/openrct2/management/Finance.cpp +++ b/src/openrct2/management/Finance.cpp @@ -78,7 +78,7 @@ void FinancePayment(money64 amount, ExpenditureType type) { // overflow check auto& gameState = GetGameState(); - gameState.Cash = AddClamp_money64(gameState.Cash, -amount); + gameState.Cash = AddClamp(gameState.Cash, -amount); gameState.ExpenditureTable[0][EnumValue(type)] -= amount; if (dword_988E60[EnumValue(type)] & 1) @@ -186,14 +186,14 @@ void FinancePayRideUpkeep() void FinanceResetHistory() { auto& gameState = GetGameState(); - for (int32_t i = 0; i < FINANCE_GRAPH_SIZE; i++) + for (auto i = 0; i < kFinanceGraphSize; i++) { gameState.CashHistory[i] = kMoney64Undefined; gameState.WeeklyProfitHistory[i] = kMoney64Undefined; gameState.Park.ValueHistory[i] = kMoney64Undefined; } - for (uint32_t i = 0; i < EXPENDITURE_TABLE_MONTH_COUNT; ++i) + for (uint32_t i = 0; i < kExpenditureTableMonthCount; ++i) { for (uint32_t j = 0; j < static_cast(ExpenditureType::Count); ++j) { @@ -318,18 +318,18 @@ money64 FinanceGetCurrentCash() void FinanceShiftExpenditureTable() { auto& gameState = GetGameState(); - // If EXPENDITURE_TABLE_MONTH_COUNT months have passed then is full, sum the oldest month - if (GetDate().GetMonthsElapsed() >= EXPENDITURE_TABLE_MONTH_COUNT) + // If kExpenditureTableMonthCount months have passed then is full, sum the oldest month + if (GetDate().GetMonthsElapsed() >= kExpenditureTableMonthCount) { const money64 sum = std::accumulate( - std::cbegin(gameState.ExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT - 1]), - std::cend(gameState.ExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT - 1]), money64{}); + std::cbegin(gameState.ExpenditureTable[kExpenditureTableMonthCount - 1]), + std::cend(gameState.ExpenditureTable[kExpenditureTableMonthCount - 1]), money64{}); GetGameState().HistoricalProfit += sum; } // Shift the table - for (size_t i = EXPENDITURE_TABLE_MONTH_COUNT - 1; i >= 1; i--) + for (size_t i = kExpenditureTableMonthCount - 1; i >= 1; i--) { for (size_t j = 0; j < static_cast(ExpenditureType::Count); j++) { diff --git a/src/openrct2/management/Finance.h b/src/openrct2/management/Finance.h index 33375b8966..c1490c8ad2 100644 --- a/src/openrct2/management/Finance.h +++ b/src/openrct2/management/Finance.h @@ -31,8 +31,8 @@ enum class ExpenditureType : int32_t Count }; -#define EXPENDITURE_TABLE_MONTH_COUNT 16 -#define FINANCE_GRAPH_SIZE 128 +constexpr uint8_t kExpenditureTableMonthCount = 16; +constexpr uint8_t kFinanceGraphSize = 128; constexpr uint8_t MaxBankLoanInterestRate = 255; diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index f36bffeb0c..369b4630ae 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -15,6 +15,7 @@ #include "../GameStateSnapshots.h" #include "../OpenRCT2.h" #include "../PlatformEnvironment.h" +#include "../Version.h" #include "../actions/LoadOrQuitAction.h" #include "../actions/NetworkModifyGroupAction.h" #include "../actions/PeepPickupAction.h" @@ -45,9 +46,9 @@ using namespace OpenRCT2; // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "0" +constexpr uint8_t kNetworkStreamVersion = 0; -#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION +const std::string kNetworkStreamID = std::string(OPENRCT2_VERSION) + "-" + std::to_string(kNetworkStreamVersion); static Peep* _pickup_peep = nullptr; static int32_t _pickup_peep_old_x = LOCATION_NULL; @@ -4056,7 +4057,7 @@ u8string NetworkGetServerProviderWebsite() std::string NetworkGetVersion() { - return NETWORK_STREAM_ID; + return kNetworkStreamID; } NetworkStats NetworkGetStats() diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 06dba26287..f3acf220bc 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -40,8 +40,6 @@ namespace ObjectSelectionFlags constexpr uint8_t AllFlags = 0xFF; }; // namespace ObjectSelectionFlags -#define OBJECT_SELECTION_NOT_SELECTED_OR_REQUIRED 0 - enum class ObjectSourceGame : uint8_t { Custom, diff --git a/src/openrct2/paint/Paint.h b/src/openrct2/paint/Paint.h index b958bcc304..41cbd36dcf 100644 --- a/src/openrct2/paint/Paint.h +++ b/src/openrct2/paint/Paint.h @@ -125,7 +125,7 @@ struct TunnelEntry // the quadrant index is based on the x and y components combined. static constexpr int32_t MaxPaintQuadrants = kMaximumMapSizeTechnical * 2; -#define TUNNEL_MAX_COUNT 65 +constexpr uint8_t kTunnelMaxCount = 65; /** * A pool of PaintEntry instances that can be rented out. @@ -202,8 +202,8 @@ struct PaintSessionCore SupportHeight SupportSegments[9]; SupportHeight Support; uint16_t WaterHeight; - TunnelEntry LeftTunnels[TUNNEL_MAX_COUNT]; - TunnelEntry RightTunnels[TUNNEL_MAX_COUNT]; + TunnelEntry LeftTunnels[kTunnelMaxCount]; + TunnelEntry RightTunnels[kTunnelMaxCount]; uint8_t LeftTunnelCount; uint8_t RightTunnelCount; uint8_t VerticalTunnelHeight; diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index 00749b44d6..b160588747 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -629,7 +629,7 @@ static void ViewportSurfaceDrawTileSideBottom( neighbourCornerHeight1 = cornerHeight2; - for (uint32_t tunnelIndex = 0; tunnelIndex < TUNNEL_MAX_COUNT;) + for (auto tunnelIndex = 0; tunnelIndex < kTunnelMaxCount;) { if (curHeight >= cornerHeight1 || curHeight >= cornerHeight2) { diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index 03879ddeb2..b935a5a6e3 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -335,7 +335,7 @@ static void PaintTileElementBase(PaintSession& session, const CoordsXY& origCoor void PaintUtilPushTunnelLeft(PaintSession& session, uint16_t height, uint8_t type) { session.LeftTunnels[session.LeftTunnelCount] = { static_cast((height / 16)), type }; - if (session.LeftTunnelCount < TUNNEL_MAX_COUNT - 1) + if (session.LeftTunnelCount < kTunnelMaxCount - 1) { session.LeftTunnels[session.LeftTunnelCount + 1] = { 0xFF, 0xFF }; session.LeftTunnelCount++; @@ -345,7 +345,7 @@ void PaintUtilPushTunnelLeft(PaintSession& session, uint16_t height, uint8_t typ void PaintUtilPushTunnelRight(PaintSession& session, uint16_t height, uint8_t type) { session.RightTunnels[session.RightTunnelCount] = { static_cast((height / 16)), type }; - if (session.RightTunnelCount < TUNNEL_MAX_COUNT - 1) + if (session.RightTunnelCount < kTunnelMaxCount - 1) { session.RightTunnels[session.RightTunnelCount + 1] = { 0xFF, 0xFF }; session.RightTunnelCount++; diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 7de94e29f9..149bfd3eb2 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -818,7 +818,7 @@ namespace OpenRCT2 // Finances if (cs.GetMode() == OrcaStream::Mode::READING) { - auto numMonths = std::min(EXPENDITURE_TABLE_MONTH_COUNT, cs.Read()); + auto numMonths = std::min(kExpenditureTableMonthCount, cs.Read()); auto numTypes = std::min(static_cast(ExpenditureType::Count), cs.Read()); for (uint32_t i = 0; i < numMonths; i++) { @@ -830,7 +830,7 @@ namespace OpenRCT2 } else { - auto numMonths = static_cast(EXPENDITURE_TABLE_MONTH_COUNT); + auto numMonths = static_cast(kExpenditureTableMonthCount); auto numTypes = static_cast(ExpenditureType::Count); cs.Write(numMonths); diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index e2e41e6fba..3805ccbb9d 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2509,7 +2509,7 @@ namespace RCT1 { const auto originalString = _s4.StringTable[stringId % 1024]; auto originalStringView = std::string_view( - originalString, RCT12::GetRCTStringBufferLen(originalString, USER_STRING_MAX_LENGTH)); + originalString, RCT12::GetRCTStringBufferLen(originalString, kUserStringMaxLength)); auto asUtf8 = RCT2StringToUTF8(originalStringView, RCT2LanguageId::EnglishUK); auto justText = RCT12RemoveFormattingUTF8(asUtf8); return justText.data(); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 297419a54f..ec021b60c9 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -2376,7 +2376,7 @@ namespace RCT2 { const auto originalString = _s6.CustomStrings[stringId % 1024]; auto originalStringView = std::string_view( - originalString, RCT12::GetRCTStringBufferLen(originalString, USER_STRING_MAX_LENGTH)); + originalString, RCT12::GetRCTStringBufferLen(originalString, kUserStringMaxLength)); auto asUtf8 = RCT2StringToUTF8(originalStringView, RCT2LanguageId::EnglishUK); auto justText = RCT12RemoveFormattingUTF8(asUtf8); return justText.data(); diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index 50868a82ea..6063a03225 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -448,7 +448,7 @@ int32_t Vehicle::CableLiftUpdateTrackMotion() vehicleCount++; massTotal += vehicle->mass; - accelerationTotal = AddClamp_int32_t(accelerationTotal, vehicle->acceleration); + accelerationTotal = AddClamp(accelerationTotal, vehicle->acceleration); } int32_t newAcceleration = (accelerationTotal / vehicleCount) >> 9; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index a81d0e8b65..4c2af58629 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -846,14 +846,14 @@ void Vehicle::UpdateMeasurements() if (curRide->average_speed_test_timeout == 0 && absVelocity > 0x8000) { - curRide->average_speed = AddClamp_int32_t(curRide->average_speed, absVelocity); + curRide->average_speed = AddClamp(curRide->average_speed, absVelocity); stationForTestSegment.SegmentTime++; } int32_t distance = abs(((velocity + acceleration) >> 10) * 42); if (NumLaps == 0) { - stationForTestSegment.SegmentLength = AddClamp_int32_t(stationForTestSegment.SegmentLength, distance); + stationForTestSegment.SegmentLength = AddClamp(stationForTestSegment.SegmentLength, distance); } if (curRide->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_HAS_G_FORCES)) @@ -1162,7 +1162,7 @@ void Vehicle::UpdateMeasurements() if (distance < 0) return; - curRide->sheltered_length = AddClamp_int32_t(curRide->sheltered_length, distance); + curRide->sheltered_length = AddClamp(curRide->sheltered_length, distance); } struct SoundIdVolume diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 6c31c7b02b..ef9ce9876b 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -232,7 +232,7 @@ void ScenarioSuccessSubmitName(GameState_t& gameState, const char* name) static void ScenarioCheckEntranceFeeTooHigh() { const auto& gameState = GetGameState(); - const auto max_fee = AddClamp_money64(gameState.TotalRideValueForMoney, gameState.TotalRideValueForMoney / 2); + const auto max_fee = AddClamp(gameState.TotalRideValueForMoney, gameState.TotalRideValueForMoney / 2); if ((gameState.Park.Flags & PARK_FLAGS_PARK_OPEN) && Park::GetEntranceFee() > max_fee) { diff --git a/src/openrct2/scenes/title/Command/FollowEntity.h b/src/openrct2/scenes/title/Command/FollowEntity.h index 4499292efa..0cc98a18a9 100644 --- a/src/openrct2/scenes/title/Command/FollowEntity.h +++ b/src/openrct2/scenes/title/Command/FollowEntity.h @@ -25,7 +25,7 @@ namespace OpenRCT2::Title struct { EntityId SpriteIndex{ EntityId::GetNull() }; - utf8 SpriteName[USER_STRING_MAX_LENGTH]{}; + utf8 SpriteName[kUserStringMaxLength]{}; } Follow; int16_t operator()(int16_t timer); diff --git a/src/openrct2/scenes/title/TitleSequence.cpp b/src/openrct2/scenes/title/TitleSequence.cpp index 45bddbd18c..a96a2e7229 100644 --- a/src/openrct2/scenes/title/TitleSequence.cpp +++ b/src/openrct2/scenes/title/TitleSequence.cpp @@ -380,7 +380,7 @@ namespace OpenRCT2::Title { auto entityID = EntityId::FromUnderlying(atoi(parts[1].data()) & 0xFFFF); auto followCommand = FollowEntityCommand{ entityID }; - SafeStrCpy(followCommand.Follow.SpriteName, parts[2].data(), USER_STRING_MAX_LENGTH); + SafeStrCpy(followCommand.Follow.SpriteName, parts[2].data(), kUserStringMaxLength); command = followCommand; } else if (String::IEquals(token, "WAIT")) diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 2b2b366d8a..32601b7722 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -501,55 +501,6 @@ std::vector Ungzip(const void* data, const size_t dataLen) return output; } -// Type-independent code left as macro to reduce duplicate code. -#define ADD_CLAMP_BODY(value, value_to_add, min_cap, max_cap) \ - if ((value_to_add > 0) && (value > (max_cap - (value_to_add)))) \ - { \ - value = max_cap; \ - } \ - else if ((value_to_add < 0) && (value < (min_cap - (value_to_add)))) \ - { \ - value = min_cap; \ - } \ - else \ - { \ - value += value_to_add; \ - } - -int8_t AddClamp_int8_t(int8_t value, int8_t value_to_add) -{ - ADD_CLAMP_BODY(value, value_to_add, INT8_MIN, INT8_MAX); - return value; -} - -int16_t AddClamp_int16_t(int16_t value, int16_t value_to_add) -{ - ADD_CLAMP_BODY(value, value_to_add, INT16_MIN, INT16_MAX); - return value; -} - -int32_t AddClamp_int32_t(int32_t value, int32_t value_to_add) -{ - ADD_CLAMP_BODY(value, value_to_add, INT32_MIN, INT32_MAX); - return value; -} - -int64_t AddClamp_int64_t(int64_t value, int64_t value_to_add) -{ - ADD_CLAMP_BODY(value, value_to_add, INT64_MIN, INT64_MAX); - return value; -} - -money64 AddClamp_money64(money64 value, money64 value_to_add) -{ - // This function is intended only for clarity, as money64 - // is technically the same as int64_t - assert_struct_size(money64, sizeof(int64_t)); - return AddClamp_int64_t(value, value_to_add); -} - -#undef add_clamp_body - uint8_t Lerp(uint8_t a, uint8_t b, float t) { if (t <= 0) diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index c99ff863c0..c83c4e5c08 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -40,12 +40,27 @@ bool UtilGzipCompress(FILE* source, FILE* dest); std::vector Gzip(const void* data, const size_t dataLen); std::vector Ungzip(const void* data, const size_t dataLen); -// TODO: Make these specialized template functions, or when possible Concepts in C++20 -int8_t AddClamp_int8_t(int8_t value, int8_t value_to_add); -int16_t AddClamp_int16_t(int16_t value, int16_t value_to_add); -int32_t AddClamp_int32_t(int32_t value, int32_t value_to_add); -int64_t AddClamp_int64_t(int64_t value, int64_t value_to_add); -money64 AddClamp_money64(money64 value, money64 value_to_add); +template constexpr T AddClamp(T value, T valueToAdd) +{ + if (std::is_same_v) + { + assert_struct_size(money64, sizeof(int64_t)); + } + auto maxCap = std::numeric_limits::max(); + auto minCap = std::numeric_limits::lowest(); + if ((valueToAdd > 0) && (value > (maxCap - (valueToAdd)))) + { + return maxCap; + } + else if ((valueToAdd < 0) && (value < (minCap - (valueToAdd)))) + { + return minCap; + } + else + { + return value + valueToAdd; + } +} uint8_t Lerp(uint8_t a, uint8_t b, float t); float FLerp(float a, float b, float t); diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index f6b002264f..28abebe80a 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -514,7 +514,7 @@ namespace OpenRCT2::Park auto result = gameState.Park.Value - gameState.BankLoan; // Clamp addition to prevent overflow - result = AddClamp_money64(result, FinanceGetCurrentCash()); + result = AddClamp(result, FinanceGetCurrentCash()); return result; } diff --git a/src/openrct2/world/Park.h b/src/openrct2/world/Park.h index 28d491433e..5a7814b753 100644 --- a/src/openrct2/world/Park.h +++ b/src/openrct2/world/Park.h @@ -66,7 +66,7 @@ namespace OpenRCT2 std::vector Entrances; uint32_t Size; money64 Value; - money64 ValueHistory[FINANCE_GRAPH_SIZE]; + money64 ValueHistory[kFinanceGraphSize]; bool IsOpen() const; };