Skip to content

Commit 55ee429

Browse files
authored
fix(basetype): Add min/max template functions to BaseType.h (TheSuperHackers#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 <algorithm> 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)
1 parent 07b9d0e commit 55ee429

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

Core/Libraries/Include/Lib/BaseType.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ inline int sign(NUM x)
5858
else return 0;
5959
}
6060

61+
// TheSuperHackers @refactor JohnsterID 24/01/2026 Add lowercase min/max templates for GameEngine layer.
62+
// GameEngine code typically uses BaseType.h, but may include WWVegas headers (which define min/max in always.h).
63+
// Header guard prevents duplicate definitions. VC6's <algorithm> lacks std::min/std::max.
64+
#ifndef _MIN_MAX_TEMPLATES_DEFINED_
65+
#define _MIN_MAX_TEMPLATES_DEFINED_
66+
67+
#ifdef min
68+
#undef min
69+
#endif
70+
71+
#ifdef max
72+
#undef max
73+
#endif
74+
75+
template <typename T>
76+
inline T min(T a, T b) { return (a < b) ? a : b; }
77+
78+
template <typename T>
79+
inline T max(T a, T b) { return (a > b) ? a : b; }
80+
81+
#endif // _MIN_MAX_TEMPLATES_DEFINED_
82+
6183
//-----------------------------------------------------------------------------
6284
inline Real rad2deg(Real rad) { return rad * (180/PI); }
6385
inline Real deg2rad(Real rad) { return rad * (PI/180); }
@@ -179,8 +201,8 @@ struct RealRange
179201
// both ranges
180202
void combine( RealRange &other )
181203
{
182-
lo = MIN( lo, other.lo );
183-
hi = MAX( hi, other.hi );
204+
lo = min( lo, other.lo );
205+
hi = max( hi, other.hi );
184206
}
185207
};
186208

0 commit comments

Comments
 (0)