mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 08:51:24 +00:00
- use BFSSearch in updatesectorneighbor.
The old bfirst_* helpers are gone now.
This commit is contained in:
parent
22e554e88a
commit
ae63bcd80b
2 changed files with 11 additions and 39 deletions
|
@ -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 <typename T>
|
||||
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 <typename T>
|
||||
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_
|
||||
|
|
|
@ -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; sectcnt<nsecs; sectcnt++)
|
||||
for (unsigned listsectnum; (listsectnum = search.GetNext()) != BFSSearch::EOL;)
|
||||
{
|
||||
int const listsectnum = sectlist[sectcnt];
|
||||
|
||||
if (inside_p(x, y, listsectnum))
|
||||
SET_AND_RETURN(*sectnum, listsectnum);
|
||||
{
|
||||
*sectnum = listsectnum;
|
||||
return;
|
||||
}
|
||||
|
||||
auto const sec = §or[listsectnum];
|
||||
int const startwall = sec->wallptr;
|
||||
int const endwall = sec->wallptr + sec->wallnum;
|
||||
auto uwal = (uwallptr_t)&wall[startwall];
|
||||
|
||||
for (int j=startwall; j<endwall; j++, uwal++)
|
||||
if (uwal->nextsector >= 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue