diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/io/image.cpp | 4 | ||||
-rw-r--r-- | core/templates/oa_hash_map.h | 4 | ||||
-rw-r--r-- | core/typedefs.h | 45 |
3 files changed, 31 insertions, 22 deletions
diff --git a/core/io/image.cpp b/core/io/image.cpp index 577fc59807..766c84bdbe 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -1465,8 +1465,8 @@ template <class Component, int CC, bool renormalize, void (*renormalize_func)(Component *)> static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint32_t p_width, uint32_t p_height) { //fast power of 2 mipmap generation - uint32_t dst_w = MAX(p_width >> 1, 1); - uint32_t dst_h = MAX(p_height >> 1, 1); + uint32_t dst_w = MAX(p_width >> 1, 1u); + uint32_t dst_h = MAX(p_height >> 1, 1u); int right_step = (p_width == 1) ? 0 : CC; int down_step = (p_height == 1) ? 0 : (p_width * CC); diff --git a/core/templates/oa_hash_map.h b/core/templates/oa_hash_map.h index c91d27ebe1..4e712fccf2 100644 --- a/core/templates/oa_hash_map.h +++ b/core/templates/oa_hash_map.h @@ -145,7 +145,7 @@ private: uint32_t old_capacity = capacity; // Capacity can't be 0. - capacity = MAX(1, p_new_capacity); + capacity = MAX(1u, p_new_capacity); TKey *old_keys = keys; TValue *old_values = values; @@ -367,7 +367,7 @@ public: OAHashMap(uint32_t p_initial_capacity = 64) { // Capacity can't be 0. - capacity = MAX(1, p_initial_capacity); + capacity = MAX(1u, p_initial_capacity); keys = static_cast<TKey *>(Memory::alloc_static(sizeof(TKey) * capacity)); values = static_cast<TValue *>(Memory::alloc_static(sizeof(TValue) * capacity)); diff --git a/core/typedefs.h b/core/typedefs.h index 2c32d102da..510b39177c 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -89,34 +89,43 @@ #undef ERROR // override (really stupid) wingdi.h standard definition #undef DELETE // override (another really stupid) winnt.h standard definition #undef MessageBox // override winuser.h standard definition -#undef MIN // override standard definition -#undef MAX // override standard definition -#undef CLAMP // override standard definition #undef Error #undef OK #undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enum #endif +// Make room for our constexpr's below by overriding potential system-specific macros. +#undef ABS +#undef SIGN +#undef MIN +#undef MAX +#undef CLAMP + // Generic ABS function, for math uses please use Math::abs. -#ifndef ABS -#define ABS(m_v) (((m_v) < 0) ? (-(m_v)) : (m_v)) -#endif +template <typename T> +constexpr T ABS(T m_v) { + return m_v < 0 ? -m_v : m_v; +} -#ifndef SIGN -#define SIGN(m_v) (((m_v) == 0) ? (0.0f) : (((m_v) < 0) ? (-1.0f) : (+1.0f))) -#endif +template <typename T> +constexpr const T SIGN(const T m_v) { + return m_v == 0 ? 0.0f : (m_v < 0 ? -1.0f : +1.0f); +} -#ifndef MIN -#define MIN(m_a, m_b) (((m_a) < (m_b)) ? (m_a) : (m_b)) -#endif +template <typename T, typename T2> +constexpr auto MIN(const T m_a, const T2 m_b) { + return m_a < m_b ? m_a : m_b; +} -#ifndef MAX -#define MAX(m_a, m_b) (((m_a) > (m_b)) ? (m_a) : (m_b)) -#endif +template <typename T, typename T2> +constexpr auto MAX(const T m_a, const T2 m_b) { + return m_a > m_b ? m_a : m_b; +} -#ifndef CLAMP -#define CLAMP(m_a, m_min, m_max) (((m_a) < (m_min)) ? (m_min) : (((m_a) > (m_max)) ? m_max : m_a)) -#endif +template <typename T, typename T2, typename T3> +constexpr auto CLAMP(const T m_a, const T2 m_min, const T3 m_max) { + return m_a < m_min ? m_min : (m_a > m_max ? m_max : m_a); +} // Generic swap template. #ifndef SWAP |