diff --git a/source/build/include/build.h b/source/build/include/build.h index ba100d816..cdf7a4184 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -38,19 +38,15 @@ typedef int64_t coord_t; enum { - MAXSECTORS = 4096, - MAXWALLS = 16384, - MAXSPRITES = 16384, - MAXVOXMIPS = 5, - MAXWALLSB = ((MAXWALLS >> 2) + (MAXWALLS >> 3)), + MAXWALLSB = 6144, MAXVOXELS = 1024, MAXSTATUS = 1024, // Maximum number of component tiles in a multi-psky: MAXPSKYTILES = 16, - MAXSPRITESONSCREEN = MAXSPRITES >> 2, + MAXSPRITESONSCREEN = 4096, MAXUNIQHUDID = 256, //Extra slots so HUD models can store animation state without messing game sprites TSPR_TEMP = 99, @@ -274,6 +270,7 @@ void insertAllSprites(SpawnSpriteDef& sprites); void allocateMapArrays(int numsprites); void ValidateSprite(spritetype& spr, int secno, int index); +void fixSectors(); void engineLoadBoard(const char *filename, int flags, vec3_t *dapos, int16_t *daang, int *dacursectnum, SpawnSpriteDef& sprites); void loadMapBackup(const char* filename); void G_LoadMapHack(const char* filename, const unsigned char*, SpawnSpriteDef& sprites); diff --git a/source/build/src/engine_priv.h b/source/build/src/engine_priv.h index 3df72f31b..ebcd98d63 100644 --- a/source/build/src/engine_priv.h +++ b/source/build/src/engine_priv.h @@ -34,8 +34,6 @@ int32_t animateoffs(int tilenum, int fakevar); inline int32_t bad_tspr(tspriteptr_t tspr) { - // NOTE: tspr->owner >= MAXSPRITES (could be model) has to be handled by - // caller. return (tspr->ownerActor == nullptr || (unsigned)tspr->picnum >= MAXTILES); } diff --git a/source/core/maphack.cpp b/source/core/maphack.cpp index f8ce40e05..6dd4c6bed 100644 --- a/source/core/maphack.cpp +++ b/source/core/maphack.cpp @@ -105,7 +105,7 @@ static int32_t LoadMapHack(const char *filename, SpawnSpriteDef& sprites) if (sc.CheckNumber()) { currentsprite = sc.Number; - if (currentsprite < 0 || currentsprite >= MAXSPRITES) + if ((unsigned)currentsprite >= sprites.sprites.Size()) { sc.ScriptMessage("Invalid sprite number %d", currentsprite); currentsprite = -1; diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index f981c622a..9dc4e8435 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -385,6 +385,22 @@ void allocateMapArrays(int numsprites) ClearAutomap(); } +void fixSectors() +{ + for(auto& sect : sectors()) + { + // Fix maps which do not set their wallptr to the first wall of the sector. Lo Wang In Time's map 11 is such a case. + auto wp = sect.firstWall(); + // Note: we do not have the 'sector' index initialized here, it would not be helpful anyway for this fix. + while (wp != wall.Data() && wp[-1].twoSided() && wp[-1].nextWall()->nextWall() == &wp[-1] && wp[-1].nextWall()->nextSector() == §) + { + sect.wallptr--; + sect.wallnum++; + wp--; + } + } +} + void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cursectnum, SpawnSpriteDef& sprites) { inputState.ClearAllInput(); @@ -411,7 +427,6 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, auto wallpos = fr.Tell(); fr.Seek((mapversion == 5 ? wallsize5 : mapversion == 6 ? wallsize6 : wallsize7)* numwalls, FileReader::SeekCur); int numsprites = fr.ReadUInt16(); - if ((unsigned)numsprites > MAXSPRITES) I_Error("%s: Invalid map, too many sprites", filename); auto spritepos = fr.Tell(); // Now that we know the map's size, set up the globals. @@ -464,6 +479,7 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, artSetupMapArt(filename); //Must be last. + fixSectors(); updatesector(pos->x, pos->y, cursectnum); guniqhudid = 0; fr.Seek(0, FileReader::SeekSet); diff --git a/source/core/rendering/hw_sections.cpp b/source/core/rendering/hw_sections.cpp index e04f8d06b..f7c8b6aac 100644 --- a/source/core/rendering/hw_sections.cpp +++ b/source/core/rendering/hw_sections.cpp @@ -42,9 +42,9 @@ #include "hw_sections.h" -SectionLine sectionLines[MAXWALLS + (MAXWALLS >> 2)]; +TArray sectionLines; TArray
Sections; -TArray sectionspersector[MAXSECTORS]; // reverse map, mainly for the automap +TArray> sectionspersector; // reverse map, mainly for the automap int numsectionlines; void hw_SplitSector(int sector, int startpos, int endpos); @@ -55,16 +55,11 @@ TArray splits; void hw_BuildSections() { Sections.Resize(numsectors); + sectionspersector.Resize(numsectors); + sectionLines.Resize(numwalls * 5 / 4); // cannot reallocate, unfortunately. + numsectionlines = numwalls; for (int i = 0; i < numsectors; i++) { - // Fix maps which do not set their wallptr to the first wall. Lo Wang In Time's map 11 is such a case. - int wp = sector[i].wallptr; - while (wp > 0 && wall[wp - 1].nextwall >= 0 && wall[wp - 1].nextWall()->nextsector == i) - { - sector[i].wallptr--; - sector[i].wallnum++; - wp--; - } Sections[i].sector = i; Sections[i].lines.Resize(sector[i].wallnum); for (int j = 0; j < sector[i].wallnum; j++) Sections[i].lines[j] = sector[i].wallptr + j; diff --git a/source/core/rendering/hw_sections.h b/source/core/rendering/hw_sections.h index 428893ef4..5c3692b31 100644 --- a/source/core/rendering/hw_sections.h +++ b/source/core/rendering/hw_sections.h @@ -21,10 +21,9 @@ struct Section }; // giving 25% more may be a bit high as normally this should be small numbers only. -extern SectionLine sectionLines[MAXWALLS + (MAXWALLS >> 2)]; +extern TArray sectionLines; extern TArray
Sections; -extern TArray sectionspersector[MAXSECTORS]; // reverse map, mainly for the automap -extern int numsectionlines; +extern TArray> sectionspersector; // reverse map, mainly for the automap void hw_BuildSections(); diff --git a/source/core/rendering/scene/hw_bunchdrawer.cpp b/source/core/rendering/scene/hw_bunchdrawer.cpp index 2a8271497..316045075 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.cpp +++ b/source/core/rendering/scene/hw_bunchdrawer.cpp @@ -74,8 +74,8 @@ void BunchDrawer::Init(HWDrawInfo *_di, Clipper* c, vec2_t& view, binangle a1, b // Precalculate the clip angles to avoid doing this repeatedly during level traversal. wall[i].clipangle = clipper->PointToAngle(wall[i].pos); } - memset(sectionstartang, -1, sizeof(sectionstartang)); - memset(sectionendang, -1, sizeof(sectionendang)); + memset(sectionstartang.Data(), -1, sectionstartang.Size() * sizeof(sectionstartang[0])); + memset(sectionendang.Data(), -1, sectionendang.Size() * sizeof(sectionendang[0])); gotwall.Resize(numwalls); blockwall.Resize(numwalls); } @@ -94,8 +94,11 @@ void BunchDrawer::StartScene() CompareData.Clear(); gotsector.Resize(numsectors); gotsector.Zero(); + gotsection2.Resize(Sections.Size()); gotsection2.Zero(); gotwall.Zero(); + sectionstartang.Resize(Sections.Size()); + sectionendang.Resize(Sections.Size()); blockwall.Zero(); } diff --git a/source/core/rendering/scene/hw_bunchdrawer.h b/source/core/rendering/scene/hw_bunchdrawer.h index ed8bd1d06..7466cd063 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.h +++ b/source/core/rendering/scene/hw_bunchdrawer.h @@ -28,12 +28,12 @@ class BunchDrawer vec2_t iview; float gcosang, gsinang; BitArray gotsector; - FixedBitArray gotsection2; + BitArray gotsection2; BitArray gotwall; BitArray blockwall; binangle ang1, ang2, angrange; - int sectionstartang[MAXSECTORS*5/4], sectionendang[MAXSECTORS*5/4]; + TArray sectionstartang, sectionendang; private: diff --git a/source/games/blood/src/aiboneel.cpp b/source/games/blood/src/aiboneel.cpp index 895d7a912..fe425cab5 100644 --- a/source/games/blood/src/aiboneel.cpp +++ b/source/games/blood/src/aiboneel.cpp @@ -67,7 +67,7 @@ void eelBiteSeqCallback(int, DBloodActor* actor) /* * workaround for - * pXSprite->target >= 0 && pXSprite->target < kMaxSprites in file NBlood/source/blood/src/aiboneel.cpp at line 86 + * pXSprite->target >= 0 in file NBlood/source/blood/src/aiboneel.cpp at line 86 * The value of pXSprite->target is -1. * copied from lines 177:181 * resolves this case, but may cause other issues? diff --git a/source/games/blood/src/bloodactor.h b/source/games/blood/src/bloodactor.h index decb84c78..360753522 100644 --- a/source/games/blood/src/bloodactor.h +++ b/source/games/blood/src/bloodactor.h @@ -111,12 +111,12 @@ public: void SetSpecialOwner() // nnext hackery { ownerActor = nullptr; - s().owner = kMaxSprites - 1; + s().owner = kMagicOwner; } bool GetSpecialOwner() { - return ownerActor == nullptr && (s().owner == kMaxSprites - 1); + return ownerActor == nullptr && (s().owner == kMagicOwner); } bool IsPlayerActor() diff --git a/source/games/blood/src/common_game.h b/source/games/blood/src/common_game.h index 5195fe2c5..bdb8b6a00 100644 --- a/source/games/blood/src/common_game.h +++ b/source/games/blood/src/common_game.h @@ -36,7 +36,7 @@ void QuitGame(void); enum { - kMaxSprites = MAXSPRITES, + kMagicOwner = 16383, kMaxTiles = MAXTILES, kMaxStatus = MAXSTATUS, diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index df5370b15..1d1df3ff1 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -645,6 +645,8 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect #endif } } + fixSectors(); + unsigned int nCRC = fr.ReadUInt32(); fr.Seek(0, FileReader::SeekSet); diff --git a/source/games/blood/src/db.h b/source/games/blood/src/db.h index b1c3c9a49..4fa6f62a5 100644 --- a/source/games/blood/src/db.h +++ b/source/games/blood/src/db.h @@ -100,21 +100,6 @@ struct BloodSpawnSpriteDef : public SpawnSpriteDef TArray xspr; }; -#ifdef POLYMER -#pragma pack(push, 1) -struct PolymerLight_t { - int16_t lightId, lightmaxrange; - _prlight* lightptr; - uint8_t lightcount; -}; -#pragma pack(pop) - -extern PolymerLight_t gPolymerLight[kMaxSprites]; - -void DeleteLight(int32_t s); - -#endif - DBloodActor* InsertSprite(sectortype* pSector, int nStat); int DeleteSprite(DBloodActor* actor); diff --git a/source/games/exhumed/src/engine.h b/source/games/exhumed/src/engine.h index 4538fa526..a81245b82 100644 --- a/source/games/exhumed/src/engine.h +++ b/source/games/exhumed/src/engine.h @@ -25,7 +25,6 @@ BEGIN_PS_NS enum { kStatIgnited = 404, - kMaxSprites = 4096, kMaxVoxels = 4096, kMaxPalookups = 256, kMaxStatus = 1024, diff --git a/source/games/sw/src/scrip2.cpp b/source/games/sw/src/scrip2.cpp index e73d93dae..c602a017a 100644 --- a/source/games/sw/src/scrip2.cpp +++ b/source/games/sw/src/scrip2.cpp @@ -58,7 +58,6 @@ ParentalStruct aVoxelArray[MAXTILES]; static char* script_p, * scriptend_p; static char token[MAXTOKEN]; -static int grabbed; static int scriptline; static bool endofscript; static bool tokenready; // only true if UnGetToken was just called @@ -196,13 +195,9 @@ void LoadKVXFromScript(const char* filename) int lNumber = 0, lTile = 0; // lNumber is the voxel no. and lTile is the editart tile being // replaced. - int grabbed = 0; // Number of lines parsed - // zero out the array memory with -1's for pics not being voxelized memset(&aVoxelArray[0], -1, sizeof(struct TILE_INFO_TYPE) * MAXTILES); - grabbed = 0; - // Load the file auto buffer = LoadScriptFile(filename); if (!buffer.Size()) @@ -235,10 +230,6 @@ void LoadKVXFromScript(const char* filename) if (lNumber >= nextvoxid) // JBF: so voxels in the def file append to the list nextvoxid = lNumber + 1; - - grabbed++; - ASSERT(grabbed < MAXSPRITES); - } while (script_p < scriptend_p);