- pass sectors to AddBusy and ReverseBusy.

This commit is contained in:
Christoph Oelckers 2021-12-26 22:35:08 +01:00
parent 9d423d19cd
commit 28840b3afa
3 changed files with 21 additions and 21 deletions

View file

@ -5229,7 +5229,7 @@ int sectorInMotion(int nSector)
for (int i = 0; i < kMaxBusyCount; i++) for (int i = 0; i < kMaxBusyCount; i++)
{ {
if (gBusy->index == nSector) return i; if (gBusy->sect == &sector[nSector]) return i;
} }
return -1; return -1;
} }
@ -5367,7 +5367,7 @@ void sectorContinueMotion(sectortype* pSector, EVENT event)
SectorStartSound(pSector, pXSector->state); SectorStartSound(pSector, pXSector->state);
nDelta = (pXSector->state) ? -nDelta : nDelta; nDelta = (pXSector->state) ? -nDelta : nDelta;
gBusy[gBusyCount].index = sectnum(pSector); gBusy[gBusyCount].sect = pSector;
gBusy[gBusyCount].delta = nDelta; gBusy[gBusyCount].delta = nDelta;
gBusy[gBusyCount].busy = pXSector->busy; gBusy[gBusyCount].busy = pXSector->busy;
gBusy[gBusyCount].type = (BUSYID)busyFunc; gBusy[gBusyCount].type = (BUSYID)busyFunc;

View file

