From 478e7a680101c6dd44e68a5560bd02939fd08db8 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 28 Aug 2022 12:09:44 +1000 Subject: [PATCH] - Eliminate some TAngle floating point Build method usage. --- source/core/gameinput.cpp | 39 +++++++++++++++++------------- source/core/gameinput.h | 3 +-- source/games/blood/src/player.cpp | 2 +- source/games/duke/src/gameexec.cpp | 4 +-- source/games/duke/src/input.cpp | 2 +- source/games/duke/src/premap.cpp | 4 +-- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 88671b17b..39313247f 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -38,26 +38,31 @@ inline static double getTicrateScale(const double value) return value * (1. / GameTicRate); } -inline static double getPushScale(const double scaleAdjust) +inline static double getPushBuild(const double scaleAdjust) { - return (2. / 9.) * (scaleAdjust < 1. ? (1. - scaleAdjust * 0.5) * 1.5 : 1.); + return 2. / 9. * (scaleAdjust < 1. ? (1. - scaleAdjust * 0.5) * 1.5 : 1.); } -inline static fixedhoriz getscaledhoriz(const double value, const double scaleAdjust, const fixedhoriz& object, const double push) +inline static DAngle getPushAngle(const double scaleAdjust) +{ + return DAngle::fromDeg(getPushBuild(scaleAdjust) * BAngToDegree); +} + +inline static fixedhoriz getscaledhoriz(const double value, const double scaleAdjust, const fixedhoriz object, const double push) { return buildfhoriz(scaleAdjust * ((object.asbuildf() * getTicrateScale(value)) + push)); } -inline static DAngle getscaledangle(const double value, const double scaleAdjust, const DAngle& object, const double push) +inline static DAngle getscaledangle(const double value, const double scaleAdjust, const DAngle object, const DAngle push) { - return DAngle::fromBuildf(scaleAdjust * ((object.Normalized180().Buildfang() * getTicrateScale(value)) + push)); + return ((object.Normalized180() * getTicrateScale(value)) + push) * scaleAdjust; } inline static void scaletozero(fixedhoriz& object, const double value, const double scaleAdjust, const double push = DBL_MAX) { if (auto sgn = Sgn(object.asq16())) { - object -= getscaledhoriz(value, scaleAdjust, object, push == DBL_MAX ? sgn * getPushScale(scaleAdjust) : push); + object -= getscaledhoriz(value, scaleAdjust, object, push == DBL_MAX ? getPushBuild(scaleAdjust) * sgn : push); if (sgn != Sgn(object.asq16())) object = q16horiz(0); } } @@ -66,7 +71,7 @@ inline static void scaletozero(DAngle& object, const double value, const double { if (auto sgn = object.Sgn()) { - object -= getscaledangle(value, scaleAdjust, object, push == DBL_MAX ? sgn * getPushScale(scaleAdjust) : push); + object -= getscaledangle(value, scaleAdjust, object, push == DBL_MAX ? getPushAngle(scaleAdjust) * sgn : DAngle::fromDeg(push)); if (sgn != object.Sgn()) object = nullAngle; } } @@ -375,8 +380,8 @@ void PlayerAngle::applyinput(float const avel, ESyncBits* actions, double const { if (*actions & key) { - look_ang += DAngle::fromBuildf(getTicrateScale(LOOKINGSPEED) * scaleAdjust * direction); - rotscrnang -= DAngle::fromBuildf(getTicrateScale(ROTATESPEED) * scaleAdjust * direction); + look_ang += DAngle::fromDeg(getTicrateScale(LOOKINGSPEED) * scaleAdjust * direction * BAngToDegree); + rotscrnang -= DAngle::fromDeg(getTicrateScale(ROTATESPEED) * scaleAdjust * direction * BAngToDegree); } }; doLookKeys(SB_LOOK_LEFT, -1); @@ -386,10 +391,10 @@ void PlayerAngle::applyinput(float const avel, ESyncBits* actions, double const { if (*actions & SB_TURNAROUND) { - if (spin == 0) + if (spin == nullAngle) { // currently not spinning, so start a spin - spin = -1024.; + spin = -DAngle180; } *actions &= ~SB_TURNAROUND; } @@ -400,23 +405,23 @@ void PlayerAngle::applyinput(float const avel, ESyncBits* actions, double const ang += DAngle::fromDeg(avel); } - if (spin < 0) + if (spin < nullAngle) { // return spin to 0 - double add = getTicrateScale(!(*actions & SB_CROUCH) ? SPINSTAND : SPINCROUCH) * scaleAdjust; + DAngle add = DAngle::fromDeg(getTicrateScale(!(*actions & SB_CROUCH) ? SPINSTAND : SPINCROUCH) * scaleAdjust * BAngToDegree); spin += add; - if (spin > 0) + if (spin > nullAngle) { // Don't overshoot our target. With variable factor this is possible. add -= spin; - spin = 0; + spin = nullAngle; } - ang += DAngle::fromBuildf(add); + ang += add; } } else { - spin = 0; + spin = nullAngle; } } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 2d670fe96..4213ebd75 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -119,8 +119,7 @@ private: struct PlayerAngle { - DAngle ang, oang, look_ang, olook_ang, rotscrnang, orotscrnang; - double spin; + DAngle ang, oang, look_ang, olook_ang, rotscrnang, orotscrnang, spin; friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def); diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index c2ca488bf..ca5b58b53 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -827,7 +827,7 @@ void playerStart(int nPlayer, int bNewLevel) pPlayer->restTime = 0; pPlayer->kickPower = 0; pPlayer->laughCount = 0; - pPlayer->angle.spin = 0; + pPlayer->angle.spin = nullAngle; pPlayer->posture = 0; pPlayer->voodooTarget = nullptr; pPlayer->voodooTargets = 0; diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index c3c0351c6..dd0f75d08 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -650,8 +650,8 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, break; case PLAYER_ONE_EIGHTY_COUNT: - if (bSet) ps[iPlayer].angle.spin = lValue; - else SetGameVarID(lVar2, int(ps[iPlayer].angle.spin), sActor, sPlayer); + if (bSet) ps[iPlayer].angle.spin = DAngle::fromBuild(lValue); + else SetGameVarID(lVar2, ps[iPlayer].angle.spin.Buildang(), sActor, sPlayer); break; case PLAYER_CHEAT_PHASE: diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 4542d7dc7..16ba1c180 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -479,7 +479,7 @@ void hud_input(int plnum) } } - if (PlayerInput(plnum, SB_TURNAROUND) && p->angle.spin == 0 && p->on_crane == nullptr) + if (PlayerInput(plnum, SB_TURNAROUND) && p->angle.spin == nullAngle && p->on_crane == nullptr) { SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); OnEvent(EVENT_TURNAROUND, plnum, nullptr, -1); diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 76a228a08..1a803f2f1 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -188,8 +188,8 @@ void resetplayerstats(int snum) p->vel.Z = 0; p->fric.X = 0; p->fric.Y = 0; - p->somethingonplayer =nullptr; - p->angle.spin = 0; + p->somethingonplayer = nullptr; + p->angle.spin = nullAngle; p->on_crane = nullptr;