From 6b579156aa808eb110e30bfdc17a8f807e4a05d9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 27 Sep 2022 16:36:19 +0200 Subject: [PATCH] - Blood HitScan fixes - changed target parameter of hitscan to a double to simplify its handling. - HitScan's nRange parameter may be an int, but it is in texel units, not Build units. --- source/build/src/clip.cpp | 2 -- source/core/gamefuncs.cpp | 9 ++++----- source/core/gamefuncs.h | 2 +- source/games/blood/src/gameutil.cpp | 11 ++--------- source/games/blood/src/gameutil.h | 6 +++--- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index b789f4cc5..f66dd862e 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -27,8 +27,6 @@ BitArray clipsectormap; int32_t quickloadboard=0; -vec2_t hitscangoal = { (1<<29)-1, (1<<29)-1 }; - ////////// CLIPMOVE ////////// inline uint8_t bitmap_test(uint8_t const* const ptr, int const n) { return ptr[n >> 3] & (1 << (n & 7)); } diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index fb436352b..3ab06f348 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -807,7 +807,7 @@ double checkSectorPlaneHit(sectortype* sec, const DVector3& start, const DVector // //========================================================================== -int hitscan(const DVector3& start, const sectortype* startsect, const DVector3& vect, HitInfoBase& hitinfo, unsigned cliptype, const DVector2* goal) +int hitscan(const DVector3& start, const sectortype* startsect, const DVector3& vect, HitInfoBase& hitinfo, unsigned cliptype, double maxrange) { double hitfactor = DBL_MAX; @@ -818,12 +818,11 @@ int hitscan(const DVector3& start, const sectortype* startsect, const DVector3& if (startsect == nullptr) return -1; - if (goal) + if (maxrange > 0) { - hitinfo.hitpos.XY() = *goal; - hitfactor = (*goal - start.XY()).Sum() / vect.Sum(); + hitfactor = maxrange / vect.Length(); } - else hitinfo.hitpos.X = hitinfo.hitpos.Y = DBL_MAX; + hitinfo.hitpos.X = hitinfo.hitpos.Y = DBL_MAX; BFSSectorSearch search(startsect); while (auto sec = search.GetNext()) diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 5ef3b7993..5ba0b1e5e 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -278,7 +278,7 @@ double checkWallHit(walltype* wal, EWallFlags flagmask, const DVector3& start, c double checkSectorPlaneHit(sectortype* sec, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor); void neartag(const DVector3& start, sectortype* sect, DAngle angle, HitInfoBase& result, double neartagrange, int tagsearch); int testpointinquad(const DVector2& pt, const DVector2* quad); -int hitscan(const DVector3& start, const sectortype* startsect, const DVector3& vect, HitInfoBase& hitinfo, unsigned cliptype, const DVector2* goal = nullptr); +int hitscan(const DVector3& start, const sectortype* startsect, const DVector3& vect, HitInfoBase& hitinfo, unsigned cliptype, double maxrange = -1); diff --git a/source/games/blood/src/gameutil.cpp b/source/games/blood/src/gameutil.cpp index 5fd6fe9f2..273d14aeb 100644 --- a/source/games/blood/src/gameutil.cpp +++ b/source/games/blood/src/gameutil.cpp @@ -291,10 +291,7 @@ int HitScan(DBloodActor* actor, double z, const DVector3& vect, unsigned int nMa gHitInfo.clearObj(); auto bakCstat = actor->spr.cstat; actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_HITSCAN; - DVector2 hitscangoal; - if (nRange > 0) hitscangoal = actor->spr.pos.XY() + vect.XY().Resized(nRange); - else hitscangoal.Zero(); - hitscan(DVector3(actor->spr.pos.XY(), z), actor->sector(), vect, gHitInfo, nMask, &hitscangoal); + hitscan(DVector3(actor->spr.pos.XY(), z), actor->sector(), vect, gHitInfo, nMask, nRange); actor->spr.cstat = bakCstat; if (gHitInfo.actor() != nullptr) @@ -332,11 +329,7 @@ int VectorScan(DBloodActor* actor, double nOffset, double nZOffset, const DVecto auto bakCstat = actor->spr.cstat; actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_HITSCAN; - DVector2 hitscangoal; - if (nRange > 0) hitscangoal = actor->spr.pos.XY() + vel.XY().Resized(nRange); - else hitscangoal.Zero(); - - hitscan(pos, actor->sector(), vel, gHitInfo, CLIPMASK1, &hitscangoal); + hitscan(pos, actor->sector(), vel, gHitInfo, CLIPMASK1, nRange); actor->spr.cstat = bakCstat; while (nNum--) diff --git a/source/games/blood/src/gameutil.h b/source/games/blood/src/gameutil.h index 35c1c5ac6..98ac2696c 100644 --- a/source/games/blood/src/gameutil.h +++ b/source/games/blood/src/gameutil.h @@ -41,15 +41,15 @@ int HitScan(DBloodActor* pSprite, double z, const DVector3& pos, unsigned int nM inline int HitScan_(DBloodActor* pSprite, int z, int dx, int dy, int dz, unsigned int nMask, int a8) { - return HitScan(pSprite, z * zinttoworld, DVector3(dx, dy, dz) * inttoworld, nMask, a8 * inttoworld); + return HitScan(pSprite, z * zinttoworld, DVector3(dx, dy, dz) * inttoworld, nMask, a8); } inline int HitScan_(DBloodActor* pSprite, double z, int dx, int dy, int dz, unsigned int nMask, int a8) { - return HitScan(pSprite, z, DVector3(dx, dy, dz) * inttoworld, nMask, a8 * inttoworld); + return HitScan(pSprite, z, DVector3(dx, dy, dz) * inttoworld, nMask, a8); } inline int HitScan_(DBloodActor* pSprite, double z, const DVector3& pos, unsigned int nMask, int a8) { - return HitScan(pSprite, z, pos, nMask, a8 * inttoworld); + return HitScan(pSprite, z, pos, nMask, a8); } int VectorScan(DBloodActor* pSprite, double nOffset, double nZOffset, const DVector3& vel, double nRange, int ac);