From 5afb52ffce339b8f3b74b3464f8e13c7352384b5 Mon Sep 17 00:00:00 2001 From: In-line Date: Tue, 7 Nov 2017 18:27:54 +0400 Subject: [PATCH] Use Q_abs float overload whenever possible (fix #107) (#201) --- regamedll/dlls/bmodels.cpp | 21 ++++++++++++++----- regamedll/dlls/bot/cs_bot_listen.cpp | 4 ++++ regamedll/dlls/bot/cs_bot_pathfind.cpp | 4 ++++ regamedll/dlls/bot/cs_bot_statemachine.cpp | 4 ++++ regamedll/dlls/bot/cs_bot_vision.cpp | 5 +++++ regamedll/dlls/doors.cpp | 16 ++++++++++++++ .../dlls/hostage/states/hostage_follow.cpp | 4 ++++ regamedll/dlls/plats.cpp | 8 ++++--- regamedll/dlls/player.cpp | 8 +++++++ regamedll/dlls/vehicle.cpp | 8 +++++++ regamedll/game_shared/bot/nav.h | 4 ++++ 11 files changed, 78 insertions(+), 8 deletions(-) diff --git a/regamedll/dlls/bmodels.cpp b/regamedll/dlls/bmodels.cpp index a6c48b90..4987ef5e 100644 --- a/regamedll/dlls/bmodels.cpp +++ b/regamedll/dlls/bmodels.cpp @@ -507,12 +507,20 @@ void CFuncRotating::RampPitchVol(BOOL fUp) int pitch; // get current angular velocity +#ifdef REGAMEDLL_FIXES + vecCur = Q_abs(vecAVel.x != 0 ? vecAVel.x : (vecAVel.y != 0 ? vecAVel.y : vecAVel.z)); +#else vecCur = Q_abs(int(vecAVel.x != 0 ? vecAVel.x : (vecAVel.y != 0 ? vecAVel.y : vecAVel.z))); +#endif // get target angular velocity vecFinal = (pev->movedir.x != 0 ? pev->movedir.x : (pev->movedir.y != 0 ? pev->movedir.y : pev->movedir.z)); vecFinal *= pev->speed; +#ifdef REGAMEDLL_FIXES + vecFinal = Q_abs(vecFinal); +#else vecFinal = Q_abs(int(vecFinal)); +#endif // calc volume and pitch as % of final vol and pitch fpct = vecCur / vecFinal; @@ -543,19 +551,22 @@ void CFuncRotating::RampPitchVol(BOOL fUp) // Accelerates a non-moving func_rotating up to it's speed void CFuncRotating::SpinUp() { - // rotational velocity - Vector vecAVel; - pev->nextthink = pev->ltime + 0.1; pev->avelocity = pev->avelocity + (pev->movedir * (pev->speed * m_flFanFriction)); // cache entity's rotational velocity - vecAVel = pev->avelocity; + Vector vecAVel = pev->avelocity; // if we've met or exceeded target speed, set target speed and stop thinking - if (Q_abs(int(vecAVel.x)) >= Q_abs(int(pev->movedir.x * pev->speed)) +#ifdef REGAMEDLL_FIXES + if (Q_abs(vecAVel.x) >= Q_abs(pev->movedir.x * pev->speed) + && Q_abs(vecAVel.y) >= Q_abs(pev->movedir.y * pev->speed) + && Q_abs(vecAVel.z) >= Q_abs(pev->movedir.z * pev->speed)) +#else + if (Q_abs(int(vecAVel.x)) >= Q_abs(int(pev->movedir.x * pev->speed)) && Q_abs(int(vecAVel.y)) >= Q_abs(int(pev->movedir.y * pev->speed)) && Q_abs(int(vecAVel.z)) >= Q_abs(int(pev->movedir.z * pev->speed))) +#endif { // set speed in case we overshot pev->avelocity = pev->movedir * pev->speed; diff --git a/regamedll/dlls/bot/cs_bot_listen.cpp b/regamedll/dlls/bot/cs_bot_listen.cpp index c9bb5c99..c58708bb 100644 --- a/regamedll/dlls/bot/cs_bot_listen.cpp +++ b/regamedll/dlls/bot/cs_bot_listen.cpp @@ -51,7 +51,11 @@ bool CCSBot::ShouldInvestigateNoise(float *retNoiseDist) float noiseDist = toNoise.Length(); float const oneStoreyHeight = 120.0f; +#ifdef REGAMEDLL_FIXES + if (Q_abs(toNoise.z) > oneStoreyHeight) +#else if (Q_abs(int64(toNoise.z)) > oneStoreyHeight) +#endif { PathCost pc(this); float travelDistToNoise = NavAreaTravelDistance(m_lastKnownArea, m_noiseArea, pc); diff --git a/regamedll/dlls/bot/cs_bot_pathfind.cpp b/regamedll/dlls/bot/cs_bot_pathfind.cpp index 0c2bda3c..0c4e811e 100644 --- a/regamedll/dlls/bot/cs_bot_pathfind.cpp +++ b/regamedll/dlls/bot/cs_bot_pathfind.cpp @@ -323,7 +323,11 @@ bool CCSBot::UpdateLadderMovement() { Vector2D perp(-m_pathLadder->m_dirVector.y, m_pathLadder->m_dirVector.x); +#ifdef REGAMEDLL_FIXES + if (Q_abs(d.x * perp.x + d.y * perp.y) < tolerance && d.Length() < closeToGoal) +#else if (Q_abs(int64(d.x * perp.x + d.y * perp.y)) < tolerance && d.Length() < closeToGoal) +#endif approached = true; } diff --git a/regamedll/dlls/bot/cs_bot_statemachine.cpp b/regamedll/dlls/bot/cs_bot_statemachine.cpp index 0055a24f..79d498ec 100644 --- a/regamedll/dlls/bot/cs_bot_statemachine.cpp +++ b/regamedll/dlls/bot/cs_bot_statemachine.cpp @@ -321,7 +321,11 @@ void CCSBot::Attack(CBasePlayer *victim) Vector toEnemy = victim->pev->origin - pev->origin; Vector idealAngle = UTIL_VecToAngles(toEnemy); +#ifdef REGAMEDLL_FIXES + float_precision deltaYaw = float_precision(Q_abs(m_lookYaw - idealAngle.y)); +#else float_precision deltaYaw = float_precision(Q_abs(int64(m_lookYaw - idealAngle.y))); +#endif while (deltaYaw > 180.0f) deltaYaw -= 360.0f; diff --git a/regamedll/dlls/bot/cs_bot_vision.cpp b/regamedll/dlls/bot/cs_bot_vision.cpp index 11a5ffe5..460be182 100644 --- a/regamedll/dlls/bot/cs_bot_vision.cpp +++ b/regamedll/dlls/bot/cs_bot_vision.cpp @@ -506,8 +506,13 @@ void CCSBot::UpdateLookAround(bool updateNow) // figure out how far along the path segment we are Vector delta = m_spotEncounter->path.to - m_spotEncounter->path.from; float_precision length = delta.Length(); +#ifdef REGAMEDLL_FIXES + float adx = Q_abs(delta.x); + float ady = Q_abs(delta.y); +#else float adx = float(Q_abs(int64(delta.x))); float ady = float(Q_abs(int64(delta.y))); +#endif float_precision t; if (adx > ady) diff --git a/regamedll/dlls/doors.cpp b/regamedll/dlls/doors.cpp index 2b2e4598..6a6d523e 100644 --- a/regamedll/dlls/doors.cpp +++ b/regamedll/dlls/doors.cpp @@ -546,14 +546,22 @@ void CBaseDoor::DoorGoUp() { if (toActivator.y < loY) { +#ifdef REGAMEDLL_FIXES + if (Q_abs(momentArmY) > Q_abs(momentArmX)) +#else if (Q_abs(int(momentArmY)) > Q_abs(int(momentArmX))) +#endif sign = (momentArmY < 0) ? 1 : -1; else sign = (momentArmX > 0) ? 1 : -1; } else if (toActivator.y > hiY) { +#ifdef REGAMEDLL_FIXES + if (Q_abs(momentArmY) > Q_abs(momentArmX)) +#else if (Q_abs(int(momentArmY)) > Q_abs(int(momentArmX))) +#endif sign = (momentArmY < 0) ? 1 : -1; else sign = (momentArmX < 0) ? 1 : -1; @@ -572,14 +580,22 @@ void CBaseDoor::DoorGoUp() } else if (toActivator.y < loY) { +#ifdef REGAMEDLL_FIXES + if (Q_abs(momentArmY) > Q_abs(momentArmX)) +#else if (Q_abs(int(momentArmY)) > Q_abs(int(momentArmX))) +#endif sign = (momentArmY > 0) ? 1 : -1; else sign = (momentArmX > 0) ? 1 : -1; } else if (toActivator.y > hiY) { +#ifdef REGAMEDLL_FIXES + if (Q_abs(momentArmY) > Q_abs(momentArmX)) +#else if (Q_abs(int(momentArmY)) > Q_abs(int(momentArmX))) +#endif sign = (momentArmY > 0) ? 1 : -1; else sign = (momentArmX < 0) ? 1 : -1; diff --git a/regamedll/dlls/hostage/states/hostage_follow.cpp b/regamedll/dlls/hostage/states/hostage_follow.cpp index 06719e54..8d8dbde6 100644 --- a/regamedll/dlls/hostage/states/hostage_follow.cpp +++ b/regamedll/dlls/hostage/states/hostage_follow.cpp @@ -188,7 +188,11 @@ void HostageFollowState::OnUpdate(CHostageImprov *improv) if (GetGroundHeight(&sideStepPos, &ground)) { +#ifdef REGAMEDLL_FIXES + if (Q_abs(ground - improv->GetFeet().z) < 18.0f) +#else if (Q_abs(int(ground - improv->GetFeet().z)) < 18.0f) +#endif { const float push = 20.0f; Vector lat = cross * push; diff --git a/regamedll/dlls/plats.cpp b/regamedll/dlls/plats.cpp index 28cd0827..1c6f2d6a 100644 --- a/regamedll/dlls/plats.cpp +++ b/regamedll/dlls/plats.cpp @@ -1048,12 +1048,14 @@ void CFuncTrackTrain::StopSound() void CFuncTrackTrain::UpdateSound() { - float flpitch; - if (!pev->noise) return; - flpitch = TRAIN_STARTPITCH + (Q_abs(int(pev->speed)) * (TRAIN_MAXPITCH - TRAIN_STARTPITCH) / TRAIN_MAXSPEED); +#ifdef REGAMEDLL_FIXES + float flpitch = TRAIN_STARTPITCH + (Q_abs(pev->speed) * (TRAIN_MAXPITCH - TRAIN_STARTPITCH) / TRAIN_MAXSPEED); +#else + float flpitch = TRAIN_STARTPITCH + (Q_abs(int(pev->speed)) * (TRAIN_MAXPITCH - TRAIN_STARTPITCH) / TRAIN_MAXSPEED); +#endif if (!m_soundPlaying) { diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 50ab110a..edcb42b7 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -4396,7 +4396,11 @@ void CBasePlayer::CheckTimeBasedDamage() return; // only check for time based damage approx. every 2 seconds +#ifdef REGAMEDLL_FIXES + if (Q_abs(gpGlobals->time - m_tbdPrev) < 2.0f) +#else if (Q_abs(int64(gpGlobals->time - m_tbdPrev)) < 2.0f) +#endif return; m_tbdPrev = gpGlobals->time; @@ -7817,7 +7821,11 @@ void CBasePlayer::StudioEstimateGait() else flYawDiff *= dt; +#ifdef REGAMEDLL_FIXES + if (float_precision(Q_abs(flYawDiff)) < 0.1f) +#else if (float_precision(Q_abs(int64(flYawDiff))) < 0.1f) +#endif flYawDiff = 0; m_flGaityaw += flYawDiff; diff --git a/regamedll/dlls/vehicle.cpp b/regamedll/dlls/vehicle.cpp index 762e2565..28fda9b9 100644 --- a/regamedll/dlls/vehicle.cpp +++ b/regamedll/dlls/vehicle.cpp @@ -117,7 +117,11 @@ void CFuncVehicle::Blocked(CBaseEntity *pOther) float maxy = Q_max(vBackLeft.y, vBackRight.y); float minz = pev->origin.z; +#ifdef REGAMEDLL_FIXES + float maxz = pev->origin.z + (2 * Q_abs(pev->mins.z - pev->maxs.z)); +#else float maxz = pev->origin.z + (2 * Q_abs(int(pev->mins.z - pev->maxs.z))); +#endif if (pOther->pev->origin.x < minx || pOther->pev->origin.x > maxx @@ -261,7 +265,11 @@ void CFuncVehicle::UpdateSound() if (!pev->noise) return; +#ifdef REGAMEDLL_FIXES + float flpitch = VEHICLE_STARTPITCH + (Q_abs(pev->speed) * (VEHICLE_MAXPITCH - VEHICLE_STARTPITCH) / VEHICLE_MAXSPEED); +#else float flpitch = VEHICLE_STARTPITCH + (Q_abs(int(pev->speed)) * (VEHICLE_MAXPITCH - VEHICLE_STARTPITCH) / VEHICLE_MAXSPEED); +#endif if (flpitch > 200) flpitch = 200; diff --git a/regamedll/game_shared/bot/nav.h b/regamedll/game_shared/bot/nav.h index b7c06367..5a127008 100644 --- a/regamedll/game_shared/bot/nav.h +++ b/regamedll/game_shared/bot/nav.h @@ -351,7 +351,11 @@ inline float AngleDifference(float a, float b) inline bool AnglesAreEqual(float a, float b, float tolerance = 5.0f) { +#ifdef REGAMEDLL_FIXES + if (Q_abs(AngleDifference(a, b)) < tolerance) +#else if (Q_abs(int64(AngleDifference(a, b))) < tolerance) +#endif return true; return false;