From 7e1caec29334d4b02907b4e77f193588f55dd4b7 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Mon, 27 Jan 2025 01:53:44 -0500 Subject: [PATCH] use RR's version of Mobj spawn height since we have cpp now --- src/Sourcefile | 1 + src/p_mapthing.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++++ src/p_mobj.c | 92 ---------------------------------------------- 3 files changed, 93 insertions(+), 92 deletions(-) create mode 100644 src/p_mapthing.cpp diff --git a/src/Sourcefile b/src/Sourcefile index 3c074f5f0..17a687d5d 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -46,6 +46,7 @@ p_inter.c p_lights.c p_map.c p_maputl.c +p_mapthing.cpp p_mobj.c p_polyobj.c p_saveg.c diff --git a/src/p_mapthing.cpp b/src/p_mapthing.cpp new file mode 100644 index 000000000..5c7dc277f --- /dev/null +++ b/src/p_mapthing.cpp @@ -0,0 +1,92 @@ +// DR. ROBOTNIK'S RING RACERS +//----------------------------------------------------------------------------- +// Copyright (C) 2024 by Kart Krew. +// Copyright (C) 2020 by Sonic Team Junior. +// Copyright (C) 2000 by DooM Legacy Team. +// Copyright (C) 1996 by id Software, Inc. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file p_mapthing.cpp +/// \brief Mapthing spawning assistance + +#include +#include +#include + +#include "core/static_vec.hpp" + +#include "doomstat.h" // mapobjectscale +#include "info.h" +#include "m_fixed.h" +#include "p_local.h" // ONFLOORZ +#include "p_mobj.h" +#include "p_slopes.h" +#include "r_defs.h" +#include "r_main.h" + +fixed_t P_GetMobjSpawnHeight( + const mobjtype_t mobjtype, + const fixed_t x, + const fixed_t y, + const fixed_t dz, + const fixed_t offset, + const size_t layer, + const boolean flip, + const fixed_t scale +) +{ + const fixed_t finalScale = FixedMul(scale, mapobjectscale); + + const fixed_t finalZOffset = flip + ? -(dz) - FixedMul(finalScale, offset + mobjinfo[mobjtype].height) + : +(dz) + FixedMul(finalScale, offset); + + const sector_t* sector = R_PointInSubsector(x, y)->sector; + + // Axis objects snap to the floor. + if (mobjtype == MT_AXIS || mobjtype == MT_AXISTRANSFER || mobjtype == MT_AXISTRANSFERLINE) + return ONFLOORZ; + + if (layer != 0) + { + // multiset is a container that automatically sorts + // each insertion. It only contains unique values, so + // two FOFs at the exact same height only count as one + // layer. + std::multiset heights; + + auto get_height = flip ? P_GetFFloorBottomZAt : P_GetFFloorTopZAt; + + for (ffloor_t* rover = sector->ffloors; rover; rover = rover->next) + { + heights.insert(get_height(rover, x, y)); + } + + if (!heights.empty()) + { + auto get_layer = [layer, &heights](auto it) + { + std::advance(it, std::min(layer, heights.size()) - 1); + return *it; + }; + + if (flip) + { + return get_layer(heights.rbegin()) + finalZOffset; + } + else + { + return get_layer(heights.begin()) + finalZOffset; + } + } + } + + // Establish height. + if (flip) + return P_GetSectorCeilingZAt(sector, x, y) + finalZOffset; + else + return P_GetSectorFloorZAt(sector, x, y) + finalZOffset; +} diff --git a/src/p_mobj.c b/src/p_mobj.c index 1e0f5d89a..551feedb7 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10845,98 +10845,6 @@ void P_MovePlayerToStarpost(INT32 playernum) // leveltime = p->starposttime; } -fixed_t P_GetMobjSpawnHeight( - const mobjtype_t mobjtype, - const fixed_t x, - const fixed_t y, - const fixed_t dz, - const fixed_t offset, - const size_t layer, - const boolean flip, - const fixed_t scale -) -{ - const fixed_t finalScale = FixedMul(scale, mapobjectscale); - - const fixed_t finalZOffset = flip - ? -(dz) - FixedMul(finalScale, offset + mobjinfo[mobjtype].height) - : +(dz) + FixedMul(finalScale, offset); - - const sector_t* sector = R_PointInSubsector(x, y)->sector; - - // Axis objects snap to the floor. - if (mobjtype == MT_AXIS || mobjtype == MT_AXISTRANSFER || mobjtype == MT_AXISTRANSFERLINE) - return ONFLOORZ; - - if (layer != 0) - { - size_t heights_count[MAXFFLOORS] = {0}; - size_t heights_i = 0; - size_t heights_size = 0; - - // multiset is a container that automatically sorts - // each insertion. It only contains unique values, so - // two FOFs at the exact same height only count as one - // layer. - aatree_t *heights = M_AATreeAlloc(AATREE_ZUSER); - - fixed_t (*get_height)(const ffloor_t*, fixed_t, fixed_t) = flip ? P_GetFFloorBottomZAt : P_GetFFloorTopZAt; - - for (ffloor_t* rover = sector->ffloors; rover; rover = rover->next) - { - fixed_t height = get_height(rover, x, y); - - size_t *count = M_AATreeGet(heights, height); - - if (!count) - { - count = &heights_count[heights_i++]; - - M_AATreeSet(heights, height, count); - } - - ++heights_size; - - ++(*count); - } - - if (heights_size) - { - aatree_iterator_t *it; - - if (flip) - it = M_AATreeBegin(heights); - else - it = M_AATreeRBegin(heights); - - size_t advance = min(layer, heights_size - 1); - - while (advance--) - { - size_t *count = M_AATreeIteratorValue(it); - - --(*count); - - if (*count == 0) - M_AATreeIteratorNext(it); - } - - //fixed_t result = M_AATreeIteratorKey(it) + finalZOffset; - - M_AATreeIteratorClose(it); - M_AATreeFree(heights); - } - - M_AATreeFree(heights); - } - - // Establish height. - if (flip) - return P_GetSectorCeilingZAt(sector, x, y) + finalZOffset; - else - return P_GetSectorFloorZAt(sector, x, y) + finalZOffset; -} - fixed_t P_GetMapThingSpawnHeight(const mobjtype_t mobjtype, const mapthing_t* mthing, const fixed_t x, const fixed_t y) { fixed_t dz = mthing->z << FRACBITS; // Base offset from the floor.