From 139969d017d1145003b7934ab9549a9c813fa181 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 22 Aug 2022 18:27:03 +0200 Subject: [PATCH] - FindSector variants with vectors --- source/games/blood/src/actor.cpp | 6 +++--- source/games/blood/src/animatesprite.cpp | 2 +- source/games/blood/src/fx.cpp | 6 +++--- source/games/blood/src/gameutil.h | 8 ++++++++ source/games/blood/src/nnexts.cpp | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index 11e832d21..f63efb4b0 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -4564,7 +4564,7 @@ static Collision MoveThing(DBloodActor* actor) else { assert(pSector); - FindSector(actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z, &pSector); + FindSector(actor->spr.pos, &pSector); } actor->add_int_z(actor->vel.Z >> 8); @@ -4746,7 +4746,7 @@ void MoveDude(DBloodActor* actor) if (pPlayer && gNoClip) { actor->add_int_pos({ actor->vel.X >> 12, actor->vel.Y >> 12, 0 }); - if (!FindSector(actor->int_pos().X, actor->int_pos().Y, &pSector)) + if (!FindSector(actor->spr.pos.XY(), &pSector)) pSector = actor->sector(); } else @@ -4830,7 +4830,7 @@ void MoveDude(DBloodActor* actor) else { assert(pSector); - FindSector(actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z, &pSector); + FindSector(actor->spr.pos, &pSector); } XSECTOR* pXSector = pSector->hasX() ? &pSector->xs() : nullptr; diff --git a/source/games/blood/src/animatesprite.cpp b/source/games/blood/src/animatesprite.cpp index 5daaf7cca..4bfa1d83b 100644 --- a/source/games/blood/src/animatesprite.cpp +++ b/source/games/blood/src/animatesprite.cpp @@ -293,7 +293,7 @@ static tspritetype* viewAddEffect(tspriteArray& tsprites, int nTSprite, VIEW_EFF int y = MulScale(nLen, Sin(nAng), 30); pNSprite->set_int_pos({ pTSprite->int_pos().X + x, pTSprite->int_pos().Y + y, pTSprite->int_pos().Z }); assert(pSector); - FindSector(pNSprite->int_pos().X, pNSprite->int_pos().Y, pNSprite->int_pos().Z, &pSector); + FindSector(pNSprite->pos, &pSector); pNSprite->sectp = pSector; pNSprite->ownerActor = pTSprite->ownerActor; pNSprite->picnum = pTSprite->picnum; diff --git a/source/games/blood/src/fx.cpp b/source/games/blood/src/fx.cpp index fbdc33543..e54136886 100644 --- a/source/games/blood/src/fx.cpp +++ b/source/games/blood/src/fx.cpp @@ -142,7 +142,7 @@ DBloodActor* CFX::fxSpawnActor(FX_ID nFx, sectortype* pSector, int x, int y, int if (pSector == nullptr) return nullptr; auto pSector2 = pSector; - if (!FindSector(x, y, z, &pSector2)) + if (!FindSector(pos, &pSector2)) return nullptr; if (adult_lockout && gGameOptions.nGameType <= 0) { @@ -271,7 +271,7 @@ void fxSpawnBlood(DBloodActor* actor, int) if (!actor->insector()) return; auto pSector = actor->sector(); - if (!FindSector(actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z, &pSector)) + if (!FindSector(actor->spr.pos, &pSector)) return; if (adult_lockout && gGameOptions.nGameType <= 0) return; @@ -297,7 +297,7 @@ void fxSpawnPodStuff(DBloodActor* actor, int) if (!actor->insector()) return; auto pSector = actor->sector(); - if (!FindSector(actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z, &pSector)) + if (!FindSector(actor->spr.pos, &pSector)) return; if (adult_lockout && gGameOptions.nGameType <= 0) return; diff --git a/source/games/blood/src/gameutil.h b/source/games/blood/src/gameutil.h index 90a8e1830..99be9e435 100644 --- a/source/games/blood/src/gameutil.h +++ b/source/games/blood/src/gameutil.h @@ -34,6 +34,14 @@ enum { bool FindSector(int nX, int nY, int nZ, sectortype** ppSector); bool FindSector(int nX, int nY, sectortype** ppSector); +inline bool FindSector(const DVector3& pos, sectortype** ppSector) +{ + return FindSector(int(pos.X * worldtoint), int(pos.Y * worldtoint), int(pos.Z * zworldtoint), ppSector); +} +inline bool FindSector(const DVector2& pos, sectortype** ppSector) +{ + return FindSector(int(pos.X * worldtoint), int(pos.Y * worldtoint), ppSector); +} 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); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 7349fcd0a..efc6b443c 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -1699,7 +1699,7 @@ void debrisMove(int listIndex) } } - else if (!FindSector(actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z, &pSector)) + else if (!FindSector(actor->spr.pos, &pSector)) { return; }