- 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.
This commit is contained in:
Christoph Oelckers 2021-12-05 17:35:23 +01:00
parent 122a1f009d
commit d088ab05a9
9 changed files with 32 additions and 32 deletions

View file

@ -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;

View file

@ -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())
{

View file

@ -5076,7 +5076,7 @@ void MoveDude(DBloodActor* actor)
if (gModernMap)
{
pPlayer->nWaterPal = 0;
auto pUpper = pSector->upperLink;
auto pUpper = static_cast<DBloodActor*>(pSector->upperLink);
if (pUpper && pUpper->hasX()) pPlayer->nWaterPal = pUpper->x().data2;
}
#endif

View file

@ -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<DBloodActor*>(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<DBloodActor*>(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<DBloodActor*>(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<DBloodActor*>(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<DBloodActor*>(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<DBloodActor*>(pSector->lowerLink);
if (actor)
{
auto link = actor->GetOwner();

View file

@ -113,7 +113,7 @@ void InitMirrors(void)
auto secti = &sector[i];
if (secti->floorpicnum == 504)
{
auto link = secti->upperLink;
auto link = static_cast<DBloodActor*>(secti->upperLink);
if (link == nullptr)
continue;
auto link2 = link->GetOwner();

View file

@ -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<DBloodActor*>(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<DBloodActor*>(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<DBloodActor*>(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<DBloodActor*>(sec.upperLink);
if (aUpper == nullptr || aUpper->x().data1 != aLink->x().data1) continue;
pLink = &aLink->s();
break;

View file

@ -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<DBloodActor*>(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<DBloodActor*>(lower)->GetOwner())
{
Printf(PRINT_HIGH, "Unpartnered lower link in sector %d\n", snum);
sect.lowerLink = nullptr;
@ -162,7 +163,7 @@ void warpInit(TArray<DBloodActor*>& actors)
for(auto& sect : sectors())
{
auto actor = sect.upperLink;
auto actor = static_cast<DBloodActor*>(sect.upperLink);
if (actor && actor->hasX())
{
spritetype *pSprite = &actor->s();
@ -170,7 +171,7 @@ void warpInit(TArray<DBloodActor*>& actors)
int nLink = pXSprite->data1;
for(auto& sect : sectors())
{
auto actor2 = sect.lowerLink;
auto actor2 = static_cast<DBloodActor*>(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<DBloodActor*>(pSector->upperLink);
auto aLower = static_cast<DBloodActor*>(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<DBloodActor*>((*pSector)->upperLink);
auto lower = static_cast<DBloodActor*>((*pSector)->lowerLink);
if (upper)
{
spritetype *pUpper = &upper->s();

View file

@ -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<DDukeActor*>(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<DDukeActor*>(sptr->hitagactor);
if (!act) break;
if (act->temp_data[4] == 0)
act->temp_data[4] = 1;

View file

@ -939,7 +939,7 @@ void spawneffector(DDukeActor* actor, TArray<DDukeActor*>* 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<DDukeActor*>* actors)
sp->extra = 0;
else sp->extra = 1;
sectp->hitag = ActorToScriptIndex(actor);
sectp->hitagactor = actor;
sectortype* s = nullptr;
for (auto& wal : wallsofsector(sectp))