- removed numsectors and numwalls entirely.

With Blood's Polymost mirror hack the risk of getting out of sync with the arrays was a genuine issue, so now only the array size counts.
This commit is contained in:
Christoph Oelckers 2021-12-21 11:58:20 +01:00
parent df0c577cf4
commit 785c7d4ceb
7 changed files with 14 additions and 19 deletions

View file

@ -1381,7 +1381,6 @@ void GameInterface::FreeLevelData()
{
// Make sure that there is no more level to toy around with.
InitSpriteLists();
numsectors = numwalls = 0;
sector.Reset();
wall.Reset();
currentLevel = nullptr;

View file

@ -51,7 +51,6 @@
extern BitArray clipsectormap;
int numsectors, numwalls; // not really needed anymore, need to be refactored out (58x numsectors, 48x numwalls)
TArray<sectortype> sector;
TArray<walltype> wall;
@ -434,10 +433,10 @@ void loadMap(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cu
*cursectnum = fr.ReadUInt16();
// Get the basics out before loading the data so that we can set up the global storage.
numsectors = fr.ReadUInt16();
unsigned numsectors = fr.ReadUInt16();
auto sectorpos = fr.Tell();
fr.Seek((mapversion == 5 ? sectorsize5 : mapversion == 6 ? sectorsize6 : sectorsize7) * numsectors, FileReader::SeekCur);
numwalls = fr.ReadUInt16();
unsigned numwalls = fr.ReadUInt16();
auto wallpos = fr.Tell();
fr.Seek((mapversion == 5 ? wallsize5 : mapversion == 6 ? wallsize6 : wallsize7)* numwalls, FileReader::SeekCur);
int numsprites = fr.ReadUInt16();

View file

@ -576,7 +576,6 @@ extern TArray<sectortype> sector;
extern TArray<walltype> wall;
extern TArray<sectortype> sectorbackup;
extern TArray<walltype> wallbackup;
extern int numsectors, numwalls;
extern BitArray gotsector;
//=============================================================================
@ -587,12 +586,12 @@ extern BitArray gotsector;
inline bool validSectorIndex(int sectnum)
{
return sectnum >= 0 && sectnum < numsectors;
return (unsigned)sectnum < sector.Size();
}
inline bool validWallIndex(int wallnum)
{
return wallnum >= 0 && wallnum < numwalls;
return (unsigned)wallnum < wall.Size();
}
inline sectortype* spritetypebase::sector() const

View file

@ -683,9 +683,7 @@ void SerializeMap(FSerializer& arc)
if (arc.BeginObject("engine"))
{
arc.Array("statlist", statList, MAXSTATUS)
("numsectors", numsectors)
("sectors", sector, sectorbackup)
("numwalls", numwalls)
("walls", wall, wallbackup)
("tailspritefree", tailspritefree)

View file

@ -209,8 +209,9 @@ void DrawMirrors(int x, int y, int z, fixed_t a, fixed_t horiz, int smooth, int
{
case 0:
{
numwalls += 4; // hack alert. Blood adds some dummy walls and sectors that must not be among the counted, but here they have to be valid.
numsectors++;
// gross hack alert. Blood adds some dummy walls and sectors that must not be among the counted, but here they have to be valid.
wall.Reserve(4);
sector.Reserve(1);
int nWall = mirror[i].link;
walltype* pWall = &wall[nWall];
int nSector = pWall->sector;
@ -248,8 +249,8 @@ void DrawMirrors(int x, int y, int z, fixed_t a, fixed_t horiz, int smooth, int
renderCompleteMirror();
pWall->nextwall = nNextWall;
pWall->nextsector = nNextSector;
numwalls -= 4;
numsectors--;
wall.Clamp(wall.Size() - 4);
sector.Clamp(sector.Size() - 1);
return;
}
@ -325,7 +326,7 @@ void DrawMirrors(int x, int y, int z, fixed_t a, fixed_t horiz, int smooth, int
void InitPolymostMirrorHack()
{
mirrorsector = numsectors;
mirrorsector = sector.Size();
for (int i = 0; i < 4; i++)
{
mirrorwall[i] = wall.Size() + i;
@ -349,9 +350,10 @@ void PolymostAllocFakeSector()
// these additional entries are needed by Blood's mirror code. We must get them upon map load to avoid a later occuring reallocation. Ugh...
// We do not want to actually increase the array size for this, though because it may screw with the savegame code.
// Before rendering this will temporarily be bumped up.
// Note that this depends on the resize operation not deleting and altering the new entries!
sector.Reserve(1);
wall.Reserve(4);
sector.Resize(numsectors);
wall.Resize(numwalls);
wall.Clamp(wall.Size() - 4);
sector.Clamp(sector.Size() - 1);
}
END_BLD_NS

View file

@ -261,8 +261,6 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect
}
parallaxtype = mapHeader.parallax;
gMapRev = mapHeader.revision;
numsectors = mapHeader.numsectors;
numwalls = mapHeader.numwalls;
allocateMapArrays(mapHeader.numwalls, mapHeader.numsectors, mapHeader.numsprites);
#if 1 // bad, bad hack, just for making Polymost happy...
PolymostAllocFakeSector();

View file

@ -146,7 +146,7 @@ void InitMirrors(void)
mirrorcnt++;
}
}
mirrorsector = numsectors;
mirrorsector = sector.Size();
mergePortals();
InitPolymostMirrorHack();
}