- busy interface + unlimiting.

This commit is contained in:
Christoph Oelckers 2021-11-24 01:38:20 +01:00
parent 28840b3afa
commit 7f94eee9bb
4 changed files with 26 additions and 61 deletions

View file

@ -5224,22 +5224,6 @@ int aiFightGetFineTargetDist(DBloodActor* actor, DBloodActor* target)
//
//---------------------------------------------------------------------------
int sectorInMotion(int nSector)
{
for (int i = 0; i < kMaxBusyCount; i++)
{
if (gBusy->sect == &sector[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);
}
//---------------------------------------------------------------------------

View file

@ -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

View file

@ -130,38 +130,30 @@ bool SetSectorState(int nSector, XSECTOR *pXSector, int nState)
return 1;
}
int gBusyCount = 0;
BUSY gBusy[];
TArray<BUSY> 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();
}
}

View file

@ -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<BUSY> gBusy;
void trTriggerSector(sectortype *pSector, int command);
void trMessageSector(sectortype* pSector, EVENT event);