From 2b3b7f880ff00b62908a4becec7a7b783f313c92 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Sep 2022 19:07:19 +0200 Subject: [PATCH] - floatified getSpritesNearWalls --- source/games/blood/src/nnsprinsect.cpp | 45 +++++++++++--------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/source/games/blood/src/nnsprinsect.cpp b/source/games/blood/src/nnsprinsect.cpp index 205ad1fa6..55dc4218c 100644 --- a/source/games/blood/src/nnsprinsect.cpp +++ b/source/games/blood/src/nnsprinsect.cpp @@ -46,7 +46,7 @@ public: struct SPRITES { unsigned int nSector; - TArray> pActors; // this is a weak reference! + TArray> pActors; }; private: TArray db; @@ -171,44 +171,35 @@ bool isMovableSector(sectortype* pSect) TArray getSpritesNearWalls(sectortype* pSrcSect, int nDist) { - int i, c = 0, nWall, nSect, swal, ewal; - int xi, yi, wx, wy, lx, ly, sx, sy, qx, qy, num, den; - TArray skip; + double dist = nDist * inttoworld; TArray out; - swal = pSrcSect->wallptr; - ewal = swal + pSrcSect->wallnum - 1; - - for (i = swal; i <= ewal; i++) + for(auto& wal : wallsofsector(pSrcSect)) { - nSect = wall[i].nextsector; - if (nSect < 0) + if (!wal.twoSided()) continue; - nWall = i; - wx = wall[nWall].wall_int_pos().X; - wy = wall[nWall].wall_int_pos().Y; - lx = wall[wall[nWall].point2].wall_int_pos().X - wx; - ly = wall[wall[nWall].point2].wall_int_pos().Y - wy; - - BloodSectIterator it(nSect); + auto wpos = wal.pos; + auto wlen = wal.delta(); + + BloodSectIterator it(wal.nextsector); while(auto ac = it.Next()) { - if (skip.Find(ac)) + if (out.Find(ac)) continue; - sx = ac->int_pos().X; qx = sx - wx; - sy = ac->int_pos().Y; qy = sy - wy; - num = DMulScale(qx, lx, qy, ly, 4); - den = DMulScale(lx, lx, ly, ly, 4); + auto spos = ac->spr.pos.XY(); + auto qpos = spos - wpos; + + double num = qpos.dot(wlen); + double den = wlen.Length(); if (num > 0 && num < den) { - xi = wx + Scale(lx, num, den); - yi = wy + Scale(ly, num, den); - if (approxDist(xi - sx, yi - sy) <= nDist) + auto vi = wpos + wlen * num / den; + + if ((vi - spos).LengthSquared() <= nDist * nDist) { - skip.Push(ac); out.Push(ac); } } @@ -219,4 +210,4 @@ TArray getSpritesNearWalls(sectortype* pSrcSect, int nDist) END_BLD_NS -#endif \ No newline at end of file +#endif