From 0e1520ab1fd4c621c44f28da51289dbcda7bde34 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 3 Oct 2023 22:50:50 +1100 Subject: [PATCH] - Duke: Clean up player/actor accesses in all input look functions. --- source/games/duke/src/funct.h | 12 +++--- source/games/duke/src/player.cpp | 68 +++++++++++++++--------------- source/games/duke/src/player_d.cpp | 12 +++--- source/games/duke/src/player_r.cpp | 12 +++--- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 2f280012b..6853e364c 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -106,12 +106,12 @@ int makepainsounds(DDukePlayer* const p, int type); void playerCrouch(DDukePlayer* const p); void playerJump(DDukePlayer* const p, double fz, double cz); -void checklook(int snum, ESyncBits actions); -void playerCenterView(int snum); -void playerLookUp(int snum, ESyncBits actions); -void playerLookDown(int snum, ESyncBits actions); -void playerAimUp(int snum, ESyncBits actions); -void playerAimDown(int snum, ESyncBits actions); +void checklook(DDukePlayer* const p, ESyncBits actions); +void playerCenterView(DDukePlayer* const p); +void playerLookUp(DDukePlayer* const p, ESyncBits actions); +void playerLookDown(DDukePlayer* const p, ESyncBits actions); +void playerAimUp(DDukePlayer* const p, ESyncBits actions); +void playerAimDown(DDukePlayer* const p, ESyncBits actions); DDukeActor* aim(DDukeActor* s, int aang, bool force = true, bool* b = nullptr); DDukeActor* aim_(DDukeActor* actor, DDukeActor* weapon, double aimangle, bool* b = nullptr); void shoot(DDukeActor* actor, PClass* cls); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 0a6ae15b9..7fe89bfdb 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -819,15 +819,15 @@ void DDukePlayer::playerweaponsway(double xvel) // //--------------------------------------------------------------------------- -void checklook(int snum, ESyncBits actions) +void checklook(DDukePlayer* const p, ESyncBits actions) { - auto p = getPlayer(snum); + const auto pact = p->GetActor(); if ((actions & SB_LOOK_LEFT) && !p->OnMotorcycle) { - SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); - OnEvent(EVENT_LOOKLEFT, snum, p->GetActor(), -1); - if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() != 0) + SetGameVarID(g_iReturnVarID, 0, pact, p->pnum); + OnEvent(EVENT_LOOKLEFT, p->pnum, pact, -1); + if (GetGameVarID(g_iReturnVarID, pact, p->pnum).value() != 0) { actions &= ~SB_LOOK_LEFT; } @@ -835,9 +835,9 @@ void checklook(int snum, ESyncBits actions) if ((actions & SB_LOOK_RIGHT) && !p->OnMotorcycle) { - SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); - OnEvent(EVENT_LOOKRIGHT, snum, p->GetActor(), -1); - if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() != 0) + SetGameVarID(g_iReturnVarID, 0, pact, p->pnum); + OnEvent(EVENT_LOOKRIGHT, p->pnum, pact, -1); + if (GetGameVarID(g_iReturnVarID, pact, p->pnum).value() != 0) { actions &= ~SB_LOOK_RIGHT; } @@ -850,16 +850,16 @@ void checklook(int snum, ESyncBits actions) // //--------------------------------------------------------------------------- -void playerCenterView(int snum) +void playerCenterView(DDukePlayer* const p) { - auto p = getPlayer(snum); - SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); - OnEvent(EVENT_RETURNTOCENTER, snum, p->GetActor(), -1); - if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0) + const auto pact = p->GetActor(); + SetGameVarID(g_iReturnVarID, 0, pact, p->pnum); + OnEvent(EVENT_RETURNTOCENTER, p->pnum, pact, -1); + if (GetGameVarID(g_iReturnVarID, pact, p->pnum).value() == 0) { p->cmd.ucmd.actions |= SB_CENTERVIEW; p->cmd.ucmd.ang.Pitch = nullAngle; - setForcedSyncInput(snum); + setForcedSyncInput(p->pnum); } else { @@ -867,12 +867,12 @@ void playerCenterView(int snum) } } -void playerLookUp(int snum, ESyncBits actions) +void playerLookUp(DDukePlayer* const p, ESyncBits actions) { - auto p = getPlayer(snum); - SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); - OnEvent(EVENT_LOOKUP, snum, p->GetActor(), -1); - if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0) + const auto pact = p->GetActor(); + SetGameVarID(g_iReturnVarID, 0, pact, p->pnum); + OnEvent(EVENT_LOOKUP, p->pnum, pact, -1); + if (GetGameVarID(g_iReturnVarID, pact, p->pnum).value() == 0) { p->cmd.ucmd.actions |= SB_CENTERVIEW; } @@ -882,12 +882,12 @@ void playerLookUp(int snum, ESyncBits actions) } } -void playerLookDown(int snum, ESyncBits actions) +void playerLookDown(DDukePlayer* const p, ESyncBits actions) { - auto p = getPlayer(snum); - SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); - OnEvent(EVENT_LOOKDOWN, snum, p->GetActor(), -1); - if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0) + const auto pact = p->GetActor(); + SetGameVarID(g_iReturnVarID, 0, pact, p->pnum); + OnEvent(EVENT_LOOKDOWN, p->pnum, pact, -1); + if (GetGameVarID(g_iReturnVarID, pact, p->pnum).value() == 0) { p->cmd.ucmd.actions |= SB_CENTERVIEW; } @@ -897,23 +897,23 @@ void playerLookDown(int snum, ESyncBits actions) } } -void playerAimUp(int snum, ESyncBits actions) +void playerAimUp(DDukePlayer* const p, ESyncBits actions) { - auto p = getPlayer(snum); - SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); - OnEvent(EVENT_AIMUP, snum, p->GetActor(), -1); - if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() != 0) + const auto pact = p->GetActor(); + SetGameVarID(g_iReturnVarID, 0, pact, p->pnum); + OnEvent(EVENT_AIMUP, p->pnum, pact, -1); + if (GetGameVarID(g_iReturnVarID, pact, p->pnum).value() != 0) { p->cmd.ucmd.actions &= ~SB_AIM_UP; } } -void playerAimDown(int snum, ESyncBits actions) +void playerAimDown(DDukePlayer* const p, ESyncBits actions) { - auto p = getPlayer(snum); - SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); - OnEvent(EVENT_AIMDOWN, snum, p->GetActor(), -1); // due to a typo in WW2GI's CON files this is the same as EVENT_AIMUP. - if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() != 0) + const auto pact = p->GetActor(); + SetGameVarID(g_iReturnVarID, 0, pact, p->pnum); + OnEvent(EVENT_AIMDOWN, p->pnum, pact, -1); // due to a typo in WW2GI's CON files this is the same as EVENT_AIMUP. + if (GetGameVarID(g_iReturnVarID, pact, p->pnum).value() != 0) { p->cmd.ucmd.actions &= ~SB_AIM_DOWN; } diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 209fe51ce..f1a7b524c 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -1671,7 +1671,7 @@ void processinput_d(int snum) doubvel = TICSPERFRAME; - checklook(snum,actions); + checklook(p, actions); p->Angles.doViewYaw(&p->cmd.ucmd); p->updatecentering(snum); @@ -1916,23 +1916,23 @@ HORIZONLY: // center_view if (actions & SB_CENTERVIEW || (p->hard_landing && (cl_dukepitchmode & kDukePitchLandingRecenter))) { - playerCenterView(snum); + playerCenterView(p); } else if ((actions & SB_LOOK_UP) == SB_LOOK_UP) { - playerLookUp(snum, actions); + playerLookUp(p, actions); } else if ((actions & SB_LOOK_DOWN) == SB_LOOK_DOWN) { - playerLookDown(snum, actions); + playerLookDown(p, actions); } else if ((actions & SB_LOOK_UP) == SB_AIM_UP) { - playerAimUp(snum, actions); + playerAimUp(p, actions); } else if ((actions & SB_LOOK_DOWN) == SB_AIM_DOWN) { // aim_down - playerAimDown(snum, actions); + playerAimDown(p, actions); } p->Angles.doPitchInput(&p->cmd.ucmd); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 445548b18..5a3c778f6 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -2482,7 +2482,7 @@ void processinput_r(int snum) doubvel = TICSPERFRAME; - checklook(snum, actions); + checklook(p, actions); p->Angles.doViewYaw(&p->cmd.ucmd); p->apply_seasick(); @@ -2865,23 +2865,23 @@ HORIZONLY: if (actions & SB_CENTERVIEW || (p->hard_landing && (cl_dukepitchmode & kDukePitchLandingRecenter))) { - playerCenterView(snum); + playerCenterView(p); } else if ((actions & SB_LOOK_UP) == SB_LOOK_UP) { - playerLookUp(snum, actions); + playerLookUp(p, actions); } else if ((actions & SB_LOOK_DOWN) == SB_LOOK_DOWN) { - playerLookDown(snum, actions); + playerLookDown(p, actions); } else if ((actions & SB_LOOK_UP) == SB_AIM_UP && !p->OnMotorcycle) { - playerAimUp(snum, actions); + playerAimUp(p, actions); } else if ((actions & SB_LOOK_DOWN) == SB_AIM_DOWN && !p->OnMotorcycle) { - playerAimDown(snum, actions); + playerAimDown(p, actions); } if (p->recoil && p->kickback_pic == 0) {