From 4bfb03b6b38e55d7c0bd05bbb5d1fd8756af0624 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 26 Nov 2021 00:25:28 +0100 Subject: [PATCH] - adapted hitscan calls in Exhumed. --- source/games/exhumed/src/bullet.cpp | 16 ++++++------ source/games/exhumed/src/exhumedactor.h | 14 ++++++---- source/games/exhumed/src/gun.cpp | 34 +++++++++---------------- source/games/exhumed/src/lion.cpp | 17 ++++--------- source/games/exhumed/src/snake.cpp | 31 ++++++++-------------- 5 files changed, 44 insertions(+), 68 deletions(-) diff --git a/source/games/exhumed/src/bullet.cpp b/source/games/exhumed/src/bullet.cpp index c8a64e070..45ffcaad1 100644 --- a/source/games/exhumed/src/bullet.cpp +++ b/source/games/exhumed/src/bullet.cpp @@ -444,19 +444,19 @@ MOVEEND: else { vec3_t startPos = { x, y, z }; - hitdata_t hitData; + HitInfo hit; int dz; if (bVanilla) dz = -bsin(pBullet->nPitch, 3); else dz = -pBullet->nPitch * 512; - hitscan(&startPos, pSprite->sectnum, bcos(pSprite->ang), bsin(pSprite->ang), dz, &hitData, CLIPMASK1); - x2 = hitData.pos.x; - y2 = hitData.pos.y; - z2 = hitData.pos.z; - hitactor = GetActor(hitData); - pHitSect = hitData.sect >= 0? §or[hitData.sect] : nullptr; - pHitWall = hitData.wall >= 0? &wall[hitData.wall] : nullptr; + hitscan(startPos, pSprite->sector(), { bcos(pSprite->ang), bsin(pSprite->ang), dz }, hit, CLIPMASK1); + x2 = hit.hitpos.x; + y2 = hit.hitpos.y; + z2 = hit.hitpos.z; + hitactor = hit.actor(); + pHitSect = hit.hitSector; + pHitWall = hit.hitWall; } lasthitx = x2; diff --git a/source/games/exhumed/src/exhumedactor.h b/source/games/exhumed/src/exhumedactor.h index a5620a1d4..800cf57fd 100644 --- a/source/games/exhumed/src/exhumedactor.h +++ b/source/games/exhumed/src/exhumedactor.h @@ -140,6 +140,15 @@ inline int Collision::actorIndex(DExhumedActor* a) inline DExhumedActor* DExhumedActor::base() { return exhumedActors; } +// subclassed to add a game specific actor() method +struct HitInfo : public HitInfoBase +{ + DExhumedActor* actor() const + { + return static_cast(hitActor); + } +}; + // Iterator wrappers that return an actor pointer, not an index. class ExhumedStatIterator : public StatIterator { @@ -254,9 +263,4 @@ inline void setActorPos(DExhumedActor* actor, vec3_t* pos) setsprite(actor->GetSpriteIndex(), pos); } -inline DExhumedActor* GetActor(const hitdata_t& hitData) -{ - return hitData.sprite < 0? nullptr : &exhumedActors[hitData.sprite]; -} - END_BLD_NS diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index 661a83572..3c52e97b5 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -243,29 +243,19 @@ void ResetSwordSeqs() Collision CheckCloseRange(int nPlayer, int *x, int *y, int *z, sectortype* *ppSector) { - int hitSect, hitWall, hitSprite; - int hitX, hitY, hitZ; - auto pActor = PlayerList[nPlayer].Actor(); int ang = pActor->s().ang; int xVect = bcos(ang); int yVect = bsin(ang); - vec3_t startPos = { *x, *y, *z }; - hitdata_t hitData; - hitscan(&startPos, sectnum(*ppSector), xVect, yVect, 0, &hitData, CLIPMASK1); - hitX = hitData.pos.x; - hitY = hitData.pos.y; - hitZ = hitData.pos.z; - hitSprite = hitData.sprite; - hitSect = hitData.sect; - hitWall = hitData.wall; + HitInfo hit; + hitscan({ *x, *y, *z }, *ppSector, { xVect, yVect, 0 }, hit, CLIPMASK1); int ecx = bsin(150, -3); - uint32_t xDiff = abs(hitX - *x); - uint32_t yDiff = abs(hitY - *y); + uint32_t yDiff = abs(hit.hitpos.y - *y); + uint32_t xDiff = abs(hit.hitpos.x - *x); uint32_t sqrtNum = xDiff * xDiff + yDiff * yDiff; @@ -279,16 +269,16 @@ Collision CheckCloseRange(int nPlayer, int *x, int *y, int *z, sectortype* *ppSe if (ksqrt(sqrtNum) >= ecx) return c; - *x = hitX; - *y = hitY; - *z = hitZ; - *ppSector = §or[hitSect]; + *x = hit.hitpos.x; + *y = hit.hitpos.y; + *z = hit.hitpos.z; + *ppSector = hit.hitSector; - if (hitSprite > -1) { - c.setSprite(&exhumedActors[hitSprite]); + if (hit.actor()) { + c.setSprite(hit.actor()); } - if (hitWall > -1) { - c.setWall(hitWall); + if (hit.hitWall) { + c.setWall(wallnum(hit.hitWall)); } return c; diff --git a/source/games/exhumed/src/lion.cpp b/source/games/exhumed/src/lion.cpp index f14bd25aa..9d28c6881 100644 --- a/source/games/exhumed/src/lion.cpp +++ b/source/games/exhumed/src/lion.cpp @@ -400,21 +400,14 @@ void AILion::Tick(RunListEvent* ev) for (int i = 0; i < 5; i++) { - int hitwall; - int hitx, hity; - vec3_t startPos = { x, y, z }; - hitdata_t hitData; + HitInfo hit; - hitscan(&startPos, pSprite->sectnum, bcos(nScanAngle), bsin(nScanAngle), 0, &hitData, CLIPMASK1); + hitscan({ x, y, z }, pSprite->sector(), { bcos(nScanAngle), bsin(nScanAngle), 0 }, hit, CLIPMASK1); - hitx = hitData.pos.x; - hity = hitData.pos.y; - hitwall = hitData.wall; - - if (hitwall > -1) + if (hit.hitWall) { - int theX = abs(hitx - x); - int theY = abs(hity - y); + int theX = abs(hit.hitpos.x - x); + int theY = abs(hit.hitpos.y - y); if ((theX + theY) < nCheckDist) { diff --git a/source/games/exhumed/src/snake.cpp b/source/games/exhumed/src/snake.cpp index 2a3c89c00..8b26cd835 100644 --- a/source/games/exhumed/src/snake.cpp +++ b/source/games/exhumed/src/snake.cpp @@ -130,22 +130,11 @@ void BuildSnake(int nPlayer, int zVal) int z = (pPlayerSprite->z + zVal) - 2560; int nAngle = pPlayerSprite->ang; - int hitsect; - int hitx, hity, hitz; - DExhumedActor* hitactor; + HitInfo hit; + hitscan({ x, y, z }, pPlayerSprite->sector(), { bcos(nAngle), bsin(nAngle), 0 }, hit, CLIPMASK1); - vec3_t pos = { x, y, z }; - hitdata_t hitData; - hitscan(&pos, pPlayerSprite->sectnum, bcos(nAngle), bsin(nAngle), 0, &hitData, CLIPMASK1); - - hitx = hitData.pos.x; - hity = hitData.pos.y; - hitz = hitData.pos.z; - hitsect = hitData.sect; - hitactor = hitData.sprite == -1? nullptr : &exhumedActors[hitData.sprite]; - - uint32_t xDiff = abs(hitx - x); - uint32_t yDiff = abs(hity - y); + uint32_t yDiff = abs(hit.hitpos.y - y); + uint32_t xDiff = abs(hit.hitpos.x - x); uint32_t sqrtNum = xDiff * xDiff + yDiff * yDiff; @@ -159,12 +148,12 @@ void BuildSnake(int nPlayer, int zVal) if (nSqrt < bsin(512, -4)) { - BackUpBullet(&hitx, &hity, nAngle); - auto pActor = insertActor(hitsect, 202); + BackUpBullet(&hit.hitpos.x, &hit.hitpos.y, nAngle); + auto pActor = insertActor(hit.hitSector, 202); auto pSprite = &pActor->s(); - pSprite->x = hitx; - pSprite->y = hity; - pSprite->z = hitz; + pSprite->x = hit.hitpos.x; + pSprite->y = hit.hitpos.y; + pSprite->z = hit.hitpos.z; ExplodeSnakeSprite(pActor, nPlayer); DeleteActor(pActor); @@ -173,7 +162,7 @@ void BuildSnake(int nPlayer, int zVal) else { DExhumedActor* pTarget = nullptr; - + auto hitactor = hit.actor(); if (hitactor && hitactor->s().statnum >= 90 && hitactor->s().statnum <= 199) { pTarget = hitactor; }