Skip to content

[CMAKE][GEN][ZH] Make all builds compatible with retail #985

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,8 @@ void Thing::setPosition( const Coord3D *pos )
}

//=============================================================================
void Thing::setOrientation( Real angle )
void Thing::setOrientation(Real angle)
{
//USE_PERF_TIMER(ThingMatrixStuff)
Coord3D u, x, y, z, pos;

// setOrientation always forces us straight up in the Z axis,
// or aligned with the terrain if we have the magic flag set.
// don't want this? call setTransformMatrix instead.
Expand All @@ -208,40 +205,26 @@ void Thing::setOrientation( Real angle )
Coord3D oldPos = m_cachedPos;
Matrix3D oldMtx = m_transform;

pos.x = m_transform.Get_X_Translation();
pos.y = m_transform.Get_Y_Translation();
pos.z = m_transform.Get_Z_Translation();
if( m_template->isKindOf( KINDOF_STICK_TO_TERRAIN_SLOPE) )
m_cachedAngle = normalizeAngle(angle);
Coord3D pos = { m_transform[0][3], m_transform[1][3] ,m_transform[2][3] };
m_cachedPos = pos;

if (m_template->isKindOf(KINDOF_STICK_TO_TERRAIN_SLOPE))
{
Matrix3D mtx;
const Bool stickToGround = true; // yes, set the "z" pos
TheTerrainLogic->alignOnTerrain(angle, pos, stickToGround, m_transform );
TheTerrainLogic->alignOnTerrain(angle, m_cachedPos, true, m_transform);
}
else
{
z.x = 0.0f;
z.y = 0.0f;
z.z = 1.0f;

u.x = Cos(angle);
u.y = Sin(angle);
u.z = 0.0f;

y.crossProduct( &z, &u, &y );
x.crossProduct( &y, &z, &x );

m_transform.Set( x.x, y.x, z.x, pos.x,
x.y, y.y, z.y, pos.y,
x.z, y.z, z.z, pos.z );
Real a = Sin(angle);
Real b = Cos(angle);
m_transform[0][0] = b; m_transform[0][1] = -a; m_transform[0][2] = 0;
m_transform[1][0] = a; m_transform[1][1] = b; m_transform[1][2] = 0;
m_transform[2][0] = 0; m_transform[2][1] = 0; m_transform[2][2] = 1;
}

//DEBUG_ASSERTCRASH(-PI <= angle && angle <= PI, ("Please pass only normalized (-PI..PI) angles to setOrientation (%f).\n", angle));
m_cachedAngle = normalizeAngle(angle);
m_cachedPos = pos;
m_cacheFlags &= ~VALID_DIRVECTOR; // but don't clear the altitude flags.

reactToTransformChange(&oldMtx, &oldPos, oldAngle);
DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'\n", m_template->getName().str() ));
}

//=============================================================================
Expand Down
8 changes: 4 additions & 4 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6650,11 +6650,11 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
Bool neighborFlags[8] = {false, false, false, false, false, false, false};

// TheSuperHackers @fix Mauller 23/05/2025 Fixes uninitialized variable.
// To keep retail compatibility it needs to be uninitialized in VC6 builds.
#if defined(_MSC_VER) && _MSC_VER < 1300
UnsignedInt newCostSoFar;
#else
// To keep retail compatibility it needs to be uninitialized.
#if defined IGNORE_COMPATABILITY
UnsignedInt newCostSoFar = 0;
#else
UnsignedInt newCostSoFar;
#endif

for( int i=0; i<numNeighbors; i++ )
Expand Down
8 changes: 4 additions & 4 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,11 +1042,11 @@ void AIPlayer::onUnitProduced( Object *factory, Object *unit )
{
Bool found = false;
// TheSuperHackers @fix Mauller 26/04/2025 Fixes uninitialized variable.
// To keep retail compatibility it needs to be set true in VS6 builds.
#if defined(_MSC_VER) && _MSC_VER < 1300
Bool supplyTruck = true;
#else
// To keep retail compatibility it needs to be set true.
#if defined IGNORE_COMPATABILITY
Bool supplyTruck = false;
#else
Bool supplyTruck = true;
#endif

// factory could be NULL at the start of the game.
Expand Down
42 changes: 14 additions & 28 deletions GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ void Thing::setPosition( const Coord3D *pos )
}

