- use distinct variable names for QAV and SEQ management.

This commit is contained in:
Christoph Oelckers 2020-10-11 10:54:05 +02:00
parent 3b59bf759c
commit 2f4c78dd73
2 changed files with 37 additions and 39 deletions

View file

@ -33,17 +33,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS BEGIN_BLD_NS
#define kMaxClients 64 #define kMaxQavClients 64
static void (*clientCallback[kMaxClients])(int, void *); static void (*qavClientCallback[kMaxQavClients])(int, void *);
static int nClients; static int nQavClients;
int qavRegisterClient(void(*pClient)(int, void *)) int qavRegisterClient(void(*pClient)(int, void *))
{ {
dassert(nClients < kMaxClients); dassert(nQavClients < kMaxQavClients);
clientCallback[nClients] = pClient; qavClientCallback[nQavClients] = pClient;
return nClients++; return nQavClients++;
} }
void DrawFrame(double x, double y, TILE_FRAME *pTile, int stat, int shade, int palnum, bool to3dview) void DrawFrame(double x, double y, TILE_FRAME *pTile, int stat, int shade, int palnum, bool to3dview)
@ -152,7 +152,7 @@ void QAV::Play(int start, int end, int nCallback, void *pData)
} }
if (pFrame->nCallbackId > 0 && nCallback != -1) { if (pFrame->nCallbackId > 0 && nCallback != -1) {
clientCallback[nCallback](pFrame->nCallbackId, pData); qavClientCallback[nCallback](pFrame->nCallbackId, pData);
} }
} }
} }
@ -218,10 +218,10 @@ void ByteSwapQAV(void* p)
// Sequences were cached in the resource and directly returned from there in writable form, with byte swapping directly performed in the cache on Big Endian systems. // Sequences were cached in the resource and directly returned from there in writable form, with byte swapping directly performed in the cache on Big Endian systems.
// To avoid such unsafe operations this caches the read data separately. // To avoid such unsafe operations this caches the read data separately.
extern FMemArena seqcache; // Use the same storage as the SEQs. extern FMemArena seqcache; // Use the same storage as the SEQs.
static TMap<int, QAV*> sequences; static TMap<int, QAV*> qavcache;
QAV* getQAV(int res_id) QAV* getQAV(int res_id)
{ {
auto p = sequences.CheckKey(res_id); auto p = qavcache.CheckKey(res_id);
if (p != nullptr) return *p; if (p != nullptr) return *p;
int index = fileSystem.FindResource(res_id, "QAV"); int index = fileSystem.FindResource(res_id, "QAV");
@ -232,7 +232,7 @@ QAV* getQAV(int res_id)
auto fr = fileSystem.OpenFileReader(index); auto fr = fileSystem.OpenFileReader(index);
auto qavdata = (QAV*)seqcache.Alloc(fr.GetLength()); auto qavdata = (QAV*)seqcache.Alloc(fr.GetLength());
fr.Read(qavdata, fr.GetLength()); fr.Read(qavdata, fr.GetLength());
sequences.Insert(res_id, qavdata); qavcache.Insert(res_id, qavdata);
ByteSwapQAV(qavdata); ByteSwapQAV(qavdata);
return qavdata; return qavdata;
} }

View file

