diff --git a/source/games/blood/src/_polymost.cpp b/source/games/blood/src/_polymost.cpp index d4c702b92..2d20d87f2 100644 --- a/source/games/blood/src/_polymost.cpp +++ b/source/games/blood/src/_polymost.cpp @@ -195,7 +195,7 @@ void setPortalFlags(int mode) } } -// Note: wall range checks on wall[] need to be disabled because this writes beyond the regular part. +// Note: debug range checks on wall [] need to be disabled because this deliberately writes beyond the regular part. void DrawMirrors(int x, int y, int z, fixed_t a, fixed_t horiz, int smooth, int viewPlayer) { diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 22da2a089..4c8834c4b 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -3515,49 +3515,51 @@ void useSeqSpawnerGen(DBloodActor* sourceactor, int objType, int index, DBloodAc switch (objType) { case OBJ_SECTOR: + { + auto pSector = §or[index]; if (pXSource->data2 <= 0) { if (pXSource->data3 == 3 || pXSource->data3 == 1) - seqKill(2, index); + seqKill(SS_FLOOR, pSector); if (pXSource->data3 == 3 || pXSource->data3 == 2) - seqKill(1, index); + seqKill(SS_CEILING, pSector); } else { if (pXSource->data3 == 3 || pXSource->data3 == 1) - seqSpawn(pXSource->data2, SS_FLOOR, index, -1); + seqSpawn(pXSource->data2, SS_FLOOR, pSector, -1); if (pXSource->data3 == 3 || pXSource->data3 == 2) - seqSpawn(pXSource->data2, SS_CEILING, index, -1); + seqSpawn(pXSource->data2, SS_CEILING, pSector, -1); } return; - + } case OBJ_WALL: { auto pWall = &wall[index]; if (pXSource->data2 <= 0) { if (pXSource->data3 == 3 || pXSource->data3 == 1) - seqKill(0, index); + seqKill(SS_WALL, pWall); if ((pXSource->data3 == 3 || pXSource->data3 == 2) && (pWall->cstat & CSTAT_WALL_MASKED)) - seqKill(4, index); + seqKill(SS_MASKED, pWall); } else { if (pXSource->data3 == 3 || pXSource->data3 == 1) - seqSpawn(pXSource->data2, SS_WALL, index, -1); + seqSpawn(pXSource->data2, SS_WALL, pWall, -1); if (pXSource->data3 == 3 || pXSource->data3 == 2) { if (pWall->nextwall < 0) { if (pXSource->data3 == 3) - seqSpawn(pXSource->data2, SS_WALL, index, -1); + seqSpawn(pXSource->data2, SS_WALL, pWall, -1); } else { if (!(pWall->cstat & CSTAT_WALL_MASKED)) pWall->cstat |= CSTAT_WALL_MASKED; - seqSpawn(pXSource->data2, SS_MASKED, index, -1); + seqSpawn(pXSource->data2, SS_MASKED, pWall, -1); } } @@ -3904,17 +3906,17 @@ bool condCheckMixed(DBloodActor* aCond, const EVENT& event, int cmpOp, bool PUSH case 70: switch (arg3) { - default: return (condCmp(seqGetID(0, wallnum(pObj)), arg1, arg2, cmpOp) || condCmp(seqGetID(4, wallnum(pObj)), arg1, arg2, cmpOp)); - case 1: return condCmp(seqGetID(0, wallnum(pObj)), arg1, arg2, cmpOp); - case 2: return condCmp(seqGetID(4, wallnum(pObj)), arg1, arg2, cmpOp); + default: return (condCmp(seqGetID(SS_WALL, pObj), arg1, arg2, cmpOp) || condCmp(seqGetID(SS_MASKED, pObj), arg1, arg2, cmpOp)); + case 1: return condCmp(seqGetID(SS_WALL, pObj), arg1, arg2, cmpOp); + case 2: return condCmp(seqGetID(SS_MASKED, pObj), arg1, arg2, cmpOp); } break; case 71: switch (arg3) { - default: return (condCmp(seqGetStatus(0, wallnum(pObj)), arg1, arg2, cmpOp) || condCmp(seqGetStatus(4, wallnum(pObj)), arg1, arg2, cmpOp)); - case 1: return condCmp(seqGetStatus(0, wallnum(pObj)), arg1, arg2, cmpOp); - case 2: return condCmp(seqGetStatus(4, wallnum(pObj)), arg1, arg2, cmpOp); + default: return (condCmp(seqGetStatus(SS_WALL, pObj), arg1, arg2, cmpOp) || condCmp(seqGetStatus(SS_MASKED, pObj), arg1, arg2, cmpOp)); + case 1: return condCmp(seqGetStatus(SS_WALL, pObj), arg1, arg2, cmpOp); + case 2: return condCmp(seqGetStatus(SS_MASKED, pObj), arg1, arg2, cmpOp); } break; } @@ -3969,17 +3971,17 @@ bool condCheckMixed(DBloodActor* aCond, const EVENT& event, int cmpOp, bool PUSH // wall??? switch (arg3) { - default: return (condCmp(seqGetID(1, sectnum(pObj)), arg1, arg2, cmpOp) || condCmp(seqGetID(2, sectnum(pObj)), arg1, arg2, cmpOp)); - case 1: return condCmp(seqGetID(1, sectnum(pObj)), arg1, arg2, cmpOp); - case 2: return condCmp(seqGetID(2, sectnum(pObj)), arg1, arg2, cmpOp); + default: return (condCmp(seqGetID(SS_CEILING, pObj), arg1, arg2, cmpOp) || condCmp(seqGetID(SS_FLOOR, pObj), arg1, arg2, cmpOp)); + case 1: return condCmp(seqGetID(SS_CEILING, pObj), arg1, arg2, cmpOp); + case 2: return condCmp(seqGetID(SS_FLOOR, pObj), arg1, arg2, cmpOp); } break; case 71: switch (arg3) { - default: return (condCmp(seqGetStatus(1, sectnum(pObj)), arg1, arg2, cmpOp) || condCmp(seqGetStatus(2, sectnum(pObj)), arg1, arg2, cmpOp)); - case 1: return condCmp(seqGetStatus(1, sectnum(pObj)), arg1, arg2, cmpOp); - case 2: return condCmp(seqGetStatus(2, sectnum(pObj)), arg1, arg2, cmpOp); + default: return (condCmp(seqGetStatus(SS_CEILING, pObj), arg1, arg2, cmpOp) || condCmp(seqGetStatus(SS_FLOOR, pObj), arg1, arg2, cmpOp)); + case 1: return condCmp(seqGetStatus(SS_CEILING, pObj), arg1, arg2, cmpOp); + case 2: return condCmp(seqGetStatus(SS_FLOOR, pObj), arg1, arg2, cmpOp); } break; } diff --git a/source/games/blood/src/seq.cpp b/source/games/blood/src/seq.cpp index 9e5ffc735..6d4bd666a 100644 --- a/source/games/blood/src/seq.cpp +++ b/source/games/blood/src/seq.cpp @@ -126,10 +126,8 @@ void seqPrecacheId(int id, int palette) // //--------------------------------------------------------------------------- -void UpdateCeiling(int nSector, SEQFRAME* pFrame) +void UpdateCeiling(sectortype* pSector, SEQFRAME* pFrame) { - assert(validSectorIndex(nSector)); - sectortype* pSector = §or[nSector]; pSector->ceilingpicnum = seqGetTile(pFrame); pSector->ceilingshade = pFrame->shade; if (pFrame->palette) @@ -142,10 +140,8 @@ void UpdateCeiling(int nSector, SEQFRAME* pFrame) // //--------------------------------------------------------------------------- -void UpdateFloor(int nSector, SEQFRAME* pFrame) +void UpdateFloor(sectortype* pSector, SEQFRAME* pFrame) { - assert(validSectorIndex(nSector)); - sectortype* pSector = §or[nSector]; pSector->floorpicnum = seqGetTile(pFrame); pSector->floorshade = pFrame->shade; if (pFrame->palette) @@ -158,10 +154,8 @@ void UpdateFloor(int nSector, SEQFRAME* pFrame) // //--------------------------------------------------------------------------- -void UpdateWall(int nWall, SEQFRAME* pFrame) +void UpdateWall(walltype* pWall, SEQFRAME* pFrame) { - assert(validWallIndex(nWall)); - walltype* pWall = &wall[nWall]; assert(pWall->hasX()); pWall->picnum = seqGetTile(pFrame); if (pFrame->palette) @@ -190,10 +184,8 @@ void UpdateWall(int nWall, SEQFRAME* pFrame) // //--------------------------------------------------------------------------- -void UpdateMasked(int nWall, SEQFRAME* pFrame) +void UpdateMasked(walltype* pWall, SEQFRAME* pFrame) { - assert(validWallIndex(nWall)); - walltype* pWall = &wall[nWall]; assert(pWall->hasX()); walltype* pWallNext = pWall->nextWall(); pWall->overpicnum = pWallNext->overpicnum = seqGetTile(pFrame); @@ -326,17 +318,22 @@ void SEQINST::Update() assert(frameIndex < pSequence->nFrames); switch (type) { - case 0: - UpdateWall(seqindex, &pSequence->frames[frameIndex]); + case SS_WALL: + assert(target.isWall()); + UpdateWall(target.wall(), &pSequence->frames[frameIndex]); break; - case 1: - UpdateCeiling(seqindex, &pSequence->frames[frameIndex]); + case SS_CEILING: + assert(target.isSector()); + UpdateCeiling(target.sector(), &pSequence->frames[frameIndex]); break; - case 2: - UpdateFloor(seqindex, &pSequence->frames[frameIndex]); + case SS_FLOOR: + assert(target.isSector()); + UpdateFloor(target.sector(), &pSequence->frames[frameIndex]); break; - case 3: + case SS_SPRITE: { + assert(target.isActor()); + auto actor = target.actor(); if (!actor) break; UpdateSprite(actor, &pSequence->frames[frameIndex]); if (pSequence->frames[frameIndex].playsound) { @@ -388,16 +385,17 @@ void SEQINST::Update() } break; } - case 4: - UpdateMasked(seqindex, &pSequence->frames[frameIndex]); + case SS_MASKED: + assert(target.isWall()); + UpdateMasked(target.wall(), &pSequence->frames[frameIndex]); break; } // all seq callbacks are for sprites, but there's no sanity checks here that what gets passed is meant to be for a sprite... if (pSequence->frames[frameIndex].trigger && callback != -1) { - assert(type == 3); - if (type == 3) seqClientCallback[callback](type, actor); + assert(type == SS_SPRITE); + if (target.isActor()) seqClientCallback[callback](type, target.actor()); } } @@ -415,8 +413,8 @@ struct ActiveList void clear() { list.Clear(); } int getSize() { return list.Size(); } SEQINST* getInst(int num) { return &list[num]; } - int getIndex(int num) { return list[num].seqindex; } - DBloodActor* getActor(int num) { return list[num].actor; } + EventObject getElement(int num) { return list[num].target; } + //DBloodActor* getActor(int num) { return list[num].actor; } int getType(int num) { return list[num].type; } void remove(int num) @@ -431,30 +429,26 @@ struct ActiveList return &list.Last(); } - SEQINST* get(int type, int index) + SEQINST* get(int type, const EventObject& eob) { for (auto& n : list) { - if (n.type == type && n.seqindex == index) return &n; + if (n.type == type && n.target == eob) return &n; } return nullptr; } SEQINST* get(DBloodActor* actor) { - for (auto& n : list) - { - if (n.type == 3 && n.actor == actor) return &n; - } - return nullptr; + return get(SS_SPRITE, EventObject(actor)); } - void remove(int type, int index) + void remove(int type, const EventObject& eob) { for (unsigned i = 0; i < list.Size(); i++) { auto& n = list[i]; - if (n.type == type && n.seqindex == index) + if (n.type == type && n.target == eob) { remove(i); return; @@ -464,15 +458,7 @@ struct ActiveList void remove(DBloodActor* actor) { - for (unsigned i = 0; i < list.Size(); i++) - { - auto& n = list[i]; - if (n.type == 3 && n.actor == actor) - { - remove(i); - return; - } - } + remove(SS_SPRITE, EventObject(actor)); } }; @@ -485,9 +471,9 @@ static ActiveList activeList; // //--------------------------------------------------------------------------- -SEQINST* GetInstance(int type, int nIndex) +SEQINST* GetInstance(int type, const EventObject& eob) { - return activeList.get(type, nIndex); + return activeList.get(type, eob); } SEQINST* GetInstance(DBloodActor* actor) @@ -495,23 +481,8 @@ SEQINST* GetInstance(DBloodActor* actor) return activeList.get(actor); } -int seqGetStatus(DBloodActor* actor) +void seqKill(int type, const EventObject& nIndex) { - SEQINST* pInst = activeList.get(actor); - if (pInst) return pInst->frameIndex; - return -1; -} - -int seqGetID(DBloodActor* actor) -{ - SEQINST* pInst = activeList.get(actor); - if (pInst) return pInst->nSeqID; - return -1; -} - -void seqKill(int type, int nIndex) -{ - assert(type != SS_SPRITE); activeList.remove(type, nIndex); } @@ -520,6 +491,16 @@ void seqKillAll() activeList.clear(); } +void seqKill(int type, sectortype* actor) +{ + activeList.remove(type, EventObject(actor)); +} + +void seqKill(int type, walltype* actor) +{ + activeList.remove(type, EventObject(actor)); +} + void seqKill(DBloodActor* actor) { activeList.remove(actor); @@ -595,14 +576,13 @@ Seq* getSequence(int res_id) // //--------------------------------------------------------------------------- -void seqSpawn(int nSeqID, int type, int nIndex, int callback) +void seqSpawn_(int nSeqID, int type, const EventObject& eob, int callback) { - assert(type != SS_SPRITE); Seq* pSequence = getSequence(nSeqID); if (pSequence == nullptr) return; - SEQINST* pInst = activeList.get(type, nIndex); + SEQINST* pInst = activeList.get(type, eob); if (!pInst) { pInst = activeList.getNew(); @@ -620,38 +600,25 @@ void seqSpawn(int nSeqID, int type, int nIndex, int callback) pInst->timeCounter = (short)pSequence->ticksPerFrame; pInst->frameIndex = 0; pInst->type = type; - pInst->seqindex = nIndex; - pInst->actor = nullptr; + pInst->target = eob; pInst->Update(); } void seqSpawn(int nSeqID, DBloodActor* actor, int callback) { - Seq* pSequence = getSequence(nSeqID); + seqSpawn_(nSeqID, SS_SPRITE, EventObject(actor), callback); +} - if (pSequence == nullptr) return; +void seqSpawn(int nSeqID, int type, sectortype* sect, int callback) +{ + assert(type == SS_FLOOR || type == SS_CEILING); + seqSpawn_(nSeqID, type, EventObject(sect), callback); +} - SEQINST* pInst = activeList.get(actor); - if (!pInst) - { - pInst = activeList.getNew(); - } - else - { - // already playing this sequence? - if (pInst->nSeqID == nSeqID) - return; - } - - pInst->pSequence = pSequence; - pInst->nSeqID = nSeqID; - pInst->callback = callback; - pInst->timeCounter = (short)pSequence->ticksPerFrame; - pInst->frameIndex = 0; - pInst->type = SS_SPRITE; - pInst->seqindex = 0; - pInst->actor = actor; - pInst->Update(); +void seqSpawn(int nSeqID, int type, walltype* wal, int callback) +{ + assert(type == SS_WALL || type == SS_MASKED); + seqSpawn_(nSeqID, type, EventObject(wal), callback); } //--------------------------------------------------------------------------- @@ -660,20 +627,49 @@ void seqSpawn(int nSeqID, DBloodActor* actor, int callback) // //--------------------------------------------------------------------------- -int seqGetStatus(int type, int nIndex) +int seqGetStatus(int type, sectortype* nIndex) { - SEQINST* pInst = activeList.get(type, nIndex); + SEQINST* pInst = activeList.get(type, EventObject(nIndex)); if (pInst) return pInst->frameIndex; return -1; } -int seqGetID(int type, int nIndex) +int seqGetID(int type, sectortype* nIndex) { - SEQINST* pInst = activeList.get(type, nIndex); + SEQINST* pInst = activeList.get(type, EventObject(nIndex)); if (pInst) return pInst->nSeqID; return -1; } +int seqGetStatus(int type, walltype* nIndex) +{ + SEQINST* pInst = activeList.get(type, EventObject(nIndex)); + if (pInst) return pInst->frameIndex; + return -1; +} + +int seqGetID(int type, walltype* nIndex) +{ + SEQINST* pInst = activeList.get(type, EventObject(nIndex)); + if (pInst) return pInst->nSeqID; + return -1; +} + +int seqGetStatus(DBloodActor* actor) +{ + SEQINST* pInst = activeList.get(actor); + if (pInst) return pInst->frameIndex; + return -1; +} + +int seqGetID(DBloodActor* actor) +{ + SEQINST* pInst = activeList.get(actor); + if (pInst) return pInst->nSeqID; + return -1; +} + + //--------------------------------------------------------------------------- // // @@ -686,8 +682,7 @@ void seqProcess(int nTicks) { SEQINST* pInst = activeList.getInst(i); Seq* pSeq = pInst->pSequence; - int index = pInst->seqindex; - auto actor = pInst->actor; + auto target = pInst->target; assert(pInst->frameIndex < pSeq->nFrames); @@ -705,6 +700,8 @@ void seqProcess(int nTicks) { if (pInst->type == SS_SPRITE) { + assert(target.isActor()); + auto actor = target.actor(); if (actor) { evKillActor(actor); @@ -716,8 +713,8 @@ void seqProcess(int nTicks) else if (pInst->type == SS_MASKED) { - assert(validWallIndex(index)); - auto pWall = &wall[index]; + assert(target.isWall()); + auto pWall = target.wall(); pWall->cstat &= ~(8 + 16 + 32); if (pWall->twoSided()) pWall->nextWall()->cstat &= ~(8 + 16 + 32); @@ -746,13 +743,12 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, SEQINST& w, SEQINS { if (arc.BeginObject(keyname)) { - arc ("type", w.type) + arc("type", w.type) ("callback", w.callback) ("seqid", w.nSeqID) ("timecounter", w.timeCounter) ("frameindex", w.frameIndex) - ("index", w.seqindex) - ("actor", w.actor); + ("target", w.target); arc.EndObject(); } diff --git a/source/games/blood/src/seq.h b/source/games/blood/src/seq.h index 188a583c7..e2a2f30a8 100644 --- a/source/games/blood/src/seq.h +++ b/source/games/blood/src/seq.h @@ -76,8 +76,8 @@ class DBloodActor; struct SEQINST { Seq* pSequence; - DBloodActor* actor; - int seqindex, type; + EventObject target; + int type; int nSeqID; int callback; @@ -93,18 +93,22 @@ inline int seqGetTile(SEQFRAME* pFrame) int seqRegisterClient(void(*pClient)(int, int)); void seqPrecacheId(int id, int palette); -SEQINST* GetInstance(int a1, int a2); +SEQINST* GetInstance(int a1, EventObject& a2); SEQINST* GetInstance(DBloodActor* actor); void UnlockInstance(SEQINST* pInst); -void seqSpawn(int a1, int a2, int a3, int a4 = -1); +void seqSpawn(int a1, int ty, walltype* a2, int a4 = -1); +void seqSpawn(int a1, int ty, sectortype* a2, int a4 = -1); void seqSpawn(int a1, DBloodActor* actor, int a4 = -1); -void seqKill(int a1, int a2); +void seqKill(int a1, walltype* a2); +void seqKill(int a1, sectortype* a2); void seqKill(DBloodActor* actor); void seqKillAll(void); -int seqGetStatus(int a1, int a2); +int seqGetStatus(int a1, walltype* a2); +int seqGetStatus(int a1, sectortype* a2); int seqGetStatus(DBloodActor*); -int seqGetID(int a1, int a2); +int seqGetID(int a1, walltype* a2); +int seqGetID(int a1, sectortype* a2); int seqGetID(DBloodActor*); void seqProcess(int a1); diff --git a/source/games/blood/src/triggers.cpp b/source/games/blood/src/triggers.cpp index 1a47cbef3..3290bc62e 100644 --- a/source/games/blood/src/triggers.cpp +++ b/source/games/blood/src/triggers.cpp @@ -1834,7 +1834,7 @@ void trMessageSprite(DBloodActor* actor, EVENT event) break; #ifdef NOONE_EXTENSIONS case kCmdModernUse: - modernTypeTrigger(SS_SPRITE, 0, actor, event); + modernTypeTrigger(OBJ_SPRITE, 0, actor, event); break; #endif default: