Merge branch 'udmf-riser' into 'master'

Add foflayer field to UDMF things, spawn offset from a specific FOF in the thing's sector

Closes #417

See merge request KartKrew/Kart!1120
This commit is contained in:
James R 2023-04-02 07:27:51 +00:00
commit 56694b2740
6 changed files with 90 additions and 22 deletions

View file

@ -50,6 +50,7 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32
p_lights.c p_lights.c
p_loop.c p_loop.c
p_map.c p_map.c
p_mapthing.cpp
p_maputl.c p_maputl.c
p_mobj.c p_mobj.c
p_polyobj.c p_polyobj.c

View file

@ -251,6 +251,7 @@ struct mapthing_t
INT16 special; INT16 special;
INT32 args[NUMMAPTHINGARGS]; INT32 args[NUMMAPTHINGARGS];
char *stringargs[NUMMAPTHINGSTRINGARGS]; char *stringargs[NUMMAPTHINGSTRINGARGS];
UINT8 layer; // FOF layer to spawn on, see P_GetMobjSpawnHeight
mobj_t *mobj; mobj_t *mobj;
}; };

78
src/p_mapthing.cpp Normal file
View file

@ -0,0 +1,78 @@
#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

@ -12095,22 +12095,6 @@ void P_MovePlayerToStarpost(INT32 playernum)
P_AfterPlayerSpawn(playernum); P_AfterPlayerSpawn(playernum);
} }
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 boolean flip, const fixed_t scale)
{
const fixed_t finalScale = FixedMul(scale, mapobjectscale);
const subsector_t *ss = R_PointInSubsector(x, y);
// Axis objects snap to the floor.
if (mobjtype == MT_AXIS || mobjtype == MT_AXISTRANSFER || mobjtype == MT_AXISTRANSFERLINE)
return ONFLOORZ;
// Establish height.
if (flip)
return P_GetSectorCeilingZAt(ss->sector, x, y) - dz - FixedMul(finalScale, offset + mobjinfo[mobjtype].height);
else
return P_GetSectorFloorZAt(ss->sector, x, y) + dz + FixedMul(finalScale, offset);
}
fixed_t P_GetMapThingSpawnHeight(const mobjtype_t mobjtype, const mapthing_t* mthing, const fixed_t x, const fixed_t y) 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. fixed_t dz = mthing->z << FRACBITS; // Base offset from the floor.
@ -12142,7 +12126,7 @@ fixed_t P_GetMapThingSpawnHeight(const mobjtype_t mobjtype, const mapthing_t* mt
break; break;
} }
if (!(dz + offset)) // Snap to the surfaces when there's no offset set. if (!(dz + offset) && mthing->layer == 0) // Snap to the surfaces when there's no offset set.
{ {
if (flip) if (flip)
return ONCEILINGZ; return ONCEILINGZ;
@ -12150,7 +12134,7 @@ fixed_t P_GetMapThingSpawnHeight(const mobjtype_t mobjtype, const mapthing_t* mt
return ONFLOORZ; return ONFLOORZ;
} }
return P_GetMobjSpawnHeight(mobjtype, x, y, dz, offset, flip, mthing->scale); return P_GetMobjSpawnHeight(mobjtype, x, y, dz, offset, mthing->layer, flip, mthing->scale);
} }
static boolean P_SpawnNonMobjMapThing(mapthing_t *mthing) static boolean P_SpawnNonMobjMapThing(mapthing_t *mthing)
@ -13509,7 +13493,7 @@ void P_SpawnHoop(mapthing_t *mthing)
TVector v, *res; TVector v, *res;
fixed_t x = mthing->x << FRACBITS; fixed_t x = mthing->x << FRACBITS;
fixed_t y = mthing->y << FRACBITS; fixed_t y = mthing->y << FRACBITS;
fixed_t z = P_GetMobjSpawnHeight(MT_HOOP, x, y, mthing->z << FRACBITS, 0, false, mthing->scale); fixed_t z = P_GetMobjSpawnHeight(MT_HOOP, x, y, mthing->z << FRACBITS, 0, mthing->layer, false, mthing->scale);
hoopcenter = P_SpawnMobj(x, y, z, MT_HOOPCENTER); hoopcenter = P_SpawnMobj(x, y, z, MT_HOOPCENTER);
hoopcenter->spawnpoint = mthing; hoopcenter->spawnpoint = mthing;
@ -13631,7 +13615,7 @@ static void P_SpawnItemRow(mapthing_t *mthing, mobjtype_t *itemtypes, UINT8 numi
itemtypes[r] = P_GetMobjtypeSubstitute(&dummything, itemtypes[r]); itemtypes[r] = P_GetMobjtypeSubstitute(&dummything, itemtypes[r]);
} }
} }
z = P_GetMobjSpawnHeight(itemtypes[0], x, y, z, 0, mthing->options & MTF_OBJECTFLIP, mthing->scale); z = P_GetMobjSpawnHeight(itemtypes[0], x, y, z, 0, mthing->layer, mthing->options & MTF_OBJECTFLIP, mthing->scale);
if (isloopend) if (isloopend)
{ {
@ -13711,7 +13695,7 @@ static void P_SpawnItemCircle(mapthing_t *mthing, mobjtype_t *itemtypes, UINT8 n
itemtypes[i] = P_GetMobjtypeSubstitute(&dummything, itemtypes[i]); itemtypes[i] = P_GetMobjtypeSubstitute(&dummything, itemtypes[i]);
} }
} }
z = P_GetMobjSpawnHeight(itemtypes[0], x, y, z, 0, false, mthing->scale); z = P_GetMobjSpawnHeight(itemtypes[0], x, y, z, 0, mthing->layer, false, mthing->scale);
for (i = 0; i < numitems; i++) for (i = 0; i < numitems; i++)
{ {

View file

@ -524,7 +524,7 @@ void P_MovePlayerToSpawn(INT32 playernum, mapthing_t *mthing);
void P_MovePlayerToStarpost(INT32 playernum); void P_MovePlayerToStarpost(INT32 playernum);
void P_AfterPlayerSpawn(INT32 playernum); void P_AfterPlayerSpawn(INT32 playernum);
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 boolean flip, const fixed_t scale); 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);
fixed_t P_GetMapThingSpawnHeight(const mobjtype_t mobjtype, const mapthing_t* mthing, const fixed_t x, const fixed_t y); fixed_t P_GetMapThingSpawnHeight(const mobjtype_t mobjtype, const mapthing_t* mthing, const fixed_t x, const fixed_t y);
mobj_t *P_SpawnMapThing(mapthing_t *mthing); mobj_t *P_SpawnMapThing(mapthing_t *mthing);

