From db0ce361437e509f5f7d0fd214c4524a7707c1f5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 25 Aug 2022 19:15:06 +0200 Subject: [PATCH] - use engine's updatesector in Blood instead of the limited homegrown FindSector variant. --- source/games/blood/src/actor.cpp | 12 ++-- source/games/blood/src/ai.cpp | 4 +- source/games/blood/src/animatesprite.cpp | 4 +- source/games/blood/src/fx.cpp | 12 ++-- source/games/blood/src/gameutil.cpp | 79 ------------------------ source/games/blood/src/gameutil.h | 11 ---- source/games/blood/src/nnexts.cpp | 9 +-- 7 files changed, 24 insertions(+), 107 deletions(-) diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index 5b2b67220..c62d47b5b 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -4564,7 +4564,9 @@ static Collision MoveThing(DBloodActor* actor) else { assert(pSector); - FindSector(actor->spr.pos, &pSector); + auto pSector2 = pSector; + updatesectorz(actor->spr.pos, &pSector2); + if (pSector2) pSector = pSector2; } actor->add_int_z(actor->vel.Z >> 8); @@ -4746,8 +4748,8 @@ void MoveDude(DBloodActor* actor) if (pPlayer && gNoClip) { actor->add_int_pos({ actor->vel.X >> 12, actor->vel.Y >> 12, 0 }); - if (!FindSector(actor->spr.pos.XY(), &pSector)) - pSector = actor->sector(); + updatesector(actor->spr.pos, &pSector); + if (!pSector) pSector = actor->sector(); } else { @@ -4830,7 +4832,9 @@ void MoveDude(DBloodActor* actor) else { assert(pSector); - FindSector(actor->spr.pos, &pSector); + auto pSector2 = pSector; + updatesectorz(actor->spr.pos, &pSector2); + if (pSector2) pSector = pSector2; } XSECTOR* pXSector = pSector->hasX() ? &pSector->xs() : nullptr; diff --git a/source/games/blood/src/ai.cpp b/source/games/blood/src/ai.cpp index 997d89b80..52eb9675d 100644 --- a/source/games/blood/src/ai.cpp +++ b/source/games/blood/src/ai.cpp @@ -146,8 +146,8 @@ bool CanMove(DBloodActor* actor, DBloodActor* target, int nAngle, int nRange) y += MulScale(nRange, Sin(nAngle), 30); auto pSector = actor->sector(); assert(pSector); - if (!FindSector(x, y, z, &pSector)) - return false; + updatesectorz(x, y, z, &pSector); + if (!pSector) return false; int floorZ = getflorzofslopeptr(pSector, x, y); auto pXSector = pSector->hasX()? &pSector->xs() : nullptr; bool Underwater = 0; diff --git a/source/games/blood/src/animatesprite.cpp b/source/games/blood/src/animatesprite.cpp index 4bfa1d83b..364fe63a3 100644 --- a/source/games/blood/src/animatesprite.cpp +++ b/source/games/blood/src/animatesprite.cpp @@ -293,7 +293,9 @@ 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->pos, &pSector); + auto pSector2 = pSector; + updatesectorz(pNSprite->pos, &pSector2); + if (pSector2) pSector = pSector2; 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 34f3dea34..70beac982 100644 --- a/source/games/blood/src/fx.cpp +++ b/source/games/blood/src/fx.cpp @@ -146,8 +146,8 @@ DBloodActor* CFX::fxSpawnActor(FX_ID nFx, sectortype* pSector, const DVector3& p if (pSector == nullptr) return nullptr; auto pSector2 = pSector; - if (!FindSector(pos, &pSector2)) - return nullptr; + updatesectorz(pos, &pSector2); + if (!pSector2) return nullptr; if (adult_lockout && gGameOptions.nGameType <= 0) { switch (nFx) @@ -275,8 +275,8 @@ void fxSpawnBlood(DBloodActor* actor, int) if (!actor->insector()) return; auto pSector = actor->sector(); - if (!FindSector(actor->spr.pos, &pSector)) - return; + updatesectorz(actor->spr.pos, &pSector); + if (!pSector) return; if (adult_lockout && gGameOptions.nGameType <= 0) return; auto bloodactor = gFX.fxSpawnActor(FX_27, actor->sector(), actor->spr.pos, 0); @@ -301,8 +301,8 @@ void fxSpawnPodStuff(DBloodActor* actor, int) if (!actor->insector()) return; auto pSector = actor->sector(); - if (!FindSector(actor->spr.pos, &pSector)) - return; + updatesectorz(actor->spr.pos, &pSector); + if (!pSector) return; if (adult_lockout && gGameOptions.nGameType <= 0) return; DBloodActor* spawnactor; diff --git a/source/games/blood/src/gameutil.cpp b/source/games/blood/src/gameutil.cpp index c8656b2c3..657ee82b3 100644 --- a/source/games/blood/src/gameutil.cpp +++ b/source/games/blood/src/gameutil.cpp @@ -41,85 +41,6 @@ HitInfo gHitInfo; // //--------------------------------------------------------------------------- -bool FindSector(int nX, int nY, int nZ, sectortype** pSector) -{ - int32_t nZFloor, nZCeil; - assert(pSector); - if (inside(nX, nY, *pSector)) - { - getzsofslopeptr(*pSector, nX, nY, &nZCeil, &nZFloor); - if (nZ >= nZCeil && nZ <= nZFloor) - { - return 1; - } - } - for (auto& wal : wallsofsector(*pSector)) - { - auto pOSector = wal.nextSector(); - if (pOSector != nullptr && inside(nX, nY, pOSector)) - { - getzsofslopeptr(pOSector, nX, nY, &nZCeil, &nZFloor); - if (nZ >= nZCeil && nZ <= nZFloor) - { - *pSector = pOSector; - return 1; - } - } - } - for (auto& sec : sector) - { - if (inside(nX, nY, &sec)) - { - getzsofslopeptr(&sec, nX, nY, &nZCeil, &nZFloor); - if (nZ >= nZCeil && nZ <= nZFloor) - { - *pSector = &sec; - return 1; - } - } - } - return 0; -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -bool FindSector(int nX, int nY, sectortype** pSector) -{ - assert(*pSector); - if (inside(nX, nY, *pSector)) - { - return 1; - } - for (auto& wal : wallsofsector(*pSector)) - { - auto pOSector = wal.nextSector(); - if (pOSector != nullptr && inside(nX, nY, pOSector)) - { - *pSector = pOSector; - return 1; - } - } - for (auto& sec : sector) - { - if (inside(nX, nY, &sec)) - { - *pSector = &sec; - return 1; - } - } - return 0; -} - -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - bool CheckProximity(DBloodActor* actor, const DVector3& pos, sectortype* pSector, int nDist) { assert(actor != nullptr); diff --git a/source/games/blood/src/gameutil.h b/source/games/blood/src/gameutil.h index 99be9e435..59e56f8a2 100644 --- a/source/games/blood/src/gameutil.h +++ b/source/games/blood/src/gameutil.h @@ -32,17 +32,6 @@ 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); bool CheckProximityWall(walltype* pWall, int x, int y, int nDist); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 2ff35433c..f340ad51a 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -1698,9 +1698,10 @@ void debrisMove(int listIndex) } } - else if (!FindSector(actor->spr.pos, &pSector)) + else { - return; + updatesectorz(actor->spr.pos, &pSector); + if (!pSector) return; } if (actor->sector() != pSector) @@ -7708,8 +7709,8 @@ bool nnExtCanMove(DBloodActor* actor, DBloodActor* target, int nAngle, int nRang x += MulScale(nRange, Cos(nAngle), 30); y += MulScale(nRange, Sin(nAngle), 30); - if (!FindSector(x, y, z, &pSector)) - return false; + updatesectorz(x, y, z, &pSector); + if (!pSector) return false; if (pSector->hasX()) {