diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index 5c8b72416..c8ce1afee 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -398,7 +398,7 @@ static void clipupdatesector(vec2_t const pos, int * const sectnum, int walldist } { - BFSSearch search(numsectors, *sectnum); + BFSSearch search(sector.Size(), *sectnum); for (unsigned listsectnum; (listsectnum = search.GetNext()) != BFSSearch::EOL;) { @@ -417,7 +417,7 @@ static void clipupdatesector(vec2_t const pos, int * const sectnum, int walldist } { - BFSSearch search(numsectors, *sectnum); + BFSSearch search(sector.Size(), *sectnum); for (unsigned listsectnum; (listsectnum = search.GetNext()) != BFSSearch::EOL;) { @@ -784,7 +784,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, int32_t tempint2, tempint1 = INT32_MAX; *sectnum = -1; - for (int j = numsectors - 1; j >= 0; j--) + for (int j = (int)sector.Size() - 1; j >= 0; j--) { auto sect = §or[j]; if (inside(pos->x, pos->y, sect) == 1) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index f260c8a6a..f96d37f3a 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -615,7 +615,7 @@ void neartag(const vec3_t& sv, sectortype* sect, int ange, HitInfoBase& result, // void dragpoint(int w, int32_t dax, int32_t day) { - BFSSearch walbitmap(numwalls); + BFSSearch walbitmap(wall.Size()); int clockwise = 0; const int tmpstartwall = w; int cnt = 16384; // limit the number of iterations. @@ -735,7 +735,7 @@ void updatesectorneighborz(int32_t const x, int32_t const y, int32_t const z, in if (checker(x, y, z, initialsectnum)) return; - BFSSearch search(numsectors, *sectnum); + BFSSearch search(sector.Size(), *sectnum); int iter = 0; for (unsigned listsectnum; (listsectnum = search.GetNext()) != BFSSearch::EOL;) @@ -777,7 +777,7 @@ void updatesector(int32_t const x, int32_t const y, int * const sectnum) // we need to support passing in a sectnum of -1, unfortunately - for (int i = numsectors - 1; i >= 0; --i) + for (int i = (int)sector.Size() - 1; i >= 0; --i) if (inside_p(x, y, i)) SET_AND_RETURN(*sectnum, i); @@ -795,7 +795,7 @@ void updatesectorz(int32_t const x, int32_t const y, int32_t const z, int* const // we need to support passing in a sectnum of -1, unfortunately - for (int i = numsectors - 1; i >= 0; --i) + for (int i = (int)sector.Size() - 1; i >= 0; --i) if (inside_z_p(x, y, z, i)) SET_AND_RETURN(*sectnum, i); diff --git a/source/core/automap.cpp b/source/core/automap.cpp index e9c88da84..2810ac804 100644 --- a/source/core/automap.cpp +++ b/source/core/automap.cpp @@ -416,7 +416,7 @@ void drawredlines(int cposx, int cposy, int czoom, int cang) int width = screen->GetWidth(); int height = screen->GetHeight(); - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { if (!gFullMap && !show2dsector[i]) continue; @@ -464,7 +464,7 @@ static void drawwhitelines(int cposx, int cposy, int czoom, int cang) int width = screen->GetWidth(); int height = screen->GetHeight(); - for (int i = numsectors - 1; i >= 0; i--) + for (int i = (int)sector.Size() - 1; i >= 0; i--) { if (!gFullMap && !show2dsector[i] && !isSWALL()) continue; @@ -556,7 +556,7 @@ void renderDrawMapView(int cposx, int cposy, int czoom, int cang) TArray floorsprites; - for (int i = numsectors - 1; i >= 0; i--) + for (int i = (int)sector.Size() - 1; i >= 0; i--) { auto sect = §or[i]; if (!gFullMap && !show2dsector[i]) continue; diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 2efc91eb6..2761e6405 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -86,7 +86,7 @@ class BFSSectorSearch : public BFSSearch { public: - BFSSectorSearch(const sectortype* startnode) : BFSSearch(numsectors, sector.IndexOf(startnode)) + BFSSectorSearch(const sectortype* startnode) : BFSSearch(sector.Size(), sector.IndexOf(startnode)) { } diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index eb74a63bc..13d4063d1 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -244,7 +244,7 @@ static void ReadWallV5(FileReader& fr, walltype& wall) static void SetWallPalV5() { - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { int startwall = sector[i].wallptr; int endwall = startwall + sector[i].wallnum; @@ -380,20 +380,20 @@ static void ReadSpriteV5(FileReader& fr, spritetype& spr, int& secno) // allocates global map storage. Blood will also call this. -void allocateMapArrays(int numsprites) +void allocateMapArrays(int numwall, int numsector, int numsprites) { ClearInterpolations(); - show2dsector.Resize(numsectors); - show2dwall.Resize(numwalls); - gotsector.Resize(numsectors); - clipsectormap.Resize(numsectors); + show2dsector.Resize(numsector); + show2dwall.Resize(numwall); + gotsector.Resize(numsector); + clipsectormap.Resize(numsector); mapDataArena.FreeAll(); - sector.Resize(numsectors); - memset(sector.Data(), 0, sizeof(sectortype) * numsectors); - wall.Resize(numwalls); + sector.Resize(numsector); + memset(sector.Data(), 0, sizeof(sectortype) * numsector); + wall.Resize(numwall); memset(wall.Data(), 0, sizeof(walltype) * wall.Size()); ClearAutomap(); @@ -444,13 +444,13 @@ void loadMap(const char* filename, int flags, vec3_t* pos, int16_t* ang, int* cu auto spritepos = fr.Tell(); // Now that we know the map's size, set up the globals. - allocateMapArrays(numsprites); + allocateMapArrays(numwalls, numsectors, numsprites); sprites.sprites.Resize(numsprites); memset(sprites.sprites.Data(), 0, numsprites * sizeof(spritetype)); // Now load the actual data. fr.Seek(sectorpos, FileReader::SeekSet); - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { switch (mapversion) { @@ -542,7 +542,7 @@ void setWallSectors() wal.lengthflags = 3; } - for (int i = 0; i < numsectors - 1; i++) + for (unsigned i = 0; i < sector.Size() - 1; i++) { auto sect = §or[i]; auto nextsect = §or[i + 1]; diff --git a/source/core/maptypes.h b/source/core/maptypes.h index 3d41dd369..7d938119f 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -700,7 +700,7 @@ inline int walltype::Length() //============================================================================= struct SpawnSpriteDef; -void allocateMapArrays(int numsprites); +void allocateMapArrays(int numwall, int numsector, int numsprites); void validateSprite(spritetype& spr, int secno, int index); void fixSectors(); void loadMap(const char *filename, int flags, vec3_t *pos, int16_t *ang, int *cursectnum, SpawnSpriteDef& sprites); diff --git a/source/core/rendering/hw_sections.cpp b/source/core/rendering/hw_sections.cpp index 421a23cd9..bf1d495d2 100644 --- a/source/core/rendering/hw_sections.cpp +++ b/source/core/rendering/hw_sections.cpp @@ -211,13 +211,13 @@ int GetWindingOrder(TArray& poly) static void CollectLoops(TArray& sectors) { BitArray visited; - visited.Resize(numwalls); + visited.Resize(wall.Size()); visited.Zero(); TArray thisloop; int count = 0; - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { int first = sector[i].wallptr; int last = first + sector[i].wallnum; @@ -251,7 +251,7 @@ static void CollectLoops(TArray& sectors) } Printf("found already visited wall %d\nLinked by:", ww); bugged.Insert(i, true); - for (int i = 0; i < numwalls; i++) + for (unsigned i = 0; i < wall.Size(); i++) { if (wall[i].point2 == ww) Printf(" %d,", i); @@ -347,13 +347,8 @@ static int insideLoop(TArray& check, TArray& loop) static void GroupData(TArray& collect, TArray& builders) { - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { - if (i == 250) - { - int a = 0; - } - auto& builder = builders[i]; builder.sectnum = i; auto& sectloops = collect[i].loops; @@ -585,37 +580,37 @@ static void ConstructSections(TArray& builders) TArray splitwalls; // Allocate all Section walls. - sectionLines.Resize(numwalls + splits.Size() * 2 / 3); + sectionLines.Resize(wall.Size() + splits.Size() * 2 / 3); for (unsigned i = 0; i < splits.Size(); i++) { if (i % 3) splitwalls.Push(splits[i]); } - int nextwall = numwalls; - for (int i = 0; i < numwalls; i++) + unsigned nextwall = wall.Size(); + for (unsigned i = 0; i < wall.Size(); i++) { sectionLines[i].startpoint = i; sectionLines[i].endpoint = wall[i].point2; sectionLines[i].wall = i; sectionLines[i].partner = wall[i].nextwall; } - for (int i = numwalls; i < (int)sectionLines.Size(); i++) + for (unsigned i = wall.Size(); i < sectionLines.Size(); i++) { - int pair = (i - numwalls); + unsigned pair = (i - wall.Size()); sectionLines[i].startpoint = splitwalls[pair]; sectionLines[i].endpoint = splitwalls[pair ^ 1]; sectionLines[i].wall = -1; - sectionLines[i].partner = numwalls + (pair ^ 1); + sectionLines[i].partner = wall.Size() + (pair ^ 1); } unsigned count = 0; // allocate as much as possible from the arena here. - size_t size = sizeof(*sectionsPerSector.Data()) * numsectors; + size_t size = sizeof(*sectionsPerSector.Data()) * sector.Size(); auto data = sectionArena.Calloc(size); - sectionsPerSector.Set(static_cast(data), numsectors); + sectionsPerSector.Set(static_cast(data), sector.Size()); - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { auto& builder = builders[i]; count += builder.sections.Size(); @@ -630,7 +625,7 @@ static void ConstructSections(TArray& builders) // now fill in the data int cursection = 0; - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { auto& builder = builders[i]; for (unsigned j = 0; j < builder.sections.Size(); j++) @@ -668,7 +663,7 @@ static void ConstructSections(TArray& builders) } else { - wall_i = numwalls + splitwalls.Find(-wall_i); + wall_i = (int)wall.Size() + splitwalls.Find(-wall_i); auto wal = §ionLines[wall_i]; section->lines[curwall++] = loop.walls[w] = wall_i; wal->section = section->index; @@ -701,7 +696,7 @@ void hw_CreateSections() TArray collect; CollectLoops(collect); - TArray builders(numsectors, true); + TArray builders(sector.Size(), true); GroupData(collect, builders); SplitLoops(builders); diff --git a/source/core/rendering/render.h b/source/core/rendering/render.h index f99effc36..407526b92 100644 --- a/source/core/rendering/render.h +++ b/source/core/rendering/render.h @@ -62,10 +62,10 @@ inline void mergePortals() pt1.targets.Append(pt2.targets); pt2.targets.Reset(); pt2.type = -1; - for (int n = 0; n < numsectors; n++) + for (auto& s : sector) { //Printf("Merged %d and %d\n", i, j); - if (sector[n].portalnum == (int)j) sector[n].portalnum = i; + if (s.portalnum == (int)j) s.portalnum = i; } didsomething = true; break; diff --git a/source/core/rendering/scene/hw_bunchdrawer.cpp b/source/core/rendering/scene/hw_bunchdrawer.cpp index 50ebf276d..0051ad43d 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.cpp +++ b/source/core/rendering/scene/hw_bunchdrawer.cpp @@ -68,16 +68,16 @@ void BunchDrawer::Init(HWDrawInfo *_di, Clipper* c, vec2_t& view, binangle a1, b gcosang = bamang(di->Viewpoint.RotAngle).fcos(); gsinang = bamang(di->Viewpoint.RotAngle).fsin(); - for (int i = 0; i < numwalls; i++) + for (auto& w : wall) { // Precalculate the clip angles to avoid doing this repeatedly during level traversal. - auto vv = wall[i].pos - view; - wall[i].clipangle = bvectangbam(vv.x, vv.y); + auto vv = w.pos - view; + w.clipangle = bvectangbam(vv.x, vv.y); } memset(sectionstartang.Data(), -1, sectionstartang.Size() * sizeof(sectionstartang[0])); memset(sectionendang.Data(), -1, sectionendang.Size() * sizeof(sectionendang[0])); - gotwall.Resize(numwalls); - //blockwall.Resize(numwalls); + gotwall.Resize(wall.Size()); + //blockwall.Resize(wall.Size()); } //========================================================================== @@ -93,7 +93,7 @@ void BunchDrawer::StartScene() StartTime = I_msTime(); Bunches.Clear(); CompareData.Clear(); - gotsector.Resize(numsectors); + gotsector.Resize(sector.Size()); gotsector.Zero(); gotsection2.Resize(numsections); gotsection2.Zero(); @@ -652,7 +652,7 @@ void BunchDrawer::ProcessSection(int sectionnum, bool portal) { if (walang1.asbam() >= angrange.asbam()) { walang1 = bamang(0); inbunch = false; } if (walang2.asbam() >= angrange.asbam()) walang2 = angrange; - if (section->lines[i] >= numwalls) inbunch = false; + if (section->lines[i] >= (int)wall.Size()) inbunch = false; if (!inbunch) { //Printf("Starting bunch:\n\tWall %d\n", section->lines[i]); diff --git a/source/core/rendering/scene/hw_portal.h b/source/core/rendering/scene/hw_portal.h index 4dc54c2d2..82b151f8f 100644 --- a/source/core/rendering/scene/hw_portal.h +++ b/source/core/rendering/scene/hw_portal.h @@ -297,6 +297,7 @@ public: struct HWLineToSpritePortal : public HWLinePortal { + walltype clipline = {}; walltype* origin; spritetype* camera; protected: @@ -309,7 +310,7 @@ protected: public: HWLineToSpritePortal(FPortalSceneState* state, walltype* from, spritetype* to) - : HWLinePortal(state, &wall[numwalls]), origin(from), camera(to) + : HWLinePortal(state, &clipline), origin(from), camera(to) { } }; diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index 3dd821f24..7658cfa4e 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -165,7 +165,7 @@ void PropagateMarkerReferences(void) case kMarkerWarpDest: { int nOwner = actor->s().owner; - if (nOwner >= 0 && nOwner < numsectors) + if (validSectorIndex(nOwner)) { if (sector[nOwner].hasX()) { @@ -178,7 +178,7 @@ void PropagateMarkerReferences(void) case kMarkerOn: { int nOwner = actor->s().owner; - if (nOwner >= 0 && nOwner < numsectors) + if (validSectorIndex(nOwner)) { if (sector[nOwner].hasX()) { diff --git a/source/games/blood/src/db.cpp b/source/games/blood/src/db.cpp index 124bd87d7..bc96e217c 100644 --- a/source/games/blood/src/db.cpp +++ b/source/games/blood/src/db.cpp @@ -263,7 +263,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect gMapRev = mapHeader.revision; numsectors = mapHeader.numsectors; numwalls = mapHeader.numwalls; - allocateMapArrays(mapHeader.numsprites); + allocateMapArrays(mapHeader.numwalls, mapHeader.numsectors, mapHeader.numsprites); #if 1 // bad, bad hack, just for making Polymost happy... PolymostAllocFakeSector(); #endif @@ -297,7 +297,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect pSky->tileofs[i] = LittleShort(tpskyoff[i]); } - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { sectortype* pSector = §or[i]; sectortypedisk load; diff --git a/source/games/blood/src/gameutil.cpp b/source/games/blood/src/gameutil.cpp index a196c1d5a..4273dab89 100644 --- a/source/games/blood/src/gameutil.cpp +++ b/source/games/blood/src/gameutil.cpp @@ -690,7 +690,7 @@ BitArray GetClosestSpriteSectors(sectortype* pSector, int x, int y, int nDist, T // E1M2: throwing TNT at the double doors while standing on the train platform // by setting newSectCheckMethod to true these issues will be resolved - BitArray sectorMap(numsectors); // this gets returned to the caller. + BitArray sectorMap(sector.Size()); // this gets returned to the caller. sectorMap.Zero(); sectorMap.Set(sectnum(pSector)); double nDist4sq = 256. * nDist * nDist; // (nDist * 16)^2 - * 16 to account for Build's 28.4 fixed point format. diff --git a/source/games/blood/src/mirrors.cpp b/source/games/blood/src/mirrors.cpp index 64eeaa909..39e89109b 100644 --- a/source/games/blood/src/mirrors.cpp +++ b/source/games/blood/src/mirrors.cpp @@ -48,7 +48,7 @@ void InitMirrors(void) { tileDelete(4080 + i); } - for (int i = numwalls - 1; i >= 0; i--) + for (int i = (int)wall.Size() - 1; i >= 0; i--) { auto pWalli = &wall[i]; if (mirrorcnt == 16) @@ -105,7 +105,7 @@ void InitMirrors(void) continue; } } - for (int i = numsectors - 1; i >= 0; i--) + for (int i = (int)sector.Size() - 1; i >= 0; i--) { if (mirrorcnt >= 15) break; diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index d6a262417..a570d9a44 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -8314,7 +8314,7 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor) } else if (chan->SourceType == SOURCE_Unattached) { - if (chan->UserData < 0 || chan->UserData >= numsectors) return false; // not a vaild sector sound. + if (chan->UserData < 0 || !validSectorIndex(chan->UserData)) return false; // not a vaild sector sound. sndx = int(chan->Point[0] * 16); sndy = int(chan->Point[1] * -16); searchsect = §or[chan->UserData]; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index f058259a1..c8c17c39f 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -398,7 +398,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int //Draw sprites auto pactor = ps[screenpeek].GetActor(); - for (i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { if (!gFullMap || !show2dsector[i]) continue; DukeSectIterator it(i); diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 45969341b..6ac2ef4c5 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -951,7 +951,7 @@ void DoWall(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, i { auto lValue = GetGameVarID(lVar2, sActor, sPlayer).safeValue(); auto vWall = GetGameVarID(lVar1, sActor, sPlayer); - iWall = vWall.safeValue(); + auto iWall = vWall.safeValue(); if (iWall < 0 || iWall >= (int)wall.Size() || vWall.isActor()) { @@ -1050,7 +1050,7 @@ void DoSector(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, iSector = vv.safeValue(); } - if (iSector < 0 || iSector >= numsectors || no) + if (iSector < 0 || iSector >= (int)sector.Size() || no) { if (!bSet) SetGameVarID(lVar2, 0, sActor, sPlayer); return; diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 223418d1c..6f4002044 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -881,7 +881,7 @@ static void SpawnPortals() } // Unfortunately the above still isn't enough. We got to do one more check to add stuff to the portals. // There is one map where a sector neighboring a portal is not marked as part of the portal itself. - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { auto sectp = §or[i]; if (sectp->floorpicnum == FOF && sectp->portalflags != PORTAL_SECTOR_FLOOR) diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index e374ddbc8..55e03a26d 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1680,7 +1680,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, int // Draw sprites auto peekActor = Player[screenpeek].Actor(); - for (i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { SWSectIterator it(i); while (auto actor = it.Next()) diff --git a/source/games/sw/src/rooms.cpp b/source/games/sw/src/rooms.cpp index d3257cf1f..d2c0841e6 100644 --- a/source/games/sw/src/rooms.cpp +++ b/source/games/sw/src/rooms.cpp @@ -917,17 +917,17 @@ void CollectPortals() testnewrenderer = true; TArray floorportals; TArray ceilingportals; - BitArray floordone(numsectors), ceilingdone(numsectors); + BitArray floordone(sector.Size()), ceilingdone(sector.Size()); - for (int i = 0; i < numsectors; i++) + for (auto& sec : sector) { - sector[i].portalflags = sector[i].portalnum = 0; + sec.portalflags = sec.portalnum = 0; } floordone.Zero(); ceilingdone.Zero(); portalClear(); - for (int i = 0; i < numsectors; i++) + for (unsigned i = 0; i < sector.Size(); i++) { if (sector[i].floorpicnum == FAF_MIRROR_PIC && !floordone[i]) {