-
Notifications
You must be signed in to change notification settings - Fork 151
fix(basetype): Add min/max template functions to BaseType.h #2183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(basetype): Add min/max template functions to BaseType.h #2183
Conversation
…yer (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) 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.
…SuperHackers#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.
d1190eb to
f9072af
Compare
|
I have a change coming soon for moving BaseType.h to Core, so this will need to wait for a moment. |
|
Moving it to Core would be good. I'll wait out. |
xezon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Finalize and Merge after moving BaseType.h to Core.
|
This can now proceed |
…yer (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) 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.
…SuperHackers#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.
f9072af to
b81e9ab
Compare
Greptile Overview
|
| Filename | Overview |
|---|---|
| Core/Libraries/Include/Lib/BaseType.h | Added lowercase min/max template functions with header guards to prevent conflicts with WWVegas headers, replacing uppercase MIN/MAX macro usage in RealRange::combine |
Sequence Diagram
sequenceDiagram
participant GE as GameEngine Code
participant BT as BaseType.h
participant RR as RealRange::combine
participant MT as min/max templates
Note over GE,MT: Compilation Flow
GE->>BT: #include "Lib/BaseType.h"
BT->>BT: Check _MIN_MAX_TEMPLATES_DEFINED_
alt Not defined
BT->>BT: #undef min/max (clear Windows macros)
BT->>MT: Define min<T>(a,b) template
BT->>MT: Define max<T>(a,b) template
BT->>BT: Set _MIN_MAX_TEMPLATES_DEFINED_
else Already defined (e.g., from always.h)
BT->>BT: Skip template definitions
end
Note over GE,RR: Runtime Usage
GE->>RR: Call combine(other)
RR->>MT: Call min(lo, other.lo)
MT-->>RR: Return smaller Real value
RR->>MT: Call max(hi, other.hi)
MT-->>RR: Return larger Real value
RR-->>GE: Updated range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 1 comment
Fixes: #2177 (closes the ternary operator workaround PR)
Alternative to: Ternary operator approach (less readable)
Adds lowercase
min/maxtemplate functions to BaseType.h for GameEngine layer, providing readable alternatives to uppercase MIN/MAX macros and ternary operators.Both BaseType.h and always.h provide min/max independently:
BaseType.h → GameEngine code that doesn't need WW3D
always.h → WWVegas/WW3D code
MinGW-w64 locally tested and CI tested: https://github.com/JohnsterID/GeneralsGameCode/actions/runs/21322546177
TODO