diff --git a/source/build/include/compat.h b/source/build/include/compat.h index 8c61fd125..fd6a7ad92 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -92,27 +92,5 @@ static_assert(sizeof(vec3f_t) == sizeof(float) * 3); inline void bitmap_set(uint8_t *const ptr, int const n) { ptr[n>>3] |= 1 << (n&7); } inline char bitmap_test(uint8_t const *const ptr, int const n) { return ptr[n>>3] & (1 << (n&7)); } -////////// Utility functions ////////// - -// breadth-first search helpers -template -void bfirst_search_init(T *const list, uint8_t *const bitmap, T *const eltnumptr, int const maxelts, int const firstelt) -{ - memset(bitmap, 0, (maxelts+7)>>3); - - list[0] = firstelt; - bitmap_set(bitmap, firstelt); - *eltnumptr = 1; -} - -template -void bfirst_search_try(T *const list, uint8_t *const bitmap, T *const eltnumptr, int const elt) -{ - if (!bitmap_test(bitmap, elt)) - { - bitmap_set(bitmap, elt); - list[(*eltnumptr)++] = elt; - } -} #endif // compat_h_ diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 7e10c0eac..89662387b 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -1308,27 +1308,21 @@ void updatesectorneighbor(int32_t const x, int32_t const y, int * const sectnum, if (inside_p(x, y, initialsectnum)) return; - static int16_t sectlist[MAXSECTORS]; - static uint8_t sectbitmap[(MAXSECTORS+7)>>3]; - int16_t nsecs; + BFSSearch search(numsectors, *sectnum); - bfirst_search_init(sectlist, sectbitmap, &nsecs, MAXSECTORS, initialsectnum); - - for (int sectcnt=0; sectcntwallptr; - int const endwall = sec->wallptr + sec->wallnum; - auto uwal = (uwallptr_t)&wall[startwall]; - - for (int j=startwall; jnextsector >= 0 && getsectordist({x, y}, uwal->nextsector) <= maxDistance) - bfirst_search_try(sectlist, sectbitmap, &nsecs, uwal->nextsector); + for (auto& wal : wallsofsector(listsectnum)) + { + if (wal.nextsector >= 0 && getsectordist({ x, y }, wal.nextsector) <= maxDistance) + search.Add(wal.nextsector); + } } }