use RR's version of Mobj spawn height since we have cpp now

This commit is contained in:
NepDisk 2025-01-27 01:53:44 -05:00
parent 897ef3d47f
commit 7e1caec293
3 changed files with 93 additions and 92 deletions

View file

@ -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

92
src/p_mapthing.cpp Normal file
View file

@ -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 <algorithm>
#include <iterator>
#include <set>
#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<fixed_t> 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;
}

View file

@ -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.