diff --git a/src/game/common/thing/thing.cpp b/src/game/common/thing/thing.cpp index d98d35ce1..0c708f97d 100644 --- a/src/game/common/thing/thing.cpp +++ b/src/game/common/thing/thing.cpp @@ -103,7 +103,8 @@ void Thing::Set_Position_Z(float z) React_To_Transform_Change(&old_tm, &old_pos, old_angle); } - captainslog_dbgassert(!gm_isnanf(Get_Position()->x) && !gm_isnanf(Get_Position()->y) && !gm_isnanf(Get_Position()->z), + captainslog_dbgassert( + !GameMath::Is_Nan(Get_Position()->x) && !GameMath::Is_Nan(Get_Position()->y) && !GameMath::Is_Nan(Get_Position()->z), "Drawable/Object position NAN! \'%s\'", m_template->Get_Name().Str()); } @@ -175,7 +176,8 @@ void Thing::Set_Orientation(float angle) m_cachedPos = pos; m_cacheFlags &= ~VALID_DIRVECTOR; React_To_Transform_Change(&old_tm, &old_pos, old_angle); - captainslog_dbgassert(!gm_isnanf(Get_Position()->x) && !gm_isnanf(Get_Position()->y) && !gm_isnanf(Get_Position()->z), + captainslog_dbgassert( + !GameMath::Is_Nan(Get_Position()->x) && !GameMath::Is_Nan(Get_Position()->y) && !GameMath::Is_Nan(Get_Position()->z), "Drawable/Object position NAN! \'%s\'", m_template->Get_Name().Str()); } @@ -198,7 +200,8 @@ void Thing::Set_Position(const Coord3D *pos) React_To_Transform_Change(&old_tm, &old_pos, old_angle); } - captainslog_dbgassert(!gm_isnanf(Get_Position()->x) && !gm_isnanf(Get_Position()->y) && !gm_isnanf(Get_Position()->z), + captainslog_dbgassert( + !GameMath::Is_Nan(Get_Position()->x) && !GameMath::Is_Nan(Get_Position()->y) && !GameMath::Is_Nan(Get_Position()->z), "Drawable/Object position NAN! \'%s\'", m_template->Get_Name().Str()); } @@ -216,7 +219,8 @@ void Thing::Set_Transform_Matrix(const Matrix3D *mx) m_cacheFlags = 0; React_To_Transform_Change(&old_tm, &old_pos, old_angle); - captainslog_dbgassert(!gm_isnanf(Get_Position()->x) && !gm_isnanf(Get_Position()->y) && !gm_isnanf(Get_Position()->z), + captainslog_dbgassert( + !GameMath::Is_Nan(Get_Position()->x) && !GameMath::Is_Nan(Get_Position()->y) && !GameMath::Is_Nan(Get_Position()->z), "Drawable/Object position NAN! \'%s\'", m_template->Get_Name().Str()); } diff --git a/src/game/logic/object/object.cpp b/src/game/logic/object/object.cpp index 834b5b117..7083d1955 100644 --- a/src/game/logic/object/object.cpp +++ b/src/game/logic/object/object.cpp @@ -527,7 +527,7 @@ bool Angle_Changed(float f1, float f2) void Object::React_To_Transform_Change(const Matrix3D *tm, const Coord3D *pos, float angle) { - if (gm_isnanf(Get_Position()->x) || gm_isnanf(Get_Position()->y) || gm_isnanf(Get_Position()->z)) { + if (GameMath::Is_Nan(Get_Position()->x) || GameMath::Is_Nan(Get_Position()->y) || GameMath::Is_Nan(Get_Position()->z)) { captainslog_dbgassert(false, "Object pos is nan."); g_theGameLogic->Destroy_Object(this); } diff --git a/src/game/logic/object/update/physicsupdate.cpp b/src/game/logic/object/update/physicsupdate.cpp index c512d4d62..068a40bcf 100644 --- a/src/game/logic/object/update/physicsupdate.cpp +++ b/src/game/logic/object/update/physicsupdate.cpp @@ -258,7 +258,8 @@ UpdateSleepTime PhysicsBehavior::Update() tm.Adjust_Z_Translation(m_vel.z); } - if (gm_isnanf(tm.Get_X_Translation()) || gm_isnanf(tm.Get_Y_Translation()) || gm_isnanf(tm.Get_Z_Translation())) { + if (GameMath::Is_Nan(tm.Get_X_Translation()) || GameMath::Is_Nan(tm.Get_Y_Translation()) + || GameMath::Is_Nan(tm.Get_Z_Translation())) { captainslog_dbgassert(false, "Object position is NAN, deleting."); g_theGameLogic->Destroy_Object(obj); } @@ -570,7 +571,8 @@ void PhysicsBehavior::On_Collide(Object *other, Coord3D const *loc, Coord3D cons force.x = f3 * center_diff.x / f1; force.y = f3 * center_diff.y / f1; force.z = f3 * center_diff.z / f1; - captainslog_dbgassert(!gm_isnanf(force.x) && !gm_isnanf(force.y) && !gm_isnanf(force.z), + captainslog_dbgassert(!GameMath::Is_Nan(force.x) && !GameMath::Is_Nan(force.y) + && !GameMath::Is_Nan(force.z), "PhysicsBehavior::onCollide force NAN!"); Apply_Force(&force); } @@ -726,10 +728,10 @@ void PhysicsBehavior::Apply_Gravitational_Forces() void PhysicsBehavior::Apply_Force(const Coord3D *force) { - captainslog_dbgassert( - !gm_isnanf(force->x) && !gm_isnanf(force->y) && !gm_isnanf(force->z), "PhysicsBehavior::applyForce force NAN!"); + captainslog_dbgassert(!GameMath::Is_Nan(force->x) && !GameMath::Is_Nan(force->y) && !GameMath::Is_Nan(force->z), + "PhysicsBehavior::applyForce force NAN!"); - if (!gm_isnanf(force->x) && !gm_isnanf(force->y) && !gm_isnanf(force->z)) { + if (!GameMath::Is_Nan(force->x) && !GameMath::Is_Nan(force->y) && !GameMath::Is_Nan(force->z)) { float mass = Get_Mass(); Coord3D new_force = *force; diff --git a/src/w3d/math/gamemath.h b/src/w3d/math/gamemath.h index fef2fc912..01ea304c7 100644 --- a/src/w3d/math/gamemath.h +++ b/src/w3d/math/gamemath.h @@ -66,24 +66,6 @@ extern const Array _FastAsinTable; extern const Array _FastSinTable; extern const Array _FastInvSinTable; -inline float Normalize_Angle(float angle) -{ - captainslog_dbgassert(!gm_isnanf(angle), "Angle is NAN in normalizeAngle!\n"); - if (gm_isnanf(angle)) { - return 0.0f; - } - - while (angle > GAMEMATH_PI) { - angle = angle - GAMEMATH_PI * 2; - } - - while (angle <= -GAMEMATH_PI) { - angle = angle + GAMEMATH_PI * 2; - } - - return angle; -} - namespace GameMath { void Init(); @@ -547,4 +529,31 @@ inline int Lrintf(float val) // return true; //} +inline bool Is_Nan(float val) +{ +#ifdef BUILD_WITH_GAMEMATH + return gm_isnanf(val) != 0; +#else + return std::isnan(val); +#endif +} + } // namespace GameMath + +inline float Normalize_Angle(float angle) +{ + captainslog_dbgassert(!GameMath::Is_Nan(angle), "Angle is NAN in normalizeAngle!\n"); + if (GameMath::Is_Nan(angle)) { + return 0.0f; + } + + while (angle > GAMEMATH_PI) { + angle = angle - GAMEMATH_PI * 2; + } + + while (angle <= -GAMEMATH_PI) { + angle = angle + GAMEMATH_PI * 2; + } + + return angle; +}