- 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.
This commit is contained in:
Christoph Oelckers 2022-09-27 16:36:19 +02:00
parent 1d8dccca04
commit 6b579156aa
5 changed files with 10 additions and 20 deletions

View file

@ -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)); }

View file

@ -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())

View file

@ -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);

View file

@ -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--)

View file

@ -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);