Skip to content

Conversation

@JohnsterID
Copy link

@JohnsterID JohnsterID commented Jan 24, 2026

Fixes: #2177 (closes the ternary operator workaround PR)
Alternative to: Ternary operator approach (less readable)

Adds lowercase min/max template 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

  • Rebase on Main after BaseType.h is in Core

…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.
@xezon
Copy link

xezon commented Jan 24, 2026

I have a change coming soon for moving BaseType.h to Core, so this will need to wait for a moment.

@JohnsterID
Copy link
Author

Moving it to Core would be good. I'll wait out.

@xezon xezon changed the title Feature/basetype min max templates fix(basetype): Add min max templates to BaseType.h Jan 25, 2026
@xezon xezon added CompileBug Bug at compile time Gen Relates to Generals ZH Relates to Zero Hour Fix Is fixing something, but is not user facing labels Jan 25, 2026
Copy link

@xezon xezon left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CompileBug Bug at compile time Fix Is fixing something, but is not user facing Gen Relates to Generals ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants