diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index d2a1032fd..ca1021d11 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -16,6 +16,7 @@ class BFSSearch unsigned curpos; public: + enum { EOL = ~0u }; BFSSearch(unsigned datasize, unsigned startnode) { bitpos = store.Size(); diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 8fbee700c..5651e35e0 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -341,27 +341,22 @@ void hitradius_d(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int h { walltype* wal; int d, q, x1, y1; - int sectcnt, sectend, dasect, startwall, endwall, nextsect; + int startwall, endwall, nextsect; int p, x; int sect; static const uint8_t statlist[] = { STAT_DEFAULT, STAT_ACTOR, STAT_STANDABLE, STAT_PLAYER, STAT_FALLER, STAT_ZOMBIEACTOR, STAT_MISC }; - int tempsect[128]; // originally hijacked a global buffer which is bad. Q: How many do we really need? RedNukem says 64. - + auto spri = actor->s; if(spri->picnum == RPG && spri->xrepeat < 11) goto SKIPWALLCHECK; if(spri->picnum != SHRINKSPARK) { - tempsect[0] = spri->sectnum; - dasect = spri->sectnum; - auto dasectp = spri->sector(); - sectcnt = 0; sectend = 1; - - do + BFSSearch search(numsectors, spri->sectnum); + + for(unsigned dasect; (dasect = search.GetNext()) != BFSSearch::EOL;) { - dasect = tempsect[sectcnt++]; - dasectp = §or[dasect]; + auto dasectp = §or[dasect]; if (((dasectp->ceilingz - spri->z) >> 8) < r) { d = abs(wall[dasectp->wallptr].x - spri->x) + abs(wall[dasectp->wallptr].y - spri->y); @@ -384,9 +379,7 @@ void hitradius_d(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int h nextsect = wal->nextsector; if (nextsect >= 0) { - for (dasect = sectend - 1; dasect >= 0; dasect--) - if (tempsect[dasect] == nextsect) break; - if (dasect < 0) tempsect[sectend++] = nextsect; + search.Add(nextsect); } x1 = (((wal->x + wall[wal->point2].x) >> 1) + spri->x) >> 1; y1 = (((wal->y + wall[wal->point2].y) >> 1) + spri->y) >> 1; @@ -394,7 +387,7 @@ void hitradius_d(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int h if (sect >= 0 && cansee(x1, y1, spri->z, sect, spri->x, spri->y, spri->z, spri->sectnum)) fi.checkhitwall(actor, x, wal->x, wal->y, spri->z, spri->picnum); } - } while (sectcnt < sectend && sectcnt < (int)countof(tempsect)); + } } SKIPWALLCHECK: diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index a74b060f7..6bae2f1e0 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -619,7 +619,7 @@ void spawneffector(DDukeActor* actor) auto sectp = sp->sector(); int sect = sp->sectnum; auto t = actor->temp_data; - int startwall, endwall, x, y, d, s, clostest = 0; + int startwall, endwall, d, s, clostest = 0; sp->yvel = sectp->extra; sp->cstat |= 32768;