- Blood: cleanup and simplification of SEQ code.

* removed all the large instance arrays. None of this is really necessary, all we need is a single dynamic array with only the active sequences that can expand as needed.
* added JSON serialization. With the above change this part now becomes trivial.
* renamed all 'atxx' variables in this code.
This commit is contained in:
Christoph Oelckers 2020-11-21 18:12:51 +01:00
parent 4aa06ff702
commit 8bfc6d98d4
5 changed files with 685 additions and 673 deletions

View file

@ -2488,10 +2488,10 @@ void actInit(bool bSaveLoad) {
break; break;
case kThingBloodChunks: { case kThingBloodChunks: {
SEQINST *pInst = GetInstance(3, pSprite->extra); SEQINST *pInst = GetInstance(3, pSprite->extra);
if (pInst && pInst->at13) { if (pInst) {
auto seq = getSequence(pInst->at8); auto seq = getSequence(pInst->nSeqID);
if (!seq) break; if (!seq) break;
seqSpawn(pInst->at8, 3, pSprite->extra); seqSpawn(pInst->nSeqID, 3, pSprite->extra);
} }
break; break;
} }

View file

@ -1460,9 +1460,9 @@ int getDispersionModifier(spritetype* pSprite, int minDisp, int maxDisp)
int disp = 1; int disp = 1;
if (pSeq != nullptr) if (pSeq != nullptr)
{ {
int nFrames = pSeq->nFrames; int ticks = pSeq->at8; int shots = 0; int nFrames = pSeq->nFrames; int ticks = pSeq->ticksPerFrame; int shots = 0;
for (int i = 0; i <= pSeq->nFrames; i++) { for (int i = 0; i <= pSeq->nFrames; i++) {
if (pSeq->frames[i].at5_5) shots++; if (pSeq->frames[i].trigger) shots++;
} }
disp = (((shots * 1000) / nFrames) / ticks) * 20; disp = (((shots * 1000) / nFrames) / ticks) * 20;
@ -2040,7 +2040,7 @@ bool genDudePrepare(spritetype* pSprite, int propId) {
{ {
pExtra->forcePunch = true; // required for those who don't have fire trigger in punch seq and for default animation pExtra->forcePunch = true; // required for those who don't have fire trigger in punch seq and for default animation
for (int i = 0; i < pSeq->nFrames; i++) { for (int i = 0; i < pSeq->nFrames; i++) {
if (!pSeq->frames[i].at5_5) continue; if (!pSeq->frames[i].trigger) continue;
pExtra->forcePunch = false; pExtra->forcePunch = false;
break; break;
} }

View file

@ -476,14 +476,6 @@ void LoadSave::Write(const void *pData, int nSize)
bool GameInterface::LoadGame() bool GameInterface::LoadGame()
{ {
sndKillAllSounds();
sfxKillAllSounds();
ambKillAll();
seqKillAll();
if (gamestate != GS_LEVEL)
{
memset(xsprite, 0, sizeof(xsprite));
}
LoadSave::hLFile = ReadSavegameChunk("snapshot.bld"); LoadSave::hLFile = ReadSavegameChunk("snapshot.bld");
if (!LoadSave::hLFile.isOpen()) if (!LoadSave::hLFile.isOpen())
return false; return false;
@ -735,7 +727,6 @@ void LevelsLoadSaveConstruct(void);
void MessagesLoadSaveConstruct(void); void MessagesLoadSaveConstruct(void);
void MirrorLoadSaveConstruct(void); void MirrorLoadSaveConstruct(void);
void PlayerLoadSaveConstruct(void); void PlayerLoadSaveConstruct(void);
void SeqLoadSaveConstruct(void);
void TriggersLoadSaveConstruct(void); void TriggersLoadSaveConstruct(void);
void ViewLoadSaveConstruct(void); void ViewLoadSaveConstruct(void);
void WarpLoadSaveConstruct(void); void WarpLoadSaveConstruct(void);
@ -754,7 +745,6 @@ void LoadSaveSetup(void)
MessagesLoadSaveConstruct(); MessagesLoadSaveConstruct();
MirrorLoadSaveConstruct(); MirrorLoadSaveConstruct();
PlayerLoadSaveConstruct(); PlayerLoadSaveConstruct();
SeqLoadSaveConstruct();
TriggersLoadSaveConstruct(); TriggersLoadSaveConstruct();
ViewLoadSaveConstruct(); ViewLoadSaveConstruct();
WarpLoadSaveConstruct(); WarpLoadSaveConstruct();
@ -765,10 +755,21 @@ void LoadSaveSetup(void)
void SerializeEvents(FSerializer& arc); void SerializeEvents(FSerializer& arc);
void SerializeSequences(FSerializer& arc);
void GameInterface::SerializeGameState(FSerializer& arc) void GameInterface::SerializeGameState(FSerializer& arc)
{ {
sndKillAllSounds();
sfxKillAllSounds();
ambKillAll();
seqKillAll();
if (gamestate != GS_LEVEL)
{
memset(xsprite, 0, sizeof(xsprite));
}
SerializeEvents(arc); SerializeEvents(arc);
SerializeSequences(arc);
} }

File diff suppressed because it is too large Load diff

View file

@ -26,68 +26,80 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS BEGIN_BLD_NS
struct SEQFRAME { struct SEQFRAME
unsigned int tile : 12; {
unsigned int at1_4 : 1; // transparent unsigned int tile : 12;
unsigned int at1_5 : 1; // transparent unsigned int transparent : 1;
unsigned int at1_6 : 1; // blockable unsigned int transparent2 : 1;
unsigned int at1_7 : 1; // hittable unsigned int blockable : 1;
unsigned int at2_0 : 8; // xrepeat unsigned int hittable : 1;
unsigned int at3_0 : 8; // yrepeat unsigned int xrepeat : 8;
signed int at4_0 : 8; // shade unsigned int yrepeat : 8;
unsigned int at5_0 : 5; // palette signed int shade : 8;
unsigned int at5_5 : 1; // unsigned int palette : 5;
unsigned int at5_6 : 1; // unsigned int trigger : 1;
unsigned int at5_7 : 1; // unsigned int smoke : 1;
unsigned int at6_0 : 1; // unsigned int aiming : 1;
unsigned int at6_1 : 1; // unsigned int pushable : 1;
unsigned int at6_2 : 1; // invisible unsigned int playsound : 1;
unsigned int at6_3 : 1; // unsigned int invisible : 1;// invisible
unsigned int at6_4 : 1; // unsigned int flipx : 1;
unsigned int tile2 : 4; unsigned int flipy : 1;
unsigned soundRange : 4; // (by NoOne) random sound range relative to global SEQ sound unsigned int tile2 : 4;
unsigned surfaceSound : 1; // (by NoOne) trigger surface sound when moving / touching unsigned soundRange : 4; // (by NoOne) random sound range relative to global SEQ sound
unsigned reserved : 2; unsigned surfaceSound : 1; // (by NoOne) trigger surface sound when moving / touching
unsigned reserved : 2;
}; };
struct Seq { struct Seq {
char signature[4]; char signature[4];
short version; short version;
short nFrames; // at6 short nFrames;
short at8; short ticksPerFrame;
short ata; short soundId;
int atc; int flags;
SEQFRAME frames[1]; SEQFRAME frames[1];
void Preload(void); void Preload(void);
void Precache(HitList &); void Precache(HitList&);
bool isLooping()
{
return (flags & 1) != 0;
}
bool isRemovable()
{
return (flags & 2) != 0;
}
}; };
struct ACTIVE struct ACTIVE
{ {
unsigned char type; unsigned char type;
unsigned short xindex; unsigned short xindex;
}; };
struct SEQINST struct SEQINST
{ {
Seq *pSequence; Seq* pSequence;
int at8; int index, type;
int atc;
short at10; int nSeqID;
unsigned char frameIndex; int callback;
char at13; short timeCounter;
void Update(ACTIVE *pActive); unsigned char frameIndex;
void Update();
}; };
inline int seqGetTile(SEQFRAME* pFrame) inline int seqGetTile(SEQFRAME* pFrame)
{ {
return pFrame->tile+(pFrame->tile2<<12); return pFrame->tile + (pFrame->tile2 << 12);
} }
int seqRegisterClient(void(*pClient)(int, int)); int seqRegisterClient(void(*pClient)(int, int));
void seqPrecacheId(int id, HitList &hits); void seqPrecacheId(int id, HitList& hits);
SEQINST * GetInstance(int a1, int a2); SEQINST* GetInstance(int a1, int a2);
void UnlockInstance(SEQINST *pInst); void UnlockInstance(SEQINST* pInst);
void seqSpawn(int a1, int a2, int a3, int a4 = -1); void seqSpawn(int a1, int a2, int a3, int a4 = -1);
void seqKill(int a1, int a2); void seqKill(int a1, int a2);
void seqKillAll(void); void seqKillAll(void);