From 5ddd201b33af9145a37220ac1c576e513e9264d3 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 4 Oct 2023 11:32:15 +1100 Subject: [PATCH] - Duke: Clean up player/actor accesses in `checkhitswitch()` and associated utilities. --- source/games/duke/src/dispatch.cpp | 4 +-- source/games/duke/src/duke3d.h | 2 +- source/games/duke/src/funct.h | 2 +- source/games/duke/src/player_d.cpp | 4 +-- source/games/duke/src/player_r.cpp | 4 +-- source/games/duke/src/sectors.cpp | 38 +++++++++++++------------- source/games/duke/src/sectors_d.cpp | 34 +++++++++++------------ source/games/duke/src/sectors_r.cpp | 42 +++++++++++++++-------------- source/games/duke/src/vmexports.cpp | 2 +- 9 files changed, 67 insertions(+), 65 deletions(-) diff --git a/source/games/duke/src/dispatch.cpp b/source/games/duke/src/dispatch.cpp index 89a674004..daa4b6b24 100644 --- a/source/games/duke/src/dispatch.cpp +++ b/source/games/duke/src/dispatch.cpp @@ -32,8 +32,8 @@ BEGIN_DUKE_NS // //--------------------------------------------------------------------------- -bool checkaccessswitch_d(int snum, int pal, DDukeActor *act, walltype* w); -bool checkaccessswitch_r(int snum, int pal, DDukeActor* act, walltype* w); +bool checkaccessswitch_d(DDukePlayer* const p, int pal, DDukeActor *act, walltype* w); +bool checkaccessswitch_r(DDukePlayer* const p, int pal, DDukeActor* act, walltype* w); void activatebysector_d(sectortype* sect, DDukeActor* j); void activatebysector_r(sectortype* sect, DDukeActor* j); void checksectors_d(int snum); diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 12dc94d59..40fe045ce 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -70,7 +70,7 @@ struct Dispatcher // sectors_?.cpp void (*think)(); void (*movetransports)(); - bool (*checkaccessswitch)(int snum, int switchpal, DDukeActor* act, walltype* w); + bool (*checkaccessswitch)(DDukePlayer* const p, int switchpal, DDukeActor* act, walltype* w); void (*activatebysector)(sectortype* sect, DDukeActor* j); void (*checksectors)(int low); diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index f6950cf11..2fcc98861 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -240,7 +240,7 @@ void underwater(DDukePlayer* p, ESyncBits actions, double floorz, double ceiling void loadcons(); void DrawStatusBar(); void thunder(void); -bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act); +bool checkhitswitch(DDukePlayer* const p, walltype* wwal, DDukeActor* act); void drawshadows(tspriteArray& tsprites, tspritetype* t, DDukeActor* h); void applyanimations(tspritetype* t, DDukeActor* h, const DVector2& viewVec, DAngle viewang); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index e00586c9c..f93c0c0b0 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -449,7 +449,7 @@ int doincrements_d(DDukePlayer* p) { if (p->access_spritenum != nullptr) { - checkhitswitch(snum, nullptr, p->access_spritenum); + checkhitswitch(p, nullptr, p->access_spritenum); switch (p->access_spritenum->spr.pal) { case 0:p->got_access &= (0xffff - 0x1); break; @@ -460,7 +460,7 @@ int doincrements_d(DDukePlayer* p) } else { - checkhitswitch(snum, p->access_wall, nullptr); + checkhitswitch(p, p->access_wall, nullptr); switch (p->access_wall->pal) { case 0:p->got_access &= (0xffff - 0x1); break; diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 7b7898175..66716117c 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -507,7 +507,7 @@ int doincrements_r(DDukePlayer* p) { if (p->access_spritenum != nullptr) { - checkhitswitch(snum, nullptr, p->access_spritenum); + checkhitswitch(p, nullptr, p->access_spritenum); switch (p->access_spritenum->spr.pal) { case 0:p->keys[1] = 1; break; @@ -518,7 +518,7 @@ int doincrements_r(DDukePlayer* p) } else { - checkhitswitch(snum, p->access_wall, nullptr); + checkhitswitch(p, p->access_wall, nullptr); switch (p->access_wall->pal) { case 0:p->keys[1] = 1; break; diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 62b2b33a0..dfd3b88c4 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -1589,7 +1589,7 @@ void resetswitch(int tag) // //--------------------------------------------------------------------------- -void tag10000specialswitch(int snum, DDukeActor* act, const DVector3& v) +static void tag10000specialswitch(DDukePlayer* const p, DDukeActor* act, const DVector3& v) { DDukeActor* switches[3]; int switchcount = 0, j; @@ -1620,7 +1620,7 @@ void tag10000specialswitch(int snum, DDukeActor* act, const DVector3& v) { switches[j]->spr.hitag = 0; switches[j]->spr.setspritetexture(::switches[GetExtInfo(switches[j]->spr.spritetexture()).switchindex].states[3]); - checkhitswitch(snum, nullptr, switches[j]); + checkhitswitch(p, nullptr, switches[j]); } } } @@ -1735,7 +1735,7 @@ void togglewallswitches(walltype* wwal, const TexExtInfo& ext, int lotag, int& c // //--------------------------------------------------------------------------- -bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act) +bool checkhitswitch(DDukePlayer* const p, walltype* wwal, DDukeActor* act) { uint8_t switchpal; int lotag, hitag, correctdips, numdips; @@ -1757,7 +1757,7 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act) switchpal = act->spr.pal; // custom switches that maintain themselves can immediately abort. - swresult = CallTriggerSwitch(act, getPlayer(snum)); + swresult = CallTriggerSwitch(act, p); if (swresult == 1) return true; } else @@ -1781,7 +1781,7 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act) break; case SwitchDef::Access: - if (fi.checkaccessswitch(snum, switchpal, act, wwal)) + if (fi.checkaccessswitch(p, switchpal, act, wwal)) return 0; [[fallthrough]]; @@ -1808,15 +1808,15 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act) if (hitag == 10001 && swdef.flags & SwitchDef::oneway && isRRRA()) { act->spr.setspritetexture(swdef.states[1]); - if (getPlayer(snum)->SeaSick == 0) - getPlayer(snum)->SeaSick = 350; - operateactivators(668, getPlayer(snum)); + if (p->SeaSick == 0) + p->SeaSick = 350; + operateactivators(668, p); operatemasterswitches(668); - S_PlayActorSound(328, getPlayer(snum)->GetActor()); + S_PlayActorSound(328, p->GetActor()); return 1; } } - DVector3 v(spos, getPlayer(snum)->GetActor()->getOffsetZ()); + DVector3 v(spos, p->GetActor()->getOffsetZ()); if (swdef.type != SwitchDef::None || isadoorwall(texid)) { @@ -1826,16 +1826,16 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act) { FSoundID sound = swdef.soundid != NO_SOUND ? swdef.soundid : S_FindSoundByResID(SWITCH_ON); if (act) S_PlaySound3D(sound, act, v); - else S_PlaySound3D(sound, getPlayer(snum)->GetActor(), v); + else S_PlaySound3D(sound, p->GetActor(), v); if (numdips != correctdips) return 0; - S_PlaySound3D(END_OF_LEVEL_WARN, getPlayer(snum)->GetActor(), v); + S_PlaySound3D(END_OF_LEVEL_WARN, p->GetActor(), v); } if (swdef.type == SwitchDef::Multi) { lotag += ext.switchphase; if (hitag == 10000 && act && isRRRA()) // no idea if the game check is really needed for something this far off the beaten path... { - tag10000specialswitch(snum, act, v); + tag10000specialswitch(p, act, v); return 1; } } @@ -1866,8 +1866,8 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act) case SE_25_PISTON: other->temp_data[4] = !other->temp_data[4]; if (other->temp_data[4]) - FTA(15, getPlayer(snum)); - else FTA(2, getPlayer(snum)); + FTA(15, p); + else FTA(2, p); break; case SE_21_DROP_FLOOR: FTA(2, getPlayer(screenpeek)); @@ -1876,8 +1876,8 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act) } } - operateactivators(lotag, getPlayer(snum)); - operateforcefields(getPlayer(snum)->GetActor(), lotag); + operateactivators(lotag, p); + operateforcefields(p->GetActor(), lotag); operatemasterswitches(lotag); if (swdef.type == SwitchDef::Combo) return 1; @@ -1886,7 +1886,7 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act) { FSoundID sound = swdef.soundid != NO_SOUND ? swdef.soundid : S_FindSoundByResID(SWITCH_ON); if (act) S_PlaySound3D(sound, act, v); - else S_PlaySound3D(sound, getPlayer(snum)->GetActor(), v); + else S_PlaySound3D(sound, p->GetActor(), v); } else if (hitag != 0) { @@ -1895,7 +1895,7 @@ bool checkhitswitch(int snum, walltype* wwal, DDukeActor* act) if (act && (flags & SF_TALK) == 0) S_PlaySound3D(hitag, act, v); else - S_PlayActorSound(hitag, getPlayer(snum)->GetActor()); + S_PlayActorSound(hitag, p->GetActor()); } return 1; diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 637f60edf..6385b3d81 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -48,37 +48,37 @@ BEGIN_DUKE_NS // //--------------------------------------------------------------------------- -bool checkaccessswitch_d(int snum, int switchpal, DDukeActor* act, walltype* wwal) +bool checkaccessswitch_d(DDukePlayer* const p, int switchpal, DDukeActor* act, walltype* wwal) { - if (getPlayer(snum)->access_incs == 0) + if (p->access_incs == 0) { if (switchpal == 0) { - if ((getPlayer(snum)->got_access & 1)) - getPlayer(snum)->access_incs = 1; - else FTA(70, getPlayer(snum)); + if ((p->got_access & 1)) + p->access_incs = 1; + else FTA(70, p); } else if (switchpal == 21) { - if (getPlayer(snum)->got_access & 2) - getPlayer(snum)->access_incs = 1; - else FTA(71, getPlayer(snum)); + if (p->got_access & 2) + p->access_incs = 1; + else FTA(71, p); } else if (switchpal == 23) { - if (getPlayer(snum)->got_access & 4) - getPlayer(snum)->access_incs = 1; - else FTA(72, getPlayer(snum)); + if (p->got_access & 4) + p->access_incs = 1; + else FTA(72, p); } - if (getPlayer(snum)->access_incs == 1) + if (p->access_incs == 1) { if (!act) - getPlayer(snum)->access_wall = wwal; + p->access_wall = wwal; else - getPlayer(snum)->access_spritenum = act; + p->access_spritenum = act; } return 1; @@ -306,7 +306,7 @@ void checksectors_d(int snum) auto const neartagsprite = near.actor(); if (neartagsprite != nullptr) { - if (checkhitswitch(snum, nullptr, neartagsprite)) return; + if (checkhitswitch(p, nullptr, neartagsprite)) return; if (CallOnUse(neartagsprite, p)) return; @@ -333,7 +333,7 @@ void checksectors_d(int snum) if (near.hitWall->lotag > 0 && isadoorwall(near.hitWall->walltexture)) { if (hitscanwall == near.hitWall || hitscanwall == nullptr) - checkhitswitch(snum, near.hitWall, nullptr); + checkhitswitch(p, near.hitWall, nullptr); return; } else if (p->newOwner != nullptr) @@ -364,7 +364,7 @@ void checksectors_d(int snum) } operatesectors(p->GetActor()->sector(), p->GetActor()); } - else checkhitswitch(snum, near.hitWall, nullptr); + else checkhitswitch(p, near.hitWall, nullptr); } } } diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index e2cfd5d0c..f8e5f66a9 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -49,49 +49,51 @@ BEGIN_DUKE_NS // //--------------------------------------------------------------------------- -bool checkaccessswitch_r(int snum, int switchpal, DDukeActor* act, walltype* wwal) +bool checkaccessswitch_r(DDukePlayer* const p, int switchpal, DDukeActor* act, walltype* wwal) { - if (getPlayer(snum)->access_incs == 0) + const auto pact = p->GetActor(); + + if (p->access_incs == 0) { if (switchpal == 0) { - if (getPlayer(snum)->keys[1]) - getPlayer(snum)->access_incs = 1; + if (p->keys[1]) + p->access_incs = 1; else { - FTA(70, getPlayer(snum)); - if (isRRRA()) S_PlayActorSound(99, act ? act : getPlayer(snum)->GetActor()); + FTA(70, p); + if (isRRRA()) S_PlayActorSound(99, act ? act : pact); } } else if (switchpal == 21) { - if (getPlayer(snum)->keys[2]) - getPlayer(snum)->access_incs = 1; + if (p->keys[2]) + p->access_incs = 1; else { - FTA(71, getPlayer(snum)); - if (isRRRA()) S_PlayActorSound(99, act ? act : getPlayer(snum)->GetActor()); + FTA(71, p); + if (isRRRA()) S_PlayActorSound(99, act ? act : pact); } } else if (switchpal == 23) { - if (getPlayer(snum)->keys[3]) - getPlayer(snum)->access_incs = 1; + if (p->keys[3]) + p->access_incs = 1; else { - FTA(72, getPlayer(snum)); - if (isRRRA()) S_PlayActorSound(99, act ? act : getPlayer(snum)->GetActor()); + FTA(72, p); + if (isRRRA()) S_PlayActorSound(99, act ? act : pact); } } - if (getPlayer(snum)->access_incs == 1) + if (p->access_incs == 1) { if (!act) - getPlayer(snum)->access_wall = wwal; + p->access_wall = wwal; else - getPlayer(snum)->access_spritenum = act; + p->access_spritenum = act; } return 1; } @@ -330,7 +332,7 @@ void checksectors_r(int snum) auto const neartagsprite = near.actor(); if (neartagsprite != nullptr) { - if (checkhitswitch(snum, nullptr, neartagsprite)) return; + if (checkhitswitch(p, nullptr, neartagsprite)) return; if (neartagsprite->GetClass() != RUNTIME_CLASS(DDukeActor)) { @@ -355,7 +357,7 @@ void checksectors_r(int snum) if (near.hitWall->lotag > 0 && isadoorwall(near.hitWall->walltexture)) { if (hitscanwall == near.hitWall || hitscanwall == nullptr) - checkhitswitch(snum, near.hitWall, nullptr); + checkhitswitch(p, near.hitWall, nullptr); return; } } @@ -400,7 +402,7 @@ void checksectors_r(int snum) FTA(41, p); } } - else checkhitswitch(snum, near.hitWall, nullptr); + else checkhitswitch(p, near.hitWall, nullptr); } } } diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index 7d54354a0..089d0aa59 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -1359,7 +1359,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, StartBoat, OnBoat) void pl_checkhitswitch(DDukePlayer* p, walltype* wal, DDukeActor* act) { - checkhitswitch(p->GetPlayerNum(), wal, act); + checkhitswitch(p, wal, act); } DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, checkhitswitch, pl_checkhitswitch)