diff --git a/source/build/include/build.h b/source/build/include/build.h index 66cd8fee7..04eb79cc3 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -148,7 +148,7 @@ extern spriteext_t spriteext[MAXSPRITES]; extern spritesmooth_t spritesmooth[MAXSPRITES + MAXUNIQHUDID]; extern TArray sector; -extern walltype wall[MAXWALLS]; +extern TArray wall; extern spritetype sprite[MAXSPRITES]; EXTERN int leveltimer; @@ -183,8 +183,7 @@ inline walltype* sectortype::firstWall() const extern TArray sectorbackup; -//extern TArray wallbackup; -extern walltype wallbackup[MAXWALLS]; +extern TArray wallbackup; inline tspriteptr_t renderAddTSpriteFromSprite(spritetype* tsprite, int& spritesortcnt, uint16_t const spritenum) { diff --git a/source/build/include/buildtypes.h b/source/build/include/buildtypes.h index 180b31f3f..102b22ee6 100644 --- a/source/build/include/buildtypes.h +++ b/source/build/include/buildtypes.h @@ -56,11 +56,6 @@ BEGIN_BLD_NS class DBloodActor; END_BLD_NS -namespace ShadowWarrior -{ - struct SECT_USER; -}; - //40 bytes struct walltype; struct sectortype diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index bfaf29da8..de3eee557 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -44,7 +44,7 @@ spriteext_t spriteext[MAXSPRITES]; spritesmooth_t spritesmooth[MAXSPRITES + MAXUNIQHUDID]; TArray sector; -walltype wall[MAXWALLS]; +TArray wall; spritetype sprite[MAXSPRITES]; int32_t r_rortexture = 0; diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 11a2ee4d6..205b0b10b 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -2268,7 +2268,7 @@ void polymost_drawrooms() maskwallcnt = 0; // NOTE: globalcursectnum has been already adjusted in ADJUST_GLOBALCURSECTNUM. - assert((unsigned)globalcursectnum < MAXSECTORS); + assert(validSectorIndex(globalcursectnum)); polymost_scansector(globalcursectnum); grhalfxdown10x = grhalfxdown10; diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 7d6a50c82..8b3514287 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -265,7 +265,7 @@ inline TArrayView wallsofsector(int sec) // these are mainly meant as refactoring aids to mark function calls to work on. inline int wallnum(const walltype* wal) { - return int(wal - wall); + return wall.IndexOf(wal); } inline int sectnum(const sectortype* sect) diff --git a/source/core/maphack.cpp b/source/core/maphack.cpp index 3f08ca67c..d78214c4d 100644 --- a/source/core/maphack.cpp +++ b/source/core/maphack.cpp @@ -117,7 +117,7 @@ static int32_t LoadMapHack(const char *filename) if (sc.CheckNumber()) { currentwall = sc.Number; - if (currentwall < 0 || currentwall >= MAXWALLS) + if (!validWallIndex(currentwall)) { sc.ScriptMessage("Invalid wall number %d", currentwall); currentwall = -1; @@ -132,7 +132,7 @@ static int32_t LoadMapHack(const char *filename) if (sc.CheckNumber()) { currentsector = sc.Number; - if (currentsector < 0 || currentsector >= MAXSECTORS) + if (!validSectorIndex(currentsector)) { sc.ScriptMessage("Invalid sector number %d", currentsector); currentsector = -1; diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index 506e05711..9120e1008 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -414,7 +414,8 @@ void allocateMapArrays(int numsprites) mapDataArena.FreeAll(); sector.Resize(numsectors); memset(sector.Data(), 0, sizeof(sectortype) * numsectors); - memset(wall, 0, sizeof(*wall) * MAXWALLS); + wall.Resize(numwalls); + memset(wall.Data(), 0, sizeof(walltype) * numwalls); memset(sprite, 0, sizeof(*sprite) * MAXSPRITES); memset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES); memset(spritesmooth, 0, sizeof(spritesmooth_t) * (MAXSPRITES + MAXUNIQHUDID)); @@ -443,11 +444,9 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, // Get the basics out before loading the data so that we can set up the global storage. numsectors = fr.ReadUInt16(); - if ((unsigned)numsectors > MAXSECTORS) I_Error("%s: Invalid map, too many sectors", filename); auto sectorpos = fr.Tell(); fr.Seek((mapversion == 5 ? sectorsize5 : mapversion == 6 ? sectorsize6 : sectorsize7) * numsectors, FileReader::SeekCur); numwalls = fr.ReadUInt16(); - if ((unsigned)numwalls > MAXWALLS) I_Error("%s: Invalid map, too many walls", filename); auto wallpos = fr.Tell(); fr.Seek((mapversion == 5 ? wallsize5 : mapversion == 6 ? wallsize6 : wallsize7)* numwalls, FileReader::SeekCur); int numsprites = fr.ReadUInt16(); @@ -521,7 +520,7 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, sectorGeometry.SetSize(numsections); - memcpy(wallbackup, wall, sizeof(wallbackup)); + wallbackup = wall; sectorbackup = sector; } diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index 8a9232d0f..c238a8f72 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -66,8 +66,7 @@ TArray sectorbackup; -//TArray wallbackup; -walltype wallbackup[MAXWALLS]; +TArray wallbackup; void WriteSavePic(FileWriter* file, int width, int height); bool WriteZip(const char* filename, TArray& filenames, TArray& content); @@ -692,7 +691,7 @@ void SerializeMap(FSerializer& arc) ("numsectors", numsectors) ("sectors", sector, sectorbackup) ("numwalls", numwalls) - .Array("walls", wall, wallbackup, numwalls) + ("walls", wall, wallbackup) .Array("headspritestat", headspritestat, MAXSTATUS + 1) .Array("nextspritestat", nextspritestat, MAXSPRITES) .Array("prevspritestat", prevspritestat, MAXSPRITES) diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index 6da088034..ee7185cac 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -958,7 +958,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, int* setWallSectors(); hw_BuildSections(); sectorGeometry.SetSize(numsections); - memcpy(wallbackup, wall, sizeof(wallbackup)); + wallbackup = wall; sectorbackup = sector; } diff --git a/source/games/blood/src/loadsave.cpp b/source/games/blood/src/loadsave.cpp index 38bc3600b..11a9f2b43 100644 --- a/source/games/blood/src/loadsave.cpp +++ b/source/games/blood/src/loadsave.cpp @@ -710,7 +710,6 @@ void SerializeState(FSerializer& arc) arc("visibility", gVisibility) ("frameclock", PlayClock) ("framecount", gFrameCount) - .Array("basewall", baseWall, numwalls) ("hitinfo", gHitInfo) .Array("statcount", gStatCount, kMaxStatus + 1) ("fogmode", gFogMode) diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index b895cebb6..aa22b1740 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -454,11 +454,9 @@ void TerminateLevel(void) KillActor(actor); } - // Free SectUser memory - TRAVERSE_CONNECT(pnum) { - PLAYERp pp = Player + pnum; + PLAYERp pp = &Player[pnum]; // Free panel sprites for players pClearSpriteList(pp);