From f216857f55f11dacff135688b7f84595ba9a6119 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 21 Dec 2021 22:28:13 +0100 Subject: [PATCH] - Getting rid of DDukeActor::s, part 1. --- source/games/duke/src/animatesprites_d.cpp | 47 ++++++++++--------- source/games/duke/src/animatesprites_r.cpp | 53 +++++++++++----------- source/games/duke/src/dukeactor.h | 10 ---- source/games/duke/src/inlines.h | 22 ++++----- source/games/duke/src/sectors_r.cpp | 1 - source/games/duke/src/sounds.cpp | 6 +-- source/games/duke/src/types.h | 8 ++-- 7 files changed, 65 insertions(+), 82 deletions(-) diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index d35a1bfdb..24b169185 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -142,7 +142,6 @@ void animatesprites_d(tspritetype* tsprite, int& spritesortcnt, int x, int y, in t = &tsprite[j]; h = static_cast(t->ownerActor); auto OwnerAc = h->GetOwner(); - auto Owner = OwnerAc ? OwnerAc->s : nullptr; switch (h->spr.picnum) { @@ -204,33 +203,33 @@ void animatesprites_d(tspritetype* tsprite, int& spritesortcnt, int x, int y, in case TRIPBOMB: continue; case FORCESPHERE: - if (t->statnum == STAT_MISC && Owner) + if (t->statnum == STAT_MISC && OwnerAc) { int sqa = getangle( - Owner->x - ps[screenpeek].pos.x, - Owner->y - ps[screenpeek].pos.y); + OwnerAc->spr.x - ps[screenpeek].pos.x, + OwnerAc->spr.y - ps[screenpeek].pos.y); int sqb = getangle( - Owner->x - t->x, - Owner->y - t->y); + OwnerAc->spr.x - t->x, + OwnerAc->spr.y - t->y); if (abs(getincangle(sqa, sqb)) > 512) - if (ldist(Owner, t) < ldist(ps[screenpeek].GetActor()->s, Owner)) + if (ldist(OwnerAc, t) < ldist(ps[screenpeek].GetActor(), OwnerAc)) t->xrepeat = t->yrepeat = 0; } continue; case BURNING: case BURNING2: - if (Owner && Owner->statnum == STAT_PLAYER) + if (OwnerAc && OwnerAc->spr.statnum == STAT_PLAYER) { - if (display_mirror == 0 && Owner->yvel == screenpeek && ps[screenpeek].over_shoulder_on == 0) + if (display_mirror == 0 && OwnerAc->spr.yvel == screenpeek && ps[screenpeek].over_shoulder_on == 0) t->xrepeat = 0; else { t->ang = getangle(x - t->x, y - t->y); - t->x = Owner->x; - t->y = Owner->y; + t->x = OwnerAc->spr.x; + t->y = OwnerAc->spr.y; t->x += bcos(t->ang, -10); t->y += bsin(t->ang, -10); } @@ -628,9 +627,9 @@ void animatesprites_d(tspritetype* tsprite, int& spritesortcnt, int x, int y, in switch (h->spr.picnum) { case LASERLINE: - if (!Owner) break; + if (!OwnerAc) break; if (t->sector()->lotag == 2) t->pal = 8; - t->z = Owner->z - (3 << 8); + t->z = OwnerAc->spr.z - (3 << 8); if (gs.lasermode == 2 && ps[screenpeek].heat_on == 0) t->yrepeat = 0; [[fallthrough]]; @@ -658,8 +657,8 @@ void animatesprites_d(tspritetype* tsprite, int& spritesortcnt, int x, int y, in [[fallthrough]]; case BURNING: case BURNING2: - if (!Owner) break; - if (Owner->picnum != TREE1 && Owner->picnum != TREE2) + if (!OwnerAc) break; + if (OwnerAc->spr.picnum != TREE1 && OwnerAc->spr.picnum != TREE2) t->z = t->sector()->floorz; t->shade = -127; break; @@ -685,7 +684,7 @@ void animatesprites_d(tspritetype* tsprite, int& spritesortcnt, int x, int y, in } t->picnum = h->spr.picnum + k + ((h->temp_data[0] < 4) * 5); - if (Owner) t->shade = Owner->shade; + if (OwnerAc) t->shade = OwnerAc->spr.shade; break; @@ -704,22 +703,22 @@ void animatesprites_d(tspritetype* tsprite, int& spritesortcnt, int x, int y, in if (h->temp_data[0] > 2) t->cstat &= ~(CSTAT_SPRITE_XFLIP | CSTAT_SPRITE_YFLIP); break; case FRAMEEFFECT1: - if (Owner && Owner->statnum < MAXSTATUS) + if (OwnerAc && OwnerAc->spr.statnum < MAXSTATUS) { - if (Owner->picnum == APLAYER) + if (OwnerAc->spr.picnum == APLAYER) if (ud.cameraactor == nullptr) - if (screenpeek == Owner->yvel && display_mirror == 0) + if (screenpeek == OwnerAc->spr.yvel && display_mirror == 0) { t->ownerActor = nullptr; break; } - if ((Owner->cstat & CSTAT_SPRITE_INVISIBLE) == 0) + if ((OwnerAc->spr.cstat & CSTAT_SPRITE_INVISIBLE) == 0) { t->picnum = OwnerAc->dispicnum; - t->pal = Owner->pal; - t->shade = Owner->shade; - t->ang = Owner->ang; - t->cstat = CSTAT_SPRITE_TRANSLUCENT | Owner->cstat; + t->pal = OwnerAc->spr.pal; + t->shade = OwnerAc->spr.shade; + t->ang = OwnerAc->spr.ang; + t->cstat = CSTAT_SPRITE_TRANSLUCENT | OwnerAc->spr.cstat; } } break; diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index ea99622d4..be8ba127c 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -127,7 +127,6 @@ void animatesprites_r(tspritetype* tsprite, int& spritesortcnt, int x, int y, in t = &tsprite[j]; h = static_cast(t->ownerActor); auto OwnerAc = h->GetOwner(); - auto Owner = OwnerAc ? OwnerAc->s : nullptr; switch (h->spr.picnum) { @@ -198,32 +197,32 @@ void animatesprites_r(tspritetype* tsprite, int& spritesortcnt, int x, int y, in case TRIPBOMBSPRITE: continue; case FORCESPHERE: - if (t->statnum == STAT_MISC && Owner) + if (t->statnum == STAT_MISC && OwnerAc) { int sqa = getangle( - Owner->x - ps[screenpeek].pos.x, - Owner->y - ps[screenpeek].pos.y); + OwnerAc->spr.x - ps[screenpeek].pos.x, + OwnerAc->spr.y - ps[screenpeek].pos.y); int sqb = getangle( - Owner->x - t->x, - Owner->y - t->y); + OwnerAc->spr.x - t->x, + OwnerAc->spr.y - t->y); if (abs(getincangle(sqa, sqb)) > 512) - if (ldist(Owner, t) < ldist(ps[screenpeek].GetActor()->s, Owner)) + if (ldist(OwnerAc, t) < ldist(ps[screenpeek].GetActor(), OwnerAc)) t->xrepeat = t->yrepeat = 0; } continue; case BURNING: - if (Owner && Owner->statnum == STAT_PLAYER) + if (OwnerAc && OwnerAc->spr.statnum == STAT_PLAYER) { - if (display_mirror == 0 && Owner->yvel == screenpeek && ps[Owner->yvel].over_shoulder_on == 0) + if (display_mirror == 0 && OwnerAc->spr.yvel == screenpeek && ps[OwnerAc->spr.yvel].over_shoulder_on == 0) t->xrepeat = 0; else { t->ang = getangle(x - t->x, y - t->y); - t->x = Owner->x; - t->y = Owner->y; + t->x = OwnerAc->spr.x; + t->y = OwnerAc->spr.y; t->x += bcos(t->ang, -10); t->y += bsin(t->ang, -10); } @@ -237,7 +236,7 @@ void animatesprites_r(tspritetype* tsprite, int& spritesortcnt, int x, int y, in t->shade = bsin(PlayClock << 4, -10); break; case SHRINKSPARK: - if (Owner && (Owner->picnum == CHEER || Owner->picnum == CHEERSTAYPUT) && isRRRA()) + if (OwnerAc && (OwnerAc->spr.picnum == CHEER || OwnerAc->spr.picnum == CHEERSTAYPUT) && isRRRA()) { t->picnum = CHEERBLADE + ((PlayClock >> 4) & 3); t->shade = -127; @@ -253,16 +252,16 @@ void animatesprites_r(tspritetype* tsprite, int& spritesortcnt, int x, int y, in } else goto default_case; case SPIT: - if (isRRRA() && Owner) + if (isRRRA() && OwnerAc) { - if (Owner->picnum == MINION && Owner->pal == 8) + if (OwnerAc->spr.picnum == MINION && OwnerAc->spr.pal == 8) t->picnum = RRTILE3500 + ((PlayClock >> 4) % 6); - else if (Owner->picnum == MINION && Owner->pal == 19) + else if (OwnerAc->spr.picnum == MINION && OwnerAc->spr.pal == 19) { t->picnum = RRTILE5090 + ((PlayClock >> 4) & 3); t->shade = -127; } - else if (Owner->picnum == MAMA) + else if (OwnerAc->spr.picnum == MAMA) { k = getangle(h->spr.x - x, h->spr.y - y); k = (((h->spr.ang + 3072 + 128 - k) & 2047) >> 8) & 7; @@ -814,7 +813,7 @@ void animatesprites_r(tspritetype* tsprite, int& spritesortcnt, int x, int y, in break; case FIRE: case BURNING: - if (Owner && Owner->picnum != TREE1 && Owner->picnum != TREE2) + if (OwnerAc && OwnerAc->spr.picnum != TREE1 && OwnerAc->spr.picnum != TREE2) t->z = t->sector()->floorz; t->shade = -127; break; @@ -913,7 +912,7 @@ void animatesprites_r(tspritetype* tsprite, int& spritesortcnt, int x, int y, in else t->cstat &= ~CSTAT_SPRITE_XFLIP; t->picnum = h->spr.picnum + k + ((h->temp_data[0] < 4) * 5); - if (Owner) t->shade = Owner->shade; + if (OwnerAc) t->shade = OwnerAc->spr.shade; break; case MUD: t->picnum = MUD + t1; @@ -933,25 +932,25 @@ void animatesprites_r(tspritetype* tsprite, int& spritesortcnt, int x, int y, in if (h->temp_data[0] > 2) t->cstat &= ~CSTAT_SPRITE_XFLIP | CSTAT_SPRITE_YFLIP; break; case FRAMEEFFECT1: - if (Owner && Owner->statnum < MAXSTATUS) + if (OwnerAc && OwnerAc->spr.statnum < MAXSTATUS) { - if (Owner->picnum == APLAYER) + if (OwnerAc->spr.picnum == APLAYER) if (ud.cameraactor == nullptr) - if (screenpeek == Owner->yvel && display_mirror == 0) + if (screenpeek == OwnerAc->spr.yvel && display_mirror == 0) { t->ownerActor = nullptr; break; } - if ((Owner->cstat & CSTAT_SPRITE_INVISIBLE) == 0) + if ((OwnerAc->spr.cstat & CSTAT_SPRITE_INVISIBLE) == 0) { - if (Owner->picnum == APLAYER) + if (OwnerAc->spr.picnum == APLAYER) t->picnum = 1554; else t->picnum = OwnerAc->dispicnum; - t->pal = Owner->pal; - t->shade = Owner->shade; - t->ang = Owner->ang; - t->cstat = CSTAT_SPRITE_TRANSLUCENT | Owner->cstat; + t->pal = OwnerAc->spr.pal; + t->shade = OwnerAc->spr.shade; + t->ang = OwnerAc->spr.ang; + t->cstat = CSTAT_SPRITE_TRANSLUCENT | OwnerAc->spr.cstat; } } break; diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h index 4fd14fccf..f93e8d976 100644 --- a/source/games/duke/src/dukeactor.h +++ b/source/games/duke/src/dukeactor.h @@ -21,16 +21,6 @@ inline int player_struct::GetPlayerNum() DDukeActor* spawn(DDukeActor* spawner, int type); -inline int ldist(DDukeActor* s1, DDukeActor* s2) -{ - return ldist(s1->s, s2->s); -} - -inline int dist(DDukeActor* s1, DDukeActor* s2) -{ - return dist(s1->s, s2->s); -} - inline int badguy(DDukeActor* pSprite) { return badguypic(pSprite->spr.picnum); diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 634cd528d..546d17808 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -81,29 +81,27 @@ inline int checkcursectnums(sectortype* se) return -1; } -// These are from duke's sector.c -inline int ldist(const spritetype* s1, const spritetype* s2) +inline int ldist(DDukeActor* s1, DDukeActor* s2) { int vx, vy; - vx = s1->x - s2->x; - vy = s1->y - s2->y; + vx = s1->spr.x - s2->spr.x; + vy = s1->spr.y - s2->spr.y; return(FindDistance2D(vx, vy) + 1); } -inline int ldist(const spritetype* s1, const tspritetype* s2) +inline int ldist(const DDukeActor* s1, const tspritetype* s2) { int vx, vy; - vx = s1->x - s2->x; - vy = s1->y - s2->y; + vx = s1->spr.x - s2->x; + vy = s1->spr.y - s2->y; return(FindDistance2D(vx, vy) + 1); } - -inline int dist(const spritetype* s1, const spritetype* s2) +inline int dist(DDukeActor* s1, DDukeActor* s2) { int vx, vy, vz; - vx = s1->x - s2->x; - vy = s1->y - s2->y; - vz = s1->z - s2->z; + vx = s1->spr.x - s2->spr.x; + vy = s1->spr.y - s2->spr.y; + vz = s1->spr.z - s2->spr.z; return(FindDistance3D(vx, vy, vz)); } diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 6641df729..3d339e0ca 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -984,7 +984,6 @@ void checkhitwall_r(DDukeActor* spr, walltype* wal, int x, int y, int z, int atw { int j; int sn = -1, darkestwall; - spritetype* s; if (wal->overpicnum == MIRROR) { diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index f57c39735..20b2fa5ac 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -354,11 +354,9 @@ void DukeSoundEngine::CalcPosVel(int type, const void* source, const float pt[3] else if (type == SOURCE_Actor) { auto aactor = (DDukeActor*)source; - auto aspr = aactor ? aactor->s : nullptr; - assert(aspr != nullptr); - if (aspr != nullptr) + if (aactor != nullptr) { - GetPositionInfo(aactor, chanSound - 1, camsect, campos, &aspr->pos, nullptr, pos); + GetPositionInfo(aactor, chanSound - 1, camsect, campos, &aactor->spr.pos, nullptr, pos); /* if (vel) // DN3D does not properly maintain this. { diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index af0058aee..e34ef3e67 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -50,9 +50,9 @@ public: sectortype* temp_sect, *actorstayput; TObjPtr temp_actor, seek_actor; - spritetype* s; // direct reference to the corresponding sprite. TArray uservars; + spritetype* s; // Todo: Once we start assigning subclasses to actors, this one needs to be moved to the proper FIREBALL subclass. FireProj fproj; @@ -95,19 +95,19 @@ public: inline bool IsActiveCrane() { - return s->owner == -2; + return spr.owner == -2; } inline void SetActiveCrane(bool yes) { ownerActor = nullptr; - s->owner = yes ? -2 : -1; + spr.owner = yes ? -2 : -1; } int PlayerIndex() const { // only valid for real players - just here to abstract yvel. - return s->yvel; + return spr.yvel; } void Serialize(FSerializer& arc) override;