diff --git a/Core/GameEngine/Include/Precompiled/PreRTS.h b/Core/GameEngine/Include/Precompiled/PreRTS.h index 7653c34d972..1cfc2216192 100644 --- a/Core/GameEngine/Include/Precompiled/PreRTS.h +++ b/Core/GameEngine/Include/Precompiled/PreRTS.h @@ -48,6 +48,7 @@ class STLSpecialAlloc; #include #include +#include #include #include #include diff --git a/Core/GameEngine/Source/Common/System/GameCommon.cpp b/Core/GameEngine/Source/Common/System/GameCommon.cpp index 7f8b4ff4015..90688b63473 100644 --- a/Core/GameEngine/Source/Common/System/GameCommon.cpp +++ b/Core/GameEngine/Source/Common/System/GameCommon.cpp @@ -53,9 +53,9 @@ static_assert(ARRAY_SIZE(TheRelationshipNames) == RELATIONSHIP_COUNT + 1, "Incor // TheSuperHackers @todo DO NOT USE THIS FUNCTION! Use WWMath::Normalize_Angle instead. Delete this. Real normalizeAngle(Real angle) { - DEBUG_ASSERTCRASH(!_isnan(angle), ("Angle is NAN in normalizeAngle!")); + DEBUG_ASSERTCRASH(!std::isnan(angle), ("Angle is NAN in normalizeAngle!")); - if( _isnan(angle) ) + if( std::isnan(angle) ) return 0;// ARGH!!!! Don't assert and then not handle it! Error bad! Fix error! while (angle > PI) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 2485d251768..78b081e13f1 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -51,6 +51,7 @@ #include "WWMath/wwmath.h" #include "WWMath/quat.h" #include +#include //#include // Static Table, for Adaptive Delta Decompressor #define FILTER_TABLE_SIZE (256) @@ -1264,7 +1265,9 @@ return; int i=0; for (;i100000.0f) value=0.0f; if (value<-100000.0f) value=0.0f; Data[i]=value; diff --git a/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp b/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp index 973aaf61c21..7ebf54f88ea 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp @@ -48,6 +48,7 @@ #include "d3d8.h" #include "statistics.h" #include +#include #include #include @@ -474,7 +475,7 @@ void SortingRendererClass::Flush_Sorting_Pool() tis_ptr->tri.k = idx3 + vertex_array_offset; tis_ptr->idx = node_id; tis_ptr->z = (v1->z + v2->z + v3->z)/3.0f; - DEBUG_ASSERTCRASH((! _isnan(tis_ptr->z) && _finite(tis_ptr->z)), ("Triangle has invalid center")); + DEBUG_ASSERTCRASH((! std::isnan(tis_ptr->z) && std::isfinite(tis_ptr->z)), ("Triangle has invalid center")); } } else { for (int i=0;ipolygon_count;++i) { @@ -497,7 +498,7 @@ void SortingRendererClass::Flush_Sorting_Pool() tis_ptr->z = (mtx[2][0]*(v1->x + v2->x + v3->x) + mtx[2][1]*(v1->y + v2->y + v3->y) + mtx[2][2]*(v1->z + v2->z + v3->z))/3.0f + mtx[2][3]; - DEBUG_ASSERTCRASH((! _isnan(tis_ptr->z) && _finite(tis_ptr->z)), ("Triangle has invalid center")); + DEBUG_ASSERTCRASH((! std::isnan(tis_ptr->z) && std::isfinite(tis_ptr->z)), ("Triangle has invalid center")); } } diff --git a/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp b/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp index 22b5e27b60a..10e14ebc2d2 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/streakRender.cpp @@ -35,6 +35,7 @@ #include "WWMath/Vector3i.h" #include "WWLib/RANDOM.h" #include "WWMath/v3_rnd.h" +#include /* We have chunking logic which handles N segments at a time. To simplify the subdivision logic, @@ -1334,7 +1335,7 @@ void StreakRendererClass::RenderStreak for (i=0; i> (32-9); + unsigned int exponent = (std::bit_cast(x) & 0x7F800000) >> (32-9); // if exponent is 0xFF, this is a NAN if (exponent == 0xFF) { @@ -979,8 +978,8 @@ WWINLINE bool WWMath::Is_Valid_Float(float x) WWINLINE bool WWMath::Is_Valid_Double(double x) { - unsigned long * plong = (unsigned long *)(&x) + 1; - unsigned long exponent = ((*plong) & 0x7FF00000) >> (32-12); + unsigned int high = (unsigned int)(std::bit_cast(x) >> 32); + unsigned int exponent = (high & 0x7FF00000) >> (32-12); // if exponent is 0x7FF, this is a NAN if (exponent == 0x7FF) { diff --git a/Dependencies/Utility/CMakeLists.txt b/Dependencies/Utility/CMakeLists.txt index b49fb225373..6b8d0e2dfd0 100644 --- a/Dependencies/Utility/CMakeLists.txt +++ b/Dependencies/Utility/CMakeLists.txt @@ -6,6 +6,7 @@ set(UTILITY_SRC Utility/atomic_adapter.h Utility/atomic_x86interlocked.inl Utility/bit_adapter.h + Utility/cmath_adapter.h Utility/compat.h Utility/comsupp_compat.h Utility/endian_compat.h diff --git a/Dependencies/Utility/Utility/cmath_adapter.h b/Dependencies/Utility/Utility/cmath_adapter.h new file mode 100644 index 00000000000..f79db9c3103 --- /dev/null +++ b/Dependencies/Utility/Utility/cmath_adapter.h @@ -0,0 +1,60 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +// This file provides std::isnan and std::isfinite. The of VC6 and STLport 4.5.3 has neither, and VC6 +// gets functions that call _isnan and _finite of . +// +// The VC6 functions differ from the standard functions in these points: +// - There are only float and double overloads. An integer or long double argument is ambiguous. +// - A float argument is converted to double before the check. NaN and infinity stay NaN and infinity in that +// conversion, so the result is the same. + +#pragma once + +#if defined(_MSC_VER) && _MSC_VER < 1300 + +#include + +namespace std +{ +inline bool isnan(float x) +{ + return _isnan(x) != 0; +} + +inline bool isnan(double x) +{ + return _isnan(x) != 0; +} + +inline bool isfinite(float x) +{ + return _finite(x) != 0; +} + +inline bool isfinite(double x) +{ + return _finite(x) != 0; +} +} + +#else + +#include + +#endif diff --git a/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp b/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp index 5a672cfb889..3d67d6ccf68 100644 --- a/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp +++ b/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp @@ -168,7 +168,7 @@ void Thing::setPositionZ( Real z ) TheTerrainLogic->alignOnTerrain(getOrientation(), pos, stickToGround, mtx ); setTransformMatrix(&mtx); } - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -181,7 +181,7 @@ void Thing::setPosition( const Coord3D *pos ) Coord3D oldPos = m_cachedPos; Matrix3D oldMtx = m_transform; - //DEBUG_ASSERTCRASH(!(_isnan(pos->x) || _isnan(pos->y) || _isnan(pos->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + //DEBUG_ASSERTCRASH(!(std::isnan(pos->x) || std::isnan(pos->y) || std::isnan(pos->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); m_transform.Set_X_Translation( pos->x ); m_transform.Set_Y_Translation( pos->y ); m_transform.Set_Z_Translation( pos->z ); @@ -197,7 +197,7 @@ void Thing::setPosition( const Coord3D *pos ) TheTerrainLogic->alignOnTerrain(getOrientation(), *pos, stickToGround, mtx ); setTransformMatrix(&mtx); } - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -247,7 +247,7 @@ void Thing::setOrientation( Real angle ) 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'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -268,7 +268,7 @@ void Thing::setTransformMatrix( const Matrix3D *mx ) m_cacheFlags = 0; reactToTransformChange(&oldMtx, &oldPos, oldAngle); - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameClient/Drawable.cpp b/Generals/Code/GameEngine/Source/GameClient/Drawable.cpp index 36b99f5c77c..33940636f4c 100644 --- a/Generals/Code/GameEngine/Source/GameClient/Drawable.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/Drawable.cpp @@ -2484,7 +2484,7 @@ const AudioEventRTS& Drawable::getAmbientSoundByDamage(BodyDamageType dt) void Drawable::validatePos() const { const Coord3D* ourPos = getPosition(); - if (_isnan(ourPos->x) || _isnan(ourPos->y) || _isnan(ourPos->z)) + if (std::isnan(ourPos->x) || std::isnan(ourPos->y) || std::isnan(ourPos->z)) { DEBUG_CRASH(("Drawable/Object position NAN! '%s'", getTemplate()->getName().str())); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp index c1c6bfe91c3..67b3228fab7 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1698,7 +1698,8 @@ void Object::reactToTurretChange( WhichTurretType turret, Real oldRotation, Real void Object::reactToTransformChange(const Matrix3D* oldMtx, const Coord3D* oldPos, Real oldAngle) { //USE_PERF_TIMER(Object_reactToTransformChange) - if(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)) { + if(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)) + { DEBUG_CRASH(("Object pos is nan.")); TheGameLogic->destroyObject(this); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 1d0ef142264..1253d38460c 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2291,7 +2291,7 @@ void AIUpdateInterface::setLocomotorGoalPositionExplicit(const Coord3D& newPos) m_locomotorGoalType = POSITION_EXPLICIT; m_locomotorGoalData = newPos; #ifdef RTS_DEBUG -if (_isnan(m_locomotorGoalData.x) || _isnan(m_locomotorGoalData.y) || _isnan(m_locomotorGoalData.z)) +if (std::isnan(m_locomotorGoalData.x) || std::isnan(m_locomotorGoalData.y) || std::isnan(m_locomotorGoalData.z)) { DEBUG_CRASH(("NAN in setLocomotorGoalPositionExplicit")); } @@ -2304,7 +2304,7 @@ void AIUpdateInterface::setLocomotorGoalOrientation(Real angle) m_locomotorGoalType = ANGLE; m_locomotorGoalData.x = angle; #ifdef RTS_DEBUG -if (_isnan(m_locomotorGoalData.x) || _isnan(m_locomotorGoalData.y) || _isnan(m_locomotorGoalData.z)) +if (std::isnan(m_locomotorGoalData.x) || std::isnan(m_locomotorGoalData.y) || std::isnan(m_locomotorGoalData.z)) { DEBUG_CRASH(("NAN in setLocomotorGoalOrientation")); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index 2a302af61f0..21fa0e70fd1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -297,9 +297,10 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) { // TheSuperHackers @info helmutbuhler 06/05/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC - DEBUG_ASSERTCRASH(!(_isnan(force->x) || _isnan(force->y) || _isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); + DEBUG_ASSERTCRASH(!(std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); #endif - if (_isnan(force->x) || _isnan(force->y) || _isnan(force->z)) { + if (std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)) + { return; } // F = ma --> a = F/m (divide force by mass) @@ -319,8 +320,8 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) m_accel.y += modForce.y * massInv; m_accel.z += modForce.z * massInv; - //DEBUG_ASSERTCRASH(!(_isnan(m_accel.x) || _isnan(m_accel.y) || _isnan(m_accel.z)), ("PhysicsBehavior::applyForce accel NAN!")); - //DEBUG_ASSERTCRASH(!(_isnan(m_vel.x) || _isnan(m_vel.y) || _isnan(m_vel.z)), ("PhysicsBehavior::applyForce vel NAN!")); + //DEBUG_ASSERTCRASH(!(std::isnan(m_accel.x) || std::isnan(m_accel.y) || std::isnan(m_accel.z)), ("PhysicsBehavior::applyForce accel NAN!")); + //DEBUG_ASSERTCRASH(!(std::isnan(m_vel.x) || std::isnan(m_vel.y) || std::isnan(m_vel.z)), ("PhysicsBehavior::applyForce vel NAN!")); //DEBUG_ASSERTCRASH(fabs(force->z) < 3, ("unlikely z-force")); #ifdef SLEEPY_PHYSICS if (getFlag(IS_IN_UPDATE)) @@ -593,8 +594,9 @@ UpdateSleepTime PhysicsBehavior::update() mtx.Adjust_Z_Translation(m_vel.z); } - if (_isnan(mtx.Get_X_Translation()) || _isnan(mtx.Get_Y_Translation()) || - _isnan(mtx.Get_Z_Translation())) { + if (std::isnan(mtx.Get_X_Translation()) || std::isnan(mtx.Get_Y_Translation()) || + std::isnan(mtx.Get_Z_Translation())) + { DEBUG_CRASH(("Object position is NAN, deleting.")); TheGameLogic->destroyObject(obj); } @@ -1339,7 +1341,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 force.x = factor * delta.x / dist; force.y = factor * delta.y / dist; force.z = factor * delta.z / dist; // will be zero for 2d case. - DEBUG_ASSERTCRASH(!(_isnan(force.x) || _isnan(force.y) || _isnan(force.z)), ("PhysicsBehavior::onCollide force NAN!")); + DEBUG_ASSERTCRASH(!(std::isnan(force.x) || std::isnan(force.y) || std::isnan(force.z)), ("PhysicsBehavior::onCollide force NAN!")); applyForce( &force ); } diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp index 26ae3a88793..89a5be83922 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp @@ -168,7 +168,7 @@ void Thing::setPositionZ( Real z ) TheTerrainLogic->alignOnTerrain(getOrientation(), pos, stickToGround, mtx ); setTransformMatrix(&mtx); } - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -181,7 +181,7 @@ void Thing::setPosition( const Coord3D *pos ) Coord3D oldPos = m_cachedPos; Matrix3D oldMtx = m_transform; - //DEBUG_ASSERTCRASH(!(_isnan(pos->x) || _isnan(pos->y) || _isnan(pos->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + //DEBUG_ASSERTCRASH(!(std::isnan(pos->x) || std::isnan(pos->y) || std::isnan(pos->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); m_transform.Set_X_Translation( pos->x ); m_transform.Set_Y_Translation( pos->y ); m_transform.Set_Z_Translation( pos->z ); @@ -197,7 +197,7 @@ void Thing::setPosition( const Coord3D *pos ) TheTerrainLogic->alignOnTerrain(getOrientation(), *pos, stickToGround, mtx ); setTransformMatrix(&mtx); } - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -247,7 +247,7 @@ void Thing::setOrientation( Real angle ) 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'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //============================================================================= @@ -268,7 +268,7 @@ void Thing::setTransformMatrix( const Matrix3D *mx ) m_cacheFlags = 0; reactToTransformChange(&oldMtx, &oldPos, oldAngle); - DEBUG_ASSERTCRASH(!(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); + DEBUG_ASSERTCRASH(!(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)), ("Drawable/Object position NAN! '%s'", m_template->getName().str() )); } //------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp index 3136edbf55d..0fbf841b40e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp @@ -2486,7 +2486,7 @@ const AudioEventRTS& Drawable::getAmbientSoundByDamage(BodyDamageType dt) void Drawable::validatePos() const { const Coord3D* ourPos = getPosition(); - if (_isnan(ourPos->x) || _isnan(ourPos->y) || _isnan(ourPos->z)) + if (std::isnan(ourPos->x) || std::isnan(ourPos->y) || std::isnan(ourPos->z)) { DEBUG_CRASH(("Drawable/Object position NAN! '%s'", getTemplate()->getName().str())); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp index 88028578414..ab1bf045988 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1858,7 +1858,8 @@ void Object::reactToTurretChange( WhichTurretType turret, Real oldRotation, Real void Object::reactToTransformChange(const Matrix3D* oldMtx, const Coord3D* oldPos, Real oldAngle) { //USE_PERF_TIMER(Object_reactToTransformChange) - if(_isnan(getPosition()->x) || _isnan(getPosition()->y) || _isnan(getPosition()->z)) { + if(std::isnan(getPosition()->x) || std::isnan(getPosition()->y) || std::isnan(getPosition()->z)) + { DEBUG_CRASH(("Object pos is nan.")); TheGameLogic->destroyObject(this); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 926ca274b4f..b73027cbdf4 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2333,7 +2333,7 @@ void AIUpdateInterface::setLocomotorGoalPositionExplicit(const Coord3D& newPos) m_locomotorGoalType = POSITION_EXPLICIT; m_locomotorGoalData = newPos; #ifdef RTS_DEBUG -if (_isnan(m_locomotorGoalData.x) || _isnan(m_locomotorGoalData.y) || _isnan(m_locomotorGoalData.z)) +if (std::isnan(m_locomotorGoalData.x) || std::isnan(m_locomotorGoalData.y) || std::isnan(m_locomotorGoalData.z)) { DEBUG_CRASH(("NAN in setLocomotorGoalPositionExplicit")); } @@ -2346,7 +2346,7 @@ void AIUpdateInterface::setLocomotorGoalOrientation(Real angle) m_locomotorGoalType = ANGLE; m_locomotorGoalData.x = angle; #ifdef RTS_DEBUG -if (_isnan(m_locomotorGoalData.x) || _isnan(m_locomotorGoalData.y) || _isnan(m_locomotorGoalData.z)) +if (std::isnan(m_locomotorGoalData.x) || std::isnan(m_locomotorGoalData.y) || std::isnan(m_locomotorGoalData.z)) { DEBUG_CRASH(("NAN in setLocomotorGoalOrientation")); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index a073dc64649..ace374c97d8 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -315,9 +315,10 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) { // TheSuperHackers @info helmutbuhler 06/05/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC - DEBUG_ASSERTCRASH(!(_isnan(force->x) || _isnan(force->y) || _isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); + DEBUG_ASSERTCRASH(!(std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)), ("PhysicsBehavior::applyForce force NAN!")); #endif - if (_isnan(force->x) || _isnan(force->y) || _isnan(force->z)) { + if (std::isnan(force->x) || std::isnan(force->y) || std::isnan(force->z)) + { return; } // F = ma --> a = F/m (divide force by mass) @@ -337,8 +338,8 @@ void PhysicsBehavior::applyForce( const Coord3D *force ) m_accel.y += modForce.y * massInv; m_accel.z += modForce.z * massInv; - //DEBUG_ASSERTCRASH(!(_isnan(m_accel.x) || _isnan(m_accel.y) || _isnan(m_accel.z)), ("PhysicsBehavior::applyForce accel NAN!")); - //DEBUG_ASSERTCRASH(!(_isnan(m_vel.x) || _isnan(m_vel.y) || _isnan(m_vel.z)), ("PhysicsBehavior::applyForce vel NAN!")); + //DEBUG_ASSERTCRASH(!(std::isnan(m_accel.x) || std::isnan(m_accel.y) || std::isnan(m_accel.z)), ("PhysicsBehavior::applyForce accel NAN!")); + //DEBUG_ASSERTCRASH(!(std::isnan(m_vel.x) || std::isnan(m_vel.y) || std::isnan(m_vel.z)), ("PhysicsBehavior::applyForce vel NAN!")); //DEBUG_ASSERTCRASH(fabs(force->z) < 3, ("unlikely z-force")); #ifdef SLEEPY_PHYSICS if (getFlag(IS_IN_UPDATE)) @@ -677,8 +678,9 @@ UpdateSleepTime PhysicsBehavior::update() mtx.Adjust_Z_Translation(m_vel.z); } - if (_isnan(mtx.Get_X_Translation()) || _isnan(mtx.Get_Y_Translation()) || - _isnan(mtx.Get_Z_Translation())) { + if (std::isnan(mtx.Get_X_Translation()) || std::isnan(mtx.Get_Y_Translation()) || + std::isnan(mtx.Get_Z_Translation())) + { DEBUG_CRASH(("Object position is NAN, deleting.")); TheGameLogic->destroyObject(obj); } @@ -1463,7 +1465,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 force.x = factor * delta.x / dist; force.y = factor * delta.y / dist; force.z = factor * delta.z / dist; // will be zero for 2d case. - DEBUG_ASSERTCRASH(!(_isnan(force.x) || _isnan(force.y) || _isnan(force.z)), ("PhysicsBehavior::onCollide force NAN!")); + DEBUG_ASSERTCRASH(!(std::isnan(force.x) || std::isnan(force.y) || std::isnan(force.z)), ("PhysicsBehavior::onCollide force NAN!")); applyForce( &force ); }