From 5505c362e20053ba5ef3f5cb9ff09db9ee10ef1e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 17 Aug 2022 18:53:45 +0200 Subject: [PATCH] - floatified hitpos --- source/build/src/clip.cpp | 10 +++++----- source/build/src/engine.cpp | 6 +++--- source/core/coreactor.h | 17 +++++++++++++++-- source/core/savegamehelp.h | 6 +++--- source/games/blood/src/actor.cpp | 6 ++---- source/games/exhumed/src/snake.cpp | 4 +++- source/games/sw/src/rooms.cpp | 10 +++++----- source/games/sw/src/weapon.cpp | 18 +++++++++--------- 8 files changed, 45 insertions(+), 32 deletions(-) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index 3b6ca01a8..899e8be31 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -1279,9 +1279,7 @@ static inline void hit_set(HitInfoBase *hit, sectortype* sect, walltype* wal, DC hit->hitSector = sect; hit->hitWall = wal; hit->hitActor = actor; - hit->__int_hitpos.X = x; - hit->__int_hitpos.Y = y; - hit->__int_hitpos.Z = z; + hit->set_int_hitpos(x, y, z); } static int32_t hitscan_hitsectcf=-1; @@ -1360,7 +1358,7 @@ int hitscan(const vec3_t& start, const sectortype* startsect, const vec3_t& dire if (startsect == nullptr) return -1; - hitinfo.__int_hitpos.vec2 = hitscangoal; + hitinfo. set_int_hitpos_xy(hitscangoal.X, hitscangoal.Y); BFSSectorSearch search(startsect); while (auto sec = search.GetNext()) @@ -1430,11 +1428,13 @@ int hitscan(const vec3_t& start, const sectortype* startsect, const vec3_t& dire { case 0: { - if (try_facespr_intersect(actor, *sv, vx, vy, vz, &hitinfo.__int_hitpos, 0)) + auto v = hitinfo.int_hitpos(); + if (try_facespr_intersect(actor, *sv, vx, vy, vz, &v, 0)) { hitinfo.hitSector = sec; hitinfo.hitWall = nullptr; hitinfo.hitActor = actor; + hitinfo.set_int_hitpos(v.X, v.Y, v.Z); } break; diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 540fb78a4..5b395dfc4 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -288,7 +288,7 @@ void neartag(const vec3_t& sv, sectortype* sect, int ange, HitInfoBase& result, vec3_t hitv = { sv.X+vx, sv.Y+vy, 0 }; result.clearObj(); - result.__int_hitpos.X = 0; + result.hitpos.X = 0; if (!sect || (tagsearch & 3) == 0) return; @@ -324,7 +324,7 @@ void neartag(const vec3_t& sv, sectortype* sect, int ange, HitInfoBase& result, { if (good & 1) result.hitSector = nextsect; if (good & 2) result.hitWall = wal; - result.__int_hitpos.X = DMulScale(intx - sv.X, bcos(ange), inty - sv.Y, bsin(ange), 14); + result.hitpos.X = DMulScale(intx - sv.X, bcos(ange), inty - sv.Y, bsin(ange), 14) * inttoworld; hitv.X = intx; hitv.Y = inty; hitv.Z = intz; } @@ -349,7 +349,7 @@ void neartag(const vec3_t& sv, sectortype* sect, int ange, HitInfoBase& result, if (try_facespr_intersect(actor, sv, vx, vy, 0, &hitv, 1)) { result.hitActor = actor; - result.__int_hitpos.X = DMulScale(hitv.X-sv.X, bcos(ange), hitv.Y-sv.Y, bsin(ange), 14); + result.hitpos.X = DMulScale(hitv.X-sv.X, bcos(ange), hitv.Y-sv.Y, bsin(ange), 14) * inttoworld; } } } diff --git a/source/core/coreactor.h b/source/core/coreactor.h index f8c839c7c..d6fec64ac 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -289,7 +289,7 @@ enum EHitBits // Not all utilities use all variables. struct HitInfoBase { - vec3_t __int_hitpos; + DVector3 hitpos; sectortype* hitSector; walltype* hitWall; DCoreActor* hitActor; @@ -303,7 +303,20 @@ struct HitInfoBase const vec3_t int_hitpos() const { - return __int_hitpos; + return { int(hitpos.X * worldtoint), int(hitpos.Y * worldtoint), int(hitpos.Z * zworldtoint), }; + } + + void set_int_hitpos(int x, int y, int z) + { + hitpos.X = x * inttoworld; + hitpos.Y = y * inttoworld; + hitpos.Z = z * zinttoworld; + } + + void set_int_hitpos_xy(int x, int y) + { + hitpos.X = x * inttoworld; + hitpos.Y = y * inttoworld; } }; diff --git a/source/core/savegamehelp.h b/source/core/savegamehelp.h index f20d09ee3..e19d10e4f 100644 --- a/source/core/savegamehelp.h +++ b/source/core/savegamehelp.h @@ -47,9 +47,9 @@ inline FSerializer& Serialize(FSerializer& arc, const char* keyname, THitInfo arc("sect", w.hitSector) ("sprite", w.hitActor) ("wall", w.hitWall) - ("x", w.__int_hitpos.X) - ("y", w.__int_hitpos.Y) - ("z", w.__int_hitpos.Z) + ("x", w.hitpos.X) + ("y", w.hitpos.Y) + ("z", w.hitpos.Z) .EndObject(); } return arc; diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index 39a522977..01e7218a0 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -5349,9 +5349,7 @@ int MoveMissile(DBloodActor* actor) } CheckLink(actor); gHitInfo.hitSector = actor->sector(); - gHitInfo.__int_hitpos.X = actor->int_pos().X; - gHitInfo.__int_hitpos.Y = actor->int_pos().Y; - gHitInfo.__int_hitpos.Z = actor->int_pos().Z; + gHitInfo.hitpos = actor->spr.pos; break; } if (Owner) Owner->spr.cstat = bakCstat; @@ -6702,7 +6700,7 @@ void actFireVector(DBloodActor* shooter, int a2, int a3, int a4, int a5, int a6, if (powerupCheck(pPlayer, kPwUpReflectShots)) { gHitInfo.hitActor = shooter; - gHitInfo.__int_hitpos = shooter->int_pos(); + gHitInfo.hitpos = shooter->spr.pos; } } } diff --git a/source/games/exhumed/src/snake.cpp b/source/games/exhumed/src/snake.cpp index e3adc789b..f1ccbcc78 100644 --- a/source/games/exhumed/src/snake.cpp +++ b/source/games/exhumed/src/snake.cpp @@ -156,7 +156,9 @@ void BuildSnake(int nPlayer, int zVal) if (nSqrt < bsin(512, -4)) { - BackUpBullet(&hit.__int_hitpos.X, &hit.__int_hitpos.Y, nAngle); + auto v = hit.int_hitpos(); + BackUpBullet(&v.X, &v.Y, nAngle); + hit.set_int_hitpos_xy(v.X, v.Y); auto pActor = insertActor(hit.hitSector, 202); pActor->set_int_pos(hit.int_hitpos()); diff --git a/source/games/sw/src/rooms.cpp b/source/games/sw/src/rooms.cpp index 4a28bf5f1..f0f282385 100644 --- a/source/games/sw/src/rooms.cpp +++ b/source/games/sw/src/rooms.cpp @@ -142,11 +142,11 @@ FAFhitscan(int32_t x, int32_t y, int32_t z, sectortype* sect, if ((hit.hitWall->cstat & CSTAT_WALL_WARP_HITSCAN)) { // back it up a bit to get a correct warp location - hit.__int_hitpos.X -= xvect>>9; - hit.__int_hitpos.Y -= yvect>>9; + hit.hitpos.X -= (xvect>>9) * inttoworld; + hit.hitpos.Y -= (yvect>>9) * inttoworld; // warp to new x,y,z, sectnum - if (Warp(&hit.__int_hitpos.X, &hit.__int_hitpos.Y, &hit.__int_hitpos.Z, &hit.hitSector)) + if (Warp(hit.hitpos, &hit.hitSector)) { // hitscan needs to pass through dest sect ResetWallWarpHitscan(hit.hitSector); @@ -177,7 +177,7 @@ FAFhitscan(int32_t x, int32_t y, int32_t z, sectortype* sect, { // hit the floor of a sector that is a warping sector sectortype* newsect = nullptr; - if (Warp(&hit.__int_hitpos.X, &hit.__int_hitpos.Y, &hit.__int_hitpos.Z, &newsect)) + if (Warp(hit.hitpos, &newsect)) { auto pos = hit.int_hitpos(); hitscan(pos, newsect, { xvect, yvect, zvect }, hit, clipmask); @@ -187,7 +187,7 @@ FAFhitscan(int32_t x, int32_t y, int32_t z, sectortype* sect, else { sectortype* newsect = nullptr; - if (WarpPlane(&hit.__int_hitpos.X, &hit.__int_hitpos.Y, &hit.__int_hitpos.Z, &newsect)) + if (WarpPlane(hit.hitpos, &newsect)) { auto pos = hit.int_hitpos(); hitscan(pos, newsect, { xvect, yvect, zvect }, hit, clipmask); diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index e42594d5d..67a2c4d66 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -12753,7 +12753,7 @@ int ContinueHitscan(PLAYER* pp, sectortype* sect, int x, int y, int z, short ang { if (labs(hit.int_hitpos().Z - hit.hitSector->int_ceilingz()) <= Z(1)) { - hit.__int_hitpos.Z += Z(16); + hit.hitpos.Z += 16; if ((hit.hitSector->ceilingstat & CSTAT_SECTOR_SKY)) return 0; } @@ -12886,7 +12886,7 @@ int InitShotgun(PLAYER* pp) { if (labs(hit.int_hitpos().Z - hit.hitSector->int_ceilingz()) <= Z(1)) { - hit.__int_hitpos.Z += Z(16); + hit.hitpos.Z += 16; cstat |= (CSTAT_SPRITE_YFLIP); if ((hit.hitSector->ceilingstat & CSTAT_SECTOR_SKY)) @@ -12894,7 +12894,7 @@ int InitShotgun(PLAYER* pp) if (SectorIsUnderwaterArea(hit.hitSector)) { - WarpToSurface(&hit.hitSector, &hit.__int_hitpos.X, &hit.__int_hitpos.Y, &hit.__int_hitpos.Z); + WarpToSurface(hit.hitpos, &hit.hitSector); ContinueHitscan(pp, hit.hitSector, hit.int_hitpos().X, hit.int_hitpos().Y, hit.int_hitpos().Z, ndaang, xvect, yvect, zvect); continue; } @@ -12907,7 +12907,7 @@ int InitShotgun(PLAYER* pp) if (SectorIsDiveArea(hit.hitSector)) { - WarpToUnderwater(&hit.hitSector, &hit.__int_hitpos.X, &hit.__int_hitpos.Y, &hit.__int_hitpos.Z); + WarpToUnderwater(hit.hitpos, &hit.hitSector); ContinueHitscan(pp, hit.hitSector, hit.int_hitpos().X, hit.int_hitpos().Y, hit.int_hitpos().Z, ndaang, xvect, yvect, zvect); } @@ -15215,7 +15215,7 @@ int InitUzi(PLAYER* pp) { if (labs(hit.int_hitpos().Z - hit.hitSector->int_ceilingz()) <= Z(1)) { - hit.__int_hitpos.Z += Z(16); + hit.hitpos.Z += 16; cstat |= (CSTAT_SPRITE_YFLIP); if ((hit.hitSector->ceilingstat & CSTAT_SECTOR_SKY)) @@ -15223,7 +15223,7 @@ int InitUzi(PLAYER* pp) if (SectorIsUnderwaterArea(hit.hitSector)) { - WarpToSurface(&hit.hitSector, &hit.__int_hitpos.X, &hit.__int_hitpos.Y, &hit.__int_hitpos.Z); + WarpToSurface(hit.hitpos, &hit.hitSector); ContinueHitscan(pp, hit.hitSector, hit.int_hitpos().X, hit.int_hitpos().Y, hit.int_hitpos().Z, daang, xvect, yvect, zvect); return 0; } @@ -15236,7 +15236,7 @@ int InitUzi(PLAYER* pp) if (SectorIsDiveArea(hit.hitSector)) { - WarpToUnderwater(&hit.hitSector, &hit.__int_hitpos.X, &hit.__int_hitpos.Y, &hit.__int_hitpos.Z); + WarpToUnderwater(hit.hitpos, &hit.hitSector); ContinueHitscan(pp, hit.hitSector, hit.int_hitpos().X, hit.int_hitpos().Y, hit.int_hitpos().Z, daang, xvect, yvect, zvect); return 0; } @@ -15704,7 +15704,7 @@ int InitSobjMachineGun(DSWActor* actor, PLAYER* pp) { if (labs(hit.int_hitpos().Z - hit.hitSector->int_ceilingz()) <= Z(1)) { - hit.__int_hitpos.Z += Z(16); + hit.hitpos.Z += 16; cstat |= (CSTAT_SPRITE_YFLIP); if ((hit.hitSector->ceilingstat & CSTAT_SECTOR_SKY)) @@ -16085,7 +16085,7 @@ int InitTurretMgun(SECTOR_OBJECT* sop) { if (labs(hit.int_hitpos().Z - hit.hitSector->int_ceilingz()) <= Z(1)) { - hit.__int_hitpos.Z += Z(16); + hit.hitpos.Z += 16; cstat |= (CSTAT_SPRITE_YFLIP); if ((hit.hitSector->ceilingstat & CSTAT_SECTOR_SKY))