diff --git a/src/openrct2-ui/TextComposition.cpp b/src/openrct2-ui/TextComposition.cpp index 7ec180a5ce..d5b5eccd6c 100644 --- a/src/openrct2-ui/TextComposition.cpp +++ b/src/openrct2-ui/TextComposition.cpp @@ -13,9 +13,9 @@ #include "interface/InGameConsole.h" #include +#include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/UiContext.Win32.cpp b/src/openrct2-ui/UiContext.Win32.cpp index 3478eca15c..b6298c7a4b 100644 --- a/src/openrct2-ui/UiContext.Win32.cpp +++ b/src/openrct2-ui/UiContext.Win32.cpp @@ -24,8 +24,8 @@ # include # include +# include # include -# include # include # include # include diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index eb3a045f04..f3555bc191 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -546,7 +545,7 @@ public: SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, gConfigGeneral.minimize_fullscreen_focus_loss ? "1" : "0"); // Set window position to default display - int32_t defaultDisplay = Math::Clamp(0, gConfigGeneral.default_display, 0xFFFF); + int32_t defaultDisplay = std::clamp(gConfigGeneral.default_display, 0, 0xFFFF); int32_t x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(defaultDisplay); int32_t y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(defaultDisplay); diff --git a/src/openrct2-ui/audio/AudioChannel.cpp b/src/openrct2-ui/audio/AudioChannel.cpp index 182c8a0565..3a907d2cdd 100644 --- a/src/openrct2-ui/audio/AudioChannel.cpp +++ b/src/openrct2-ui/audio/AudioChannel.cpp @@ -11,11 +11,11 @@ #include "AudioFormat.h" #include +#include #include #include #include #include -#include #include namespace OpenRCT2::Audio @@ -159,7 +159,7 @@ namespace OpenRCT2::Audio void SetVolume(int32_t volume) override { - _volume = Math::Clamp(0, volume, MIXER_VOLUME_MAX); + _volume = std::clamp(volume, 0, MIXER_VOLUME_MAX); } float GetPan() const override @@ -169,7 +169,7 @@ namespace OpenRCT2::Audio void SetPan(float pan) override { - _pan = Math::Clamp(0.0f, pan, 1.0f); + _pan = std::clamp(pan, 0.0f, 1.0f); double decibels = (std::abs(_pan - 0.5) * 2.0) * 100.0; double attenuation = pow(10, decibels / 20.0); if (_pan <= 0.5) diff --git a/src/openrct2-ui/audio/AudioMixer.cpp b/src/openrct2-ui/audio/AudioMixer.cpp index ce9a5992ce..a7e80ae25e 100644 --- a/src/openrct2-ui/audio/AudioMixer.cpp +++ b/src/openrct2-ui/audio/AudioMixer.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/audio/FileAudioSource.cpp b/src/openrct2-ui/audio/FileAudioSource.cpp index d4b189ccba..2d47f2eb3d 100644 --- a/src/openrct2-ui/audio/FileAudioSource.cpp +++ b/src/openrct2-ui/audio/FileAudioSource.cpp @@ -11,9 +11,9 @@ #include "AudioFormat.h" #include +#include #include #include -#include namespace OpenRCT2::Audio { diff --git a/src/openrct2-ui/audio/MemoryAudioSource.cpp b/src/openrct2-ui/audio/MemoryAudioSource.cpp index a805dbfb35..d87db88cda 100644 --- a/src/openrct2-ui/audio/MemoryAudioSource.cpp +++ b/src/openrct2-ui/audio/MemoryAudioSource.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include namespace OpenRCT2::Audio diff --git a/src/openrct2-ui/drawing/engines/opengl/TextureCache.h b/src/openrct2-ui/drawing/engines/opengl/TextureCache.h index ef13b20044..69ac59783b 100644 --- a/src/openrct2-ui/drawing/engines/opengl/TextureCache.h +++ b/src/openrct2-ui/drawing/engines/opengl/TextureCache.h @@ -13,6 +13,7 @@ #include "OpenGLAPI.h" #include +#include #include #include #include diff --git a/src/openrct2-ui/input/KeyboardShortcuts.cpp b/src/openrct2-ui/input/KeyboardShortcuts.cpp index cc4a056bb7..14d88eaaa6 100644 --- a/src/openrct2-ui/input/KeyboardShortcuts.cpp +++ b/src/openrct2-ui/input/KeyboardShortcuts.cpp @@ -10,6 +10,7 @@ #include "KeyboardShortcuts.h" #include +#include #include #include #include diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index 5b81b6d28c..25663c5a2c 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -126,8 +126,8 @@ void game_handle_input() { int32_t screenWidth = context_get_width(); int32_t screenHeight = context_get_height(); - x = Math::Clamp(0, x, screenWidth - 1); - y = Math::Clamp(0, y, screenHeight - 1); + x = std::clamp(x, 0, screenWidth - 1); + y = std::clamp(y, 0, screenHeight - 1); game_handle_input_mouse(x, y, state); process_mouse_over(x, y); diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index 2740580fe6..0dd188e42b 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -143,7 +142,7 @@ void InGameConsole::Scroll(int32_t linesToScroll) if (numLines > maxVisibleLines) { int32_t maxScrollValue = numLines - maxVisibleLines; - _consoleScrollPos = Math::Clamp(0, _consoleScrollPos - linesToScroll, maxScrollValue); + _consoleScrollPos = std::clamp(_consoleScrollPos - linesToScroll, 0, maxScrollValue); } } diff --git a/src/openrct2-ui/interface/Theme.cpp b/src/openrct2-ui/interface/Theme.cpp index c56e27edb2..8afd239d7d 100644 --- a/src/openrct2-ui/interface/Theme.cpp +++ b/src/openrct2-ui/interface/Theme.cpp @@ -13,6 +13,7 @@ #include "Window.h" +#include #include #include #include @@ -23,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 552aa060f2..6e54b4c112 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -10,13 +10,13 @@ #include "Viewport.h" #include "Window.h" +#include #include #include #include #include #include #include -#include #include #include #include @@ -653,8 +653,8 @@ void sub_68A15E(int32_t screenX, int32_t screenY, int16_t* x, int16_t* y, int32_ z = tile_element_height(map_pos.x, map_pos.y); } map_pos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z); - map_pos.x = Math::Clamp(map_pos.x, my_x, my_x + 31); - map_pos.y = Math::Clamp(map_pos.y, my_y, my_y + 31); + map_pos.x = std::clamp(map_pos.x, my_x, my_x + 31); + map_pos.y = std::clamp(map_pos.y, my_y, my_y + 31); } // Determine to which edge the cursor is closest diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index 23d5e64be5..d5cac3a33f 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -11,6 +11,7 @@ #include "Theme.h" +#include #include #include #include diff --git a/src/openrct2-ui/title/TitleSequencePlayer.cpp b/src/openrct2-ui/title/TitleSequencePlayer.cpp index d5ef36fd7f..6d585eccad 100644 --- a/src/openrct2-ui/title/TitleSequencePlayer.cpp +++ b/src/openrct2-ui/title/TitleSequencePlayer.cpp @@ -11,6 +11,7 @@ #include "../interface/Window.h" +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -289,7 +289,7 @@ private: SetViewZoom(command->Zoom); break; case TITLE_SCRIPT_SPEED: - gGameSpeed = Math::Clamp(1, command->Speed, 4); + gGameSpeed = std::clamp(command->Speed, 1, 4); break; case TITLE_SCRIPT_FOLLOW: FollowSprite(command->SpriteIndex); diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index b1a3ef3e8f..151e356ca6 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -7,13 +7,13 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp index 86e1535904..50ca6eed17 100644 --- a/src/openrct2-ui/windows/Cheats.cpp +++ b/src/openrct2-ui/windows/Cheats.cpp @@ -7,12 +7,12 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include #include -#include #include #include #include @@ -641,36 +641,36 @@ static void window_cheats_money_mousedown(rct_window* w, rct_widgetindex widgetI break; case WIDX_YEAR_UP: year_spinner_value++; - year_spinner_value = Math::Clamp(1, year_spinner_value, 8192); + year_spinner_value = std::clamp(year_spinner_value, 1, 8192); widget_invalidate(w, WIDX_YEAR_BOX); break; case WIDX_YEAR_DOWN: year_spinner_value--; - year_spinner_value = Math::Clamp(1, year_spinner_value, 8192); + year_spinner_value = std::clamp(year_spinner_value, 1, 8192); widget_invalidate(w, WIDX_YEAR_BOX); break; case WIDX_MONTH_UP: month_spinner_value++; - month_spinner_value = Math::Clamp(1, month_spinner_value, (int)MONTH_COUNT); - day_spinner_value = Math::Clamp(1, day_spinner_value, (int)days_in_month[month_spinner_value - 1]); + month_spinner_value = std::clamp(month_spinner_value, 1, (int)MONTH_COUNT); + day_spinner_value = std::clamp(day_spinner_value, 1, (int)days_in_month[month_spinner_value - 1]); widget_invalidate(w, WIDX_MONTH_BOX); widget_invalidate(w, WIDX_DAY_BOX); break; case WIDX_MONTH_DOWN: month_spinner_value--; - month_spinner_value = Math::Clamp(1, month_spinner_value, (int)MONTH_COUNT); - day_spinner_value = Math::Clamp(1, day_spinner_value, (int)days_in_month[month_spinner_value - 1]); + month_spinner_value = std::clamp(month_spinner_value, 1, (int)MONTH_COUNT); + day_spinner_value = std::clamp(day_spinner_value, 1, (int)days_in_month[month_spinner_value - 1]); widget_invalidate(w, WIDX_MONTH_BOX); widget_invalidate(w, WIDX_DAY_BOX); break; case WIDX_DAY_UP: day_spinner_value++; - day_spinner_value = Math::Clamp(1, day_spinner_value, (int)days_in_month[month_spinner_value - 1]); + day_spinner_value = std::clamp(day_spinner_value, 1, (int)days_in_month[month_spinner_value - 1]); widget_invalidate(w, WIDX_DAY_BOX); break; case WIDX_DAY_DOWN: day_spinner_value--; - day_spinner_value = Math::Clamp(1, day_spinner_value, (int)days_in_month[month_spinner_value - 1]); + day_spinner_value = std::clamp(day_spinner_value, 1, (int)days_in_month[month_spinner_value - 1]); widget_invalidate(w, WIDX_DAY_BOX); break; case WIDX_DATE_SET: diff --git a/src/openrct2-ui/windows/ClearScenery.cpp b/src/openrct2-ui/windows/ClearScenery.cpp index eee098b2f4..24bb6e3a0c 100644 --- a/src/openrct2-ui/windows/ClearScenery.cpp +++ b/src/openrct2-ui/windows/ClearScenery.cpp @@ -7,11 +7,11 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include -#include #include #include diff --git a/src/openrct2-ui/windows/DebugPaint.cpp b/src/openrct2-ui/windows/DebugPaint.cpp index 570ae1e26c..182febca51 100644 --- a/src/openrct2-ui/windows/DebugPaint.cpp +++ b/src/openrct2-ui/windows/DebugPaint.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include diff --git a/src/openrct2-ui/windows/Dropdown.cpp b/src/openrct2-ui/windows/Dropdown.cpp index f70d30845d..b9efcb083e 100644 --- a/src/openrct2-ui/windows/Dropdown.cpp +++ b/src/openrct2-ui/windows/Dropdown.cpp @@ -7,11 +7,11 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/EditorScenarioOptions.cpp b/src/openrct2-ui/windows/EditorScenarioOptions.cpp index a420660e51..0f32eab36b 100644 --- a/src/openrct2-ui/windows/EditorScenarioOptions.cpp +++ b/src/openrct2-ui/windows/EditorScenarioOptions.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -14,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -754,7 +754,7 @@ static void window_editor_scenario_options_financial_paint(rct_window* w, rct_dr x = w->x + w->widgets[WIDX_INTEREST_RATE].left + 1; y = w->y + w->widgets[WIDX_INTEREST_RATE].top; - int16_t interestRate = Math::Clamp(INT16_MIN, (int16_t)gBankLoanInterestRate, INT16_MAX); + int16_t interestRate = std::clamp((int16_t)gBankLoanInterestRate, INT16_MIN, INT16_MAX); gfx_draw_string_left(dpi, STR_PERCENT_FORMAT_LABEL, &interestRate, COLOUR_BLACK, x, y); } } diff --git a/src/openrct2-ui/windows/Error.cpp b/src/openrct2-ui/windows/Error.cpp index 00e78f3553..432c91cb5b 100644 --- a/src/openrct2-ui/windows/Error.cpp +++ b/src/openrct2-ui/windows/Error.cpp @@ -7,12 +7,12 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include #include -#include #include #include #include @@ -127,7 +127,7 @@ rct_window* window_error_open(rct_string_id title, rct_string_id message) int32_t screenHeight = context_get_height(); const CursorState* state = context_get_cursor_state(); x = state->x - (width / 2); - x = Math::Clamp(0, x, screenWidth); + x = std::clamp(x, 0, screenWidth); y = state->y + 26; y = std::max(22, y); diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index 8a3778a6b0..1a448a5f22 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -16,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index c82c5f2193..1418f4663a 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -9,6 +9,7 @@ #include "../interface/Theme.h" +#include #include #include #include @@ -16,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/InstallTrack.cpp b/src/openrct2-ui/windows/InstallTrack.cpp index aa4dc60d03..7abd2ad2b9 100644 --- a/src/openrct2-ui/windows/InstallTrack.cpp +++ b/src/openrct2-ui/windows/InstallTrack.cpp @@ -7,11 +7,11 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/Land.cpp b/src/openrct2-ui/windows/Land.cpp index 3d3efd3f7b..f409774bc9 100644 --- a/src/openrct2-ui/windows/Land.cpp +++ b/src/openrct2-ui/windows/Land.cpp @@ -7,12 +7,12 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/LandRights.cpp b/src/openrct2-ui/windows/LandRights.cpp index 859a0dd9a5..253457130c 100644 --- a/src/openrct2-ui/windows/LandRights.cpp +++ b/src/openrct2-ui/windows/LandRights.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -14,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index a22c47b991..fa33ec25ca 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -563,8 +562,8 @@ static void window_map_scrollgetsize(rct_window* w, int32_t scrollIndex, int32_t static void window_map_scrollmousedown(rct_window* w, int32_t scrollIndex, int32_t x, int32_t y) { CoordsXY c = map_window_screen_to_map(x, y); - int32_t mapX = Math::Clamp(0, c.x, MAXIMUM_MAP_SIZE_TECHNICAL * 32 - 1); - int32_t mapY = Math::Clamp(0, c.y, MAXIMUM_MAP_SIZE_TECHNICAL * 32 - 1); + int32_t mapX = std::clamp(c.x, 0, MAXIMUM_MAP_SIZE_TECHNICAL * 32 - 1); + int32_t mapY = std::clamp(c.y, 0, MAXIMUM_MAP_SIZE_TECHNICAL * 32 - 1); int32_t mapZ = tile_element_height(x, y); rct_window* mainWindow = window_get_main(); @@ -636,7 +635,7 @@ static void window_map_textinput(rct_window* w, rct_widgetindex widgetIndex, cha size = strtol(text, &end, 10); if (*end == '\0') { - size = Math::Clamp(MINIMUM_TOOL_SIZE, size, MAXIMUM_TOOL_SIZE); + size = std::clamp(size, MINIMUM_TOOL_SIZE, MAXIMUM_TOOL_SIZE); _landRightsToolSize = size; window_invalidate(w); } @@ -647,7 +646,7 @@ static void window_map_textinput(rct_window* w, rct_widgetindex widgetIndex, cha { // The practical size is 2 lower than the technical size size += 2; - size = Math::Clamp(MINIMUM_MAP_SIZE_TECHNICAL, size, MAXIMUM_MAP_SIZE_TECHNICAL); + size = std::clamp(size, MINIMUM_MAP_SIZE_TECHNICAL, MAXIMUM_MAP_SIZE_TECHNICAL); int32_t currentSize = gMapSize; while (size < currentSize) diff --git a/src/openrct2-ui/windows/MapGen.cpp b/src/openrct2-ui/windows/MapGen.cpp index ae96e0e199..86074fde8b 100644 --- a/src/openrct2-ui/windows/MapGen.cpp +++ b/src/openrct2-ui/windows/MapGen.cpp @@ -7,13 +7,13 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include #include #include -#include #include #include #include @@ -715,13 +715,13 @@ static void window_mapgen_textinput(rct_window* w, rct_widgetindex widgetIndex, case WIDX_SIMPLEX_MAP_SIZE: // The practical size is 2 lower than the technical size value += 2; - _mapSize = Math::Clamp(MINIMUM_MAP_SIZE_TECHNICAL, value, MAXIMUM_MAP_SIZE_TECHNICAL); + _mapSize = std::clamp(value, MINIMUM_MAP_SIZE_TECHNICAL, MAXIMUM_MAP_SIZE_TECHNICAL); break; case WIDX_BASE_HEIGHT: - _baseHeight = Math::Clamp(BASESIZE_MIN, (value * 2) + 12, BASESIZE_MAX); + _baseHeight = std::clamp((value * 2) + 12, BASESIZE_MIN, BASESIZE_MAX); break; case WIDX_WATER_LEVEL: - _waterLevel = Math::Clamp(WATERLEVEL_MIN, (value * 2) + 12, WATERLEVEL_MAX); + _waterLevel = std::clamp((value * 2) + 12, WATERLEVEL_MIN, WATERLEVEL_MAX); break; } diff --git a/src/openrct2-ui/windows/NewCampaign.cpp b/src/openrct2-ui/windows/NewCampaign.cpp index bd1979083b..00d352e141 100644 --- a/src/openrct2-ui/windows/NewCampaign.cpp +++ b/src/openrct2-ui/windows/NewCampaign.cpp @@ -7,13 +7,13 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index 3ca7400437..d27accb5bb 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -15,7 +16,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/News.cpp b/src/openrct2-ui/windows/News.cpp index 07d6abebfb..2d3b7bf509 100644 --- a/src/openrct2-ui/windows/News.cpp +++ b/src/openrct2-ui/windows/News.cpp @@ -7,11 +7,11 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index c1eb59091c..da354b3c05 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -14,6 +14,7 @@ #include "../interface/Theme.h" +#include #include #include #include @@ -23,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index bfe236e6b5..112d94745f 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -9,6 +9,7 @@ #include "../interface/Theme.h" +#include #include #include #include @@ -21,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 062558dafd..4c182367b8 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -9,6 +9,7 @@ #include "../interface/Theme.h" +#include #include #include #include @@ -22,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -1499,7 +1499,7 @@ static void window_ride_update_overall_view(uint8_t ride_index) { // Each farther zoom level shows twice as many tiles (log) // Appropriate zoom is lowered by one to fill the entire view with the ride - view->zoom = Math::Clamp(0, (int32_t)std::ceil(std::log(size / 80)) - 1, 3); + view->zoom = std::clamp(std::ceil(std::log(size / 80)) - 1, 0, 3); } else { @@ -2400,7 +2400,7 @@ static void window_ride_main_dropdown(rct_window* w, rct_widgetindex widgetIndex case WIDX_RIDE_TYPE_DROPDOWN: if (dropdownIndex != -1 && dropdownIndex < RIDE_TYPE_COUNT) { - uint8_t rideLabelId = Math::Clamp(0, dropdownIndex, RIDE_TYPE_COUNT - 1); + uint8_t rideLabelId = std::clamp(dropdownIndex, 0, RIDE_TYPE_COUNT - 1); uint8_t rideType = RideDropdownData[rideLabelId].ride_type_id; if (rideType < RIDE_TYPE_COUNT) { @@ -3187,7 +3187,7 @@ static void window_ride_mode_tweak_increase(rct_window* w) uint8_t increment = ride->mode == RIDE_MODE_BUMPERCAR ? 10 : 1; - window_ride_mode_tweak_set(w, Math::Clamp(minValue, ride->operation_option + increment, maxValue)); + window_ride_mode_tweak_set(w, std::clamp(ride->operation_option + increment, minValue, maxValue)); } /** @@ -3207,7 +3207,7 @@ static void window_ride_mode_tweak_decrease(rct_window* w) uint8_t decrement = ride->mode == RIDE_MODE_BUMPERCAR ? 10 : 1; - window_ride_mode_tweak_set(w, Math::Clamp(minValue, ride->operation_option - decrement, maxValue)); + window_ride_mode_tweak_set(w, std::clamp(ride->operation_option - decrement, minValue, maxValue)); } /** @@ -3357,42 +3357,42 @@ static void window_ride_operating_mousedown(rct_window* w, rct_widgetindex widge lower_bound = gCheatsFastLiftHill ? 0 : RideLiftData[ride->type].minimum_speed; set_operating_setting( w->number, RIDE_SETTING_LIFT_HILL_SPEED, - Math::Clamp(lower_bound, ride->lift_hill_speed + 1, upper_bound)); + std::clamp(ride->lift_hill_speed + 1, lower_bound, upper_bound)); break; case WIDX_LIFT_HILL_SPEED_DECREASE: upper_bound = gCheatsFastLiftHill ? 255 : RideLiftData[ride->type].maximum_speed; lower_bound = gCheatsFastLiftHill ? 0 : RideLiftData[ride->type].minimum_speed; set_operating_setting( w->number, RIDE_SETTING_LIFT_HILL_SPEED, - Math::Clamp(lower_bound, ride->lift_hill_speed - 1, upper_bound)); + std::clamp(ride->lift_hill_speed - 1, lower_bound, upper_bound)); break; case WIDX_MINIMUM_LENGTH_INCREASE: upper_bound = 250; lower_bound = 0; set_operating_setting( w->number, RIDE_SETTING_MIN_WAITING_TIME, - Math::Clamp(lower_bound, ride->min_waiting_time + 1, upper_bound)); + std::clamp(ride->min_waiting_time + 1, lower_bound, upper_bound)); break; case WIDX_MINIMUM_LENGTH_DECREASE: upper_bound = 250; lower_bound = 0; set_operating_setting( w->number, RIDE_SETTING_MIN_WAITING_TIME, - Math::Clamp(lower_bound, ride->min_waiting_time - 1, upper_bound)); + std::clamp(ride->min_waiting_time - 1, lower_bound, upper_bound)); break; case WIDX_MAXIMUM_LENGTH_INCREASE: upper_bound = 250; lower_bound = 0; set_operating_setting( w->number, RIDE_SETTING_MAX_WAITING_TIME, - Math::Clamp(lower_bound, ride->max_waiting_time + 1, upper_bound)); + std::clamp(ride->max_waiting_time + 1, lower_bound, upper_bound)); break; case WIDX_MAXIMUM_LENGTH_DECREASE: upper_bound = 250; lower_bound = 0; set_operating_setting( w->number, RIDE_SETTING_MAX_WAITING_TIME, - Math::Clamp(lower_bound, ride->max_waiting_time - 1, upper_bound)); + std::clamp(ride->max_waiting_time - 1, lower_bound, upper_bound)); break; case WIDX_MODE_DROPDOWN: window_ride_mode_dropdown(w, widget); @@ -3404,13 +3404,13 @@ static void window_ride_operating_mousedown(rct_window* w, rct_widgetindex widge upper_bound = gCheatsFastLiftHill ? 255 : 20; lower_bound = 1; set_operating_setting( - w->number, RIDE_SETTING_NUM_CIRCUITS, Math::Clamp(lower_bound, ride->num_circuits + 1, upper_bound)); + w->number, RIDE_SETTING_NUM_CIRCUITS, std::clamp(ride->num_circuits + 1, lower_bound, upper_bound)); break; case WIDX_OPERATE_NUMBER_OF_CIRCUITS_DECREASE: upper_bound = gCheatsFastLiftHill ? 255 : 20; lower_bound = 1; set_operating_setting( - w->number, RIDE_SETTING_NUM_CIRCUITS, Math::Clamp(lower_bound, ride->num_circuits - 1, upper_bound)); + w->number, RIDE_SETTING_NUM_CIRCUITS, std::clamp(ride->num_circuits - 1, lower_bound, upper_bound)); break; } } @@ -5118,7 +5118,7 @@ static void window_ride_music_paint(rct_window* w, rct_drawpixelinfo* dpi) static rct_string_id get_rating_name(ride_rating rating) { - int32_t index = Math::Clamp(0, rating >> 8, (int32_t)Util::CountOf(RatingNames) - 1); + int32_t index = std::clamp(rating >> 8, 0, (int32_t)Util::CountOf(RatingNames) - 1); return RatingNames[index]; } @@ -5763,7 +5763,7 @@ static void window_ride_graphs_update(rct_window* w) x = measurement == nullptr ? 0 : measurement->current_item - (((widget->right - widget->left) / 4) * 3); } - w->scrolls[0].h_left = Math::Clamp(0, x, w->scrolls[0].h_right - ((widget->right - widget->left) - 2)); + w->scrolls[0].h_left = std::clamp(x, 0, w->scrolls[0].h_right - ((widget->right - widget->left) - 2)); widget_scroll_update_thumbs(w, WIDX_GRAPH); } @@ -6309,7 +6309,7 @@ static void window_ride_income_textinput(rct_window* w, rct_widgetindex widgetIn return; } - price = Math::Clamp(MONEY(0, 00), price, MONEY(20, 00)); + price = std::clamp(price, MONEY(0, 00), MONEY(20, 00)); money16 price16 = (money16)price; if (widgetIndex == WIDX_PRIMARY_PRICE) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index b1cf7ae0fc..8e11691b34 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -18,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 113f281abd..23e378802e 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -14,7 +15,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 cad088fa69..3f833db3e9 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -14,11 +14,11 @@ * that is used for inputing new text for ride names and peep names. */ +#include #include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index b2670f233a..247c29d2a9 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -14,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/Tooltip.cpp b/src/openrct2-ui/windows/Tooltip.cpp index df23ce178e..83ced24de1 100644 --- a/src/openrct2-ui/windows/Tooltip.cpp +++ b/src/openrct2-ui/windows/Tooltip.cpp @@ -7,11 +7,11 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include -#include #include #include @@ -107,7 +107,7 @@ void window_tooltip_show(rct_string_id id, int32_t x, int32_t y) int32_t screenWidth = context_get_width(); int32_t screenHeight = context_get_height(); - x = Math::Clamp(0, x - (width / 2), screenWidth - width); + x = std::clamp(x - (width / 2), 0, screenWidth - width); // TODO The cursor size will be relative to the window DPI. // The amount to offset the y should be adjusted. @@ -118,7 +118,7 @@ void window_tooltip_show(rct_string_id id, int32_t x, int32_t y) // If y is too large, the tooltip could be forced below the cursor if we'd just clamped y, // so we'll subtract a bit more y -= height + 40; - y = Math::Clamp(22, y, max_y); + y = std::clamp(y, 22, max_y); w = window_create(x, y, width, height, &window_tooltip_events, WC_TOOLTIP, WF_TRANSPARENT | WF_STICK_TO_FRONT); w->widgets = window_tooltip_widgets; diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 8608d66126..940fb8aa3b 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -10,6 +10,7 @@ #include "../UiContext.h" #include "../interface/InGameConsole.h" +#include #include #include #include @@ -24,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/TrackDesignManage.cpp b/src/openrct2-ui/windows/TrackDesignManage.cpp index ca7f7db797..b74e679e0d 100644 --- a/src/openrct2-ui/windows/TrackDesignManage.cpp +++ b/src/openrct2-ui/windows/TrackDesignManage.cpp @@ -7,10 +7,10 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index 4d75d0a04f..8f27e81b76 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/TrackList.cpp b/src/openrct2-ui/windows/TrackList.cpp index b129639390..b81e0111da 100644 --- a/src/openrct2-ui/windows/TrackList.cpp +++ b/src/openrct2-ui/windows/TrackList.cpp @@ -7,13 +7,13 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/ViewClipping.cpp b/src/openrct2-ui/windows/ViewClipping.cpp index ce02a23c89..0a461e1c74 100644 --- a/src/openrct2-ui/windows/ViewClipping.cpp +++ b/src/openrct2-ui/windows/ViewClipping.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include diff --git a/src/openrct2-ui/windows/Water.cpp b/src/openrct2-ui/windows/Water.cpp index 2fbfdbf394..aaaf504ddd 100644 --- a/src/openrct2-ui/windows/Water.cpp +++ b/src/openrct2-ui/windows/Water.cpp @@ -7,11 +7,11 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include #include -#include #include #include diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 76c5d75425..bb8d32246e 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -34,7 +34,6 @@ #include "core/FileScanner.h" #include "core/FileStream.hpp" #include "core/Guard.hpp" -#include "core/Math.hpp" #include "core/MemoryStream.h" #include "core/Path.hpp" #include "core/String.hpp" diff --git a/src/openrct2/Date.cpp b/src/openrct2/Date.cpp index 943bfc101b..698d99d17e 100644 --- a/src/openrct2/Date.cpp +++ b/src/openrct2/Date.cpp @@ -11,7 +11,8 @@ #include "Date.h" #include "core/Guard.hpp" -#include "core/Math.hpp" + +#include using namespace OpenRCT2; @@ -37,7 +38,7 @@ Date Date::FromYMD(int32_t year, int32_t month, int32_t day) if (day != 0) { auto daysInMonth = GetDaysInMonth(month); - day = Math::Clamp(0, day, daysInMonth - 1); + day = std::clamp(day, 0, daysInMonth - 1); monthTicks = (day << 16) / daysInMonth; } diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 3babaf05f8..075bdc6ef9 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -17,7 +17,6 @@ #include "OpenRCT2.h" #include "ParkImporter.h" #include "audio/audio.h" -#include "core/Math.hpp" #include "interface/Viewport.h" #include "localisation/Localisation.h" #include "management/NewsItem.h" @@ -35,6 +34,7 @@ #include "world/Park.h" #include "world/Scenery.h" +#include #include #include @@ -328,16 +328,16 @@ namespace Editor gParkFlags &= ~PARK_FLAGS_SPRITES_INITIALISED; - gGuestInitialCash = Math::Clamp((money16)MONEY(10, 00), gGuestInitialCash, (money16)MAX_ENTRANCE_FEE); + gGuestInitialCash = std::clamp(gGuestInitialCash, (money16)MONEY(10, 00), (money16)MAX_ENTRANCE_FEE); gInitialCash = std::min(gInitialCash, 100000); finance_reset_cash_to_initial(); - gBankLoan = Math::Clamp(MONEY(0, 00), gBankLoan, MONEY(5000000, 00)); + gBankLoan = std::clamp(gBankLoan, MONEY(0, 00), MONEY(5000000, 00)); - gMaxBankLoan = Math::Clamp(MONEY(0, 00), gMaxBankLoan, MONEY(5000000, 00)); + gMaxBankLoan = std::clamp(gMaxBankLoan, MONEY(0, 00), MONEY(5000000, 00)); - gBankLoanInterestRate = Math::Clamp((uint8_t)5, gBankLoanInterestRate, (uint8_t)80); + gBankLoanInterestRate = std::clamp(gBankLoanInterestRate, 5, 80); } climate_reset(gClimate); @@ -576,23 +576,23 @@ namespace Editor } break; case EDIT_SCENARIOOPTIONS_SETINITIALCASH: - gInitialCash = Math::Clamp(MONEY(0, 00), *edx, MONEY(1000000, 00)); + gInitialCash = std::clamp(*edx, MONEY(0, 00), MONEY(1000000, 00)); gCash = gInitialCash; window_invalidate_by_class(WC_FINANCES); window_invalidate_by_class(WC_BOTTOM_TOOLBAR); break; case EDIT_SCENARIOOPTIONS_SETINITIALLOAN: - gBankLoan = Math::Clamp(MONEY(0, 00), *edx, MONEY(5000000, 00)); + gBankLoan = std::clamp(*edx, MONEY(0, 00), MONEY(5000000, 00)); gMaxBankLoan = std::max(gBankLoan, gMaxBankLoan); window_invalidate_by_class(WC_FINANCES); break; case EDIT_SCENARIOOPTIONS_SETMAXIMUMLOANSIZE: - gMaxBankLoan = Math::Clamp(MONEY(0, 00), *edx, MONEY(5000000, 00)); + gMaxBankLoan = std::clamp(*edx, MONEY(0, 00), MONEY(5000000, 00)); gBankLoan = std::min(gBankLoan, gMaxBankLoan); window_invalidate_by_class(WC_FINANCES); break; case EDIT_SCENARIOOPTIONS_SETANNUALINTERESTRATE: - gBankLoanInterestRate = Math::Clamp(0, *edx, 80); + gBankLoanInterestRate = std::clamp(*edx, 0, 80); window_invalidate_by_class(WC_FINANCES); break; case EDIT_SCENARIOOPTIONS_SETFORBIDMARKETINGCAMPAIGNS: @@ -606,16 +606,16 @@ namespace Editor } break; case EDIT_SCENARIOOPTIONS_SETAVERAGECASHPERGUEST: - gGuestInitialCash = Math::Clamp(MONEY(0, 00), *edx, MONEY(1000, 00)); + gGuestInitialCash = std::clamp(*edx, MONEY(0, 00), MONEY(1000, 00)); break; case EDIT_SCENARIOOPTIONS_SETGUESTINITIALHAPPINESS: - gGuestInitialHappiness = Math::Clamp(40, *edx, 250); + gGuestInitialHappiness = std::clamp(*edx, 40, 250); break; case EDIT_SCENARIOOPTIONS_SETGUESTINITIALHUNGER: - gGuestInitialHunger = Math::Clamp(40, *edx, 250); + gGuestInitialHunger = std::clamp(*edx, 40, 250); break; case EDIT_SCENARIOOPTIONS_SETGUESTINITIALTHIRST: - gGuestInitialThirst = Math::Clamp(40, *edx, 250); + gGuestInitialThirst = std::clamp(*edx, 40, 250); break; case EDIT_SCENARIOOPTIONS_SETGUESTSPREFERLESSINTENSERIDES: if (*edx != 0) @@ -638,10 +638,10 @@ namespace Editor } break; case EDIT_SCENARIOOPTIONS_SETCOSTTOBUYLAND: - gLandPrice = Math::Clamp(MONEY(5, 00), *edx, MONEY(200, 00)); + gLandPrice = std::clamp(*edx, MONEY(5, 00), MONEY(200, 00)); break; case EDIT_SCENARIOOPTIONS_SETCOSTTOBUYCONSTRUCTIONRIGHTS: - gConstructionRightsPrice = Math::Clamp(MONEY(5, 00), *edx, MONEY(200, 00)); + gConstructionRightsPrice = std::clamp(*edx, MONEY(5, 00), MONEY(200, 00)); break; case EDIT_SCENARIOOPTIONS_SETPARKCHARGEMETHOD: if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) @@ -687,7 +687,7 @@ namespace Editor } break; case EDIT_SCENARIOOPTIONS_SETPARKCHARGEENTRYFEE: - gParkEntranceFee = Math::Clamp(MONEY(0, 00), *edx, MAX_ENTRANCE_FEE); + gParkEntranceFee = std::clamp(*edx, MONEY(0, 00), MAX_ENTRANCE_FEE); window_invalidate_by_class(WC_PARK_INFORMATION); break; case EDIT_SCENARIOOPTIONS_SETFORBIDTREEREMOVAL: diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 3e6dd8c0a7..a6f97b39ee 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -19,7 +19,6 @@ #include "audio/audio.h" #include "config/Config.h" #include "core/FileScanner.h" -#include "core/Math.hpp" #include "core/Util.hpp" #include "interface/Screenshot.h" #include "interface/Viewport.h" @@ -61,6 +60,7 @@ #include "world/Surface.h" #include "world/Water.h" +#include #include #define NUMBER_OF_AUTOSAVES_TO_KEEP 9 diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 010ba94382..f49c265829 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -13,7 +13,6 @@ #include "Editor.h" #include "Input.h" #include "OpenRCT2.h" -#include "core/Math.hpp" #include "interface/Screenshot.h" #include "localisation/Date.h" #include "localisation/Localisation.h" @@ -30,6 +29,8 @@ #include "world/Park.h" #include "world/Scenery.h" +#include + using namespace OpenRCT2; GameState::GameState() @@ -97,7 +98,7 @@ void GameState::Update() else { numUpdates = gTicksSinceLastUpdate / GAME_UPDATE_TIME_MS; - numUpdates = Math::Clamp(1, numUpdates, GAME_MAX_UPDATES); + numUpdates = std::clamp(numUpdates, 1, GAME_MAX_UPDATES); } if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index e555a81f1e..764d431b0f 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -26,6 +26,8 @@ #include "AudioContext.h" #include "AudioMixer.h" +#include + using namespace OpenRCT2::Audio; struct AudioParams diff --git a/src/openrct2/cmdline/CommandLine.cpp b/src/openrct2/cmdline/CommandLine.cpp index b9085aafeb..d15ddc2af3 100644 --- a/src/openrct2/cmdline/CommandLine.cpp +++ b/src/openrct2/cmdline/CommandLine.cpp @@ -11,9 +11,9 @@ #include "../OpenRCT2.h" #include "../core/Console.hpp" -#include "../core/Math.hpp" #include "../core/String.hpp" +#include #include #pragma region CommandLineArgEnumerator diff --git a/src/openrct2/core/FileStream.hpp b/src/openrct2/core/FileStream.hpp index 0bc50093dc..907c5c851f 100644 --- a/src/openrct2/core/FileStream.hpp +++ b/src/openrct2/core/FileStream.hpp @@ -12,9 +12,10 @@ #include "../common.h" #include "../localisation/Language.h" #include "IStream.hpp" -#include "Math.hpp" #include "String.hpp" +#include + enum { FILE_MODE_OPEN, diff --git a/src/openrct2/core/Math.hpp b/src/openrct2/core/Math.hpp deleted file mode 100644 index 4c81bb3b3a..0000000000 --- a/src/openrct2/core/Math.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2018 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 - -/** - * Common mathematical functions. - */ -namespace Math -{ - template static T Clamp(T low, T x, T high) - { - return (std::min)((std::max)(low, x), high); - } - - template static T Sign(T x) - { - if (x < 0) - return -1; - if (x > 0) - return 1; - return 0; - } -} // namespace Math diff --git a/src/openrct2/core/MemoryStream.cpp b/src/openrct2/core/MemoryStream.cpp index 346264d7b2..c309f7b757 100644 --- a/src/openrct2/core/MemoryStream.cpp +++ b/src/openrct2/core/MemoryStream.cpp @@ -9,7 +9,6 @@ #include "MemoryStream.h" -#include "Math.hpp" #include "Memory.hpp" #include diff --git a/src/openrct2/core/Path.cpp b/src/openrct2/core/Path.cpp index 27d7460407..08c8752e7a 100644 --- a/src/openrct2/core/Path.cpp +++ b/src/openrct2/core/Path.cpp @@ -16,7 +16,6 @@ #include "../platform/platform.h" #include "../util/Util.h" #include "File.h" -#include "Math.hpp" #include "Memory.hpp" #include "Path.hpp" #include "String.hpp" diff --git a/src/openrct2/core/String.cpp b/src/openrct2/core/String.cpp index 292f341c21..2d0e48f239 100644 --- a/src/openrct2/core/String.cpp +++ b/src/openrct2/core/String.cpp @@ -13,6 +13,7 @@ # define _WIN32_WINNT 0x0600 #endif // __MINGW32__ +#include #include #include #include @@ -34,7 +35,6 @@ #include "../localisation/ConversionTables.h" #include "../localisation/Language.h" #include "../util/Util.h" -#include "Math.hpp" #include "Memory.hpp" #include "String.hpp" #include "StringBuilder.hpp" diff --git a/src/openrct2/core/StringBuilder.hpp b/src/openrct2/core/StringBuilder.hpp index c090e11484..38d6925b61 100644 --- a/src/openrct2/core/StringBuilder.hpp +++ b/src/openrct2/core/StringBuilder.hpp @@ -10,7 +10,6 @@ #pragma once #include "../common.h" -#include "Math.hpp" #include "Memory.hpp" #include "String.hpp" diff --git a/src/openrct2/drawing/Drawing.Sprite.cpp b/src/openrct2/drawing/Drawing.Sprite.cpp index e4009b63be..84ff52b416 100644 --- a/src/openrct2/drawing/Drawing.Sprite.cpp +++ b/src/openrct2/drawing/Drawing.Sprite.cpp @@ -19,6 +19,7 @@ #include "../util/Util.h" #include "Drawing.h" +#include #include #include #include diff --git a/src/openrct2/drawing/X8DrawingEngine.cpp b/src/openrct2/drawing/X8DrawingEngine.cpp index 6b0f328a8d..284f267fca 100644 --- a/src/openrct2/drawing/X8DrawingEngine.cpp +++ b/src/openrct2/drawing/X8DrawingEngine.cpp @@ -13,7 +13,6 @@ #include "../Game.h" #include "../Intro.h" #include "../config/Config.h" -#include "../core/Math.hpp" #include "../interface/Screenshot.h" #include "../interface/Viewport.h" #include "../interface/Window.h" diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 205192497c..a70d7f450c 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -16,7 +16,6 @@ #include "../Version.h" #include "../config/Config.h" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../core/String.hpp" #include "../drawing/Drawing.h" #include "../drawing/Font.h" @@ -696,23 +695,23 @@ static int32_t cc_set(InteractiveConsole& console, const utf8** argv, int32_t ar } else if (strcmp(argv[0], "scenario_initial_cash") == 0 && invalidArguments(&invalidArgs, int_valid[0])) { - gInitialCash = Math::Clamp(MONEY(0, 0), MONEY(int_val[0], 0), MONEY(1000000, 00)); + gInitialCash = std::clamp(MONEY(int_val[0], 0), MONEY(0, 0), MONEY(1000000, 00)); console.Execute("get scenario_initial_cash"); } else if (strcmp(argv[0], "current_loan") == 0 && invalidArguments(&invalidArgs, int_valid[0])) { - gBankLoan = Math::Clamp(MONEY(0, 0), MONEY(int_val[0] - (int_val[0] % 1000), 0), gMaxBankLoan); + gBankLoan = std::clamp(MONEY(int_val[0] - (int_val[0] % 1000), 0), MONEY(0, 0), gMaxBankLoan); console.Execute("get current_loan"); } else if (strcmp(argv[0], "max_loan") == 0 && invalidArguments(&invalidArgs, int_valid[0])) { - gMaxBankLoan = Math::Clamp(MONEY(0, 0), MONEY(int_val[0] - (int_val[0] % 1000), 0), MONEY(5000000, 0)); + gMaxBankLoan = std::clamp(MONEY(int_val[0] - (int_val[0] % 1000), 0), MONEY(0, 0), MONEY(5000000, 0)); console.Execute("get max_loan"); } else if (strcmp(argv[0], "guest_initial_cash") == 0 && invalidArguments(&invalidArgs, double_valid[0])) { - gGuestInitialCash = Math::Clamp( - MONEY(0, 0), MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100), MONEY(1000, 0)); + gGuestInitialCash = std::clamp( + MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100), MONEY(0, 0), MONEY(1000, 0)); console.Execute("get guest_initial_cash"); } else if (strcmp(argv[0], "guest_initial_happiness") == 0 && invalidArguments(&invalidArgs, int_valid[0])) @@ -722,12 +721,12 @@ static int32_t cc_set(InteractiveConsole& console, const utf8** argv, int32_t ar } else if (strcmp(argv[0], "guest_initial_hunger") == 0 && invalidArguments(&invalidArgs, int_valid[0])) { - gGuestInitialHunger = (Math::Clamp(1, int_val[0], 84) * 255 / 100 - 255) * -1; + gGuestInitialHunger = (std::clamp(int_val[0], 1, 84) * 255 / 100 - 255) * -1; console.Execute("get guest_initial_hunger"); } else if (strcmp(argv[0], "guest_initial_thirst") == 0 && invalidArguments(&invalidArgs, int_valid[0])) { - gGuestInitialThirst = (Math::Clamp(1, int_val[0], 84) * 255 / 100 - 255) * -1; + gGuestInitialThirst = (std::clamp(int_val[0], 1, 84) * 255 / 100 - 255) * -1; console.Execute("get guest_initial_thirst"); } else if (strcmp(argv[0], "guest_prefer_less_intense_rides") == 0 && invalidArguments(&invalidArgs, int_valid[0])) @@ -787,21 +786,21 @@ static int32_t cc_set(InteractiveConsole& console, const utf8** argv, int32_t ar } else if (strcmp(argv[0], "land_rights_cost") == 0 && invalidArguments(&invalidArgs, double_valid[0])) { - gLandPrice = Math::Clamp( - MONEY(0, 0), MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100), MONEY(200, 0)); + gLandPrice = std::clamp( + MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100), MONEY(0, 0), MONEY(200, 0)); console.Execute("get land_rights_cost"); } else if (strcmp(argv[0], "construction_rights_cost") == 0 && invalidArguments(&invalidArgs, double_valid[0])) { - gConstructionRightsPrice = Math::Clamp( - MONEY(0, 0), MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100), MONEY(200, 0)); + gConstructionRightsPrice = std::clamp( + MONEY((int32_t)double_val[0], ((int32_t)(double_val[0] * 100)) % 100), MONEY(0, 0), MONEY(200, 0)); console.Execute("get construction_rights_cost"); } else if (strcmp(argv[0], "climate") == 0) { if (int_valid[0]) { - gClimate = Math::Clamp(0, int_val[0], 3); + gClimate = std::clamp(int_val[0], 0, 3); } else { @@ -822,7 +821,7 @@ static int32_t cc_set(InteractiveConsole& console, const utf8** argv, int32_t ar } else if (strcmp(argv[0], "game_speed") == 0 && invalidArguments(&invalidArgs, int_valid[0])) { - gGameSpeed = Math::Clamp(1, int_val[0], 8); + gGameSpeed = std::clamp(int_val[0], 1, 8); console.Execute("get game_speed"); } else if (strcmp(argv[0], "console_small_font") == 0 && invalidArguments(&invalidArgs, int_valid[0])) @@ -859,7 +858,7 @@ static int32_t cc_set(InteractiveConsole& console, const utf8** argv, int32_t ar else if (strcmp(argv[0], "window_scale") == 0 && invalidArguments(&invalidArgs, double_valid[0])) { float newScale = (float)(0.001 * std::trunc(1000 * double_val[0])); - gConfigGeneral.window_scale = Math::Clamp(0.5f, newScale, 5.0f); + gConfigGeneral.window_scale = std::clamp(newScale, 0.5f, 5.0f); config_save_default(); gfx_invalidate_screen(); context_trigger_resize(); @@ -1240,7 +1239,7 @@ static int32_t cc_for_date( // YYYY OR YYYY MM (no day provided, preserve existing day) if (argc <= 2) { - day = Math::Clamp(1, gDateMonthTicks / (0x10000 / days_in_month[month - 1]) + 1, (int)days_in_month[month - 1]); + day = std::clamp(gDateMonthTicks / (0x10000 / days_in_month[month - 1]) + 1, 1, (int)days_in_month[month - 1]); } // YYYY MM DD (year, month, and day provided) diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 61de2571aa..796af9e810 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -14,7 +14,6 @@ #include "../Input.h" #include "../OpenRCT2.h" #include "../config/Config.h" -#include "../core/Math.hpp" #include "../drawing/Drawing.h" #include "../paint/Paint.h" #include "../peep/Staff.h" @@ -1761,8 +1760,8 @@ void screen_get_map_xy(int32_t screenX, int32_t screenY, int16_t* x, int16_t* y, { int32_t z = tile_element_height(map_pos.x, map_pos.y); map_pos = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z); - map_pos.x = Math::Clamp(map_pos.x, my_x, my_x + 31); - map_pos.y = Math::Clamp(map_pos.y, my_y, my_y + 31); + map_pos.x = std::clamp(map_pos.x, my_x, my_x + 31); + map_pos.y = std::clamp(map_pos.y, my_y, my_y + 31); } *x = map_pos.x; diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index b70661cdf1..6efb78bbcd 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -17,7 +17,6 @@ #include "../audio/audio.h" #include "../config/Config.h" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../drawing/Drawing.h" #include "../interface/Cursors.h" @@ -196,7 +195,7 @@ static void window_close_surplus(int32_t cap, int8_t avoid_classification) void window_set_window_limit(int32_t value) { int32_t prev = gConfigGeneral.window_limit; - int32_t val = Math::Clamp(WINDOW_LIMIT_MIN, value, WINDOW_LIMIT_MAX); + int32_t val = std::clamp(value, WINDOW_LIMIT_MIN, WINDOW_LIMIT_MAX); gConfigGeneral.window_limit = val; config_save_default(); // Checks if value decreases and then closes surplus @@ -1045,7 +1044,7 @@ void window_zoom_set(rct_window* w, int32_t zoomLevel, bool atCursor) { rct_viewport* v = w->viewport; - zoomLevel = Math::Clamp(0, zoomLevel, MAX_ZOOM_LEVEL); + zoomLevel = std::clamp(zoomLevel, 0, MAX_ZOOM_LEVEL); if (v->zoom == zoomLevel) return; @@ -1325,8 +1324,8 @@ void window_resize(rct_window* w, int32_t dw, int32_t dh) window_invalidate(w); // Clamp new size to minimum and maximum - w->width = Math::Clamp(w->min_width, w->width + dw, w->max_width); - w->height = Math::Clamp(w->min_height, w->height + dh, w->max_height); + w->width = std::clamp(w->width + dw, w->min_width, w->max_width); + w->height = std::clamp(w->height + dh, w->min_height, w->max_height); window_event_resize_call(w); window_event_invalidate_call(w); @@ -1351,8 +1350,8 @@ void window_set_resize(rct_window* w, int32_t minWidth, int32_t minHeight, int32 w->max_height = maxHeight; // Clamp width and height to minimum and maximum - int32_t width = Math::Clamp(minWidth, w->width, maxWidth); - int32_t height = Math::Clamp(minHeight, w->height, maxHeight); + int32_t width = std::clamp(w->width, minWidth, maxWidth); + int32_t height = std::clamp(w->height, minHeight, maxHeight); // Resize window if size has changed if (w->width != width || w->height != height) @@ -1947,7 +1946,7 @@ void window_move_and_snap(rct_window* w, int32_t newWindowX, int32_t newWindowY, int32_t originalY = w->y; int32_t minY = (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) ? 1 : TOP_TOOLBAR_HEIGHT + 2; - newWindowY = Math::Clamp(minY, newWindowY, context_get_height() - 34); + newWindowY = std::clamp(newWindowY, minY, context_get_height() - 34); if (snapProximity > 0) { diff --git a/src/openrct2/localisation/LanguagePack.cpp b/src/openrct2/localisation/LanguagePack.cpp index ef69292e69..4829c09f15 100644 --- a/src/openrct2/localisation/LanguagePack.cpp +++ b/src/openrct2/localisation/LanguagePack.cpp @@ -11,7 +11,6 @@ #include "../common.h" #include "../core/FileStream.hpp" -#include "../core/Math.hpp" #include "../core/Memory.hpp" #include "../core/String.hpp" #include "../core/StringBuilder.hpp" @@ -621,7 +620,7 @@ private: int32_t number; if (sscanf(tokenName, "%d", &number) == 1) { - *token = Math::Clamp(0, number, 255); + *token = std::clamp(number, 0, 255); *isByte = true; } } diff --git a/src/openrct2/localisation/Localisation.Date.cpp b/src/openrct2/localisation/Localisation.Date.cpp index ef2ab07f67..8f7e5320a6 100644 --- a/src/openrct2/localisation/Localisation.Date.cpp +++ b/src/openrct2/localisation/Localisation.Date.cpp @@ -8,10 +8,10 @@ *****************************************************************************/ #include "../Game.h" -#include "../core/Math.hpp" #include "Date.h" #include "StringIds.h" +#include #include uint16_t gDateMonthTicks; @@ -66,9 +66,9 @@ void date_reset() void date_set(int32_t year, int32_t month, int32_t day) { - year = Math::Clamp(1, year, 8192); - month = Math::Clamp(1, month, (int)MONTH_COUNT); - day = Math::Clamp(1, day, (int)days_in_month[month - 1]); + year = std::clamp(year, 1, 8192); + month = std::clamp(month, 1, (int)MONTH_COUNT); + day = std::clamp(day, 1, (int)days_in_month[month - 1]); gDateMonthsElapsed = (year - 1) * MONTH_COUNT + month - 1; gDateMonthTicks = 0x10000 / days_in_month[month - 1] * (day - 1) + 4; } diff --git a/src/openrct2/localisation/Localisation.cpp b/src/openrct2/localisation/Localisation.cpp index 5256f0bf76..fa6d882fa7 100644 --- a/src/openrct2/localisation/Localisation.cpp +++ b/src/openrct2/localisation/Localisation.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -26,7 +27,6 @@ #include "../common.h" #include "../config/Config.h" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../core/String.hpp" #include "../core/Util.hpp" #include "../management/Marketing.h" diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 959108ad7e..7f5840360b 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -19,6 +19,7 @@ #include "../util/SawyerCoding.h" #include "../world/Location.hpp" +#include #include #define ACTION_COOLDOWN_TIME_PLACE_SCENERY 20 @@ -43,7 +44,6 @@ static int32_t _pickup_peep_old_x = LOCATION_NULL; # include "../core/Console.hpp" # include "../core/FileStream.hpp" # include "../core/Json.hpp" -# include "../core/Math.hpp" # include "../core/MemoryStream.h" # include "../core/Path.hpp" # include "../core/String.hpp" diff --git a/src/openrct2/network/Twitch.cpp b/src/openrct2/network/Twitch.cpp index 12f481b419..5aa1ff810c 100644 --- a/src/openrct2/network/Twitch.cpp +++ b/src/openrct2/network/Twitch.cpp @@ -26,7 +26,6 @@ void twitch_update() # include "../OpenRCT2.h" # include "../config/Config.h" # include "../core/Json.hpp" -# include "../core/Math.hpp" # include "../core/String.hpp" # include "../drawing/Drawing.h" # include "../interface/InteractiveConsole.h" diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index fa0d4c934c..60b29256cc 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -35,6 +35,7 @@ #include "WallObject.h" #include "WaterObject.h" +#include #include interface IFileDataRetriever diff --git a/src/openrct2/object/ObjectJsonHelpers.cpp b/src/openrct2/object/ObjectJsonHelpers.cpp index 1ed700e188..26910e145a 100644 --- a/src/openrct2/object/ObjectJsonHelpers.cpp +++ b/src/openrct2/object/ObjectJsonHelpers.cpp @@ -15,7 +15,6 @@ #include "../PlatformEnvironment.h" #include "../core/File.h" #include "../core/FileScanner.h" -#include "../core/Math.hpp" #include "../core/Memory.hpp" #include "../core/Path.hpp" #include "../core/String.hpp" @@ -26,6 +25,7 @@ #include "Object.h" #include "ObjectFactory.h" +#include #include #include #include diff --git a/src/openrct2/object/ObjectList.cpp b/src/openrct2/object/ObjectList.cpp index be7fb19b35..8201e70ba4 100644 --- a/src/openrct2/object/ObjectList.cpp +++ b/src/openrct2/object/ObjectList.cpp @@ -11,7 +11,6 @@ #include "../Context.h" #include "../Game.h" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../object/Object.h" #include "../util/SawyerCoding.h" @@ -19,6 +18,7 @@ #include "ObjectManager.h" #include "ObjectRepository.h" +#include #include // 98DA00 diff --git a/src/openrct2/object/RideObject.cpp b/src/openrct2/object/RideObject.cpp index 14efaf82df..8fef5cb140 100644 --- a/src/openrct2/object/RideObject.cpp +++ b/src/openrct2/object/RideObject.cpp @@ -13,7 +13,6 @@ #include "../OpenRCT2.h" #include "../core/IStream.hpp" -#include "../core/Math.hpp" #include "../core/Memory.hpp" #include "../core/String.hpp" #include "../core/Util.hpp" diff --git a/src/openrct2/object/SmallSceneryObject.cpp b/src/openrct2/object/SmallSceneryObject.cpp index 97b89c683b..2fb6f5f3f3 100644 --- a/src/openrct2/object/SmallSceneryObject.cpp +++ b/src/openrct2/object/SmallSceneryObject.cpp @@ -12,7 +12,6 @@ #include "SmallSceneryObject.h" #include "../core/IStream.hpp" -#include "../core/Math.hpp" #include "../core/Memory.hpp" #include "../core/String.hpp" #include "../drawing/Drawing.h" @@ -22,6 +21,8 @@ #include "../world/SmallScenery.h" #include "ObjectJsonHelpers.h" +#include + void SmallSceneryObject::ReadLegacy(IReadObjectContext* context, IStream* stream) { stream->Seek(6, STREAM_SEEK_CURRENT); diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index e3a95c7fa5..169dcbd993 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -10,7 +10,6 @@ #include "Paint.h" #include "../config/Config.h" -#include "../core/Math.hpp" #include "../drawing/Drawing.h" #include "../interface/Viewport.h" #include "../localisation/Localisation.h" @@ -77,7 +76,7 @@ static void paint_session_init(paint_session* session, rct_drawpixelinfo* dpi) static void paint_session_add_ps_to_quadrant(paint_session* session, paint_struct* ps, int32_t positionHash) { - uint32_t paintQuadrantIndex = Math::Clamp(0, positionHash / 32, MAX_PAINT_QUADRANTS - 1); + uint32_t paintQuadrantIndex = std::clamp(positionHash / 32, 0, MAX_PAINT_QUADRANTS - 1); ps->quadrant_index = paintQuadrantIndex; ps->next_quadrant_ps = session->Quadrants[paintQuadrantIndex]; session->Quadrants[paintQuadrantIndex] = ps; diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index ce3252681d..0a9e31fe4c 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -13,7 +13,6 @@ #include "../../OpenRCT2.h" #include "../../config/Config.h" #include "../../core/Guard.hpp" -#include "../../core/Math.hpp" #include "../../core/Util.hpp" #include "../../drawing/Drawing.h" #include "../../interface/Colour.h" @@ -26,6 +25,7 @@ #include "../../world/Surface.h" #include "Paint.TileElement.h" +#include #include // clang-format off diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index 85f1e36159..f9e90aebb1 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -12,7 +12,6 @@ #include "../../Game.h" #include "../../Input.h" #include "../../config/Config.h" -#include "../../core/Math.hpp" #include "../../drawing/Drawing.h" #include "../../interface/Viewport.h" #include "../../localisation/Localisation.h" @@ -31,6 +30,8 @@ #include "../VirtualFloor.h" #include "Paint.Surface.h" +#include + #ifdef __TESTPAINT__ uint16_t testPaintVerticalTunnelHeight; #endif diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 61da1e31f8..c64f458b38 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -13,7 +13,6 @@ #include "../audio/audio.h" #include "../config/Config.h" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../localisation/Localisation.h" #include "../management/Finance.h" @@ -37,6 +36,8 @@ #include "../world/Surface.h" #include "Peep.h" +#include + // Locations of the spiral slide platform that a peep walks from the entrance of the ride to the // entrance of the slide. Up to 4 waypoints for each 4 sides that an ride entrance can be located // and 4 different rotations of the ride. 4 * 4 * 4 = 64 locations. @@ -1485,7 +1486,7 @@ void rct_peep::OnEnterRide(uint8_t rideIndex) SetHasRidden(current_ride); peep_update_favourite_ride(this, ride); - happiness_target = Math::Clamp(0, happiness_target + satisfaction, PEEP_MAX_HAPPINESS); + happiness_target = std::clamp(happiness_target + satisfaction, 0, PEEP_MAX_HAPPINESS); peep_update_ride_nausea_growth(this, ride); } @@ -2475,7 +2476,7 @@ static int16_t peep_calculate_ride_satisfaction(rct_peep* peep, Ride* ride) static void peep_update_favourite_ride(rct_peep* peep, Ride* ride) { peep->peep_flags &= ~PEEP_FLAGS_RIDE_SHOULD_BE_MARKED_AS_FAVOURITE; - uint8_t peepRideRating = Math::Clamp(0, (ride->excitement / 4) + peep->happiness, PEEP_MAX_HAPPINESS); + uint8_t peepRideRating = std::clamp((ride->excitement / 4) + peep->happiness, 0, PEEP_MAX_HAPPINESS); if (peepRideRating >= peep->favourite_ride_rating) { if (peep->happiness >= 160 && peep->happiness_target >= 160) @@ -2621,7 +2622,7 @@ static int16_t peep_calculate_ride_intensity_nausea_satisfaction(rct_peep* peep, */ static void peep_update_ride_nausea_growth(rct_peep* peep, Ride* ride) { - uint32_t nauseaMultiplier = Math::Clamp(64, 256 - peep->happiness_target, 200); + uint32_t nauseaMultiplier = std::clamp(256 - peep->happiness_target, 64, 200); uint32_t nauseaGrowthRateChange = (ride->nausea * nauseaMultiplier) / 512; nauseaGrowthRateChange *= std::max(static_cast(128), peep->hunger) / 64; nauseaGrowthRateChange >>= (peep->nausea_tolerance & 3); @@ -5629,7 +5630,7 @@ void rct_peep::UpdateWatching() sub_state++; - time_to_stand = Math::Clamp(0, ((129 - energy) * 16 + 50) / 2, 255); + time_to_stand = std::clamp(((129 - energy) * 16 + 50) / 2, 0, 255); UpdateSpriteType(); } else if (sub_state == 1) diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 41e6d9318d..8c0004e772 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -18,7 +18,6 @@ #include "../audio/audio.h" #include "../config/Config.h" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../interface/Window.h" #include "../localisation/Localisation.h" @@ -47,6 +46,7 @@ #include "../world/Surface.h" #include "Staff.h" +#include #include #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 @@ -1806,7 +1806,7 @@ rct_peep* peep_generate(int32_t x, int32_t y, int32_t z) /* Initial value will vary by -15..16 */ int8_t happiness_delta = (scenario_rand() & 0x1F) - 15; /* Adjust by the delta, clamping at min=0 and max=255. */ - peep->happiness = Math::Clamp(0, peep->happiness + happiness_delta, PEEP_MAX_HAPPINESS); + peep->happiness = std::clamp(peep->happiness + happiness_delta, 0, PEEP_MAX_HAPPINESS); peep->happiness_target = peep->happiness; peep->nausea = 0; peep->nausea_target = 0; @@ -1818,7 +1818,7 @@ rct_peep* peep_generate(int32_t x, int32_t y, int32_t z) /* Initial value will vary by -15..16 */ int8_t hunger_delta = (scenario_rand() & 0x1F) - 15; /* Adjust by the delta, clamping at min=0 and max=255. */ - peep->hunger = Math::Clamp(0, peep->hunger + hunger_delta, 255); + peep->hunger = std::clamp(peep->hunger + hunger_delta, 0, 255); /* Scenario editor limits initial guest thirst to between 37..253. * To be on the safe side, assume the value could have been hacked @@ -1827,7 +1827,7 @@ rct_peep* peep_generate(int32_t x, int32_t y, int32_t z) /* Initial value will vary by -15..16 */ int8_t thirst_delta = (scenario_rand() & 0x1F) - 15; /* Adjust by the delta, clamping at min=0 and max=255. */ - peep->thirst = Math::Clamp(0, peep->thirst + thirst_delta, 0xFF); + peep->thirst = std::clamp(peep->thirst + thirst_delta, 0, 0xFF); peep->toilet = 0; peep->time_to_consume = 0; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 2aff1739c5..a20217d4cf 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -14,7 +14,6 @@ #include "../Input.h" #include "../audio/audio.h" #include "../config/Config.h" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../interface/Viewport.h" #include "../localisation/Date.h" @@ -37,6 +36,8 @@ #include "../world/Surface.h" #include "Peep.h" +#include + // clang-format off const rct_string_id StaffCostumeNames[] = { STR_STAFF_OPTION_COSTUME_PANDA, diff --git a/src/openrct2/rct12/SawyerChunkWriter.cpp b/src/openrct2/rct12/SawyerChunkWriter.cpp index 34d77bc14d..4a298b5bd5 100644 --- a/src/openrct2/rct12/SawyerChunkWriter.cpp +++ b/src/openrct2/rct12/SawyerChunkWriter.cpp @@ -10,7 +10,6 @@ #include "SawyerChunkWriter.h" #include "../core/IStream.hpp" -#include "../core/Math.hpp" #include "../util/SawyerCoding.h" // Maximum buffer size to store compressed data, maximum of 16 MiB diff --git a/src/openrct2/rct12/SawyerEncoding.cpp b/src/openrct2/rct12/SawyerEncoding.cpp index c0c915756f..55758dc54a 100644 --- a/src/openrct2/rct12/SawyerEncoding.cpp +++ b/src/openrct2/rct12/SawyerEncoding.cpp @@ -10,7 +10,8 @@ #include "SawyerEncoding.h" #include "../core/IStream.hpp" -#include "../core/Math.hpp" + +#include namespace SawyerEncoding { diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index 08f8371595..329f02b6db 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -9,7 +9,6 @@ #include "CableLift.h" -#include "../core/Math.hpp" #include "../rct12/RCT12.h" #include "../util/Util.h" #include "../world/Sprite.h" @@ -18,6 +17,8 @@ #include "Track.h" #include "VehicleData.h" +#include + static void cable_lift_update_moving_to_end_of_station(rct_vehicle* vehicle); static void cable_lift_update_waiting_to_depart(rct_vehicle* vehicle); static void cable_lift_update_departing(rct_vehicle* vehicle); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index cbdbe5185f..02768c0eeb 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -19,7 +19,6 @@ #include "../audio/audio.h" #include "../common.h" #include "../config/Config.h" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../interface/Window.h" #include "../localisation/Date.h" @@ -56,6 +55,7 @@ #include "Track.h" #include "TrackData.h" +#include #include #include #include @@ -3071,8 +3071,8 @@ static void ride_measurement_update(rct_ride_measurement* measurement) if (measurement->flags & RIDE_MEASUREMENT_FLAG_G_FORCES) { vehicle_get_g_forces(vehicle, &verticalG, &lateralG); - verticalG = Math::Clamp(-127, verticalG / 8, 127); - lateralG = Math::Clamp(-127, lateralG / 8, 127); + verticalG = std::clamp(verticalG / 8, -127, 127); + lateralG = std::clamp(lateralG / 8, -127, 127); if (gScenarioTicks & 1) { @@ -7650,7 +7650,7 @@ void ride_update_max_vehicles(int32_t rideIndex) { case RIDE_MODE_CONTINUOUS_CIRCUIT_BLOCK_SECTIONED: case RIDE_MODE_POWERED_LAUNCH_BLOCK_SECTIONED: - maxNumTrains = Math::Clamp(1, ride->num_stations + ride->num_block_brakes - 1, 31); + maxNumTrains = std::clamp(ride->num_stations + ride->num_block_brakes - 1, 1, 31); break; case RIDE_MODE_REVERSE_INCLINE_LAUNCHED_SHUTTLE: case RIDE_MODE_POWERED_LAUNCH_PASSTROUGH: @@ -7870,7 +7870,7 @@ static money32 ride_set_vehicles(uint8_t rideIndex, uint8_t setting, uint8_t val rideEntry = get_ride_entry(ride->subtype); if (!gCheatsDisableTrainLengthLimit) { - value = Math::Clamp(rideEntry->min_cars_in_train, value, rideEntry->max_cars_in_train); + value = std::clamp(value, rideEntry->min_cars_in_train, rideEntry->max_cars_in_train); } ride->proposed_num_cars_per_train = value; break; @@ -7912,8 +7912,8 @@ static money32 ride_set_vehicles(uint8_t rideIndex, uint8_t setting, uint8_t val ride_set_vehicle_colours_to_random_preset(ride, preset); if (!gCheatsDisableTrainLengthLimit) { - ride->proposed_num_cars_per_train = Math::Clamp( - rideEntry->min_cars_in_train, ride->proposed_num_cars_per_train, rideEntry->max_cars_in_train); + ride->proposed_num_cars_per_train = std::clamp( + ride->proposed_num_cars_per_train, rideEntry->min_cars_in_train, rideEntry->max_cars_in_train); } break; } diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 548f7b8f97..7c77b47351 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -11,7 +11,6 @@ #include "../Cheats.h" #include "../OpenRCT2.h" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../interface/Window.h" #include "../localisation/Date.h" @@ -1329,7 +1328,7 @@ static rating_tuple ride_ratings_get_gforce_ratings(Ride* ride) // Apply maximum negative G force factor fixed16_2dp gforce = ride->max_negative_vertical_g; - result.excitement += (Math::Clamp(-FIXED_2DP(2, 50), gforce, FIXED_2DP(0, 00)) * -15728) >> 16; + result.excitement += (std::clamp(gforce, -FIXED_2DP(2, 50), FIXED_2DP(0, 00)) * -15728) >> 16; result.intensity += ((gforce - FIXED_2DP(1, 00)) * -52428) >> 16; result.nausea += ((gforce - FIXED_2DP(1, 00)) * -14563) >> 16; @@ -1458,9 +1457,9 @@ static void ride_ratings_add(rating_tuple* rating, int32_t excitement, int32_t i int32_t newExcitement = rating->excitement + excitement; int32_t newIntensity = rating->intensity + intensity; int32_t newNausea = rating->nausea + nausea; - rating->excitement = Math::Clamp(0, newExcitement, INT16_MAX); - rating->intensity = Math::Clamp(0, newIntensity, INT16_MAX); - rating->nausea = Math::Clamp(0, newNausea, INT16_MAX); + rating->excitement = std::clamp(newExcitement, 0, INT16_MAX); + rating->intensity = std::clamp(newIntensity, 0, INT16_MAX); + rating->nausea = std::clamp(newNausea, 0, INT16_MAX); } static void ride_ratings_apply_length(rating_tuple* ratings, Ride* ride, int32_t maxLength, int32_t excitementMultiplier) diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 705fd8d158..5585bdf44e 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -15,7 +15,6 @@ #include "../actions/WallRemoveAction.hpp" #include "../audio/audio.h" #include "../core/File.h" -#include "../core/Math.hpp" #include "../core/String.hpp" #include "../core/Util.hpp" #include "../localisation/Localisation.h" @@ -41,6 +40,8 @@ #include "TrackData.h" #include "TrackDesignRepository.h" +#include + struct map_backup { rct_tile_element tile_elements[MAX_TILE_ELEMENTS]; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index ba9903efa0..a7acb5e92b 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -16,7 +16,6 @@ #include "../audio/AudioMixer.h" #include "../audio/audio.h" #include "../config/Config.h" -#include "../core/Math.hpp" #include "../core/Memory.hpp" #include "../core/Util.hpp" #include "../interface/Viewport.h" @@ -42,6 +41,8 @@ #include "TrackData.h" #include "VehicleData.h" +#include + static void vehicle_update(rct_vehicle* vehicle); static void vehicle_update_crossings(const rct_vehicle* vehicle); static void vehicle_claxon(const rct_vehicle* vehicle); @@ -5571,7 +5572,7 @@ static void vehicle_update_sound(rct_vehicle* vehicle) // Calculate Sound Vector (used for sound frequency calcs) int32_t soundDirection = SpriteDirectionToSoundDirection[vehicle->sprite_direction]; int32_t soundVector = ((vehicle->velocity >> 14) * soundDirection) >> 14; - soundVector = Math::Clamp(-127, soundVector, 127); + soundVector = std::clamp(soundVector, -127, 127); vehicle->sound_vector_factor = soundVector & 0xFF; } @@ -7208,8 +7209,8 @@ static void vehicle_update_spinning_car(rct_vehicle* vehicle) break; } - spinSpeed = Math::Clamp( - static_cast(-VEHICLE_MAX_SPIN_SPEED), vehicle->spin_speed, static_cast(VEHICLE_MAX_SPIN_SPEED)); + spinSpeed = std::clamp( + vehicle->spin_speed, static_cast(-VEHICLE_MAX_SPIN_SPEED), static_cast(VEHICLE_MAX_SPIN_SPEED)); vehicle->spin_speed = spinSpeed; vehicle->spin_sprite += spinSpeed >> 8; // Note this actually increases the spin speed if going right! @@ -9417,8 +9418,8 @@ loc_6DCEFF: if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING) { - vehicle->spin_speed = Math::Clamp( - static_cast(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE), vehicle->spin_speed, + vehicle->spin_speed = std::clamp( + vehicle->spin_speed, static_cast(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE), static_cast(VEHICLE_MAX_SPIN_SPEED_WATER_RIDE)); } @@ -9537,8 +9538,8 @@ static void vehicle_update_track_motion_powered_ride_acceleration( if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING) { - vehicle->spin_speed = Math::Clamp( - static_cast(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE), vehicle->spin_speed, + vehicle->spin_speed = std::clamp( + vehicle->spin_speed, static_cast(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE), static_cast(VEHICLE_MAX_SPIN_SPEED_WATER_RIDE)); } diff --git a/src/openrct2/ride/coaster/JuniorRollerCoaster.cpp b/src/openrct2/ride/coaster/JuniorRollerCoaster.cpp index 03042afc89..92daf9a1f9 100644 --- a/src/openrct2/ride/coaster/JuniorRollerCoaster.cpp +++ b/src/openrct2/ride/coaster/JuniorRollerCoaster.cpp @@ -9,7 +9,6 @@ #include "JuniorRollerCoaster.h" -#include "../../core/Math.hpp" #include "../../drawing/Drawing.h" #include "../../interface/Viewport.h" #include "../../interface/Window.h" @@ -23,6 +22,8 @@ #include "../TrackData.h" #include "../TrackPaint.h" +#include + enum { SPR_JUNIOR_RC_FLAT_SW_NE = 27807, diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 6a8e8a7c7c..86713c30f8 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -46,6 +46,8 @@ #include "ScenarioRepository.h" #include "ScenarioSources.h" +#include + const rct_string_id ScenarioCategoryStringIds[SCENARIO_CATEGORY_COUNT] = { STR_BEGINNER_PARKS, STR_CHALLENGING_PARKS, STR_EXPERT_PARKS, STR_REAL_PARKS, STR_OTHER_PARKS, diff --git a/src/openrct2/scenario/ScenarioRepository.cpp b/src/openrct2/scenario/ScenarioRepository.cpp index 21325540b5..ba89ef0734 100644 --- a/src/openrct2/scenario/ScenarioRepository.cpp +++ b/src/openrct2/scenario/ScenarioRepository.cpp @@ -18,7 +18,6 @@ #include "../core/File.h" #include "../core/FileIndex.hpp" #include "../core/FileStream.hpp" -#include "../core/Math.hpp" #include "../core/Path.hpp" #include "../core/String.hpp" #include "../core/Util.hpp" @@ -48,7 +47,10 @@ static int32_t ScenarioCategoryCompare(int32_t categoryA, int32_t categoryB) return -1; if (categoryB == SCENARIO_CATEGORY_BUILD_YOUR_OWN) return 1; - return Math::Sign(categoryA - categoryB); + if (categoryA < categoryB) + return -1; + else + return 1; } static int32_t scenario_index_entry_CompareByCategory(const scenario_index_entry& entryA, const scenario_index_entry& entryB) diff --git a/src/openrct2/title/TitleSequence.cpp b/src/openrct2/title/TitleSequence.cpp index 9eafbb4a69..d771514179 100644 --- a/src/openrct2/title/TitleSequence.cpp +++ b/src/openrct2/title/TitleSequence.cpp @@ -16,7 +16,6 @@ #include "../core/FileScanner.h" #include "../core/FileStream.hpp" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../core/Memory.hpp" #include "../core/MemoryStream.h" #include "../core/Path.hpp" @@ -27,6 +26,7 @@ #include "../scenario/ScenarioSources.h" #include "../util/Util.h" +#include #include #include diff --git a/src/openrct2/util/SawyerCoding.cpp b/src/openrct2/util/SawyerCoding.cpp index e5c0036b94..ab2c6d92e4 100644 --- a/src/openrct2/util/SawyerCoding.cpp +++ b/src/openrct2/util/SawyerCoding.cpp @@ -9,11 +9,11 @@ #include "SawyerCoding.h" -#include "../core/Math.hpp" #include "../platform/platform.h" #include "../scenario/Scenario.h" #include "Util.h" +#include #include static size_t decode_chunk_rle(const uint8_t* src_buffer, uint8_t* dst_buffer, size_t length); diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 1c0e571e7f..e62d8a9086 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -11,13 +11,13 @@ #include "../common.h" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../interface/Window.h" #include "../localisation/Localisation.h" #include "../platform/platform.h" #include "../title/TitleScreen.h" #include "zlib.h" +#include #include #include #include @@ -706,7 +706,7 @@ uint8_t soft_light(uint8_t a, uint8_t b) { fr = (2 * fa * (1 - fb)) + (std::sqrt(fa) * ((2 * fb) - 1)); } - return (uint8_t)(Math::Clamp(0.0f, fr, 1.0f) * 255.0f); + return (uint8_t)(std::clamp(fr, 0.0f, 1.0f) * 255.0f); } /** diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index 65f853e4df..d82a53bda4 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -11,7 +11,6 @@ #include "../Context.h" #include "../Game.h" -#include "../core/Math.hpp" #include "../core/Memory.hpp" #include "../core/String.hpp" #include "../core/Util.hpp" diff --git a/src/openrct2/world/Climate.cpp b/src/openrct2/world/Climate.cpp index ba8e0e99ff..82551e543e 100644 --- a/src/openrct2/world/Climate.cpp +++ b/src/openrct2/world/Climate.cpp @@ -16,7 +16,6 @@ #include "../audio/AudioMixer.h" #include "../audio/audio.h" #include "../config/Config.h" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../drawing/Drawing.h" #include "../interface/Window.h" @@ -26,6 +25,8 @@ #include "../util/Util.h" #include "../windows/Intent.h" +#include + constexpr int32_t MAX_THUNDER_INSTANCES = 2; enum class THUNDER_STATUS diff --git a/src/openrct2/world/Duck.cpp b/src/openrct2/world/Duck.cpp index 55e56a4827..a3d022f34a 100644 --- a/src/openrct2/world/Duck.cpp +++ b/src/openrct2/world/Duck.cpp @@ -9,7 +9,6 @@ #include "../Game.h" #include "../audio/audio.h" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../localisation/Date.h" #include "../scenario/Scenario.h" @@ -17,6 +16,7 @@ #include "../world/Surface.h" #include "Sprite.h" +#include #include // clang-format off diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 8dda42aa11..21bc639f0a 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -13,7 +13,6 @@ #include "../OpenRCT2.h" #include "../actions/FootpathRemoveAction.hpp" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../localisation/Localisation.h" #include "../management/Finance.h" @@ -31,6 +30,8 @@ #include "Sprite.h" #include "Surface.h" +#include + void footpath_update_queue_entrance_banner(int32_t x, int32_t y, rct_tile_element* tileElement); uint8_t gFootpathProvisionalFlags; @@ -858,8 +859,8 @@ void footpath_get_coordinates_from_pos( z = tile_element_height(position.x, position.y); } position = viewport_coord_to_map_coord(start_vp_pos.x, start_vp_pos.y, z); - position.x = Math::Clamp(minPosition.x, position.x, maxPosition.x); - position.y = Math::Clamp(minPosition.y, position.y, maxPosition.y); + position.x = std::clamp(position.x, minPosition.x, maxPosition.x); + position.y = std::clamp(position.y, minPosition.y, maxPosition.y); } // Determine to which edge the cursor is closest diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index df2ddfd88b..5d448e6a3e 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -19,7 +19,6 @@ #include "../audio/audio.h" #include "../config/Config.h" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../interface/Cursors.h" #include "../interface/Window.h" @@ -46,6 +45,8 @@ #include "TileInspector.h" #include "Wall.h" +#include + /** * Replaces 0x00993CCC, 0x00993CCE */ @@ -1767,18 +1768,18 @@ static money32 map_set_land_ownership(uint8_t flags, int16_t x1, int16_t y1, int return 0; // Clamp to maximum addressable element to prevent long loop spamming the log - x1 = Math::Clamp(32, (int32_t)x1, gMapSizeUnits - 32); - y1 = Math::Clamp(32, (int32_t)y1, gMapSizeUnits - 32); - x2 = Math::Clamp(32, (int32_t)x2, gMapSizeUnits - 32); - y2 = Math::Clamp(32, (int32_t)y2, gMapSizeUnits - 32); + x1 = std::clamp(x1, 32, gMapSizeUnits - 32); + y1 = std::clamp(y1, 32, gMapSizeUnits - 32); + x2 = std::clamp(x2, 32, gMapSizeUnits - 32); + y2 = std::clamp(y2, 32, gMapSizeUnits - 32); gMapLandRightsUpdateSuccess = false; map_buy_land_rights(x1, y1, x2, y2, BUY_LAND_RIGHTS_FLAG_SET_OWNERSHIP_WITH_CHECKS, flags | (newOwnership << 8)); if (!gMapLandRightsUpdateSuccess) return 0; - int16_t x = Math::Clamp(32, (int32_t)x1, gMapSizeUnits - 32); - int16_t y = Math::Clamp(32, (int32_t)y1, gMapSizeUnits - 32); + int16_t x = std::clamp(x1, 32, gMapSizeUnits - 32); + int16_t y = std::clamp(y1, 32, gMapSizeUnits - 32); x += 16; y += 16; @@ -2455,8 +2456,8 @@ static money32 smooth_land( // Cap bounds to map mapLeft = std::max(mapLeft, 32); mapTop = std::max(mapTop, 32); - mapRight = Math::Clamp(0, mapRight, (MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32); - mapBottom = Math::Clamp(0, mapBottom, (MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32); + mapRight = std::clamp(mapRight, 0, (MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32); + mapBottom = std::clamp(mapBottom, 0, (MAXIMUM_MAP_SIZE_TECHNICAL - 1) * 32); // Play sound (only once) int32_t centreZ = tile_element_height(centreX, centreY); @@ -2486,22 +2487,22 @@ static money32 smooth_land( // Smooth the 4 corners { // top-left rct_tile_element* tileElement = map_get_surface_element_at({ mapLeft, mapTop }); - int32_t z = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 2), maxHeight); + int32_t z = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 2), minHeight, maxHeight); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapTop, z, -32, -32, 0, 2, raiseLand); } { // bottom-left rct_tile_element* tileElement = map_get_surface_element_at(mapLeft >> 5, mapBottom >> 5); - int32_t z = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 3), maxHeight); + int32_t z = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 3), minHeight, maxHeight); totalCost += smooth_land_row_by_corner(flags, mapLeft, mapBottom, z, -32, 32, 1, 3, raiseLand); } { // bottom-right rct_tile_element* tileElement = map_get_surface_element_at(mapRight >> 5, mapBottom >> 5); - int32_t z = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 0), maxHeight); + int32_t z = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 0), minHeight, maxHeight); totalCost += smooth_land_row_by_corner(flags, mapRight, mapBottom, z, 32, 32, 2, 0, raiseLand); } { // top-right rct_tile_element* tileElement = map_get_surface_element_at(mapRight >> 5, mapTop >> 5); - int32_t z = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 1), maxHeight); + int32_t z = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 1), minHeight, maxHeight); totalCost += smooth_land_row_by_corner(flags, mapRight, mapTop, z, 32, -32, 3, 1, raiseLand); } @@ -2511,26 +2512,26 @@ static money32 smooth_land( for (int32_t y = mapTop; y <= mapBottom; y += 32) { tileElement = map_get_surface_element_at({ mapLeft, y }); - z1 = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 3), maxHeight); - z2 = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 2), maxHeight); + z1 = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 3), minHeight, maxHeight); + z2 = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 2), minHeight, maxHeight); totalCost += smooth_land_row_by_edge(flags, mapLeft, y, z1, z2, -32, 0, 0, 1, 3, 2, raiseLand); tileElement = map_get_surface_element_at({ mapRight, y }); - z1 = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 1), maxHeight); - z2 = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 0), maxHeight); + z1 = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 1), minHeight, maxHeight); + z2 = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 0), minHeight, maxHeight); totalCost += smooth_land_row_by_edge(flags, mapRight, y, z1, z2, 32, 0, 2, 3, 1, 0, raiseLand); } for (int32_t x = mapLeft; x <= mapRight; x += 32) { tileElement = map_get_surface_element_at({ x, mapTop }); - z1 = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 1), maxHeight); - z2 = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 2), maxHeight); + z1 = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 1), minHeight, maxHeight); + z2 = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 2), minHeight, maxHeight); totalCost += smooth_land_row_by_edge(flags, x, mapTop, z1, z2, 0, -32, 0, 3, 1, 2, raiseLand); tileElement = map_get_surface_element_at({ x, mapBottom }); - z1 = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 0), maxHeight); - z2 = Math::Clamp(minHeight, (uint8_t)tile_element_get_corner_height(tileElement, 3), maxHeight); + z1 = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 0), minHeight, maxHeight); + z2 = std::clamp((uint8_t)tile_element_get_corner_height(tileElement, 3), minHeight, maxHeight); totalCost += smooth_land_row_by_edge(flags, x, mapBottom, z1, z2, 0, 32, 1, 2, 0, 3, raiseLand); } break; diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index aaa7de5c83..9fb76f4604 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -14,7 +14,6 @@ #include "../common.h" #include "../core/Guard.hpp" #include "../core/Imaging.h" -#include "../core/Math.hpp" #include "../core/String.hpp" #include "../core/Util.hpp" #include "../localisation/StringIds.h" @@ -27,6 +26,7 @@ #include "SmallScenery.h" #include "Surface.h" +#include #include #include #include @@ -514,7 +514,7 @@ static float fractal_noise(int32_t x, int32_t y, float frequency, int32_t octave static float generate(float x, float y) { const float F2 = 0.366025403f; // F2 = 0.5*(sqrt(3.0)-1.0) - const float G2 = 0.211324865f; // G2 = (3.0-Math.sqrt(3.0))/6.0 + const float G2 = 0.211324865f; // G2 = (3.0-sqrt(3.0))/6.0 float n0, n1, n2; // Noise contributions from the three corners @@ -625,7 +625,7 @@ static void mapgen_simplex(mapgen_settings* settings) { for (x = 0; x < _heightSize; x++) { - float noiseValue = Math::Clamp(-1.0f, fractal_noise(x, y, freq, octaves, 2.0f, 0.65f), 1.0f); + float noiseValue = std::clamp(fractal_noise(x, y, freq, octaves, 2.0f, 0.65f), -1.0f, 1.0f); float normalisedNoiseValue = (noiseValue + 1.0f) / 2.0f; set_height(x, y, low + (int32_t)(normalisedNoiseValue * high)); @@ -736,8 +736,8 @@ static void mapgen_smooth_heightmap(uint8_t* src, int32_t strength) { // Clamp x and y so they stay within the image // This assumes the height map is not tiled, and increases the weight of the edges - const int32_t readX = Math::Clamp((int32_t)x + offsetX, 0, (int32_t)_heightMapData.width - 1); - const int32_t readY = Math::Clamp((int32_t)y + offsetY, 0, (int32_t)_heightMapData.height - 1); + const int32_t readX = std::clamp(x + offsetX, 0, _heightMapData.width - 1); + const int32_t readY = std::clamp(y + offsetY, 0, _heightMapData.height - 1); heightSum += src[readX + readY * _heightMapData.width]; } } diff --git a/src/openrct2/world/MapHelpers.cpp b/src/openrct2/world/MapHelpers.cpp index de1daa5aed..5b7fc84b3b 100644 --- a/src/openrct2/world/MapHelpers.cpp +++ b/src/openrct2/world/MapHelpers.cpp @@ -9,7 +9,6 @@ #include "MapHelpers.h" -#include "../core/Math.hpp" #include "Map.h" #include "Surface.h" @@ -250,14 +249,14 @@ int32_t tile_smooth(int32_t x, int32_t y) } // Count number from the three tiles that is currently higher - int8_t thresholdW = Math::Clamp(0, neighbourHeightOffset.SW, 1) + Math::Clamp(0, neighbourHeightOffset.W, 1) - + Math::Clamp(0, neighbourHeightOffset.NW, 1); - int8_t thresholdN = Math::Clamp(0, neighbourHeightOffset.NW, 1) + Math::Clamp(0, neighbourHeightOffset.N, 1) - + Math::Clamp(0, neighbourHeightOffset.NE, 1); - int8_t thresholdE = Math::Clamp(0, neighbourHeightOffset.NE, 1) + Math::Clamp(0, neighbourHeightOffset.E, 1) - + Math::Clamp(0, neighbourHeightOffset.SE, 1); - int8_t thresholdS = Math::Clamp(0, neighbourHeightOffset.SE, 1) + Math::Clamp(0, neighbourHeightOffset.S, 1) - + Math::Clamp(0, neighbourHeightOffset.SW, 1); + int8_t thresholdW = std::clamp(neighbourHeightOffset.SW, 0, 1) + std::clamp(neighbourHeightOffset.W, 0, 1) + + std::clamp(neighbourHeightOffset.NW, 0, 1); + int8_t thresholdN = std::clamp(neighbourHeightOffset.NW, 0, 1) + std::clamp(neighbourHeightOffset.N, 0, 1) + + std::clamp(neighbourHeightOffset.NE, 0, 1); + int8_t thresholdE = std::clamp(neighbourHeightOffset.NE, 0, 1) + std::clamp(neighbourHeightOffset.E, 0, 1) + + std::clamp(neighbourHeightOffset.SE, 0, 1); + int8_t thresholdS = std::clamp(neighbourHeightOffset.SE, 0, 1) + std::clamp(neighbourHeightOffset.S, 0, 1) + + std::clamp(neighbourHeightOffset.SW, 0, 1); uint8_t slope = TILE_ELEMENT_SLOPE_FLAT; slope |= (thresholdW >= 1) ? SLOPE_W_THRESHOLD_FLAGS : 0; diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 7bd8449dab..539b62c98f 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -16,7 +16,6 @@ #include "../GameState.h" #include "../OpenRCT2.h" #include "../config/Config.h" -#include "../core/Math.hpp" #include "../core/Memory.hpp" #include "../core/Util.hpp" #include "../interface/Colour.h" @@ -40,6 +39,8 @@ #include "Sprite.h" #include "Surface.h" +#include + using namespace OpenRCT2; rct_string_id gParkName; @@ -777,7 +778,7 @@ int32_t Park::CalculateParkRating() const } result -= gParkRatingCasualtyPenalty; - result = Math::Clamp(0, result, 999); + result = std::clamp(result, 0, 999); return result; } @@ -893,7 +894,7 @@ uint32_t Park::CalculateSuggestedMaxGuests() const uint32_t Park::CalculateGuestGenerationProbability() const { // Begin with 50 + park rating - uint32_t probability = 50 + Math::Clamp(0, gParkRating - 200, 650); + uint32_t probability = 50 + std::clamp(gParkRating - 200, 0, 650); // The more guests, the lower the chance of a new one int32_t numGuests = gNumGuestsInPark + gNumGuestsHeadingForPark; @@ -948,7 +949,7 @@ uint32_t Park::CalculateGuestGenerationProbability() const uint8_t Park::CalculateGuestInitialHappiness(uint8_t percentage) { - percentage = Math::Clamp(15, percentage, 98); + percentage = std::clamp(percentage, 15, 98); // The percentages follow this sequence: // 15 17 18 20 21 23 25 26 28 29 31 32 34 36 37 39 40 42 43 45 47 48 50 51 53... diff --git a/src/openrct2/world/Sprite.cpp b/src/openrct2/world/Sprite.cpp index bc7bdfa11d..1446c06bc9 100644 --- a/src/openrct2/world/Sprite.cpp +++ b/src/openrct2/world/Sprite.cpp @@ -15,7 +15,6 @@ #include "../audio/audio.h" #include "../core/Crypt.h" #include "../core/Guard.hpp" -#include "../core/Math.hpp" #include "../core/Util.hpp" #include "../interface/Viewport.h" #include "../localisation/Date.h" @@ -194,8 +193,8 @@ static size_t GetSpatialIndexOffset(int32_t x, int32_t y) size_t index = SPATIAL_INDEX_LOCATION_NULL; if (x != LOCATION_NULL) { - x = Math::Clamp(0, x, 0xFFFF); - y = Math::Clamp(0, y, 0xFFFF); + x = std::clamp(x, 0, 0xFFFF); + y = std::clamp(y, 0, 0xFFFF); int16_t flooredX = floor2(x, 32); uint8_t tileY = y >> 5;