From 7f94eee9bb52601924a4b63ddb4d6d30ce2d114c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 24 Nov 2021 01:38:20 +0100 Subject: [PATCH] - busy interface + unlimiting. --- source/games/blood/src/nnexts.cpp | 28 ++------------- source/games/blood/src/nnexts.h | 1 - source/games/blood/src/triggers.cpp | 54 ++++++++++++----------------- source/games/blood/src/triggers.h | 4 +-- 4 files changed, 26 insertions(+), 61 deletions(-) diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 343994abe..3b8f8d8d0 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -5224,22 +5224,6 @@ int aiFightGetFineTargetDist(DBloodActor* actor, DBloodActor* target) // //--------------------------------------------------------------------------- -int sectorInMotion(int nSector) -{ - - for (int i = 0; i < kMaxBusyCount; i++) - { - if (gBusy->sect == §or[nSector]) return i; - } - return -1; -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - void sectorKillSounds(sectortype* pSector) { BloodSectIterator it(pSector); @@ -5278,11 +5262,6 @@ void sectorPauseMotion(sectortype* pSector) void sectorContinueMotion(sectortype* pSector, EVENT event) { if (!pSector->hasX()) return; - else if (gBusyCount >= kMaxBusyCount) - { - Printf(PRINT_HIGH, "Failed to continue motion for sector. Max (%d) busy objects count reached!", kMaxBusyCount); - return; - } XSECTOR* pXSector = &pSector->xs(); pXSector->unused1 = 0; @@ -5367,11 +5346,8 @@ void sectorContinueMotion(sectortype* pSector, EVENT event) SectorStartSound(pSector, pXSector->state); nDelta = (pXSector->state) ? -nDelta : nDelta; - gBusy[gBusyCount].sect = pSector; - gBusy[gBusyCount].delta = nDelta; - gBusy[gBusyCount].busy = pXSector->busy; - gBusy[gBusyCount].type = (BUSYID)busyFunc; - gBusyCount++; + BUSY b = { pSector, nDelta, (int)pXSector->busy, (BUSYID)busyFunc }; + gBusy.Push(b); } //--------------------------------------------------------------------------- diff --git a/source/games/blood/src/nnexts.h b/source/games/blood/src/nnexts.h index a2ac46d26..930ddc5bc 100644 --- a/source/games/blood/src/nnexts.h +++ b/source/games/blood/src/nnexts.h @@ -411,7 +411,6 @@ inline bool aiInPatrolState(int nAiStateType) { } // ------------------------------------------------------------------------- // bool readyForCrit(DBloodActor* pHunter, DBloodActor* pVictim); -int sectorInMotion(int nSector); void clampSprite(DBloodActor* actor, int which = 3); #endif diff --git a/source/games/blood/src/triggers.cpp b/source/games/blood/src/triggers.cpp index e9bc49e7d..b70e2d00e 100644 --- a/source/games/blood/src/triggers.cpp +++ b/source/games/blood/src/triggers.cpp @@ -130,38 +130,30 @@ bool SetSectorState(int nSector, XSECTOR *pXSector, int nState) return 1; } -int gBusyCount = 0; -BUSY gBusy[]; +TArray gBusy; void AddBusy(sectortype* pSector, BUSYID a2, int nDelta) { assert(nDelta != 0); - int i; - for (i = 0; i < gBusyCount; i++) + for (auto& b : gBusy) { - if (gBusy[i].sect == pSector && gBusy[i].type == a2) - break; - } - if (i == gBusyCount) - { - if (gBusyCount == kMaxBusyCount) + if (b.sect == pSector && b.type == a2) + { + b.delta = nDelta; return; - gBusy[i].sect = pSector; - gBusy[i].type = a2; - gBusy[i].busy = nDelta > 0 ? 0 : 65536; - gBusyCount++; + } } - gBusy[i].delta = nDelta; + BUSY b = { pSector, nDelta, nDelta > 0 ? 0 : 65536, a2 }; + gBusy.Push(b); } void ReverseBusy(sectortype* pSector, BUSYID a2) { - int i; - for (i = 0; i < gBusyCount; i++) + for (auto& b : gBusy) { - if (gBusy[i].sect == pSector && gBusy[i].type == a2) + if (b.sect == pSector && b.type == a2) { - gBusy[i].delta = -gBusy[i].delta; + b.delta = -b.delta; break; } } @@ -1949,27 +1941,28 @@ void trProcessBusy(void) { sect.velCeil = sect.velFloor = 0; } - for (int i = gBusyCount-1; i >= 0; i--) + for (auto& b : backwards(gBusy)) { int nStatus; - int oldBusy = gBusy[i].busy; - gBusy[i].busy = ClipRange(oldBusy+gBusy[i].delta*4, 0, 65536); + int oldBusy = b.busy; + b.busy = ClipRange(oldBusy+b.delta*4, 0, 65536); #ifdef NOONE_EXTENSIONS - if (!gModernMap || !gBusy[i].sect->xs().unused1) nStatus = gBusyProc[gBusy[i].type](gBusy[i].sect, gBusy[i].busy); + if (!gModernMap || !b.sect->xs().unused1) nStatus = gBusyProc[b.type](b.sect, b.busy); else nStatus = 3; // allow to pause/continue motion for sectors any time by sending special command #else - nStatus = gBusyProc[gBusy[i].type](gBusy[i].at0, gBusy[i].at8); + nStatus = gBusyProc[b.type](b.at0, b.at8); #endif switch (nStatus) { case 1: - gBusy[i].busy = oldBusy; + b.busy = oldBusy; break; case 2: - gBusy[i].busy = oldBusy; - gBusy[i].delta = -gBusy[i].delta; + b.busy = oldBusy; + b.delta = -b.delta; break; case 3: - gBusy[i] = gBusy[--gBusyCount]; + b = gBusy.Last(); + gBusy.Pop(); break; } } @@ -1981,7 +1974,7 @@ void InitGenerator(DBloodActor*); void trInit(void) { - gBusyCount = 0; + gBusy.Clear(); for(auto& wal : walls()) for (int i = 0; i < numwalls; i++) { @@ -2275,8 +2268,7 @@ void SerializeTriggers(FSerializer& arc) { if (arc.BeginObject("triggers")) { - arc("busycount", gBusyCount) - .Array("busy", gBusy, gBusyCount) + arc("busy", gBusy) .EndObject(); } } diff --git a/source/games/blood/src/triggers.h b/source/games/blood/src/triggers.h index afccce78b..0f7834dcb 100644 --- a/source/games/blood/src/triggers.h +++ b/source/games/blood/src/triggers.h @@ -42,7 +42,6 @@ enum BUSYID { BUSYID_7, }; -#define kMaxBusyCount 128 struct BUSY { sectortype* sect; int delta; @@ -50,8 +49,7 @@ struct BUSY { int/*BUSYID*/ type; }; -extern BUSY gBusy[kMaxBusyCount]; -extern int gBusyCount; +extern TArray gBusy; void trTriggerSector(sectortype *pSector, int command); void trMessageSector(sectortype* pSector, EVENT event);