From 9a4aa4bb9434cd9a70a3623207223c2c85b4febb Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 14 May 2024 16:25:52 +0200 Subject: [PATCH] Move fixed point types to FixedPoint.hpp --- src/openrct2/common.h | 15 --------------- src/openrct2/core/FixedPoint.hpp | 27 +++++++++++++++++++++++++++ src/openrct2/libopenrct2.vcxproj | 1 + src/openrct2/rct1/RCT1.h | 1 + src/openrct2/rct2/RCT2.h | 1 + src/openrct2/ride/Ride.h | 1 + src/openrct2/ride/RideRatings.h | 1 + src/openrct2/ride/Vehicle.cpp | 1 + 8 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 src/openrct2/core/FixedPoint.hpp diff --git a/src/openrct2/common.h b/src/openrct2/common.h index 35420c7111..e3e00e98ac 100644 --- a/src/openrct2/common.h +++ b/src/openrct2/common.h @@ -38,26 +38,11 @@ using datetime64 = uint64_t; constexpr datetime64 DATETIME64_MIN = 0; -// Represent fixed point numbers. dp = decimal point -using fixed8_1dp = uint8_t; -using fixed8_2dp = uint8_t; -using fixed16_1dp = int16_t; -using fixed16_2dp = int16_t; -using fixed32_1dp = int32_t; -using fixed32_2dp = int32_t; -using fixed64_1dp = int64_t; - // Money is stored as a multiple of 0.10. using money16 = fixed16_1dp; using money32 = fixed32_1dp; using money64 = fixed64_1dp; -// Construct a fixed point number. For example, to create the value 3.65 you -// would write FIXED_2DP(3,65) -#define FIXED_XDP(x, whole, fraction) ((whole) * (10 * (x)) + (fraction)) -#define FIXED_1DP(whole, fraction) FIXED_XDP(1, whole, fraction) -#define FIXED_2DP(whole, fraction) FIXED_XDP(10, whole, fraction) - // For a user defined floating point literal, the parameter type must be a // `long double` which is problematic on ppc64el, as the architecture uses a // pair of `doubles` to represent that type. This cannot be converted to a diff --git a/src/openrct2/core/FixedPoint.hpp b/src/openrct2/core/FixedPoint.hpp new file mode 100644 index 0000000000..b6bdaa849f --- /dev/null +++ b/src/openrct2/core/FixedPoint.hpp @@ -0,0 +1,27 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 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 + +// Represent fixed point numbers. dp = decimal point +using fixed8_1dp = uint8_t; +using fixed8_2dp = uint8_t; +using fixed16_1dp = int16_t; +using fixed16_2dp = int16_t; +using fixed32_1dp = int32_t; +using fixed32_2dp = int32_t; +using fixed64_1dp = int64_t; + +// Construct a fixed point number. For example, to create the value 3.65 you +// would write FIXED_2DP(3,65) +#define FIXED_XDP(x, whole, fraction) ((whole) * (10 * (x)) + (fraction)) +#define FIXED_1DP(whole, fraction) FIXED_XDP(1, whole, fraction) +#define FIXED_2DP(whole, fraction) FIXED_XDP(10, whole, fraction) diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index dd78fd728f..8edac9ca3b 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -199,6 +199,7 @@ + diff --git a/src/openrct2/rct1/RCT1.h b/src/openrct2/rct1/RCT1.h index 7ba5978708..63b90d09b9 100644 --- a/src/openrct2/rct1/RCT1.h +++ b/src/openrct2/rct1/RCT1.h @@ -9,6 +9,7 @@ #pragma once +#include "../core/FixedPoint.hpp" #include "../rct12/RCT12.h" #include "../ride/RideRatings.h" #include "../world/Park.h" diff --git a/src/openrct2/rct2/RCT2.h b/src/openrct2/rct2/RCT2.h index 16ddbbe13d..890f690114 100644 --- a/src/openrct2/rct2/RCT2.h +++ b/src/openrct2/rct2/RCT2.h @@ -11,6 +11,7 @@ #include "../common.h" #include "../core/FileSystem.hpp" +#include "../core/FixedPoint.hpp" #include "../rct12/RCT12.h" #include "../ride/RideRatings.h" #include "../world/Park.h" diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 9ae087ed4b..02e48ed38a 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -13,6 +13,7 @@ #include "../actions/ResultWithMessage.h" #include "../common.h" #include "../core/BitSet.hpp" +#include "../core/FixedPoint.hpp" #include "../object/MusicObject.h" #include "../rct2/DATLimits.h" #include "../rct2/Limits.h" diff --git a/src/openrct2/ride/RideRatings.h b/src/openrct2/ride/RideRatings.h index 257f617106..fdd6bda0ea 100644 --- a/src/openrct2/ride/RideRatings.h +++ b/src/openrct2/ride/RideRatings.h @@ -10,6 +10,7 @@ #pragma once #include "../common.h" +#include "../core/FixedPoint.hpp" #include "../world/Location.hpp" #include "RideTypes.h" diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 9467065bc3..d06b08760a 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -19,6 +19,7 @@ #include "../audio/AudioMixer.h" #include "../audio/audio.h" #include "../config/Config.h" +#include "../core/FixedPoint.hpp" #include "../core/Memory.hpp" #include "../core/Speed.hpp" #include "../entity/EntityRegistry.h"