diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 73893734d..de077520c 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -2606,28 +2606,29 @@ void polymost_completeMirror() static inline int32_t polymost_findwall(tspritetype const * const tspr, vec2_t const * const tsiz, int32_t * rd) { - int32_t dist = 4, closest = -1; + int32_t dist = 4; auto const sect = tspr->sector(); vec2_t n; + walltype* closest = nullptr; - for (intptr_t i=sect->wallptr; iwallptr + sect->wallnum; i++) + for(auto& wal : wallsofsector(sect)) { - if ((wall[i].nextsector == -1 || ((sector[wall[i].nextsector].ceilingz > (tspr->z - ((tsiz->y * tspr->yrepeat) << 2))) || - sector[wall[i].nextsector].floorz < tspr->z)) && !polymost_getclosestpointonwall((const vec2_t *) tspr, i, &n)) + if ((!wal.twoSided() || ((wal.nextSector()->ceilingz > (tspr->z - ((tsiz->y * tspr->yrepeat) << 2))) || + wal.nextSector()->floorz < tspr->z)) && !polymost_getclosestpointonwall((const vec2_t *) tspr, wallnum(&wal), &n)) { int const dst = abs(tspr->x - n.x) + abs(tspr->y - n.y); if (dst <= dist) { dist = dst; - closest = i; + closest = &wal; } } } *rd = dist; - return closest; + return closest? wallnum(closest) : -1; } static int32_t polymost_lintersect(int32_t x1, int32_t y1, int32_t x2, int32_t y2, diff --git a/source/core/automap.cpp b/source/core/automap.cpp index e0fbed31e..0165e5f69 100644 --- a/source/core/automap.cpp +++ b/source/core/automap.cpp @@ -419,33 +419,26 @@ void drawredlines(int cposx, int cposy, int czoom, int cang) { if (!gFullMap && !show2dsector[i]) continue; - int startwall = sector[i].wallptr; - int endwall = sector[i].wallptr + sector[i].wallnum; - int z1 = sector[i].ceilingz; int z2 = sector[i].floorz; - walltype* wal; - int j; - for (j = startwall, wal = &wall[startwall]; j < endwall; j++, wal++) + for (auto& wal : wallsofsector(i)) { - int k = wal->nextwall; - if (k < 0 || k >= numwalls) continue; + if (!wal.twoSided()) continue; - int s = wal->nextsector; - if (s < 0 || s >= numsectors) continue; + auto osec = wal.nextSector(); - if (sector[s].ceilingz == z1 && sector[s].floorz == z2) - if (((wal->cstat | wal->nextWall()->cstat) & (16 + 32)) == 0) continue; + if (osec->ceilingz == z1 && osec->floorz == z2) + if (((wal.cstat | wal.nextWall()->cstat) & (16 + 32)) == 0) continue; - if (ShowRedLine(j, i)) + if (ShowRedLine(wallnum(&wal), i)) { - int ox = wal->x - cposx; - int oy = wal->y - cposy; + int ox = wal.x - cposx; + int oy = wal.y - cposy; int x1 = DMulScale(ox, xvect, -oy, yvect, 16) + (width << 11); int y1 = DMulScale(oy, xvect, ox, yvect, 16) + (height << 11); - auto wal2 = wal->point2Wall(); + auto wal2 = wal.point2Wall(); ox = wal2->x - cposx; oy = wal2->y - cposy; int x2 = DMulScale(ox, xvect, -oy, yvect, 16) + (width << 11); @@ -474,26 +467,20 @@ static void drawwhitelines(int cposx, int cposy, int czoom, int cang) { if (!gFullMap && !show2dsector[i] && !isSWALL()) continue; - int startwall = sector[i].wallptr; - int endwall = sector[i].wallptr + sector[i].wallnum; - - walltype* wal; - int j; - - for (j = startwall, wal = &wall[startwall]; j < endwall; j++, wal++) + for (auto& wal : wallsofsector(i)) { - if (wal->nextwall >= 0) continue; - if (!gFullMap && !tileGetTexture(wal->picnum)->isValid()) continue; + if (wal.nextwall >= 0) continue; + if (!gFullMap && !tileGetTexture(wal.picnum)->isValid()) continue; - if (isSWALL() && !gFullMap && !show2dwall[j]) + if (isSWALL() && !gFullMap && !show2dwall[wallnum(&wal)]) continue; - int ox = wal->x - cposx; - int oy = wal->y - cposy; + int ox = wal.x - cposx; + int oy = wal.y - cposy; int x1 = DMulScale(ox, xvect, -oy, yvect, 16) + (width << 11); int y1 = DMulScale(oy, xvect, ox, yvect, 16) + (height << 11); - int k = wal->point2; + int k = wal.point2; auto wal2 = &wall[k]; ox = wal2->x - cposx; oy = wal2->y - cposy; diff --git a/source/core/rendering/hw_sections.h b/source/core/rendering/hw_sections.h index 4a8b73f0d..bc361f664 100644 --- a/source/core/rendering/hw_sections.h +++ b/source/core/rendering/hw_sections.h @@ -4,13 +4,13 @@ struct SectionLine { - int16_t section; - int16_t partnersection; - int16_t startpoint; - int16_t endpoint; - int16_t wall; - int16_t partner; - int16_t point2index; + int section; + int partnersection; + int startpoint; + int endpoint; + int wall; + int partner; + int point2index; }; struct Section diff --git a/source/core/rendering/scene/hw_portal.cpp b/source/core/rendering/scene/hw_portal.cpp index 4d218a3cf..c8b2baaed 100644 --- a/source/core/rendering/scene/hw_portal.cpp +++ b/source/core/rendering/scene/hw_portal.cpp @@ -481,7 +481,7 @@ int HWLinePortal::ClipSector(sectortype *sub) // this seg is completely behind the mirror for (int i = 0; iwallnum; i++) { - if (PointOnLineSide(WallStart(&wall[sub->wallptr]), line) == 0) return PClip_Inside; + if (PointOnLineSide(WallStart(sub->firstWall()), line) == 0) return PClip_Inside; } return PClip_InFront; } diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index c9374d2c4..a037df233 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -109,27 +109,27 @@ static int GetClosestPointOnWall(tspritetype* spr, walltype* wal, vec2_t* const static int IsOnWall(tspritetype* tspr, int height) { - int dist = 3, closest = -1; + int dist = 3; auto sect = tspr->sector(); vec2_t n; + walltype* closest = nullptr; int topz = (tspr->z - ((height * tspr->yrepeat) << 2)); - for (int i = sect->wallptr; i < sect->wallptr + sect->wallnum; i++) + for(auto& wal : wallsofsector(sect)) { - auto wal = &wall[i]; - if ((wal->nextsector == -1 || ((wal->nextSector()->ceilingz > topz) || - wal->nextSector()->floorz < tspr->z)) && !GetClosestPointOnWall(tspr, wal, &n)) + if ((wal.nextsector == -1 || ((wal.nextSector()->ceilingz > topz) || + wal.nextSector()->floorz < tspr->z)) && !GetClosestPointOnWall(tspr, &wal, &n)) { int const dst = abs(tspr->x - n.x) + abs(tspr->y - n.y); if (dst <= dist) { dist = dst; - closest = i; + closest = &wal; } } } - return closest == -1? -1 : dist; + return closest == nullptr? -1 : dist; } //==========================================================================