From 3c72eb43f90f18440e059ca289dc8f088b854762 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 25 Oct 2022 19:54:44 +0200 Subject: [PATCH] - split off one part of clipmove into a utility function. --- source/core/gamefuncs.cpp | 48 +++++++++++++++++++++++++++++++++++++++ source/core/gamefuncs.h | 1 + 2 files changed, 49 insertions(+) diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index 0d7c75f3f..df329eb66 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -1606,6 +1606,54 @@ void collectClipObjects(MoveClipper& clip, int spritemask) // //========================================================================== +int FindBestSector(const DVector3& pos) +{ + int bestnum = 1; + double bestdist = FLT_MAX; + for (int secnum = (int)sector.Size() - 1; secnum >= 0; secnum--) + { + auto sect = §or[secnum]; + if (inside(pos.X, pos.Y, sect)) + { + double ceilz, floorz; + calcSlope(sect, pos.X, pos.Y, &ceilz, &floorz); + + if (pos.Z < ceilz) + { + // above ceiling + double dist = ceilz - pos.Z; + if (dist < bestdist) + { + bestnum = secnum; + bestdist = dist; + } + } + else if (pos.Z > floorz) + { + // below floor + double dist = pos.Z - floorz; + if (dist < bestdist) + { + bestnum = secnum; + bestdist = dist; + } + } + else + { + // inside sector + return secnum; + } + } + } + return bestnum; +} + +//========================================================================== +// +// +// +//========================================================================== + bool isAwayFromWall(DCoreActor* ac, double delta) { sectortype* s1; diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index f82cfde7a..22d88e270 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -312,6 +312,7 @@ struct MoveClipper }; void collectClipObjects(MoveClipper& clip, int spritemask); +int FindBestSector(const DVector3& pos); int FindBestSector(const DVector3& pos);