- Blood: use a TArray for gPost and store actors as pointers.

This also does not need to be serialized because it gets cleared at the end of each game tick and will always be empty when saving is done.
This commit is contained in:
Christoph Oelckers 2021-08-30 20:12:19 +02:00
parent 4526f4149b
commit 6db18e61d9
2 changed files with 52 additions and 53 deletions

View file

@ -2324,14 +2324,13 @@ const int DudeDifficulty[5] = {
512, 384, 256, 208, 160
};
int gPostCount = 0;
struct POSTPONE {
short sprite;
short status;
struct POSTPONE
{
DBloodActor* sprite;
int status;
};
POSTPONE gPost[kMaxSprites];
TArray<POSTPONE> gPost;
//---------------------------------------------------------------------------
//
@ -7264,59 +7263,59 @@ void DudeToGibCallback2(int, DBloodActor* actor)
pXSprite->state = 1;
}
void actPostSprite(int nSprite, int nStatus)
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void actPostSprite(DBloodActor* actor, int nStatus)
{
int n;
assert(gPostCount < kMaxSprites);
assert(nSprite < kMaxSprites && sprite[nSprite].statnum < kMaxStatus);
assert(nStatus >= 0 && nStatus <= kStatFree);
if (sprite[nSprite].flags&32)
auto sp = &actor->s();
if (sp->flags & 32)
{
for (n = 0; n < gPostCount; n++)
if (gPost[n].sprite == nSprite)
break;
assert(n < gPostCount);
}
for (auto& post : gPost)
if (post.sprite == actor)
{
post.status = nStatus;
return;
}
}
else
{
n = gPostCount;
sprite[nSprite].flags |= 32;
gPostCount++;
sp->flags |= 32;
gPost.Push({ actor, nStatus });
}
gPost[n].sprite = nSprite;
gPost[n].status = nStatus;
}
void actPostSprite(DBloodActor* actor, int status)
{
actPostSprite(actor->s().index, status);
}
void actPostProcess(void)
{
for (int i = 0; i < gPostCount; i++)
for (auto& p : gPost)
{
POSTPONE *pPost = &gPost[i];
int nSprite = pPost->sprite;
spritetype *pSprite = &sprite[nSprite];
pSprite->flags &= ~32;
int nStatus = pPost->status;
p.sprite->s().flags &= ~32;
int nStatus = p.status;
if (nStatus == kStatFree)
{
if (pSprite->statnum != kStatFree)
if (p.sprite->s().statnum != kStatFree)
{
evKill(nSprite, 3);
if (sprite[nSprite].extra > 0)
seqKill(3, pSprite->extra);
DeleteSprite(nSprite);
evKill(p.sprite);
if (p.sprite->hasX()) seqKill(p.sprite);
DeleteSprite(p.sprite->s().index);
}
}
else
ChangeSpriteStat(nSprite, nStatus);
ChangeSpriteStat(p.sprite->s().index, nStatus);
}
gPostCount = 0;
gPost.Clear();
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void MakeSplash(DBloodActor* actor)
{
auto pXSprite = &actor->x();
@ -7351,17 +7350,6 @@ void MakeSplash(DBloodActor* actor)
//
//---------------------------------------------------------------------------
FSerializer& Serialize(FSerializer& arc, const char* keyname, POSTPONE& w, POSTPONE* def)
{
if (arc.BeginObject(keyname))
{
arc("sprite", w.sprite)
("status", w.status)
.EndObject();
}
return arc;
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, SPRITEHIT& w, SPRITEHIT* def)
{
int empty = 0;
@ -7382,11 +7370,9 @@ void SerializeActor(FSerializer& arc)
{
arc("maxdist20", gVectorData[kVectorTchernobogBurn].maxDist) // The code messes around with this field so better save it.
.SparseArray("spritehit", gSpriteHit, kMaxSprites, activeXSprites)
("postcount", gPostCount)
.Array("post", gPost, gPostCount)
.EndObject();
if (arc.isReading() && gGameOptions.nMonsterSettings != 0)
if (arc.isReading() && gGameOptions.nMonsterSettings != 0)
{
for (int i = 0; i < kDudeMax - kDudeBase; i++)
for (int j = 0; j < 7; j++)
@ -7416,5 +7402,10 @@ int actDamageSprite(int nSource, spritetype* pSprite, DAMAGE_TYPE damageType, in
return actDamageSprite(nSource == -1 ? nullptr : &bloodActors[nSource], &bloodActors[pSprite->index], damageType, damage);
}
void actPostSprite(int nSprite, int nStatus)
{
actPostSprite(&bloodActors[nSprite], nStatus);
}
END_BLD_NS

View file

@ -283,4 +283,12 @@ inline void viewBackupSpriteLoc(DBloodActor* actor)
viewBackupSpriteLoc(actor->s().index, &actor->s());
}
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DBloodActor*& w, DBloodActor** def)
{
int index = w? int(w - bloodActors) : -1;
Serialize(arc, keyname, index, nullptr);
if (arc.isReading()) w = index == -1? nullptr : &bloodActors[index];
return arc;
}
END_BLD_NS