From d088ab05a923316a90fdf0600c5a320ef07a9592 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 5 Dec 2021 17:35:23 +0100 Subject: [PATCH] - eliminate storage of actors in the sector's hitag for some of Duke's sector effectors. Also demoted Blood's upperLink and lowerLink to DCoreActor pointers and use static_cast for access to avoid savegame problems. The core code cannot safely serialize a DBloodActor anymore. --- source/build/include/buildtypes.h | 4 ++-- source/core/savegamehelp.cpp | 9 ++++----- source/games/blood/src/actor.cpp | 2 +- source/games/blood/src/gameutil.cpp | 12 ++++++------ source/games/blood/src/mirrors.cpp | 2 +- source/games/blood/src/nnexts.cpp | 8 ++++---- source/games/blood/src/warp.cpp | 19 ++++++++++--------- source/games/duke/src/sectors.cpp | 4 ++-- source/games/duke/src/spawn.cpp | 4 ++-- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/source/build/include/buildtypes.h b/source/build/include/buildtypes.h index 1362ac318..f0493db79 100644 --- a/source/build/include/buildtypes.h +++ b/source/build/include/buildtypes.h @@ -53,7 +53,6 @@ enum BEGIN_BLD_NS struct XWALL; struct XSECTOR; - class DBloodActor; END_BLD_NS //40 bytes @@ -98,11 +97,12 @@ struct sectortype { uint8_t keyinfo; uint8_t shadedsector; + DCoreActor* hitagactor; // we need this because Duke stores an actor in the hitag field. Is really a DDukeActor, but cannot be declared here safely. }; struct // Blood { BLD_NS::XSECTOR* _xs; - BLD_NS::DBloodActor* upperLink, *lowerLink; + DCoreActor* upperLink, *lowerLink; int baseFloor, baseCeil; int velFloor, velCeil; uint8_t slopewallofs; diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index 8d2f2c54f..47ba6f8d0 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -79,11 +79,8 @@ void SerializeMap(FSerializer &arc); CVAR(String, cl_savedir, "", CVAR_ARCHIVE | CVAR_GLOBALCONFIG) BEGIN_BLD_NS - FSerializer& Serialize(FSerializer& arc, const char* keyname, XWALL& w, XWALL* def); FSerializer& Serialize(FSerializer& arc, const char* keyname, XSECTOR& w, XSECTOR* def); -FSerializer& Serialize(FSerializer& arc, const char* keyname, DBloodActor*& w, DBloodActor** def); - END_BLD_NS //============================================================================= @@ -541,8 +538,10 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sectortype &c, sectort // Save the extensions only when playing their respective games. if (isDukeLike()) { - arc("keyinfo", c.keyinfo, def->keyinfo); - arc("shadedsector", c.shadedsector, def->shadedsector); + arc("keyinfo", c.keyinfo, def->keyinfo) + ("shadedsector", c.shadedsector, def->shadedsector) + ("hitagactor", c.hitagactor, def->hitagactor); + } else if (isBlood()) { diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index 810e9ec92..0d20b550c 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -5076,7 +5076,7 @@ void MoveDude(DBloodActor* actor) if (gModernMap) { pPlayer->nWaterPal = 0; - auto pUpper = pSector->upperLink; + auto pUpper = static_cast(pSector->upperLink); if (pUpper && pUpper->hasX()) pPlayer->nWaterPal = pUpper->x().data2; } #endif diff --git a/source/games/blood/src/gameutil.cpp b/source/games/blood/src/gameutil.cpp index 4211418f1..482889de7 100644 --- a/source/games/blood/src/gameutil.cpp +++ b/source/games/blood/src/gameutil.cpp @@ -523,7 +523,7 @@ int VectorScan(DBloodActor *actor, int nOffset, int nZOffset, int dx, int dy, in { if (dz > 0) { - auto actor = gHitInfo.hitSector->upperLink; + auto actor = static_cast(gHitInfo.hitSector->upperLink); if (!actor) return 2; auto link = actor->GetOwner(); gHitInfo.clearObj(); @@ -537,7 +537,7 @@ int VectorScan(DBloodActor *actor, int nOffset, int nZOffset, int dx, int dy, in } else { - auto actor = gHitInfo.hitSector->lowerLink; + auto actor = static_cast(gHitInfo.hitSector->lowerLink); if (!actor) return 1; auto link = actor->GetOwner(); gHitInfo.clearObj(); @@ -574,7 +574,7 @@ void GetZRange(DBloodActor *actor, int *ceilZ, Collision *ceilColl, int *floorZ, XSECTOR *pXSector = &pSector->xs(); *floorZ += pXSector->Depth << 10; } - auto actor = pSector->upperLink; + auto actor = static_cast(pSector->upperLink); if (actor) { auto link = actor->GetOwner(); @@ -588,7 +588,7 @@ void GetZRange(DBloodActor *actor, int *ceilZ, Collision *ceilColl, int *floorZ, auto pSector = ceilColl->hitSector; if ((nClipParallax & PARALLAXCLIP_CEILING) == 0 && (pSector->ceilingstat & 1)) *ceilZ = 0x80000000; - auto actor = pSector->lowerLink; + auto actor = static_cast(pSector->lowerLink); if (actor) { auto link = actor->GetOwner(); @@ -616,7 +616,7 @@ void GetZRangeAtXYZ(int x, int y, int z, sectortype* pSector, int *ceilZ, Collis XSECTOR* pXSector = &pSector->xs(); *floorZ += pXSector->Depth << 10; } - auto actor = pSector->upperLink; + auto actor = static_cast(pSector->upperLink); if (actor) { auto link = actor->GetOwner(); @@ -630,7 +630,7 @@ void GetZRangeAtXYZ(int x, int y, int z, sectortype* pSector, int *ceilZ, Collis auto pSector = ceilColl->hitSector; if ((nClipParallax & PARALLAXCLIP_CEILING) == 0 && (pSector->ceilingstat & 1)) *ceilZ = 0x80000000; - auto actor = pSector->lowerLink; + auto actor = static_cast(pSector->lowerLink); if (actor) { auto link = actor->GetOwner(); diff --git a/source/games/blood/src/mirrors.cpp b/source/games/blood/src/mirrors.cpp index c00e84c2d..cd12a683c 100644 --- a/source/games/blood/src/mirrors.cpp +++ b/source/games/blood/src/mirrors.cpp @@ -113,7 +113,7 @@ void InitMirrors(void) auto secti = §or[i]; if (secti->floorpicnum == 504) { - auto link = secti->upperLink; + auto link = static_cast(secti->upperLink); if (link == nullptr) continue; auto link2 = link->GetOwner(); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 58133d0c9..ded572342 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -2846,7 +2846,7 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, sectortype* pSe spritetype* pUpper = NULL; XSPRITE* pXUpper = NULL; - auto aLower = pSector->lowerLink; + auto aLower = static_cast(pSector->lowerLink); spritetype* pLower = nullptr; XSPRITE* pXLower = nullptr; if (aLower) @@ -2857,7 +2857,7 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, sectortype* pSe // must be sure we found exact same upper link for (auto& sec : sectors()) { - auto aUpper = sec.upperLink; + auto aUpper = static_cast(sec.upperLink); if (aUpper == nullptr || aUpper->x().data1 != pXLower->data1) continue; pUpper = &aUpper->s(); pXUpper = &aUpper->x(); @@ -3022,14 +3022,14 @@ void useTeleportTarget(DBloodActor* sourceactor, DBloodActor* actor) if (pXSector->Underwater) { - auto aLink = pSource->sector()->lowerLink; + auto aLink = static_cast(pSource->sector()->lowerLink); spritetype* pLink = nullptr; if (aLink) { // must be sure we found exact same upper link for(auto& sec : sectors()) { - auto aUpper = sec.upperLink; + auto aUpper = static_cast(sec.upperLink); if (aUpper == nullptr || aUpper->x().data1 != aLink->x().data1) continue; pLink = &aLink->s(); break; diff --git a/source/games/blood/src/warp.cpp b/source/games/blood/src/warp.cpp index 65811b239..6e17dc5a1 100644 --- a/source/games/blood/src/warp.cpp +++ b/source/games/blood/src/warp.cpp @@ -40,13 +40,14 @@ void validateLinks() int snum = 0; for (auto& sect : sectors()) { - - if (sect.upperLink && !sect.upperLink->GetOwner()) + DCoreActor* upper = sect.upperLink; + if (upper && !static_cast(upper)->GetOwner()) { Printf(PRINT_HIGH, "Unpartnered upper link in sector %d\n", snum); sect.upperLink = nullptr; } - if (sect.upperLink && !sect.upperLink->GetOwner()) + DCoreActor* lower = sect.lowerLink; + if (lower && !static_cast(lower)->GetOwner()) { Printf(PRINT_HIGH, "Unpartnered lower link in sector %d\n", snum); sect.lowerLink = nullptr; @@ -162,7 +163,7 @@ void warpInit(TArray& actors) for(auto& sect : sectors()) { - auto actor = sect.upperLink; + auto actor = static_cast(sect.upperLink); if (actor && actor->hasX()) { spritetype *pSprite = &actor->s(); @@ -170,7 +171,7 @@ void warpInit(TArray& actors) int nLink = pXSprite->data1; for(auto& sect : sectors()) { - auto actor2 = sect.lowerLink; + auto actor2 = static_cast(sect.lowerLink); if (actor2 && actor2->hasX()) { spritetype *pSprite2 = &actor2->s(); @@ -191,8 +192,8 @@ int CheckLink(DBloodActor *actor) { auto pSprite = &actor->s(); auto pSector = pSprite->sector(); - auto aUpper = pSector->upperLink; - auto aLower = pSector->lowerLink; + auto aUpper = static_cast(pSector->upperLink); + auto aLower = static_cast(pSector->lowerLink); if (aUpper) { spritetype* pUpper = &aUpper->s(); @@ -252,8 +253,8 @@ int CheckLink(DBloodActor *actor) int CheckLink(int *x, int *y, int *z, sectortype** pSector) { - auto upper = (*pSector)->upperLink; - auto lower = (*pSector)->lowerLink; + auto upper = static_cast((*pSector)->upperLink); + auto lower = static_cast((*pSector)->lowerLink); if (upper) { spritetype *pUpper = &upper->s(); diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 16b476633..a2b609eed 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -980,7 +980,7 @@ void operatesectors(sectortype* sptr, DDukeActor *actor) case ST_30_ROTATE_RISE_BRIDGE: { - auto act = ScriptIndexToActor(sptr->hitag); + auto act = static_cast(sptr->hitagactor); if (!act) break; if (act->tempang == 0 || act->tempang == 256) callsound(sptr, actor); if (act->s->extra == 1) act->s->extra = 3; @@ -990,7 +990,7 @@ void operatesectors(sectortype* sptr, DDukeActor *actor) case ST_31_TWO_WAY_TRAIN: { - auto act = ScriptIndexToActor(sptr->hitag); + auto act = static_cast(sptr->hitagactor); if (!act) break; if (act->temp_data[4] == 0) act->temp_data[4] = 1; diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index f6480d971..890e94b52 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -939,7 +939,7 @@ void spawneffector(DDukeActor* actor, TArray* actors) if (sp->pal) sp->clipdist = 1; else sp->clipdist = 0; t[3] = sectp->floorz; - sectp->hitag = ActorToScriptIndex(actor); + sectp->hitagactor = actor; } @@ -991,7 +991,7 @@ void spawneffector(DDukeActor* actor, TArray* actors) sp->extra = 0; else sp->extra = 1; - sectp->hitag = ActorToScriptIndex(actor); + sectp->hitagactor = actor; sectortype* s = nullptr; for (auto& wal : wallsofsector(sectp))