Remove Math::Clamp in favour of std::clamp

This commit is contained in:
Linus Unnebäck 2018-08-12 12:50:40 +01:00
parent 54fe6a7590
commit fd07be587a
No known key found for this signature in database
GPG Key ID: CE70CEAE9C0FA66F
101 changed files with 248 additions and 249 deletions

View File

@ -13,9 +13,9 @@
#include "interface/InGameConsole.h"
#include <SDL2/SDL.h>
#include <algorithm>
#include <openrct2-ui/interface/Window.h>
#include <openrct2/common.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Memory.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/interface/InteractiveConsole.h>

View File

@ -24,8 +24,8 @@
# include <SDL2/SDL.h>
# include <SDL2/SDL_syswm.h>
# include <algorithm>
# include <openrct2/common.h>
# include <openrct2/core/Math.hpp>
# include <openrct2/core/Path.hpp>
# include <openrct2/core/String.hpp>
# include <openrct2/ui/UiContext.h>

View File

@ -31,7 +31,6 @@
#include <openrct2/Version.h>
#include <openrct2/audio/AudioMixer.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/drawing/IDrawingEngine.h>
@ -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);

View File

@ -11,11 +11,11 @@
#include "AudioFormat.h"
#include <SDL2/SDL.h>
#include <algorithm>
#include <cmath>
#include <openrct2/audio/AudioChannel.h>
#include <openrct2/audio/AudioSource.h>
#include <openrct2/common.h>
#include <openrct2/core/Math.hpp>
#include <speex/speex_resampler.h>
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)

View File

@ -22,7 +22,6 @@
#include <openrct2/common.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Guard.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/platform/platform.h>

View File

@ -11,9 +11,9 @@
#include "AudioFormat.h"
#include <SDL2/SDL.h>
#include <algorithm>
#include <openrct2/audio/AudioSource.h>
#include <openrct2/common.h>
#include <openrct2/core/Math.hpp>
namespace OpenRCT2::Audio
{

View File

@ -15,7 +15,6 @@
#include <openrct2/audio/AudioMixer.h>
#include <openrct2/audio/AudioSource.h>
#include <openrct2/common.h>
#include <openrct2/core/Math.hpp>
#include <vector>
namespace OpenRCT2::Audio

View File

@ -13,6 +13,7 @@
#include "OpenGLAPI.h"
#include <SDL2/SDL_pixels.h>
#include <algorithm>
#include <array>
#include <openrct2/common.h>
#include <unordered_map>

View File

@ -10,6 +10,7 @@
#include "KeyboardShortcuts.h"
#include <SDL2/SDL.h>
#include <algorithm>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/common.h>
#include <openrct2/core/Console.hpp>

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <cmath>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Viewport.h>
@ -19,7 +20,6 @@
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/interface/Chat.h>
#include <openrct2/interface/Cursors.h>
@ -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);

View File

@ -16,7 +16,6 @@
#include <openrct2/Context.h>
#include <openrct2/Version.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/interface/Colour.h>
#include <openrct2/interface/Window.h>
@ -143,7 +142,7 @@ void InGameConsole::Scroll(int32_t linesToScroll)
if (numLines > maxVisibleLines)
{
int32_t maxScrollValue = numLines - maxVisibleLines;
_consoleScrollPos = Math::Clamp<int32_t>(0, _consoleScrollPos - linesToScroll, maxScrollValue);
_consoleScrollPos = std::clamp<int32_t>(_consoleScrollPos - linesToScroll, 0, maxScrollValue);
}
}

View File

@ -13,6 +13,7 @@
#include "Window.h"
#include <algorithm>
#include <jansson.h>
#include <memory>
#include <openrct2/Context.h>
@ -23,7 +24,6 @@
#include <openrct2/core/FileScanner.h>
#include <openrct2/core/Guard.hpp>
#include <openrct2/core/Json.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/drawing/Drawing.h>

View File

@ -10,13 +10,13 @@
#include "Viewport.h"
#include "Window.h"
#include <algorithm>
#include <openrct2/Context.h>
#include <openrct2/Editor.h>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/WallRemoveAction.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/ride/Ride.h>
#include <openrct2/ride/RideData.h>
@ -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<int16_t>(map_pos.x, my_x, my_x + 31);
map_pos.y = Math::Clamp<int16_t>(map_pos.y, my_y, my_y + 31);
map_pos.x = std::clamp<int16_t>(map_pos.x, my_x, my_x + 31);
map_pos.y = std::clamp<int16_t>(map_pos.y, my_y, my_y + 31);
}
// Determine to which edge the cursor is closest

