diff --git a/source/build/include/build.h b/source/build/include/build.h index 012257510..1616a77a7 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -1223,8 +1223,8 @@ int clipshape_idx_for_sprite(uspritetype const * const curspr, int curidx); 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); -int32_t sectorofwall(int16_t theline); -int32_t sectorofwall_noquick(int16_t theline); +int32_t sectorofwall(int16_t wallNum); +int32_t sectorofwall_noquick(int16_t wallNum); int32_t loopnumofsector(int16_t sectnum, int16_t wallnum); void setslope(int32_t sectnum, int32_t cf, int16_t slope); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index e84f2def4..fc90a2c34 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -12473,39 +12473,38 @@ void completemirror(void) // // sectorofwall // -static int32_t sectorofwall_internal(int16_t theline) +static int32_t sectorofwall_internal(int16_t wallNum) { - int32_t gap = numsectors>>1, i = gap; + native_t gap = numsectors>>1, sectNum = gap; while (gap > 1) { gap >>= 1; - if (sector[i].wallptr < theline) i += gap; else i -= gap; + native_t const n = !!(sector[sectNum].wallptr < wallNum); + sectNum += (n ^ (n - 1)) * gap; } - while (sector[i].wallptr > theline) i--; - while (sector[i].wallptr+sector[i].wallnum <= theline) i++; + while (sector[sectNum].wallptr > wallNum) sectNum--; + while (sector[sectNum].wallptr + sector[sectNum].wallnum <= wallNum) sectNum++; - return i; + return sectNum; } -int32_t sectorofwall(int16_t theline) +int32_t sectorofwall(int16_t wallNum) { - if ((unsigned)theline >= (unsigned)numwalls) + if (EDUKE32_PREDICT_FALSE((unsigned)wallNum >= (unsigned)numwalls)) return -1; - int i = wall[theline].nextwall; - if ((unsigned)i < MAXWALLS) - return wall[i].nextsector; + native_t const w = wall[wallNum].nextwall; - return sectorofwall_internal(theline); + return ((unsigned)w < MAXWALLS) ? wall[w].nextsector : sectorofwall_internal(wallNum); } -int32_t sectorofwall_noquick(int16_t theline) +int32_t sectorofwall_noquick(int16_t wallNum) { - if ((unsigned)theline >= (unsigned)numwalls) + if (EDUKE32_PREDICT_FALSE((unsigned) wallNum >= (unsigned) numwalls)) return -1; - return sectorofwall_internal(theline); + return sectorofwall_internal(wallNum); }