From a9a6552aecd38aab0b9ed4448b4905e319f1ef25 Mon Sep 17 00:00:00 2001 From: JohnsterID <69278611+JohnsterID@users.noreply.github.com> Date: Sat, 24 Jan 2026 22:28:57 +0000 Subject: [PATCH 1/2] refactor(basetype): Add lowercase min/max templates for GameEngine layer (#2183) Add lowercase min/max template functions to BaseType.h alongside existing uppercase MIN/MAX macros from BaseTypeCore.h. Problem: BitFlags.h and other GameEngine code needed readable min() calls, but VC6's lacks std::min/std::max. GameEngine code cannot rely on always.h (WWVegas layer). Solution: Add min/max templates to BaseType.h with header guard to prevent conflicts when GameEngine code includes both BaseType.h and WWVegas headers (which also define min/max in always.h). Implementation: - Use same header guard as always.h (_MIN_MAX_TEMPLATES_DEFINED_) - Templates coexist with uppercase MIN/MAX macros - Works with VC6, MSVC, and MinGW-w64 - Follows existing BaseType.h pattern (sqr, clamp, sign templates) Architecture note: GameEngine intentionally depends on WWVegas (declared in CMakeLists.txt). When GameEngine includes WW3D headers, always.h is transitively included. Header guard prevents duplicate definitions. --- Core/Libraries/Include/Lib/BaseType.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Core/Libraries/Include/Lib/BaseType.h b/Core/Libraries/Include/Lib/BaseType.h index 7d3da6b9f2..20ef1218f3 100644 --- a/Core/Libraries/Include/Lib/BaseType.h +++ b/Core/Libraries/Include/Lib/BaseType.h @@ -58,6 +58,28 @@ inline int sign(NUM x) else return 0; } +// TheSuperHackers @refactor JohnsterID 24/01/2026 Add lowercase min/max templates for GameEngine layer. +// GameEngine code typically uses BaseType.h, but may include WWVegas headers (which define min/max in always.h). +// Header guard prevents duplicate definitions. VC6's lacks std::min/std::max. +#ifndef _MIN_MAX_TEMPLATES_DEFINED_ +#define _MIN_MAX_TEMPLATES_DEFINED_ + +#ifdef min +#undef min +#endif + +#ifdef max +#undef max +#endif + +template +inline T min(T a, T b) { return (a < b) ? a : b; } + +template +inline T max(T a, T b) { return (a > b) ? a : b; } + +#endif // _MIN_MAX_TEMPLATES_DEFINED_ + //----------------------------------------------------------------------------- inline Real rad2deg(Real rad) { return rad * (180/PI); } inline Real deg2rad(Real rad) { return rad * (PI/180); } From b81e9ab332a0f4353b3df990bc1ca7c09ee397c8 Mon Sep 17 00:00:00 2001 From: JohnsterID <69278611+JohnsterID@users.noreply.github.com> Date: Sat, 24 Jan 2026 22:29:17 +0000 Subject: [PATCH 2/2] refactor(basetype): Use lowercase min/max templates in RealRange (#2183) Replace uppercase MIN/MAX macros with new lowercase min/max templates in RealRange::combine() for better type safety and readability. This demonstrates usage of the templates added in the previous commit and provides a concrete example of improved code clarity. --- Core/Libraries/Include/Lib/BaseType.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Libraries/Include/Lib/BaseType.h b/Core/Libraries/Include/Lib/BaseType.h index 20ef1218f3..743da75c72 100644 --- a/Core/Libraries/Include/Lib/BaseType.h +++ b/Core/Libraries/Include/Lib/BaseType.h @@ -201,8 +201,8 @@ struct RealRange // both ranges void combine( RealRange &other ) { - lo = MIN( lo, other.lo ); - hi = MAX( hi, other.hi ); + lo = min( lo, other.lo ); + hi = max( hi, other.hi ); } };