@ -133,20 +133,20 @@ bool SetSectorState(int nSector, XSECTOR *pXSector, int nState)
int gBusyCount = 0; int gBusyCount = 0;
BUSY gBusy[]; BUSY gBusy[];
void AddBusy(int a1, BUSYID a2, int nDelta) void AddBusy(sectortype* pSector, BUSYID a2, int nDelta)
{ {
assert(nDelta != 0); assert(nDelta != 0);
int i; int i;
for (i = 0; i < gBusyCount; i++) for (i = 0; i < gBusyCount; i++)
{ {
if (gBusy[i].index == a1 && gBusy[i].type == a2) if (gBusy[i].sect == pSector && gBusy[i].type == a2)
break; break;
} }
if (i == gBusyCount) if (i == gBusyCount)
{ {
if (gBusyCount == kMaxBusyCount) if (gBusyCount == kMaxBusyCount)
return; return;
gBusy[i].index = a1; gBusy[i].sect = pSector;
gBusy[i].type = a2; gBusy[i].type = a2;
gBusy[i].busy = nDelta > 0 ? 0 : 65536; gBusy[i].busy = nDelta > 0 ? 0 : 65536;
gBusyCount++; gBusyCount++;
@ -154,12 +154,12 @@ void AddBusy(int a1, BUSYID a2, int nDelta)
gBusy[i].delta = nDelta; gBusy[i].delta = nDelta;
} }
void ReverseBusy(int a1, BUSYID a2) void ReverseBusy(sectortype* pSector, BUSYID a2)
{ {
int i; int i;
for (i = 0; i < gBusyCount; i++) for (i = 0; i < gBusyCount; i++)
{ {
if (gBusy[i].index == a1 && gBusy[i].type == a2) if (gBusy[i].sect == pSector && gBusy[i].type == a2)
{ {
gBusy[i].delta = -gBusy[i].delta; gBusy[i].delta = -gBusy[i].delta;
break; break;
@ -1347,18 +1347,18 @@ void OperateDoor(unsigned int nSector, XSECTOR *pXSector, EVENT event, BUSYID bu
switch (event.cmd) { switch (event.cmd) {
case kCmdOff: case kCmdOff:
if (!pXSector->busy) break; if (!pXSector->busy) break;
AddBusy(sectnum(pSector), busyWave, -65536/ClipLow((pXSector->busyTimeB*120)/10, 1)); AddBusy(pSector, busyWave, -65536/ClipLow((pXSector->busyTimeB*120)/10, 1));
SectorStartSound(pSector, 1); SectorStartSound(pSector, 1);
break; break;
case kCmdOn: case kCmdOn:
if (pXSector->busy == 0x10000) break; if (pXSector->busy == 0x10000) break;
AddBusy(sectnum(pSector), busyWave, 65536/ClipLow((pXSector->busyTimeA*120)/10, 1)); AddBusy(pSector, busyWave, 65536/ClipLow((pXSector->busyTimeA*120)/10, 1));
SectorStartSound(pSector, 0); SectorStartSound(pSector, 0);
break; break;
default: default:
if (pXSector->busy & 0xffff) { if (pXSector->busy & 0xffff) {
if (pXSector->interruptable) { if (pXSector->interruptable) {
ReverseBusy(sectnum(pSector), busyWave); ReverseBusy(pSector, busyWave);
pXSector->state = !pXSector->state; pXSector->state = !pXSector->state;
} }
} else { } else {
@ -1367,7 +1367,7 @@ void OperateDoor(unsigned int nSector, XSECTOR *pXSector, EVENT event, BUSYID bu
if (t) nDelta = 65536/ClipLow((pXSector->busyTimeA*120)/10, 1); if (t) nDelta = 65536/ClipLow((pXSector->busyTimeA*120)/10, 1);
else nDelta = -65536/ClipLow((pXSector->busyTimeB*120)/10, 1); else nDelta = -65536/ClipLow((pXSector->busyTimeB*120)/10, 1);
AddBusy(sectnum(pSector), busyWave, nDelta); AddBusy(pSector, busyWave, nDelta);
SectorStartSound(pSector, pXSector->state); SectorStartSound(pSector, pXSector->state);
} }
break; break;
@ -1490,7 +1490,7 @@ void OperatePath(unsigned int nSector, XSECTOR *pXSector, EVENT event)
case kCmdOn: case kCmdOn:
pXSector->state = 0; pXSector->state = 0;
pXSector->busy = 0; pXSector->busy = 0;
AddBusy(nSector, BUSYID_7, 65536/ClipLow((120*pXSprite2->busyTime)/10,1)); AddBusy(pSector, BUSYID_7, 65536/ClipLow((120*pXSprite2->busyTime)/10,1));
if (pXSprite2->data3) PathSound(nSector, pXSprite2->data3); if (pXSprite2->data3) PathSound(nSector, pXSprite2->data3);
break; break;
} }
@ -1553,13 +1553,13 @@ void OperateSector(sectortype* pSector, EVENT event)
case kCmdOn: case kCmdOn:
pXSector->state = 0; pXSector->state = 0;
pXSector->busy = 0; pXSector->busy = 0;
AddBusy(nSector, BUSYID_5, 65536/ClipLow((120*pXSector->busyTimeA)/10, 1)); AddBusy(pSector, BUSYID_5, 65536/ClipLow((120*pXSector->busyTimeA)/10, 1));
SectorStartSound(pSector, 0); SectorStartSound(pSector, 0);
break; break;
case kCmdOff: case kCmdOff:
pXSector->state = 1; pXSector->state = 1;
pXSector->busy = 65536; pXSector->busy = 65536;
AddBusy(nSector, BUSYID_5, -65536/ClipLow((120*pXSector->busyTimeB)/10, 1)); AddBusy(pSector, BUSYID_5, -65536/ClipLow((120*pXSector->busyTimeB)/10, 1));
SectorStartSound(pSector, 1); SectorStartSound(pSector, 1);
break; break;
} }
@ -1636,20 +1636,20 @@ void LinkSector(int nSector, XSECTOR *pXSector, EVENT event)
int nBusy = GetSourceBusy(event); int nBusy = GetSourceBusy(event);
switch (pSector->type) { switch (pSector->type) {
case kSectorZMotionSprite: case kSectorZMotionSprite:
VSpriteBusy(&sector[nSector], nBusy); VSpriteBusy(pSector, nBusy);
break; break;
case kSectorZMotion: case kSectorZMotion:
VDoorBusy(&sector[nSector], nBusy); VDoorBusy(pSector, nBusy);
break; break;
case kSectorSlideMarked: case kSectorSlideMarked:
case kSectorSlide: case kSectorSlide:
HDoorBusy(&sector[nSector], nBusy); HDoorBusy(pSector, nBusy);
break; break;
case kSectorRotateMarked: case kSectorRotateMarked:
case kSectorRotate: case kSectorRotate:
// force synchronised input here for now. // force synchronised input here for now.
setForcedSyncInput(); setForcedSyncInput();
RDoorBusy(&sector[nSector], nBusy); RDoorBusy(pSector, nBusy);
break; break;
default: default:
pXSector->busy = nBusy; pXSector->busy = nBusy;
@ -1955,7 +1955,7 @@ void trProcessBusy(void)
int oldBusy = gBusy[i].busy; int oldBusy = gBusy[i].busy;
gBusy[i].busy = ClipRange(oldBusy+gBusy[i].delta*4, 0, 65536); gBusy[i].busy = ClipRange(oldBusy+gBusy[i].delta*4, 0, 65536);
#ifdef NOONE_EXTENSIONS #ifdef NOONE_EXTENSIONS
if (!gModernMap || !sector[gBusy[i].index].xs().unused1) nStatus = gBusyProc[gBusy[i].type](&sector[gBusy[i].index], gBusy[i].busy); if (!gModernMap || !gBusy[i].sect->xs().unused1) nStatus = gBusyProc[gBusy[i].type](gBusy[i].sect, gBusy[i].busy);
else nStatus = 3; // allow to pause/continue motion for sectors any time by sending special command else nStatus = 3; // allow to pause/continue motion for sectors any time by sending special command
#else #else
nStatus = gBusyProc[gBusy[i].type](gBusy[i].at0, gBusy[i].at8); nStatus = gBusyProc[gBusy[i].type](gBusy[i].at0, gBusy[i].at8);
@ -2262,7 +2262,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, BUSY& w, BUSY* def
{ {
if (arc.BeginObject(keyname)) if (arc.BeginObject(keyname))
{ {
arc("index", w.index) arc("index", w.sect)
("type", w.type) ("type", w.type)
("delta", w.delta) ("delta", w.delta)
("busy", w.busy) ("busy", w.busy)

View file

@ -44,7 +44,7 @@ enum BUSYID {
#define kMaxBusyCount 128 #define kMaxBusyCount 128
struct BUSY { struct BUSY {
int index; sectortype* sect;
int delta; int delta;
int busy; int busy;
int/*BUSYID*/ type; int/*BUSYID*/ type;