View File

@ -11,6 +11,7 @@
#include "Theme.h"
#include <algorithm>
#include <openrct2/Context.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>

View File

@ -11,6 +11,7 @@
#include "../interface/Window.h"
#include <algorithm>
#include <memory>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
@ -20,7 +21,6 @@
#include <openrct2/common.h>
#include <openrct2/core/Console.hpp>
#include <openrct2/core/Guard.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/interface/Viewport.h>
@ -289,7 +289,7 @@ private:
SetViewZoom(command->Zoom);
break;
case TITLE_SCRIPT_SPEED:
gGameSpeed = Math::Clamp<uint8_t>(1, command->Speed, 4);
gGameSpeed = std::clamp<uint8_t>(command->Speed, 1, 4);
break;
case TITLE_SCRIPT_FOLLOW:
FollowSprite(command->SpriteIndex);

View File

@ -7,13 +7,13 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <fstream>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>

View File

@ -7,12 +7,12 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/localisation/Date.h>
#include <openrct2/localisation/Localisation.h>
@ -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:

View File

@ -7,11 +7,11 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/world/Scenery.h>

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>

View File

@ -7,11 +7,11 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2/Context.h>
#include <openrct2/Input.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
@ -14,7 +15,6 @@
#include <openrct2/Editor.h>
#include <openrct2/Game.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/localisation/StringIds.h>
@ -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_t>(INT16_MIN, (int16_t)gBankLoanInterestRate, INT16_MAX);
int16_t interestRate = std::clamp<int16_t>((int16_t)gBankLoanInterestRate, INT16_MIN, INT16_MAX);
gfx_draw_string_left(dpi, STR_PERCENT_FORMAT_LABEL, &interestRate, COLOUR_BLACK, x, y);
}
}

View File

@ -7,12 +7,12 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/drawing/Font.h>
#include <openrct2/localisation/Localisation.h>
@ -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);

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Graph.h>
#include <openrct2-ui/interface/Widget.h>
@ -16,7 +17,6 @@
#include <openrct2/actions/ParkSetLoanAction.hpp>
#include <openrct2/actions/ParkSetResearchFundingAction.hpp>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Date.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/Finance.h>

View File

@ -9,6 +9,7 @@
#include "../interface/Theme.h"
#include <algorithm>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
@ -16,7 +17,6 @@
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Date.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/Finance.h>

View File

@ -7,11 +7,11 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/audio/audio.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/platform/platform.h>

View File

@ -7,12 +7,12 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/world/Park.h>

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Viewport.h>
#include <openrct2-ui/interface/Widget.h>
@ -14,7 +15,6 @@
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/world/Park.h>

View File

@ -18,7 +18,6 @@
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/ride/Track.h>
@ -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)

View File

@ -7,13 +7,13 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/Input.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/util/Util.h>
@ -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;
}

View File

@ -7,13 +7,13 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Game.h>
#include <openrct2/actions/ParkMarketingAction.hpp>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/ride/Ride.h>

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <limits>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
@ -15,7 +16,6 @@
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/localisation/Localisation.h>

View File

@ -7,11 +7,11 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/audio/audio.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/NewsItem.h>

View File

@ -14,6 +14,7 @@
#include "../interface/Theme.h"
#include <algorithm>
#include <cmath>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Viewport.h>
@ -23,7 +24,6 @@
#include <openrct2/audio/AudioMixer.h>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/localisation/Currency.h>

View File

@ -9,6 +9,7 @@
#include "../interface/Theme.h"
#include <algorithm>
#include <limits>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Graph.h>
@ -21,7 +22,6 @@
#include <openrct2/Input.h>
#include <openrct2/actions/ParkSetNameAction.hpp>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Date.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/Award.h>

View File

