diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index e70c7c4f83..f514c424cc 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index ca9ea239bd..95028f8525 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 433fc10250..3fb9c53b5e 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/openrct2/actions/LandSetRightsAction.cpp b/src/openrct2/actions/LandSetRightsAction.cpp index ab0d0203f4..e977285795 100644 --- a/src/openrct2/actions/LandSetRightsAction.cpp +++ b/src/openrct2/actions/LandSetRightsAction.cpp @@ -18,7 +18,7 @@ #include "../localisation/StringIds.h" #include "../management/Finance.h" #include "../ride/RideData.h" -#include "../util/Util.h" +#include "../util/Math.hpp" #include "../windows/Intent.h" #include "../world/Park.h" #include "../world/Scenery.h" diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index 39b508c804..c1287a714b 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -15,7 +15,7 @@ #include "../ride/Track.h" #include "../ride/TrackData.h" #include "../ride/TrackDesign.h" -#include "../util/Util.h" +#include "../util/Math.hpp" #include "../world/MapAnimation.h" #include "../world/Surface.h" #include "RideSetSettingAction.h" diff --git a/src/openrct2/common.h b/src/openrct2/common.h index 5a5cae5ade..12c6552dce 100644 --- a/src/openrct2/common.h +++ b/src/openrct2/common.h @@ -23,7 +23,6 @@ #include #include #include -#include using utf8 = char; using utf8string = utf8*; @@ -38,30 +37,6 @@ using const_utf8string = const utf8*; using codepoint_t = uint32_t; using colour_t = uint8_t; -namespace -{ - [[maybe_unused]] constexpr bool is_power_of_2(int v) - { - return v && ((v & (v - 1)) == 0); - } - - // Rounds an integer down to the given power of 2. y must be a power of 2. - [[maybe_unused]] constexpr int floor2(const int x, const int y) - { - if (!is_power_of_2(y)) - throw std::logic_error("floor2 should only operate on power of 2"); - return x & ~(y - 1); - } - - // Rounds an integer up to the given power of 2. y must be a power of 2. - [[maybe_unused]] constexpr int ceil2(const int x, const int y) - { - if (!is_power_of_2(y)) - throw std::logic_error("ceil2 should only operate on power of 2"); - return (x + y - 1) & ~(y - 1); - } -} // namespace - // Gets the name of a symbol as a C string #define nameof(symbol) #symbol diff --git a/src/openrct2/interface/Cursors.h b/src/openrct2/interface/Cursors.h index f485b27e40..2eca575a86 100644 --- a/src/openrct2/interface/Cursors.h +++ b/src/openrct2/interface/Cursors.h @@ -11,6 +11,8 @@ #include "../common.h" +#include + enum class CursorID : uint8_t { Arrow, diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 73450b4978..17b610dcba 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -25,6 +25,7 @@ #include "../ride/Vehicle.h" #include "../ui/UiContext.h" #include "../ui/WindowManager.h" +#include "../util/Math.hpp" #include "../world/Climate.h" #include "../world/EntityList.h" #include "../world/Map.h" diff --git a/src/openrct2/localisation/Localisation.Date.cpp b/src/openrct2/localisation/Localisation.Date.cpp index ce4330600b..7e1a415a4a 100644 --- a/src/openrct2/localisation/Localisation.Date.cpp +++ b/src/openrct2/localisation/Localisation.Date.cpp @@ -8,6 +8,7 @@ *****************************************************************************/ #include "../Game.h" +#include "../util/Math.hpp" #include "Date.h" #include "StringIds.h" diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 2cf3886736..c688b2524c 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -17,6 +17,7 @@ #include "../localisation/Localisation.h" #include "../localisation/LocalisationService.h" #include "../paint/Painter.h" +#include "../util/Math.hpp" #include "sprite/Paint.Sprite.h" #include "tile_element/Paint.TileElement.h" diff --git a/src/openrct2/paint/Supports.cpp b/src/openrct2/paint/Supports.cpp index c60a18ad63..9ae4a481c5 100644 --- a/src/openrct2/paint/Supports.cpp +++ b/src/openrct2/paint/Supports.cpp @@ -12,6 +12,7 @@ #include "../interface/Viewport.h" #include "../object/FootpathRailingsObject.h" #include "../sprites.h" +#include "../util/Math.hpp" #include "../world/Surface.h" #include "Paint.h" #include "tile_element/Paint.TileElement.h" diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 03a3f66302..7a5fb800aa 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -30,7 +30,7 @@ #include "../scenario/Scenario.h" #include "../scripting/HookEngine.h" #include "../scripting/ScriptEngine.h" -#include "../util/Util.h" +#include "../util/Math.hpp" #include "../windows/Intent.h" #include "../world/Balloon.h" #include "../world/Climate.h" diff --git a/src/openrct2/util/Math.hpp b/src/openrct2/util/Math.hpp new file mode 100644 index 0000000000..e43ead1e23 --- /dev/null +++ b/src/openrct2/util/Math.hpp @@ -0,0 +1,37 @@ + +/***************************************************************************** + * Copyright (c) 2014-2021 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 + +namespace +{ + [[maybe_unused]] constexpr bool is_power_of_2(int v) + { + return v && ((v & (v - 1)) == 0); + } + + // Rounds an integer down to the given power of 2. y must be a power of 2. + [[maybe_unused]] constexpr int floor2(const int x, const int y) + { + if (!is_power_of_2(y)) + throw std::logic_error("floor2 should only operate on power of 2"); + return x & ~(y - 1); + } + + // Rounds an integer up to the given power of 2. y must be a power of 2. + [[maybe_unused]] constexpr int ceil2(const int x, const int y) + { + if (!is_power_of_2(y)) + throw std::logic_error("ceil2 should only operate on power of 2"); + return (x + y - 1) & ~(y - 1); + } +} // namespace diff --git a/src/openrct2/windows/_legacy.cpp b/src/openrct2/windows/_legacy.cpp index 1d6947d88b..96f0a9e519 100644 --- a/src/openrct2/windows/_legacy.cpp +++ b/src/openrct2/windows/_legacy.cpp @@ -20,6 +20,7 @@ #include "../ride/RideData.h" #include "../ride/Track.h" #include "../ride/TrackData.h" +#include "../util/Math.hpp" #include "../world/Banner.h" #include "../world/Scenery.h" #include "Intent.h" diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 42e2915565..6dba7e7ab6 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -10,6 +10,7 @@ #pragma once #include "../common.h" +#include "../util/Math.hpp" #include