diff --git a/common/main/gameseg.h b/common/main/gameseg.h index 858834dfd..7a83d6e46 100644 --- a/common/main/gameseg.h +++ b/common/main/gameseg.h @@ -73,7 +73,8 @@ static inline vms_vector compute_segment_center(vcsegptr_t sp) compute_segment_center(v, sp); return v; } -int_fast32_t find_connect_side(vcsegptridx_t base_seg, vcsegptr_t con_seg) __attribute_warn_unused_result; +__attribute_warn_unused_result +uint_fast32_t find_connect_side(vcsegidx_t base_seg, const segment &con_seg); // Fill in array with four absolute point numbers for a given side void get_side_verts(side_vertnum_list_t &vertlist, const segment &seg, unsigned sidenum); diff --git a/similar/main/gameseg.cpp b/similar/main/gameseg.cpp index f2b314da8..c60712c1d 100644 --- a/similar/main/gameseg.cpp +++ b/similar/main/gameseg.cpp @@ -92,9 +92,19 @@ constexpr vm_distance fcd_abort_return_value{-1}; } +namespace dcx { + // How far a point can be from a plane, and still be "in" the plane #define PLANE_DIST_TOLERANCE 250 +static uint_fast32_t find_connect_child(const vcsegidx_t base_seg, const array &children) +{ + const auto &&b = begin(children); + return std::distance(b, std::find(b, end(children), base_seg)); +} + +} + namespace dsx { #if defined(DXX_BUILD_DESCENT_II) array Dl_indices; @@ -131,13 +141,9 @@ void compute_segment_center(vms_vector &vp,const vcsegptr_t sp) // ----------------------------------------------------------------------------- // Given two segments, return the side index in the connecting segment which connects to the base segment // Optimized by MK on 4/21/94 because it is a 2% load. -int_fast32_t find_connect_side(const vcsegptridx_t base_seg, const vcsegptr_t con_seg) +uint_fast32_t find_connect_side(const vcsegidx_t base_seg, const segment &con_seg) { - auto &children = con_seg->children; - auto b = begin(children); - auto i = std::find(b, end(children), base_seg); - // legal to return -1, used in object_move_one(), mk, 06/08/94: Assert(0); // Illegal -- there is no connecting side between these two segments - return std::distance(b, i); + return find_connect_child(base_seg, con_seg.children); } }