@ -9,6 +9,7 @@
#include "../interface/Theme.h"
#include <algorithm>
#include <cmath>
#include <limits>
#include <openrct2-ui/interface/Dropdown.h>
@ -22,7 +23,6 @@
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/localisation/Date.h>
#include <openrct2/localisation/Localisation.h>
@ -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<int32_t>(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<int16_t>(minValue, ride->operation_option + increment, maxValue));
window_ride_mode_tweak_set(w, std::clamp<int16_t>(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<int16_t>(minValue, ride->operation_option - decrement, maxValue));
window_ride_mode_tweak_set(w, std::clamp<int16_t>(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<int16_t>(lower_bound, ride->lift_hill_speed + 1, upper_bound));
std::clamp<int16_t>(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<int16_t>(lower_bound, ride->lift_hill_speed - 1, upper_bound));
std::clamp<int16_t>(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<int16_t>(lower_bound, ride->min_waiting_time + 1, upper_bound));
std::clamp<int16_t>(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<int16_t>(lower_bound, ride->min_waiting_time - 1, upper_bound));
std::clamp<int16_t>(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<int16_t>(lower_bound, ride->max_waiting_time + 1, upper_bound));
std::clamp<int16_t>(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<int16_t>(lower_bound, ride->max_waiting_time - 1, upper_bound));
std::clamp<int16_t>(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<int16_t>(lower_bound, ride->num_circuits + 1, upper_bound));
w->number, RIDE_SETTING_NUM_CIRCUITS, std::clamp<int16_t>(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<int16_t>(lower_bound, ride->num_circuits - 1, upper_bound));
w->number, RIDE_SETTING_NUM_CIRCUITS, std::clamp<int16_t>(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<int32_t>(0, rating >> 8, (int32_t)Util::CountOf(RatingNames) - 1);
int32_t index = std::clamp<int32_t>(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)

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <limits>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Viewport.h>
@ -18,7 +19,6 @@
#include <openrct2/Input.h>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/network/network.h>

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Viewport.h>
#include <openrct2-ui/interface/Widget.h>
@ -14,7 +15,6 @@
#include <openrct2/Context.h>
#include <openrct2/Input.h>
#include <openrct2/audio/audio.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/Research.h>
#include <openrct2/network/network.h>

View File

@ -14,11 +14,11 @@
* that is used for inputing new text for ride names and peep names.
*/
#include <algorithm>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/drawing/Drawing.h>

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
@ -14,7 +15,6 @@
#include <openrct2/Input.h>
#include <openrct2/common.h>
#include <openrct2/core/Guard.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/localisation/StringIds.h>

View File

@ -7,11 +7,11 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/Input.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
@ -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;

View File

@ -10,6 +10,7 @@
#include "../UiContext.h"
#include "../interface/InGameConsole.h"
#include <algorithm>
#include <limits>
#include <openrct2-ui/interface/Dropdown.h>
#include <openrct2-ui/interface/LandTool.h>
@ -24,7 +25,6 @@
#include <openrct2/ParkImporter.h>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/interface/InteractiveConsole.h>
#include <openrct2/interface/Screenshot.h>

View File

@ -7,10 +7,10 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/ride/TrackDesignRepository.h>

View File

@ -16,7 +16,6 @@
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/audio/audio.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/ride/Track.h>
#include <openrct2/ride/TrackData.h>

View File

@ -7,13 +7,13 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/Editor.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/localisation/Localisation.h>

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <cmath>
#include <openrct2-ui/interface/Viewport.h>
#include <openrct2-ui/interface/Widget.h>

View File

@ -7,11 +7,11 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <openrct2-ui/interface/LandTool.h>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>

View File

@ -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"

View File

@ -11,7 +11,8 @@
#include "Date.h"
#include "core/Guard.hpp"
#include "core/Math.hpp"
#include <algorithm>
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;
}

View File

@ -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 <algorithm>
#include <array>
#include <vector>
@ -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<uint8_t>(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:

View File

@ -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 <algorithm>
#include <memory>
#define NUMBER_OF_AUTOSAVES_TO_KEEP 9

View File

@ -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 <algorithm>
using namespace OpenRCT2;
GameState::GameState()
@ -97,7 +98,7 @@ void GameState::Update()
else
{
numUpdates = gTicksSinceLastUpdate / GAME_UPDATE_TIME_MS;
numUpdates = Math::Clamp<uint32_t>(1, numUpdates, GAME_MAX_UPDATES);
numUpdates = std::clamp<uint32_t>(numUpdates, 1, GAME_MAX_UPDATES);
}
if (network_get_mode() == NETWORK_MODE_CLIENT && network_get_status() == NETWORK_STATUS_CONNECTED

View File

@ -26,6 +26,8 @@
#include "AudioContext.h"
#include "AudioMixer.h"
#include <algorithm>
using namespace OpenRCT2::Audio;
struct AudioParams

View File

@ -11,9 +11,9 @@
#include "../OpenRCT2.h"
#include "../core/Console.hpp"
#include "../core/Math.hpp"
#include "../core/String.hpp"
#include <algorithm>
#include <cstring>
#pragma region CommandLineArgEnumerator

View File

@ -12,9 +12,10 @@
#include "../common.h"
#include "../localisation/Language.h"
#include "IStream.hpp"
#include "Math.hpp"
#include "String.hpp"
#include <algorithm>
enum
{
FILE_MODE_OPEN,

View File

@ -16,11 +16,6 @@
*/
namespace Math
{
template<typename T> static T Clamp(T low, T x, T high)
{
return (std::min)((std::max)(low, x), high);
}
template<typename T> static T Sign(T x)
{
if (x < 0)

View File

@ -9,7 +9,6 @@
#include "MemoryStream.h"
#include "Math.hpp"
#include "Memory.hpp"
#include <algorithm>

View File

@ -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"

View File

@ -13,6 +13,7 @@
# define _WIN32_WINNT 0x0600
#endif // __MINGW32__
#include <algorithm>
#include <cwctype>
#include <stdexcept>
#include <vector>
@ -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"

View File

@ -10,7 +10,6 @@
#pragma once
#include "../common.h"
#include "Math.hpp"
#include "Memory.hpp"
#include "String.hpp"

View File

@ -19,6 +19,7 @@
#include "../util/Util.h"
#include "Drawing.h"
#include <algorithm>
#include <memory>
#include <stdexcept>
#include <vector>

View File

@ -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"

View File

@ -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)

View File

@ -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<int16_t>(map_pos.x, my_x, my_x + 31);
map_pos.y = Math::Clamp<int16_t>(map_pos.y, my_y, my_y + 31);
map_pos.x = std::clamp<int16_t>(map_pos.x, my_x, my_x + 31);
map_pos.y = std::clamp<int16_t>(map_pos.y, my_y, my_y + 31);
}
*x = map_pos.x;

View File

@ -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<int16_t>(w->min_width, w->width + dw, w->max_width);
w->height = Math::Clamp<int16_t>(w->min_height, w->height + dh, w->max_height);
w->width = std::clamp<int16_t>(w->width + dw, w->min_width, w->max_width);
w->height = std::clamp<int16_t>(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<int32_t>(minWidth, w->width, maxWidth);
int32_t height = Math::Clamp<int32_t>(minHeight, w->height, maxHeight);
int32_t width = std::clamp<int32_t>(w->width, minWidth, maxWidth);
int32_t height = std::clamp<int32_t>(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)
{

View File

@ -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;
}
}

View File

@ -8,10 +8,10 @@
*****************************************************************************/
#include "../Game.h"
#include "../core/Math.hpp"
#include "Date.h"
#include "StringIds.h"
#include <algorithm>
#include <time.h>
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;
}

View File

@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <algorithm>
#include <cstring>
#include <ctype.h>
#include <limits.h>
@ -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"

View File

@ -19,6 +19,7 @@
#include "../util/SawyerCoding.h"
#include "../world/Location.hpp"
#include <algorithm>
#include <stdexcept>
#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"

View File

@ -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"

View File

@ -35,6 +35,7 @@
#include "WallObject.h"
#include "WaterObject.h"
#include <algorithm>
#include <unordered_map>
interface IFileDataRetriever

View File

@ -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 <algorithm>
#include <cstdlib>
#include <cstring>
#include <unordered_map>

View File

@ -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 <algorithm>
#include <cstring>
// 98DA00

View File

@ -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"

View File

@ -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 <algorithm>
void SmallSceneryObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
{
stream->Seek(6, STREAM_SEEK_CURRENT);

View File

@ -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;

View File

@ -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 <algorithm>
#include <cstring>
// clang-format off

View File

@ -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 <algorithm>
#ifdef __TESTPAINT__
uint16_t testPaintVerticalTunnelHeight;
#endif

View File

@ -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 <algorithm>
// 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<uint8_t>(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)

View File

@ -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 <algorithm>
#include <limits>
#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;

View File

@ -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 <algorithm>
// clang-format off
const rct_string_id StaffCostumeNames[] = {
STR_STAFF_OPTION_COSTUME_PANDA,

View File

@ -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

View File

@ -10,7 +10,8 @@
#include "SawyerEncoding.h"
#include "../core/IStream.hpp"
#include "../core/Math.hpp"
#include <algorithm>
namespace SawyerEncoding
{

View File

@ -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 <algorithm>
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);

View File

@ -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 <algorithm>
#include <climits>
#include <cstdlib>
#include <limits>
@ -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;
}

View File

@ -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<fixed16_2dp>(-FIXED_2DP(2, 50), gforce, FIXED_2DP(0, 00)) * -15728) >> 16;
result.excitement += (std::clamp<fixed16_2dp>(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<int32_t>(0, newExcitement, INT16_MAX);
rating->intensity = Math::Clamp<int32_t>(0, newIntensity, INT16_MAX);
rating->nausea = Math::Clamp<int32_t>(0, newNausea, INT16_MAX);
rating->excitement = std::clamp<int32_t>(newExcitement, 0, INT16_MAX);
rating->intensity = std::clamp<int32_t>(newIntensity, 0, INT16_MAX);
rating->nausea = std::clamp<int32_t>(newNausea, 0, INT16_MAX);
}
static void ride_ratings_apply_length(rating_tuple* ratings, Ride* ride, int32_t maxLength, int32_t excitementMultiplier)

View File

@ -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 <algorithm>
struct map_backup
{
rct_tile_element tile_elements[MAX_TILE_ELEMENTS];

View File

@ -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 <algorithm>
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<int16_t>(-VEHICLE_MAX_SPIN_SPEED), vehicle->spin_speed, static_cast<int16_t>(VEHICLE_MAX_SPIN_SPEED));
spinSpeed = std::clamp(
vehicle->spin_speed, static_cast<int16_t>(-VEHICLE_MAX_SPIN_SPEED), static_cast<int16_t>(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<int16_t>(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE), vehicle->spin_speed,
vehicle->spin_speed = std::clamp(
vehicle->spin_speed, static_cast<int16_t>(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE),
static_cast<int16_t>(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<int16_t>(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE), vehicle->spin_speed,
vehicle->spin_speed = std::clamp(
vehicle->spin_speed, static_cast<int16_t>(-VEHICLE_MAX_SPIN_SPEED_WATER_RIDE),
static_cast<int16_t>(VEHICLE_MAX_SPIN_SPEED_WATER_RIDE));
}

View File

@ -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 <algorithm>
enum
{
SPR_JUNIOR_RC_FLAT_SW_NE = 27807,

View File

@ -46,6 +46,8 @@
#include "ScenarioRepository.h"
#include "ScenarioSources.h"
#include <algorithm>
const rct_string_id ScenarioCategoryStringIds[SCENARIO_CATEGORY_COUNT] = {
STR_BEGINNER_PARKS, STR_CHALLENGING_PARKS, STR_EXPERT_PARKS, STR_REAL_PARKS, STR_OTHER_PARKS,

View File

@ -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 <algorithm>
#include <memory>
#include <vector>

View File

@ -9,11 +9,11 @@
#include "SawyerCoding.h"
#include "../core/Math.hpp"
#include "../platform/platform.h"
#include "../scenario/Scenario.h"
#include "Util.h"
#include <algorithm>
#include <cstring>
static size_t decode_chunk_rle(const uint8_t* src_buffer, uint8_t* dst_buffer, size_t length);

View File

@ -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 <algorithm>
#include <cctype>
#include <cmath>
#include <ctime>
@ -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);
}
/**

View File

@ -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"

View File

@ -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 <algorithm>
constexpr int32_t MAX_THUNDER_INSTANCES = 2;
enum class THUNDER_STATUS

View File

@ -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 <algorithm>
#include <limits>
// clang-format off

View File

@ -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 <algorithm>
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

View File

@ -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 <algorithm>
/**
* 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<int16_t>(x1, 32, gMapSizeUnits - 32);
y1 = std::clamp<int16_t>(y1, 32, gMapSizeUnits - 32);
x2 = std::clamp<int16_t>(x2, 32, gMapSizeUnits - 32);
y2 = std::clamp<int16_t>(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<int16_t>(x1, 32, gMapSizeUnits - 32);
int16_t y = std::clamp<int16_t>(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;

View File

@ -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 <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
@ -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<int32_t>(x + offsetX, 0, _heightMapData.width - 1);
const int32_t readY = std::clamp<int32_t>(y + offsetY, 0, _heightMapData.height - 1);
heightSum += src[readX + readY * _heightMapData.width];
}
}

View File

@ -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;

View File

@ -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 <algorithm>
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<uint8_t>(15, percentage, 98);
percentage = std::clamp<uint8_t>(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...

Some files were not shown because too many files have changed in this diff Show More