@ -41,19 +41,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS BEGIN_BLD_NS
#define kMaxClients 256 #define kMaxSeqClients 256
#define kMaxSequences 1024 #define kMaxSequences 1024
static ACTIVE activeList[kMaxSequences]; static ACTIVE activeList[kMaxSequences];
static int activeCount = 0; static int seqActiveCount = 0;
static int nClients = 0; static int nSeqClients = 0;
static void(*clientCallback[kMaxClients])(int, int); static void(*seqClientCallback[kMaxSeqClients])(int, int);
int seqRegisterClient(void(*pClient)(int, int)) int seqRegisterClient(void(*pClient)(int, int))
{ {
dassert(nClients < kMaxClients); dassert(nSeqClients < kMaxSeqClients);
clientCallback[nClients] = pClient; seqClientCallback[nSeqClients] = pClient;
return nClients++; return nSeqClients++;
} }
void Seq::Preload(void) void Seq::Preload(void)
@ -338,7 +338,7 @@ void SEQINST::Update(ACTIVE *pActive)
break; break;
} }
if (pSequence->frames[frameIndex].at5_5 && atc != -1) if (pSequence->frames[frameIndex].at5_5 && atc != -1)
clientCallback[atc](pActive->type, pActive->xindex); seqClientCallback[atc](pActive->type, pActive->xindex);
} }
SEQINST * GetInstance(int a1, int a2) SEQINST * GetInstance(int a1, int a2)
@ -381,18 +381,18 @@ void seqSpawn(int a1, int a2, int a3, int a4)
if (!pSeq) if (!pSeq)
ThrowError("Missing sequence #%d", a1); ThrowError("Missing sequence #%d", a1);
int i = activeCount; int i = seqActiveCount;
if (pInst->at13) if (pInst->at13)
{ {
if (pSeq == pInst->pSequence) if (pSeq == pInst->pSequence)
return; return;
UnlockInstance(pInst); UnlockInstance(pInst);
for (i = 0; i < activeCount; i++) for (i = 0; i < seqActiveCount; i++)
{ {
if (activeList[i].type == a2 && activeList[i].xindex == a3) if (activeList[i].type == a2 && activeList[i].xindex == a3)
break; break;
} }
dassert(i < activeCount); dassert(i < seqActiveCount);
} }
if (memcmp(pSeq->signature, "SEQ\x1a", 4) != 0) if (memcmp(pSeq->signature, "SEQ\x1a", 4) != 0)
ThrowError("Invalid sequence %d", a1); ThrowError("Invalid sequence %d", a1);
@ -409,12 +409,12 @@ void seqSpawn(int a1, int a2, int a3, int a4)
pInst->atc = a4; pInst->atc = a4;
pInst->at10 = pSeq->at8; pInst->at10 = pSeq->at8;
pInst->frameIndex = 0; pInst->frameIndex = 0;
if (i == activeCount) if (i == seqActiveCount)
{ {
dassert(activeCount < kMaxSequences); dassert(seqActiveCount < kMaxSequences);
activeList[activeCount].type = a2; activeList[seqActiveCount].type = a2;
activeList[activeCount].xindex = a3; activeList[seqActiveCount].xindex = a3;
activeCount++; seqActiveCount++;
} }
pInst->Update(&activeList[i]); pInst->Update(&activeList[i]);
} }
@ -425,14 +425,14 @@ void seqKill(int a1, int a2)
if (!pInst || !pInst->at13) if (!pInst || !pInst->at13)
return; return;
int i; int i;
for (i = 0; i < activeCount; i++) for (i = 0; i < seqActiveCount; i++)
{ {
if (activeList[i].type == a1 && activeList[i].xindex == a2) if (activeList[i].type == a1 && activeList[i].xindex == a2)
break; break;
} }
dassert(i < activeCount); dassert(i < seqActiveCount);
activeCount--; seqActiveCount--;
activeList[i] = activeList[activeCount]; activeList[i] = activeList[seqActiveCount];
pInst->at13 = 0; pInst->at13 = 0;
UnlockInstance(pInst); UnlockInstance(pInst);
} }
@ -458,7 +458,7 @@ void seqKillAll(void)
if (siSprite[i].at13) if (siSprite[i].at13)
UnlockInstance(&siSprite[i]); UnlockInstance(&siSprite[i]);
} }
activeCount = 0; seqActiveCount = 0;
} }
int seqGetStatus(int a1, int a2) int seqGetStatus(int a1, int a2)
@ -479,7 +479,7 @@ int seqGetID(int a1, int a2)
void seqProcess(int a1) void seqProcess(int a1)
{ {
for (int i = 0; i < activeCount; i++) for (int i = 0; i < seqActiveCount; i++)
{ {
SEQINST *pInst = GetInstance(activeList[i].type, activeList[i].xindex); SEQINST *pInst = GetInstance(activeList[i].type, activeList[i].xindex);
Seq *pSeq = pInst->pSequence; Seq *pSeq = pInst->pSequence;
@ -524,7 +524,7 @@ void seqProcess(int a1)
} }
} }
} }
activeList[i--] = activeList[--activeCount]; activeList[i--] = activeList[--seqActiveCount];
break; break;
} }
} }
@ -546,7 +546,7 @@ void SeqLoadSave::Load(void)
Read(&siFloor, sizeof(siFloor)); Read(&siFloor, sizeof(siFloor));
Read(&siSprite, sizeof(siSprite)); Read(&siSprite, sizeof(siSprite));
Read(&activeList, sizeof(activeList)); Read(&activeList, sizeof(activeList));
Read(&activeCount, sizeof(activeCount)); Read(&seqActiveCount, sizeof(seqActiveCount));
for (int i = 0; i < kMaxXWalls; i++) for (int i = 0; i < kMaxXWalls; i++)
{ {
siWall[i].pSequence = NULL; siWall[i].pSequence = NULL;
@ -561,7 +561,7 @@ void SeqLoadSave::Load(void)
{ {
siSprite[i].pSequence = NULL; siSprite[i].pSequence = NULL;
} }
for (int i = 0; i < activeCount; i++) for (int i = 0; i < seqActiveCount; i++)
{ {
SEQINST *pInst = GetInstance(activeList[i].type, activeList[i].xindex); SEQINST *pInst = GetInstance(activeList[i].type, activeList[i].xindex);
if (pInst->at13) if (pInst->at13)
@ -589,14 +589,12 @@ void SeqLoadSave::Save(void)
Write(&siFloor, sizeof(siFloor)); Write(&siFloor, sizeof(siFloor));
Write(&siSprite, sizeof(siSprite)); Write(&siSprite, sizeof(siSprite));
Write(&activeList, sizeof(activeList)); Write(&activeList, sizeof(activeList));
Write(&activeCount, sizeof(activeCount)); Write(&seqActiveCount, sizeof(seqActiveCount));
} }
static SeqLoadSave *myLoadSave;
void SeqLoadSaveConstruct(void) void SeqLoadSaveConstruct(void)
{ {
myLoadSave = new SeqLoadSave(); new SeqLoadSave();
} }