- actor clearing cleaned up.

We still need this until we can get rid of the static arrays...
This commit is contained in:
Christoph Oelckers 2021-12-05 10:40:31 +01:00
parent c4d23188d5
commit 8a2385dd89
17 changed files with 36 additions and 30 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -94,7 +94,6 @@ TArray<DBloodActor*> 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() = {};

View file

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

View file

@ -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 = {};
}
}
//---------------------------------------------------------------------------

View file

@ -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 },

View file

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

View file

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

View file

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

View file

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

View file

@ -78,7 +78,6 @@ static TArray<DExhumedActor*> 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() = {};

View file

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

View file

@ -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.
}

View file

@ -23,9 +23,11 @@ public:
}
DSWActor& operator=(const DSWActor& other) = default;
void Clear()
void ClearContent()
{
Super::ClearContent();
clearUser();
tempwall = nullptr;
}
bool hasU() { return hasUser; }

View file

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