From 8a2385dd89e2fde3c7529e9bf31a6e40f1277a6b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 5 Dec 2021 10:40:31 +0100 Subject: [PATCH] - actor clearing cleaned up. We still need this until we can get rid of the static arrays... --- source/core/actorlist.cpp | 3 ++- source/core/coreactor.h | 8 ++++++++ source/core/gamecontrol.cpp | 2 ++ source/core/savegamehelp.cpp | 10 +++++----- source/games/blood/src/blood.cpp | 1 - source/games/blood/src/bloodactor.h | 7 ++++++- source/games/blood/src/nnexts.cpp | 7 ------- source/games/duke/src/conlabeldef.h | 2 +- source/games/duke/src/premap.cpp | 1 - source/games/duke/src/savegame.cpp | 1 - source/games/duke/src/types.h | 6 ++++-- source/games/exhumed/src/exhumedactor.h | 5 ++++- source/games/exhumed/src/init.cpp | 1 - source/games/sw/src/game.cpp | 1 - source/games/sw/src/save.cpp | 5 ----- source/games/sw/src/swactor.h | 4 +++- source/games/sw/src/weapon.cpp | 2 +- 17 files changed, 36 insertions(+), 30 deletions(-) diff --git a/source/core/actorlist.cpp b/source/core/actorlist.cpp index bd265e030..94254ba80 100644 --- a/source/core/actorlist.cpp +++ b/source/core/actorlist.cpp @@ -388,6 +388,7 @@ int DeleteActor(DCoreActor* actor) assert(actor->prevSect == nullptr && actor->nextSect == nullptr); } Numsprites--; + actor->ClearContent(); freeList.push_front(actor); return 0; } @@ -411,7 +412,7 @@ void InitSpriteLists() freeList.clear(); for(auto& actor : actorArray) { - actor->prevSect = actor->prevStat = actor->nextSect = actor->nextStat = nullptr; + actor->ClearContent(); freeList.push_front(actor); } Numsprites = 0; diff --git a/source/core/coreactor.h b/source/core/coreactor.h index 83626bc23..1003ff99e 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -24,6 +24,14 @@ public: virtual ~DCoreActor() = default; virtual void Serialize(FSerializer& arc); + // This may only be called when all actor lists are clean. + virtual void ClearContent() + { + link_stat = MAXSTATUS; + link_sector = nullptr; + prevStat = nextStat = prevSect = nextSect = nullptr; + spr = {}; + } bool exists() const { diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 23c5ac124..82d2f8dfd 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1379,6 +1379,8 @@ void GameInterface::FreeLevelData() // Make sure that there is no more level to toy around with. InitSpriteLists(); numsectors = numwalls = 0; + sector.Reset(); + wall.Reset(); currentLevel = nullptr; } diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index 151302f54..8d2f2c54f 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -736,12 +736,13 @@ static int nextquicksave = -1; void DoLoadGame(const char* name) { + gi->FreeLevelData(); if (ReadSavegame(name)) { - gameaction = ga_level; - } - else - { + gameaction = ga_level; + } + else + { I_Error("%s: Failed to open savegame", name); } } @@ -765,7 +766,6 @@ static int nextquicksave = -1; } inputState.ClearAllInput(); - gi->FreeLevelData(); DoLoadGame(savename); BackupSaveGame = savename; } diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index 2a9ba17ac..714bf3cfb 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -94,7 +94,6 @@ TArray SpawnActors(BloodSpawnSpriteDef& sprites) auto sprt = &sprites.sprites[i]; auto actor = InsertSprite(sprt->sector(), sprt->statnum); spawns[j++] = actor; - actor->Clear(); actor->s() = sprites.sprites[i]; if (sprites.sprext.Size()) actor->sx() = sprites.sprext[i]; else actor->sx() = {}; diff --git a/source/games/blood/src/bloodactor.h b/source/games/blood/src/bloodactor.h index 9ad8aa05e..c044f0be2 100644 --- a/source/games/blood/src/bloodactor.h +++ b/source/games/blood/src/bloodactor.h @@ -44,7 +44,7 @@ public: DBloodActor& operator=(const DBloodActor& other) = default; - void Clear() + void ClearContent() override { dudeSlope = 0; hit = {}; @@ -52,6 +52,7 @@ public: spriteMass = {}; genDudeExtra = {}; prevmarker = nullptr; + ownerActor = nullptr; basePoint = {}; xsprite = {}; hasx = false; @@ -59,6 +60,10 @@ public: xvel = yvel = zvel = 0; explosionhackflag = false; interpolated = false; + condition[0] = {}; + condition[1] = {}; + cumulDamage = 0; + Super::ClearContent(); } bool hasX() { return hasx; } void addX() { hasx = true; } diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 002fb69b6..58133d0c9 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -501,13 +501,6 @@ void nnExtResetGlobals() pCond->length = 0; } gTrackingCondsCount = 0; - - // clear sprite mass cache - for (int i = 0; i < kMaxSprites; i++) - { - bloodActors[i].spriteMass = {}; - } - } //--------------------------------------------------------------------------- diff --git a/source/games/duke/src/conlabeldef.h b/source/games/duke/src/conlabeldef.h index a103d21b3..782680198 100644 --- a/source/games/duke/src/conlabeldef.h +++ b/source/games/duke/src/conlabeldef.h @@ -93,7 +93,7 @@ LABELS actorlabels[]= { "hitag", ACTOR_HITAG, 0, 0 }, { "extra", ACTOR_EXTRA, 0, 0 }, - // hittype labels... + // hit type labels... { "htcgg", ACTOR_HTCGG, 0, 0 }, { "htpicnum", ACTOR_HTPICNUM, 0, 0 }, { "htang", ACTOR_HTANG, 0, 0 }, diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 2a5b54e05..d30577894 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -681,7 +681,6 @@ void prelevel_common(int g) resetprestat(0, g); numclouds = 0; - for (auto& h : hittype) h.clear(); memset(geosectorwarp, -1, sizeof(geosectorwarp)); memset(geosectorwarp2, -1, sizeof(geosectorwarp2)); memset(ambienthitag, -1, sizeof(ambienthitag)); diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index cbb8e8833..6bce52a0d 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -337,7 +337,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) { if (arc.isReading()) { - for (auto& h : hittype) h.clear(); memset(geosectorwarp, -1, sizeof(geosectorwarp)); memset(geosectorwarp2, -1, sizeof(geosectorwarp2)); memset(ambienthitag, -1, sizeof(ambienthitag)); diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 761b5b634..4bf9002c2 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -54,9 +54,11 @@ struct DDukeActor : public DCoreActor } DDukeActor(const DDukeActor& other) = delete; // we also do not want to allow copies. DDukeActor& operator=(const DDukeActor& other) = delete; - void clear() + void ClearContent() override { - actorstayput = nullptr; + Super::ClearContent(); + temp_sect = actorstayput = nullptr; + temp_actor = seek_actor = nullptr; ownerActor = nullptr; hitOwnerActor = nullptr; cgg = spriteextra = 0; diff --git a/source/games/exhumed/src/exhumedactor.h b/source/games/exhumed/src/exhumedactor.h index 6395cf406..e2ef12803 100644 --- a/source/games/exhumed/src/exhumedactor.h +++ b/source/games/exhumed/src/exhumedactor.h @@ -47,8 +47,11 @@ public: } DExhumedActor& operator=(const DExhumedActor& other) = default; - void Clear() + void ClearContent() override { + Super::ClearContent(); + pTarget = nullptr; + nPhase = nHealth = nFrame = nAction = nCount = nRun = nIndex = nIndex2 = nChannel = nDamage = nTurn = x = y = 0; } void Serialize(FSerializer& arc) override; diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index 09654eba1..f891d125f 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -78,7 +78,6 @@ static TArray spawnactors(SpawnSpriteDef& sprites) auto sprt = &sprites.sprites[i]; auto actor = insertActor(sprt->sector(), sprt->statnum); spawns[j++] = actor; - actor->Clear(); actor->s() = sprites.sprites[i]; if (sprites.sprext.Size()) actor->sx() = sprites.sprext[i]; else actor->sx() = {}; diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index b2c442caa..b3caf5dae 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -304,7 +304,6 @@ void spawnactors(SpawnSpriteDef& sprites) } auto sprt = &sprites.sprites[i]; auto actor = insertActor(sprt->sector(), sprt->statnum); - actor->Clear(); actor->s() = sprites.sprites[i]; if (sprites.sprext.Size()) actor->sx() = sprites.sprext[i]; else actor->sx() = {}; diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index 381ee02b5..a8cafa9cf 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -1112,11 +1112,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, TRACK& w, TRACK* d void DSWActor::Serialize(FSerializer& arc) { Super::Serialize(arc); - if (arc.isReading()) - { - // nuke the User before loading anything. - Clear(); - } arc("hasuser", hasUser); if (hasUser) arc("user", user); // only write if defined. } diff --git a/source/games/sw/src/swactor.h b/source/games/sw/src/swactor.h index 9240bb72e..0cbf28807 100644 --- a/source/games/sw/src/swactor.h +++ b/source/games/sw/src/swactor.h @@ -23,9 +23,11 @@ public: } DSWActor& operator=(const DSWActor& other) = default; - void Clear() + void ClearContent() { + Super::ClearContent(); clearUser(); + tempwall = nullptr; } bool hasU() { return hasUser; } diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 8247936a0..2e1449e89 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -7675,7 +7675,7 @@ int DoStar(DSWActor* actor) vel = ksqrt(SQ(u->xchange) + SQ(u->ychange)); if (vel < 500) - break; // will be killed below - hittype != 0 + break; // will be killed below - actor != 0 // 32000 to 96000 u->xchange = MulScale(u->xchange, 64000 + (RandomRange(64000) - 32000), 16);