//=============================================================================
void Thing::setOrientation( Real angle )
//
// TheSuperHackers @bugfix Aliendroid1 05/May/2025 Fix mismatching due to floating point innacuracies
void Thing::setOrientation(Real angle)
{
//USE_PERF_TIMER(ThingMatrixStuff)
Coord3D u, x, y, z, pos;

// setOrientation always forces us straight up in the Z axis,
// or aligned with the terrain if we have the magic flag set.
Expand All @@ -208,40 +208,26 @@ void Thing::setOrientation( Real angle )
Coord3D oldPos = m_cachedPos;
Matrix3D oldMtx = m_transform;

pos.x = m_transform.Get_X_Translation();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vector3 vec = Get_Translation(); could had been used

pos.y = m_transform.Get_Y_Translation();
pos.z = m_transform.Get_Z_Translation();
if( m_template->isKindOf( KINDOF_STICK_TO_TERRAIN_SLOPE) )
m_cachedAngle = normalizeAngle(angle);
Coord3D pos = { m_transform[0][3], m_transform[1][3] ,m_transform[2][3] };
m_cachedPos = pos;

if (m_template->isKindOf(KINDOF_STICK_TO_TERRAIN_SLOPE))
{
Matrix3D mtx;
const Bool stickToGround = true; // yes, set the "z" pos

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing bool is just change for change sake, that said matrix removal is useful as it avoids unnecessary codegen

TheTerrainLogic->alignOnTerrain(angle, pos, stickToGround, m_transform );
TheTerrainLogic->alignOnTerrain(angle, m_cachedPos, true, m_transform);
Copy link

@tomsons26 tomsons26 May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if down the alignOnTerrain call chain it uses m_cachedPos or m_cachedAngle it will cause a mismatch since you moved the assignment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values are not mutated. Also the section under the if block is never actually run because the functionality was never implemented.

}
else
{
z.x = 0.0f;
z.y = 0.0f;
z.z = 1.0f;

u.x = Cos(angle);
u.y = Sin(angle);
u.z = 0.0f;

y.crossProduct( &z, &u, &y );
x.crossProduct( &y, &z, &x );

m_transform.Set( x.x, y.x, z.x, pos.x,
x.y, y.y, z.y, pos.y,
x.z, y.z, z.z, pos.z );
Real a = Sin(angle);
Real b = Cos(angle);
m_transform[0][0] = b; m_transform[0][1] = -a; m_transform[0][2] = 0;
Copy link

@tomsons26 tomsons26 May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?
if you thought this is cheaper, nope, m_transform[][] actually makes extra calls, Matrix3D::operator[] Vector4::operator[]

m_transform[1][0] = a; m_transform[1][1] = b; m_transform[1][2] = 0;
m_transform[2][0] = 0; m_transform[2][1] = 0; m_transform[2][2] = 1;
}

//DEBUG_ASSERTCRASH(-PI <= angle && angle <= PI, ("Please pass only normalized (-PI..PI) angles to setOrientation (%f).\n", angle));
m_cachedAngle = normalizeAngle(angle);
m_cachedPos = pos;
m_cacheFlags &= ~VALID_DIRVECTOR; // but don't clear the altitude flags.

reactToTransformChange(&oldMtx, &oldPos, oldAngle);
DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'\n", m_template->getName().str() ));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this

}

//=============================================================================
Expand Down
8 changes: 4 additions & 4 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7194,11 +7194,11 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
Bool neighborFlags[8] = {false, false, false, false, false, false, false};

// TheSuperHackers @fix Mauller 23/05/2025 Fixes uninitialized variable.
// To keep retail compatibility it needs to be uninitialized in VC6 builds.
#if defined(_MSC_VER) && _MSC_VER < 1300
UnsignedInt newCostSoFar;
#else
// To keep retail compatibility it needs to be uninitialized.
#if defined IGNORE_COMPATABILITY
UnsignedInt newCostSoFar = 0;
#else
UnsignedInt newCostSoFar;
#endif

for( int i=0; i<numNeighbors; i++ )
Expand Down
8 changes: 4 additions & 4 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,11 @@ void AIPlayer::onUnitProduced( Object *factory, Object *unit )
{
Bool found = false;
// TheSuperHackers @fix Mauller 26/04/2025 Fixes uninitialized variable.
// To keep retail compatibility it needs to be set true in VS6 builds.
#if defined(_MSC_VER) && _MSC_VER < 1300
Bool supplyTruck = true;
#else
// To keep retail compatibility it needs to be set true.
#if defined IGNORE_COMPATABILITY
Bool supplyTruck = false;
#else
Bool supplyTruck = true;
#endif

// factory could be NULL at the start of the game.
Expand Down
6 changes: 6 additions & 0 deletions cmake/config-build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option(RTS_BUILD_OPTION_PROFILE "Build code with the \"Profile\" configuration."
option(RTS_BUILD_OPTION_DEBUG "Build code with the \"Debug\" configuration." OFF)
option(RTS_BUILD_OPTION_ASAN "Build code with Address Sanitizer." OFF)
option(RTS_BUILD_OPTION_FFMPEG "Enable FFmpeg support" OFF)
option(RTS_BUILD_OPTION_IGNORE_COMPATABILITY "Enable fixes that break retail compatibility" OFF)

if(NOT RTS_BUILD_ZEROHOUR AND NOT RTS_BUILD_GENERALS)
set(RTS_BUILD_ZEROHOUR TRUE)
Expand All @@ -23,6 +24,7 @@ add_feature_info(ProfileBuild RTS_BUILD_OPTION_PROFILE "Building as a \"Profile\
add_feature_info(DebugBuild RTS_BUILD_OPTION_DEBUG "Building as a \"Debug\" build")
add_feature_info(AddressSanitizer RTS_BUILD_OPTION_ASAN "Building with address sanitizer")
add_feature_info(FFmpegSupport RTS_BUILD_OPTION_FFMPEG "Building with FFmpeg support")
add_feature_info(IGNORE_COMPATABILITY RTS_BUILD_OPTION_IGNORE_COMPATABILITY "Building with retal-incompatibile fixes")

if(RTS_BUILD_ZEROHOUR)
option(RTS_BUILD_ZEROHOUR_TOOLS "Build tools for Zero Hour" ON)
Expand All @@ -49,6 +51,10 @@ if(NOT IS_VS6_BUILD)
target_compile_features(core_config INTERFACE cxx_std_20)
endif()

if(RTS_BUILD_OPTION_IGNORE_COMPATABILITY)
target_compile_definitions(core_config INTERFACE IGNORE_COMPATABILITY)
endif()

target_compile_options(core_config INTERFACE ${RTS_FLAGS})

# This disables a lot of warnings steering developers to use windows only functions/function names.
Expand Down
Loading