From 7111b2470c99730dc72ab1875584c1bd751f7fef Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 16 Nov 2021 23:47:17 +0100 Subject: [PATCH] - SW: use BFSSearch in TraverseBreakableWalls --- source/core/gamefuncs.cpp | 2 -- source/core/gamefuncs.h | 2 -- source/games/sw/src/weapon.cpp | 50 ++++++++++------------------------ 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index c3954e173..488621870 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -24,8 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gamestruct.h" #include "intvec.h" -TArray GlobalSectorList; //This is a shared list. Every client must leave it in the same state as it was when it started. - //--------------------------------------------------------------------------- // // Unified chasecam function for all games. diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index bc2c8108f..44a9fcd41 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -71,8 +71,6 @@ public: } }; -extern TArray GlobalSectorList; - extern int cameradist, cameraclock; void loaddefinitionsfile(const char* fn, bool cumulative = false, bool maingrp = false); diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 31a93a79c..f11a40aec 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -7621,9 +7621,8 @@ short StatBreakList[] = void TraverseBreakableWalls(short start_sect, int x, int y, int z, short ang, int radius) { - int j, k; + int k; int sect, startwall, endwall, nextsector; - unsigned sectlistplc, sectliststart; int xmid,ymid; int dist; short break_count; @@ -7633,29 +7632,24 @@ void TraverseBreakableWalls(short start_sect, int x, int y, int z, short ang, in int hit_x,hit_y,hit_z; - sectliststart = sectlistplc = GlobalSectorList.Size(); - GlobalSectorList.Push(start_sect); - // limit radius if (radius > 2000) radius = 2000; break_count = 0; - while (sectlistplc < GlobalSectorList.Size()) + + + BFSSearch search(numsectors, start_sect); + for (unsigned sect; (sect = search.GetNext()) != BFSSearch::EOL;) { - sect = GlobalSectorList[sectlistplc++]; - - startwall = sector[sect].wallptr; - endwall = startwall + sector[sect].wallnum; - - for (j = startwall; j < endwall - 1; j++) + for(auto& wal : wallsofsector(sect)) { // see if this wall should be broken - if (wall[j].lotag == TAG_WALL_BREAK) + if (wal.lotag == TAG_WALL_BREAK) { // find midpoint - xmid = (wall[j].x + wall[j+1].x) >> 1; - ymid = (wall[j].y + wall[j+1].y) >> 1; + xmid = (wal.x + wal.point2Wall()->x) >> 1; + ymid = (wal.y + wal.point2Wall()->y) >> 1; // don't need to go further if wall is too far out @@ -7663,44 +7657,28 @@ void TraverseBreakableWalls(short start_sect, int x, int y, int z, short ang, in if (dist > radius) continue; - if (WallBreakPosition(j, §num, &hit_x, &hit_y, &hit_z, &wall_ang)) + if (WallBreakPosition(wallnum(&wal), §num, &hit_x, &hit_y, &hit_z, &wall_ang)) { if (hit_x != INT32_MAX && sectnum >= 0 && FAFcansee(x, y, z, start_sect, hit_x, hit_y, hit_z, sectnum)) { - //HitBreakWall(&wall[j], x, y, z, ang, 0); - HitBreakWall(&wall[j], INT32_MAX, INT32_MAX, INT32_MAX, ang, 0); + HitBreakWall(&wal, INT32_MAX, INT32_MAX, INT32_MAX, ang, 0); break_count++; if (break_count > 4) { - GlobalSectorList.Resize(sectliststart); return; } } } } - nextsector = wall[j].nextsector; + nextsector = wal.nextsector; - if (nextsector < 0) - continue; - - // make sure its not on the list - for (k = GlobalSectorList.Size() - 1; k >= (int)sectliststart; k--) - { - if (GlobalSectorList[k] == nextsector) - break; - } - - // if its not on the list add it to the end - if (k < 0) - { - GlobalSectorList.Push(nextsector); - } + if (nextsector >= 0) + search.Add(nextsector); } } - GlobalSectorList.Resize(sectliststart); }