-Exhumed: better handling of BuildNear/BelowNear.

BuildNear was only called right before calling BelowNear - now both functions are merged and use the global GlobalSectorList array for storage.
Since the data in this is local to this function it is also unnecessary to write it out to a savegame as it will get recereate each time before it is used.
This commit is contained in:
Christoph Oelckers 2021-11-11 01:09:51 +01:00
parent d70e76e5c6
commit 794c4483ca

View file

@ -30,13 +30,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS BEGIN_PS_NS
int NearSector[kMaxSectors] = { 0 };
short nPushBlocks; short nPushBlocks;
// TODO - moveme? // TODO - moveme?
short overridesect; short overridesect;
int NearCount = -1;
DExhumedActor* nBodySprite[50]; DExhumedActor* nBodySprite[50];
@ -71,9 +68,7 @@ void SerializeMove(FSerializer& arc)
{ {
if (arc.BeginObject("move")) if (arc.BeginObject("move"))
{ {
arc("nearcount", NearCount) arc ("pushcount", nPushBlocks)
.Array("nearsector", NearSector, NearCount)
("pushcount", nPushBlocks)
.Array("blocks", sBlockInfo, nPushBlocks) .Array("blocks", sBlockInfo, nPushBlocks)
("chunkcount", nCurChunkNum) ("chunkcount", nCurChunkNum)
.Array("chunks", nChunkSprite, kMaxMoveChunks) .Array("chunks", nChunkSprite, kMaxMoveChunks)
@ -228,16 +223,16 @@ void clipwall()
} }
void BuildNear(int x, int y, int walldist, int nSector) int BelowNear(DExhumedActor* pActor, int x, int y, int walldist, int nSector)
{ {
NearSector[0] = nSector; unsigned nearstart = GlobalSectorList.Size();
NearCount = 1; GlobalSectorList.Push(nSector);
int i = 0; unsigned i = nearstart;
while (i < NearCount) while (i < GlobalSectorList.Size())
{ {
int nSector =NearSector[i]; int nSector = GlobalSectorList[i];
int nWall = sector[nSector].wallptr; int nWall = sector[nSector].wallptr;
int nWallCount = sector[nSector].wallnum; int nWallCount = sector[nSector].wallnum;
@ -255,21 +250,20 @@ void BuildNear(int x, int y, int walldist, int nSector)
if (nNextSector >= 0) if (nNextSector >= 0)
{ {
int j = 0; unsigned j = nearstart;
for (; j < NearCount; j++) for (; j < GlobalSectorList.Size(); j++)
{ {
// loc_14F4D: // loc_14F4D:
if (nNextSector == NearSector[j]) if (nNextSector == GlobalSectorList[j])
break; break;
} }
if (j >= NearCount) if (j >= GlobalSectorList.Size())
{ {
vec2_t pos = { x, y }; vec2_t pos = { x, y };
if (clipinsidebox(&pos, nWall, walldist)) if (clipinsidebox(&pos, nWall, walldist))
{ {
NearSector[NearCount] = wall[nWall].nextsector; GlobalSectorList.Push(wall[nWall].nextsector);
NearCount++;
} }
} }
} }
@ -277,12 +271,9 @@ void BuildNear(int x, int y, int walldist, int nSector)
nWall++; nWall++;
} }
} }
}
int BelowNear(DExhumedActor* pActor) auto pSprite = &pActor->s();
{ nSector = pSprite->sectnum;
auto pSprite = &pActor->s();
int nSector =pSprite->sectnum;
int z = pSprite->z; int z = pSprite->z;
int z2; int z2;
@ -295,13 +286,13 @@ int BelowNear(DExhumedActor* pActor)
{ {
z2 = sector[nSector].floorz + SectDepth[nSector]; z2 = sector[nSector].floorz + SectDepth[nSector];
if (NearCount > 0) if (GlobalSectorList.Size() > nearstart)
{ {
short edx; short edx;
for (int i = 0; i < NearCount; i++) for (unsigned i = nearstart; i < GlobalSectorList.Size(); i++)
{ {
int nSect2 = NearSector[i]; int nSect2 = GlobalSectorList[i];
while (nSect2 >= 0) while (nSect2 >= 0)
{ {
@ -320,6 +311,7 @@ int BelowNear(DExhumedActor* pActor)
} }
} }
} }
GlobalSectorList.Resize(nearstart);
if (z2 < pSprite->z) if (z2 < pSprite->z)
{ {
@ -508,8 +500,7 @@ Collision movespritez(DExhumedActor* pActor, int z, int height, int, int clipdis
if (pSprite->statnum == 100) if (pSprite->statnum == 100)
{ {
BuildNear(pSprite->x, pSprite->y, clipdist + (clipdist / 2), pSprite->sectnum); nRet.exbits |= BelowNear(pActor, pSprite->x, pSprite->y, clipdist + (clipdist / 2), pSprite->sectnum);
nRet.exbits |= BelowNear(pActor);
} }
return nRet; return nRet;