From 41ef7c88af0b393695ec63d0409cbadc469babc9 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sat, 25 Feb 2023 23:58:46 +0100 Subject: [PATCH] Codechange: make a numer of Slope related functions constexpr --- src/core/bitmath_func.hpp | 2 +- src/slope_func.h | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp index 745a32afc4..b2d21dacbf 100644 --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -29,7 +29,7 @@ * @return The selected bits, aligned to a LSB. */ template -debug_inline static uint GB(const T x, const uint8 s, const uint8 n) +debug_inline constexpr static uint GB(const T x, const uint8 s, const uint8 n) { return (x >> s) & (((T)1U << n) - 1); } diff --git a/src/slope_func.h b/src/slope_func.h index 47a89bfcf9..afc49eeafa 100644 --- a/src/slope_func.h +++ b/src/slope_func.h @@ -21,7 +21,7 @@ * @param corner A #Corner. * @return true iff corner is in a valid range. */ -static inline bool IsValidCorner(Corner corner) +static constexpr inline bool IsValidCorner(Corner corner) { return IsInsideMM(corner, 0, CORNER_END); } @@ -33,7 +33,7 @@ static inline bool IsValidCorner(Corner corner) * @param s The given #Slope. * @return True if the slope is steep, else false. */ -static inline bool IsSteepSlope(Slope s) +static constexpr inline bool IsSteepSlope(Slope s) { return (s & SLOPE_STEEP) != 0; } @@ -44,7 +44,7 @@ static inline bool IsSteepSlope(Slope s) * @param s The given #Slope. * @return True if the slope is non-continuous, else false. */ -static inline bool IsHalftileSlope(Slope s) +static constexpr inline bool IsHalftileSlope(Slope s) { return (s & SLOPE_HALFTILE) != 0; } @@ -57,7 +57,7 @@ static inline bool IsHalftileSlope(Slope s) * @param s A #Slope. * @return The slope s without its halftile slope. */ -static inline Slope RemoveHalftileSlope(Slope s) +static constexpr inline Slope RemoveHalftileSlope(Slope s) { return s & ~SLOPE_HALFTILE_MASK; } @@ -145,7 +145,7 @@ static inline Corner GetHighestSlopeCorner(Slope s) * @param s The #Slope. * @return The corner of the leveled halftile. */ -static inline Corner GetHalftileSlopeCorner(Slope s) +static constexpr inline Corner GetHalftileSlopeCorner(Slope s) { assert(IsHalftileSlope(s)); return (Corner)((s >> 6) & 3); @@ -157,7 +157,7 @@ static inline Corner GetHalftileSlopeCorner(Slope s) * @param s The #Slope. * @return Relative height of highest corner. */ -static inline int GetSlopeMaxZ(Slope s) +static constexpr inline int GetSlopeMaxZ(Slope s) { if (s == SLOPE_FLAT) return 0; if (IsSteepSlope(s)) return 2; @@ -170,7 +170,7 @@ static inline int GetSlopeMaxZ(Slope s) * @param s The #Slope. * @return Relative height of highest corner. */ -static inline int GetSlopeMaxPixelZ(Slope s) +static constexpr inline int GetSlopeMaxPixelZ(Slope s) { return GetSlopeMaxZ(s) * TILE_HEIGHT; } @@ -271,7 +271,7 @@ static inline Slope InclinedSlope(DiagDirection dir) * @param corner The #Corner of the halftile. * @return The #Slope s with the halftile slope added. */ -static inline Slope HalftileSlope(Slope s, Corner corner) +static constexpr inline Slope HalftileSlope(Slope s, Corner corner) { assert(IsValidCorner(corner)); return (Slope)(s | SLOPE_HALFTILE | (corner << 6));