diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index b81aaa706..bed66b326 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -221,16 +221,8 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect, if (!clip.precise) { DVector3 fpos(pos->X* inttoworld, pos->Y* inttoworld, pos->Z* inttoworld); - - clip.search.Rewind(); - while (auto sect = clip.search.GetNext()) - if (inside(fpos.X, fpos.Y, sect) == 1) - { - *sectnum = ::sectnum(sect); - return clipReturn; - } - - *sectnum = FindBestSector(fpos); + *sectnum = FindSectorInSearchList(fpos, clip.search); + if (*sectnum == -1) *sectnum = FindBestSector(fpos); } return clipReturn; diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index df329eb66..5e22b704d 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -1606,6 +1606,23 @@ void collectClipObjects(MoveClipper& clip, int spritemask) // //========================================================================== +int FindSectorInSearchList(const DVector3& pos, BFSSectorSearch& search) +{ + search.Rewind(); + while (auto sect = search.GetNext()) + if (inside(pos.X, pos.Y, sect) == 1) + { + return ::sectnum(sect); + } + return -1; +} + +//========================================================================== +// +// +// +//========================================================================== + int FindBestSector(const DVector3& pos) { int bestnum = 1; diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 22d88e270..5736d1353 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -313,6 +313,7 @@ struct MoveClipper void collectClipObjects(MoveClipper& clip, int spritemask); int FindBestSector(const DVector3& pos); +int FindSectorInSearchList(const DVector3& pos, BFSSectorSearch& search); int FindBestSector(const DVector3& pos);