diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 70b18867755..333695aea0c 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -1130,16 +1130,12 @@ int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out /*= int32_t distance = INT32_MAX; - auto const sec = (usectorptr_t)§or[sectnum]; - int const startwall = sec->wallptr; - int const endwall = sec->wallptr + sec->wallnum; - auto uwal = (uwallptr_t)&wall[startwall]; vec2_t closest = {}; - for (int j = startwall; j < endwall; j++, uwal++) + for (auto& wal : wallsofsector(sectnum)) { vec2_t p; - int32_t const walldist = getwalldist(in, j, &p); + int32_t const walldist = getwalldist(in, wallnum(&wal), &p); if (walldist < distance) { @@ -1402,7 +1398,8 @@ void getzsofslopeptr(usectorptr_t sec, int32_t dax, int32_t day, int32_t *ceilz, // void alignceilslope(int16_t dasect, int32_t x, int32_t y, int32_t z) { - auto const wal = (uwallptr_t)&wall[sector[dasect].wallptr]; + auto sect = §or[dasect]; + auto const wal = (uwallptr_t)sect->firstWall(); const int32_t dax = wal->point2Wall()->x-wal->x; const int32_t day = wal->point2Wall()->y-wal->y; @@ -1410,11 +1407,11 @@ void alignceilslope(int16_t dasect, int32_t x, int32_t y, int32_t z) if (i == 0) return; - sector[dasect].ceilingheinum = Scale((z-sector[dasect].ceilingz)<<8, + sect->ceilingheinum = Scale((z-sect->ceilingz)<<8, ksqrt(uhypsq(dax,day)), i); - if (sector[dasect].ceilingheinum == 0) - sector[dasect].ceilingstat &= ~2; - else sector[dasect].ceilingstat |= 2; + if (sect->ceilingheinum == 0) + sect->ceilingstat &= ~2; + else sect->ceilingstat |= 2; } @@ -1423,7 +1420,8 @@ void alignceilslope(int16_t dasect, int32_t x, int32_t y, int32_t z) // void alignflorslope(int16_t dasect, int32_t x, int32_t y, int32_t z) { - auto const wal = (uwallptr_t)&wall[sector[dasect].wallptr]; + auto sect = §or[dasect]; + auto const wal = (uwallptr_t)sect->firstWall(); const int32_t dax = wal->point2Wall()->x-wal->x; const int32_t day = wal->point2Wall()->y-wal->y; @@ -1431,11 +1429,11 @@ void alignflorslope(int16_t dasect, int32_t x, int32_t y, int32_t z) if (i == 0) return; - sector[dasect].floorheinum = Scale((z-sector[dasect].floorz)<<8, + sect->floorheinum = Scale((z-sect->floorz)<<8, ksqrt(uhypsq(dax,day)), i); - if (sector[dasect].floorheinum == 0) - sector[dasect].floorstat &= ~2; - else sector[dasect].floorstat |= 2; + if (sect->floorheinum == 0) + sect->floorstat &= ~2; + else sect->floorstat |= 2; }