View file

@ -1286,6 +1286,7 @@ static void P_LoadThings(UINT8 *data)
memset(mt->stringargs, 0x00, NUMMAPTHINGSTRINGARGS*sizeof(*mt->stringargs)); memset(mt->stringargs, 0x00, NUMMAPTHINGSTRINGARGS*sizeof(*mt->stringargs));
mt->special = 0; mt->special = 0;
mt->pitch = mt->roll = 0; mt->pitch = mt->roll = 0;
mt->layer = 0;
mt->type &= 4095; mt->type &= 4095;
@ -1793,6 +1794,8 @@ static void ParseTextmapThingParameter(UINT32 i, const char *param, const char *
else if (fastcmp(param, "special")) else if (fastcmp(param, "special"))
mapthings[i].special = atol(val); mapthings[i].special = atol(val);
else if (fastcmp(param, "foflayer"))
mapthings[i].layer = atol(val);
else if (fastncmp(param, "stringarg", 9) && strlen(param) > 9) else if (fastncmp(param, "stringarg", 9) && strlen(param) > 9)
{ {
size_t argnum = atol(param + 9); size_t argnum = atol(param + 9);
@ -2766,6 +2769,7 @@ static void P_LoadTextmap(void)
memset(mt->args, 0, NUMMAPTHINGARGS*sizeof(*mt->args)); memset(mt->args, 0, NUMMAPTHINGARGS*sizeof(*mt->args));
memset(mt->stringargs, 0x00, NUMMAPTHINGSTRINGARGS*sizeof(*mt->stringargs)); memset(mt->stringargs, 0x00, NUMMAPTHINGSTRINGARGS*sizeof(*mt->stringargs));
mt->special = 0; mt->special = 0;
mt->layer = 0;
mt->mobj = NULL; mt->mobj = NULL;
TextmapParse(mapthingsPos[i], i, ParseTextmapThingParameter); TextmapParse(mapthingsPos[i], i, ParseTextmapThingParameter);