From 138690d34ecf3487e1c1d2921f02b6aa024902ab Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 6 Dec 2021 00:20:46 +0100 Subject: [PATCH] - do not use auto to make local copies of TObjPtr's. This will just copy the object without performing the read barrier on the source data which is not what we want here. For these assignments the type must be explicit. --- source/common/objects/dobjgc.h | 3 +- source/games/blood/src/actor.cpp | 2 +- source/games/blood/src/nnexts.cpp | 30 ++++++++--------- source/games/blood/src/player.cpp | 22 ++++++------- source/games/blood/src/qav.cpp | 2 +- source/games/blood/src/weapon.cpp | 53 ++++++++++++++++-------------- source/games/duke/src/actors.cpp | 2 +- source/games/duke/src/actors_d.cpp | 4 +-- source/games/duke/src/actors_r.cpp | 2 +- 9 files changed, 62 insertions(+), 58 deletions(-) diff --git a/source/common/objects/dobjgc.h b/source/common/objects/dobjgc.h index bd33a896c..125070a54 100644 --- a/source/common/objects/dobjgc.h +++ b/source/common/objects/dobjgc.h @@ -185,7 +185,8 @@ class TObjPtr }; public: TObjPtr() = default; - TObjPtr(const TObjPtr &q) = default; + + TObjPtr(const TObjPtr &q) = delete; TObjPtr(T q) noexcept : pp(q) diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index efa8b7a63..f45577378 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -5992,7 +5992,7 @@ static void actCheckExplosion() for (int i = 0; i < gPhysSpritesCount; i++) { if (gPhysSpritesList[i] == nullptr) continue; - auto physactor = gPhysSpritesList[i]; + DBloodActor* physactor = gPhysSpritesList[i]; spritetype* pDebris = &physactor->s(); if (!pDebris->insector() || (pDebris->flags & kHitagFree) != 0) continue; diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 5c106f0b8..7e05fa504 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -1340,9 +1340,9 @@ void nnExtProcessSuperSprites() for (int a = connecthead; a != -1; a = connectpoint2[a]) { pPlayer = &gPlayer[a]; - auto pact = pPlayer->actor; + DBloodActor* pact = pPlayer->actor; - if (pact->hit.hit.type == kHitSprite && pact->hit.hit.actor() == debrisactor) + if (pact && pact->hit.hit.type == kHitSprite && pact->hit.hit.actor() == debrisactor) { int nSpeed = approxDist(pact->xvel, pact->yvel); nSpeed = ClipLow(nSpeed - MulScale(nSpeed, mass, 6), 0x9000 - (mass << 3)); @@ -1582,7 +1582,7 @@ int debrisGetFreeIndex(void) void debrisConcuss(DBloodActor* owneractor, int listIndex, int x, int y, int z, int dmg) { - auto actor = gPhysSpritesList[listIndex]; + DBloodActor* actor = gPhysSpritesList[listIndex]; if (actor != nullptr && actor->hasX()) { spritetype* pSprite = &actor->s(); @@ -1652,7 +1652,7 @@ void debrisBubble(DBloodActor* actor) void debrisMove(int listIndex) { - auto actor = gPhysSpritesList[listIndex]; + DBloodActor* actor = gPhysSpritesList[listIndex]; XSPRITE* pXSprite = &actor->x(); spritetype* pSprite = &actor->s(); auto pSector = pSprite->sector(); @@ -4324,21 +4324,21 @@ bool condCheckDude(DBloodActor* aCond, int cmpOp, bool PUSH) case kDudeModernCustomBurning: switch (cond) { case 20: // life leech is thrown? - { - auto act = objActor->genDudeExtra.pLifeLeech; - if (!act) return false; + { + DBloodActor* act = objActor->genDudeExtra.pLifeLeech; + if (!act) return false; else if (PUSH) condPush(aCond, act); return true; - } + } case 21: // life leech is destroyed? - { - auto act = objActor->genDudeExtra.pLifeLeech; - if (!act) return false; - if (objActor->GetSpecialOwner()) return true; + { + DBloodActor* act = objActor->genDudeExtra.pLifeLeech; + if (!act) return false; + if (objActor->GetSpecialOwner()) return true; else if (PUSH) condPush(aCond, act); return false; - } + } case 22: // are required amount of dudes is summoned? return condCmp(objActor->genDudeExtra.slaveCount, arg1, arg2, cmpOp); @@ -8400,9 +8400,9 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor) if (hearDist) { - auto act = pPlayer->actor; + DBloodActor* act = pPlayer->actor; itCanHear = (!deaf && (nDist < hearDist || hearChance > 0)); - if (itCanHear && nDist < feelDist && (act->xvel || act->yvel || act->zvel)) + if (act && itCanHear && nDist < feelDist && (act->xvel || act->yvel || act->zvel)) hearChance += ClipLow(mulscale8(1, ClipLow(((feelDist - nDist) + (abs(act->xvel) + abs(act->yvel) + abs(act->zvel))) >> 6, 0)), 0); } diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index ef0b47072..9ca6d5d5b 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -753,7 +753,7 @@ void playerStart(int nPlayer, int bNewLevel) XSPRITE* pXCtrl = &iactor->x(); if (pXCtrl->data1 == pPlayer->nPlayer + 1) { - auto SpriteOld = iactor->prevmarker; + DBloodActor* SpriteOld = iactor->prevmarker; trPlayerCtrlLink(iactor, pPlayer, (SpriteOld == nullptr)); // this modifies iactor's prevmarker field! if (SpriteOld) condUpdateObjectIndex(SpriteOld, iactor->prevmarker); @@ -1355,7 +1355,7 @@ void ProcessInput(PLAYER *pPlayer) pPlayer->horizon.resetadjustment(); pPlayer->angle.resetadjustment(); - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; spritetype *pSprite = pPlayer->pSprite; XSPRITE *pXSprite = pPlayer->pXSprite; POSTURE *pPosture = &pPlayer->pPosture[pPlayer->lifeMode][pPlayer->posture]; @@ -1373,7 +1373,7 @@ void ProcessInput(PLAYER *pPlayer) if (pXSprite->health == 0) { bool bSeqStat = playerSeqPlaying(pPlayer, 16); - auto fragger = pPlayer->fragger; + DBloodActor* fragger = pPlayer->fragger; if (fragger) { pPlayer->angle.addadjustment(getincanglebam(pPlayer->angle.ang, bvectangbam(fragger->s().x - pSprite->x, fragger->s().y - pSprite->y))); @@ -1577,14 +1577,14 @@ void ProcessInput(PLAYER *pPlayer) pPlayer->handTime = ClipLow(pPlayer->handTime-4*(6-gGameOptions.nDifficulty), 0); if (pPlayer->handTime <= 0 && pPlayer->hand) { - auto pactor = pPlayer->actor; + DBloodActor* pactor = pPlayer->actor; auto spawned = actSpawnDude(pactor, kDudeHand, pPlayer->pSprite->clipdist<<1, 0); if (spawned) { - spritetype* pSprite2 = &spawned->s(); + spritetype* pSprite2 = &spawned->s(); pSprite2->ang = (pPlayer->pSprite->ang + 1024) & 2047; - int x = bcos(pPlayer->pSprite->ang); - int y = bsin(pPlayer->pSprite->ang); + int x = bcos(pPlayer->pSprite->ang); + int y = bsin(pPlayer->pSprite->ang); spawned->xvel = pPlayer->actor->xvel + MulScale(0x155555, x, 14); spawned->yvel = pPlayer->actor->yvel + MulScale(0x155555, y, 14); spawned->zvel = pPlayer->actor->zvel; @@ -1660,7 +1660,7 @@ void ProcessInput(PLAYER *pPlayer) void playerProcess(PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; spritetype *pSprite = pPlayer->pSprite; XSPRITE *pXSprite = pPlayer->pXSprite; POSTURE* pPosture = &pPlayer->pPosture[pPlayer->lifeMode][pPlayer->posture]; @@ -1902,7 +1902,7 @@ int playerDamageArmor(PLAYER *pPlayer, DAMAGE_TYPE nType, int nDamage) void flagDropped(PLAYER *pPlayer, int a2) { - auto playeractor = pPlayer->actor; + DBloodActor* playeractor = pPlayer->actor; DBloodActor* actor; char buffer[80]; switch (a2) @@ -1938,7 +1938,7 @@ int playerDamageSprite(DBloodActor* source, PLAYER *pPlayer, DAMAGE_TYPE nDamage spritetype *pSprite = pPlayer->pSprite; XSPRITE *pXSprite = pPlayer->pXSprite; - auto pActor = pPlayer->actor; + DBloodActor* pActor = pPlayer->actor; DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type); int nDeathSeqID = -1; int nKneelingPlayer = -1; @@ -2104,7 +2104,7 @@ int UseAmmo(PLAYER *pPlayer, int nAmmoType, int nDec) void voodooTarget(PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; int v4 = pPlayer->aim.dz; int dz = pPlayer->zWeapon-pPlayer->pSprite->z; if (UseAmmo(pPlayer, 9, 0) < 8) diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index f3ee785f1..58150e09c 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -204,7 +204,7 @@ void QAV::Draw(double x, double y, int ticks, int stat, int shade, int palnum, b void QAV::Play(int start, int end, int nCallback, PLAYER *pData) { - auto pActor = pData ? pData->actor : nullptr; + auto pActor = pData ? pData->actor.Get() : nullptr; assert(ticksPerFrame > 0); int frame; int ticks; diff --git a/source/games/blood/src/weapon.cpp b/source/games/blood/src/weapon.cpp index 840d8f002..6f1f66e02 100644 --- a/source/games/blood/src/weapon.cpp +++ b/source/games/blood/src/weapon.cpp @@ -173,7 +173,7 @@ static bool BannedUnderwater(int nWeapon) return nWeapon == kWeapSpraycan || nWeapon == kWeapDynamite; } -static bool CheckWeaponAmmo(PLAYER *pPlayer, int weapon, int ammotype, int count) +static bool CheckWeaponAmmo(const PLAYER *pPlayer, int weapon, int ammotype, int count) { if (gInfiniteAmmo) return 1; @@ -186,7 +186,7 @@ static bool CheckWeaponAmmo(PLAYER *pPlayer, int weapon, int ammotype, int count return pPlayer->ammoCount[ammotype] >= count; } -static bool CheckAmmo(PLAYER *pPlayer, int ammotype, int count) +static bool CheckAmmo(const PLAYER *pPlayer, int ammotype, int count) { if (gInfiniteAmmo) return 1; @@ -199,7 +199,7 @@ static bool CheckAmmo(PLAYER *pPlayer, int ammotype, int count) return pPlayer->ammoCount[ammotype] >= count; } -static bool checkAmmo2(PLAYER *pPlayer, int ammotype, int amount) +static bool checkAmmo2(const PLAYER *pPlayer, int ammotype, int amount) { if (gInfiniteAmmo) return 1; @@ -1059,7 +1059,7 @@ void WeaponUpdateState(PLAYER *pPlayer) void FirePitchfork(int, PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; Aim *aim = &pPlayer->aim; int r1 = Random2(2000); int r2 = Random2(2000); @@ -1216,7 +1216,7 @@ enum { kMaxShotgunBarrels = 4 }; void FireShotgun(int nTrigger, PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; assert(nTrigger > 0 && nTrigger <= kMaxShotgunBarrels); if (nTrigger == 1) { @@ -1263,7 +1263,7 @@ void EjectShell(int, PLAYER *pPlayer) void FireTommy(int nTrigger, PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; Aim *aim = &pPlayer->aim; sfxPlay3DSound(pPlayer->actor, 431, -1, 0); switch (nTrigger) @@ -1302,7 +1302,7 @@ enum { kMaxSpread = 14 }; void FireSpread(int nTrigger, PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; assert(nTrigger > 0 && nTrigger <= kMaxSpread); Aim *aim = &pPlayer->aim; int angle = (getangle(aim->dx, aim->dy)+((112*(nTrigger-1))/14-56))&2047; @@ -1324,7 +1324,7 @@ void FireSpread(int nTrigger, PLAYER *pPlayer) void AltFireSpread(int nTrigger, PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; assert(nTrigger > 0 && nTrigger <= kMaxSpread); Aim *aim = &pPlayer->aim; int angle = (getangle(aim->dx, aim->dy)+((112*(nTrigger-1))/14-56))&2047; @@ -1354,7 +1354,7 @@ void AltFireSpread(int nTrigger, PLAYER *pPlayer) void AltFireSpread2(int nTrigger, PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; assert(nTrigger > 0 && nTrigger <= kMaxSpread); Aim *aim = &pPlayer->aim; int angle = (getangle(aim->dx, aim->dy)+((112*(nTrigger-1))/14-56))&2047; @@ -1447,15 +1447,15 @@ void AltFireFlare(int nTrigger, PLAYER *pPlayer) void FireVoodoo(int nTrigger, PLAYER *pPlayer) { nTrigger--; - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; spritetype *pSprite = pPlayer->pSprite; if (nTrigger == 4) { actDamageSprite(actor, actor, kDamageBullet, 1<<4); return; } - assert(pPlayer->voodooTarget != nullptr); - auto targetactor = pPlayer->voodooTarget; + DBloodActor* targetactor = pPlayer->voodooTarget; + if (!targetactor) return; spritetype *pTarget = &targetactor->s(); if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pPlayer, pTarget)) return; @@ -1505,7 +1505,7 @@ void FireVoodoo(int nTrigger, PLAYER *pPlayer) void AltFireVoodoo(int nTrigger, PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; if (nTrigger == 2) { // by NoOne: trying to simulate v1.0x voodoo here. @@ -1516,7 +1516,8 @@ void AltFireVoodoo(int nTrigger, PLAYER *pPlayer) { for (int i = 0; i < pPlayer->aimTargetsCount; i++) { - auto targetactor = pPlayer->aimTargets[i]; + DBloodActor* targetactor = pPlayer->aimTargets[i]; + if (!targetactor) continue; spritetype* pTarget = &targetactor->s(); if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pPlayer, pTarget)) continue; @@ -1552,7 +1553,8 @@ void AltFireVoodoo(int nTrigger, PLAYER *pPlayer) int v4 = pPlayer->ammoCount[9] - (pPlayer->ammoCount[9] / nCount) * nCount; for (int i = 0; i < pPlayer->aimTargetsCount; i++) { - auto targetactor = pPlayer->aimTargets[i]; + DBloodActor* targetactor = pPlayer->aimTargets[i]; + if (!targetactor) continue; spritetype* pTarget = &targetactor->s(); if (!gGameOptions.bFriendlyFire && IsTargetTeammate(pPlayer, pTarget)) continue; @@ -1706,7 +1708,7 @@ void FireLifeLeech(int nTrigger, PLAYER *pPlayer) int r1 = Random2(2000); int r2 = Random2(2000); int r3 = Random2(1000); - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; auto missileActor = playerFireMissile(pPlayer, 0, pPlayer->aim.dx+r1, pPlayer->aim.dy+r2, pPlayer->aim.dz+r3, 315); if (missileActor) { @@ -1722,7 +1724,7 @@ void FireLifeLeech(int nTrigger, PLAYER *pPlayer) void AltFireLifeLeech(int , PLAYER *pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; sfxPlay3DSound(pPlayer->actor, 455, 2, 0); auto missile = playerFireThing(pPlayer, 0, -4730, kThingDroppedLifeLeech, 0x19999); if (missile) @@ -1758,7 +1760,7 @@ void AltFireLifeLeech(int , PLAYER *pPlayer) void FireBeast(int , PLAYER * pPlayer) { - auto actor = pPlayer->actor; + DBloodActor* actor = pPlayer->actor; int r1 = Random2(2000); int r2 = Random2(2000); int r3 = Random2(2000); @@ -1792,7 +1794,7 @@ int WeaponUpgrade(PLAYER *pPlayer, int newWeapon) int OrderNext[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 1 }; int OrderPrev[] = { 12, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1 }; -static int WeaponFindNext(PLAYER *pPlayer, int *a2, int bDir) +static int WeaponFindNext(const PLAYER *pPlayer, int *a2, int bDir) { int weapon = pPlayer->curWeapon; do @@ -1825,7 +1827,7 @@ static int WeaponFindNext(PLAYER *pPlayer, int *a2, int bDir) return weapon; } -static int WeaponFindLoaded(PLAYER *pPlayer, int *a2) +static int WeaponFindLoaded(const PLAYER *pPlayer, int *a2) { int v4 = 1; int v14 = 0; @@ -2246,18 +2248,19 @@ void WeaponProcess(PLAYER *pPlayer) { { if (prevNewWeaponVal == WeaponSel_Next || prevNewWeaponVal == WeaponSel_Prev) // if player switched weapons { - PLAYER tmpPlayer = *pPlayer; - tmpPlayer.curWeapon = pPlayer->newWeapon; // set current banned weapon to curweapon so WeaponFindNext() can find the next weapon + int saveweapon = pPlayer->curWeapon; + pPlayer->curWeapon = pPlayer->newWeapon; // set current banned weapon to curweapon so WeaponFindNext() can find the next weapon for (int i = 0; i < 3; i++) // attempt twice to find a new weapon { - tmpPlayer.curWeapon = WeaponFindNext(&tmpPlayer, NULL, (char)(prevNewWeaponVal == WeaponSel_Next)); - if (!BannedUnderwater(tmpPlayer.curWeapon)) // if new weapon is not a banned weapon, set to new current weapon + pPlayer->curWeapon = WeaponFindNext(pPlayer, NULL, (char)(prevNewWeaponVal == WeaponSel_Next)); + if (!BannedUnderwater(pPlayer->curWeapon)) // if new weapon is not a banned weapon, set to new current weapon { - pPlayer->newWeapon = tmpPlayer.curWeapon; + pPlayer->newWeapon = pPlayer->curWeapon; pPlayer->weaponMode[pPlayer->newWeapon] = 0; break; } } + pPlayer->curWeapon = saveweapon; } } if (pPlayer->newWeapon == kWeapDynamite) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 18c99c741..b09680995 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -5162,7 +5162,7 @@ void alterang(int ang, DDukeActor* actor, int playernum) s->ang = WindDir; else if (ang & seekplayer) { - auto holoduke = !isRR()? ps[playernum].holoduke_on : nullptr; + DDukeActor* holoduke = !isRR()? ps[playernum].holoduke_on.Get() : nullptr; // NOTE: looks like 'Owner' is set to target sprite ID... diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 1177928d8..a2fb9f3a7 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1461,7 +1461,7 @@ static bool movefireball(DDukeActor* actor) if (actor->temp_data[0] >= 1 && actor->temp_data[0] < 6) { float siz = 1.0f - (actor->temp_data[0] * 0.2f); - auto trail = actor->temp_actor; + DDukeActor* trail = actor->temp_actor; auto ball = spawn(actor, FIREBALL); if (ball) { @@ -2474,7 +2474,7 @@ static void greenslime(DDukeActor *actor) if (t[0] == -2) //On top of somebody (an enemy) { - auto s5 = actor->temp_actor; + DDukeActor* s5 = actor->temp_actor; makeitfall(actor); if (s5) { diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 2474db293..2b1bbe5dd 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -1090,7 +1090,7 @@ static void chickenarrow(DDukeActor* actor) spawn(actor, MONEY); } } - auto ts = actor->seek_actor; + DDukeActor* ts = actor->seek_actor; if (!ts) return; if (ts->s->extra <= 0)