From f2d89b76094602c76417ac11ba3fc372c7e2e9ee Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 3 Sep 2022 09:37:52 +0200 Subject: [PATCH] - refactored actWallBounceVector as well This completes the abstraction of velocity in Blood. --- source/games/blood/src/actor.cpp | 18 ++++++++---------- source/games/blood/src/actor.h | 2 +- source/games/blood/src/gameutil.cpp | 14 -------------- source/games/blood/src/gameutil.h | 1 - source/games/blood/src/nnexts.cpp | 2 +- 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index f0fb489b9..267bdae93 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -2589,15 +2589,13 @@ static void ConcussSprite(DBloodActor* source, DBloodActor* actor, const DVector // //--------------------------------------------------------------------------- -int actWallBounceVector(int* x, int* y, walltype* pWall, int a4) +void actWallBounceVector(DBloodActor* actor, walltype* pWall, double factor) { - int wx, wy; - GetWallNormal(pWall, &wx, &wy); - int t = DMulScale(*x, wx, *y, wy, 16); - int t2 = mulscale16r(t, a4 + 0x10000); - *x -= MulScale(wx, t2, 16); - *y -= MulScale(wy, t2, 16); - return mulscale16r(t, 0x10000 - a4); + auto delta = pWall->delta().Unit(); + auto vel = actor->fVel().XY(); + double t = vel.X * -delta.Y + vel.Y * delta.X; + double t2 = t * (factor+1); + actor->set_float_bvel_xy(vel - DVector2(-delta.Y * t2, delta.X * t2)); } //--------------------------------------------------------------------------- @@ -4548,7 +4546,7 @@ static Collision MoveThing(DBloodActor* actor) auto& coll = actor->hit.hit; if (coll.type == kHitWall) { - actWallBounceVector(&actor->__int_vel.X, &actor->__int_vel.Y, coll.hitWall, pThingInfo->elastic); + actWallBounceVector(actor, coll.hitWall, FixedToFloat(pThingInfo->elastic)); switch (actor->spr.type) { case kThingZombieHead: @@ -4829,7 +4827,7 @@ void MoveDude(DBloodActor* actor) // ??? } } - actWallBounceVector((int*)&actor->__int_vel.X, (int*)&actor->__int_vel.Y, pHitWall, 0); + actWallBounceVector(actor, pHitWall, 0); break; } } diff --git a/source/games/blood/src/actor.h b/source/games/blood/src/actor.h index a6deffa88..5065d2025 100644 --- a/source/games/blood/src/actor.h +++ b/source/games/blood/src/actor.h @@ -210,7 +210,7 @@ void TreeToGibCallback(int, int); bool IsUnderwaterSector(sectortype* pSector); void actInit(TArray& actors); -int actWallBounceVector(int *x, int *y, walltype* pWall, int a4); +void actWallBounceVector(DBloodActor* actor, walltype* pWall, double factor); DVector4 actFloorBounceVector(DBloodActor* actor, double oldz, sectortype* pSector, double factor); void actRadiusDamage(DBloodActor* source, const DVector3& pos, sectortype* pSector, int nDist, int a7, int a8, DAMAGE_TYPE a9, int a10, int a11); DBloodActor *actDropObject(DBloodActor *pSprite, int nType); diff --git a/source/games/blood/src/gameutil.cpp b/source/games/blood/src/gameutil.cpp index e580a9aa6..55a83d51d 100644 --- a/source/games/blood/src/gameutil.cpp +++ b/source/games/blood/src/gameutil.cpp @@ -239,20 +239,6 @@ int GetWallAngle(walltype* pWall) return getangle(pWall->delta()); } -void GetWallNormal(walltype* pWall, int* pX, int* pY) -{ - - auto delta = pWall->int_delta(); - int dX = -delta.Y >> 4; - int dY = delta.X >> 4; - - int nLength = ksqrt(dX * dX + dY * dY); - if (nLength <= 0) - nLength = 1; - *pX = DivScale(dX, nLength, 16); - *pY = DivScale(dY, nLength, 16); -} - //--------------------------------------------------------------------------- // // diff --git a/source/games/blood/src/gameutil.h b/source/games/blood/src/gameutil.h index 77f76b3e9..3cf655dd3 100644 --- a/source/games/blood/src/gameutil.h +++ b/source/games/blood/src/gameutil.h @@ -35,7 +35,6 @@ enum { bool CheckProximity(DBloodActor* pSprite, const DVector3& pos, sectortype* pSector, int nDist); bool CheckProximityPoint(int nX1, int nY1, int nZ1, int nX2, int nY2, int nZ2, int nDist); int GetWallAngle(walltype* pWall); -void GetWallNormal(walltype* pWall, int* pX, int* pY); bool IntersectRay(int wx, int wy, int wdx, int wdy, int x1, int y1, int z1, int x2, int y2, int z2, int* ix, int* iy, int* iz); int HitScan(DBloodActor* pSprite, int z, int dx, int dy, int dz, unsigned int nMask, int a8); inline int HitScan(DBloodActor* pSprite, double z, int dx, int dy, int dz, unsigned int nMask, int a8) diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 41f6628f9..ca438a7f3 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -1689,7 +1689,7 @@ void debrisMove(int listIndex) if (actor->hit.hit.type == kHitWall) { moveHit = actor->hit.hit; - actWallBounceVector(&actor->__int_vel.X, &actor->__int_vel.Y, moveHit.hitWall, tmpFraction); + actWallBounceVector(actor, moveHit.hitWall, FixedToFloat(tmpFraction)); } }