decouple precipmobj_t from mobj_t

vissprite_t now keeps pointer to precipmobj directly instead of just a simple boolean check
this has multiple benefits
the mobj_t struct now can be reorderer and modified as pleased without having to worry about precipmobj struct layouts since all precipmobj -> mobj casts are eliminated
this allows to remove a massive amount of fields from precipmobj struct which never were used massively reducing the footprint of a precipmobj thing
kinda wish there was a neat way to template function headers to take different types for the same arguments in C to reduce code duplication, but this glady is atleast a rather small case
This commit is contained in:
Alug committed 2025-09-17 17:42:16 +02:00
1 parent 2aaa52c639
commit d27a849d79
11 files changed
+64 -63

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ p_floor.c
p_inter.c
p_lights.c
p_map.c
p_maputl.c
p_maputl.cpp
p_mobj.c
p_polyobj.c
p_saveg.c
+1 -1
View File
@@ -40,7 +40,7 @@ typedef struct gl_vissprite_s
boolean flip;
UINT8 translucency; //alpha level 0-255
mobj_t *mobj;
boolean precip; // Tails 08-25-2002
precipmobj_t *precip; // Tails 08-25-2002
boolean vflip;
//Hurdler: 25/04/2000: now support colormap in hardware mode
UINT8 *colormap;
+9 -9
View File
@@ -3573,7 +3573,7 @@ static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts
// do interpolation
if (precip)
{
R_InterpolatePrecipMobjState((precipmobj_t *)spr->mobj, R_GetMobjTimeFrac(spr->mobj), &interp);
R_InterpolatePrecipMobjState(spr->precip, R_GetPrecipMobjTimeFrac(spr->precip), &interp);
}
else
{
@@ -4073,7 +4073,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr)
INT32 shader = SHADER_NONE;
const mobj_t *sprmo = spr->mobj;
const precipmobj_t *sprmo = spr->precip;
if (UNLIKELY(!sprmo || !sprmo->subsector))
return;
@@ -4121,7 +4121,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr)
{
INT32 light;
light = R_GetPlaneLight(sector, sprmo->z + sprmo->height, false); // Always use the light at the top instead of whatever I was doing before
light = R_GetPlaneLight(sector, sprmo->z, false); // Always use the light at the top instead of whatever I was doing before
if (!(sprmo->frame & FF_FULLBRIGHT))
lightlevel = static_cast<INT32>(*sector->lightlist[light].lightlevel);
@@ -4183,8 +4183,8 @@ static int CompareVisSprites(const void *p1, const void *p2)
// "boolean to int"
// check for precip first, because then sprX->mobj is actually a precipmobj_t and does not have flags2 or tracer
const int transparency1 = (!spr1->precip && (spr1->mobj->flags2 & MF2_SHADOW)) || (spr1->mobj->frame & FF_TRANSMASK);
const int transparency2 = (!spr2->precip && (spr2->mobj->flags2 & MF2_SHADOW)) || (spr2->mobj->frame & FF_TRANSMASK);
const int transparency1 = (spr1->precip ? (spr1->precip->frame & FF_TRANSMASK) : ((spr1->mobj->flags2 & MF2_SHADOW)) || (spr1->mobj->frame & FF_TRANSMASK));
const int transparency2 = (spr2->precip ? (spr2->precip->frame & FF_TRANSMASK) : ((spr2->mobj->flags2 & MF2_SHADOW)) || (spr2->mobj->frame & FF_TRANSMASK));
idiff = transparency1 - transparency2;
if (idiff != 0) return idiff;
@@ -5016,7 +5016,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
vis->vflip = vflip;
vis->precip = false;
vis->precip = NULL;
}
// Precipitation projector for hardware mode
@@ -5048,7 +5048,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing)
interpmobjstate_t interp = {};
// do interpolation
R_InterpolatePrecipMobjState(thing, R_GetMobjTimeFrac((mobj_t*)thing), &interp);
R_InterpolatePrecipMobjState(thing, R_GetPrecipMobjTimeFrac(thing), &interp);
// transform the origin point
tr_x = FixedToFloat(interp.x);
@@ -5126,7 +5126,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing)
vis->dispoffset = 0; // Monster Iestyn: 23/11/15: HARDWARE SUPPORT AT LAST
vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE);
vis->flip = flip;
vis->mobj = (mobj_t *)thing;
vis->mobj = NULL;
vis->colormap = NULL;
@@ -5139,7 +5139,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing)
vis->gzt = FixedToFloat(interp.z) + (FixedToFloat(spritecachedinfo[lumpoff].topoffset) * this_scale);
vis->gz = vis->gzt - (FixedToFloat(spritecachedinfo[lumpoff].height) * this_scale);
vis->precip = true;
vis->precip = thing;
}
+8
View File
@@ -14,6 +14,10 @@
#ifndef __P_LOCAL__
#define __P_LOCAL__
#ifdef __cplusplus
extern "C" {
#endif
#include "command.h"
#include "d_player.h"
#include "d_think.h"
@@ -486,4 +490,8 @@ void P_Thrust(mobj_t *mo, angle_t angle, fixed_t move);
void P_ExplodeMissile(mobj_t *mo);
void P_CheckGravity(mobj_t *mo, boolean affect);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // __P_LOCAL__
+6 -8
View File
@@ -730,7 +730,8 @@ void P_UnsetPrecipThingPosition(precipmobj_t *thing)
bnext->bprev = bprev;
}
static void P_LinkToBlockMap(mobj_t *thing, mobj_t **bmap)
template<typename T>
static void P_LinkToBlockMap(T *thing, T **bmap)
{
const INT32 blockx = (unsigned)(thing->x - bmaporgx) >> MAPBLOCKSHIFT;
const INT32 blocky = (unsigned)(thing->y - bmaporgy) >> MAPBLOCKSHIFT;
@@ -742,8 +743,8 @@ static void P_LinkToBlockMap(mobj_t *thing, mobj_t **bmap)
// pointer-to-pointer prev pointers --
// allows head nodes to be treated like everything else
mobj_t **link = &bmap[(blocky * bmapwidth) + blockx];
mobj_t *bnext = *link;
T **link = &bmap[(blocky * bmapwidth) + blockx];
T *bnext = *link;
thing->bnext = bnext;
@@ -871,10 +872,7 @@ void P_SetUnderlayPosition(mobj_t *thing)
void P_SetPrecipitationThingPosition(precipmobj_t *thing)
{
thing->subsector = R_PointInSubsectorFast(thing->x, thing->y);
// NOTE: this works because bnext/bprev are at the same
// offsets in precipmobj_t and mobj_t
P_LinkToBlockMap((mobj_t*)thing, (mobj_t**)precipblocklinks);
P_LinkToBlockMap(thing, precipblocklinks);
}
//
@@ -1003,7 +1001,7 @@ static void P_CheckIntercepts(void)
else
max_intercepts *= 2;
intercepts = Z_Realloc(intercepts, sizeof (*intercepts) * max_intercepts, PU_STATIC, NULL);
intercepts = static_cast<intercept_t*>(Z_Realloc(intercepts, sizeof (*intercepts) * max_intercepts, PU_STATIC, NULL));
intercept_p = intercepts + count;
}
+9
View File
@@ -13,6 +13,10 @@
#ifndef __P_MAPUTL__
#define __P_MAPUTL__
#ifdef __cplusplus
extern "C" {
#endif
#include "doomtype.h"
#include "r_defs.h"
#include "m_fixed.h"
@@ -86,4 +90,9 @@ extern fixed_t tmbbox[4]; // p_map.c
// bbox defined by the radius
//boolean P_RadiusLinesCheck(fixed_t radius, fixed_t x, fixed_t y,
// boolean (*func)(line_t *));
#ifdef __cplusplus
} // extern "C"
#endif
#endif // __P_MAPUTL__
-27
View File
@@ -437,40 +437,17 @@ typedef struct precipmobj_s
// Info for drawing: position.
fixed_t x, y, z;
fixed_t old_x, old_y, old_z; // position interpolation
fixed_t old_x2, old_y2, old_z2;
mobjtype_t type;
const mobjinfo_t *info; // &mobjinfo[mobj->type]
// More drawing info: to determine current sprite.
angle_t angle, pitch, roll; // orientation
angle_t old_angle, old_pitch, old_roll; // orientation interpolation
angle_t old_angle2, old_pitch2, old_roll2;
angle_t rollangle;
spritenum_t sprite; // used to find patch_t and flip value
UINT32 frame; // frame number, plus bits see p_pspr.h
UINT16 anim_duration; // for FF_ANIMATE states
UINT8 blendmode; // blend mode
fixed_t spritexscale, spriteyscale;
fixed_t spritexoffset, spriteyoffset;
fixed_t old_spritexscale, old_spriteyscale;
fixed_t old_spritexscale2, old_spriteyscale2;
fixed_t old_spritexoffset, old_spriteyoffset;
fixed_t old_spritexoffset2, old_spriteyoffset2;
INT16 lightlevel; // Add to sector lightlevel, -255 - 255
fixed_t realxscale, realyscale; // funn-E streeetch
fixed_t realxoffset, realyoffset;
fixed_t stretchslam; // "squish" effect when you land
//sloperollangle
angle_t sloperoll, slopepitch;
angle_t old_sloperoll, old_slopepitch;
angle_t old_sloperoll2, old_slopepitch2;
angle_t pitch_sprite, roll_sprite;
struct mprecipsecnode_s *touching_sectorlist; // a linked list of sectors where this object appears
struct subsector_s *subsector; // Subsector the mobj resides in.
@@ -479,10 +456,6 @@ typedef struct precipmobj_s
fixed_t floorz; // Nearest floor below.
fixed_t ceilingz; // Nearest ceiling above.
// For movement checking.
fixed_t radius; // Fixed at 2*FRACUNIT
fixed_t height; // Fixed at 4*FRACUNIT
// Momentums, used to update position.
fixed_t momx, momy, momz;
fixed_t precipflags; // fixed_t so it uses the same spot as "pmomz" even as we use precipflags_t for it
-9
View File
@@ -835,16 +835,7 @@ void R_ResetMobjInterpolationState(mobj_t *mobj)
//
void R_ResetPrecipitationMobjInterpolationState(precipmobj_t *mobj)
{
mobj->old_x2 = mobj->old_x;
mobj->old_y2 = mobj->old_y;
mobj->old_z2 = mobj->old_z;
mobj->old_angle2 = mobj->old_angle;
mobj->old_x = mobj->x;
mobj->old_y = mobj->y;
mobj->old_z = mobj->z;
mobj->old_angle = mobj->angle;
mobj->old_spritexscale = mobj->spritexscale;
mobj->old_spriteyscale = mobj->spriteyscale;
mobj->old_spritexoffset = mobj->spritexoffset;
mobj->old_spriteyoffset = mobj->spriteyoffset;
}
+10 -1
View File
@@ -22,6 +22,7 @@ extern "C" {
#include "m_fixed.h"
#include "p_local.h"
#include "r_state.h"
#include "r_things.h"
#include "m_perfstats.h"
extern consvar_t cv_fpscap, cv_fpscapbg;
@@ -44,7 +45,15 @@ UINT32 R_GetFramerateCap(void);
fixed_t R_GetTimeFrac(timefrac_e level);
void R_SetTimeFrac(fixed_t frac);
#define R_GetMobjTimeFrac(mobj) (R_CheckInterpDist(mobj) ? R_GetTimeFrac(RTF_LEVEL) : FRACUNIT)
static inline fixed_t R_GetMobjTimeFrac(mobj_t *mo)
{
return R_CheckMobjInterpDist(mo) ? R_GetTimeFrac(RTF_LEVEL) : FRACUNIT;
}
static inline fixed_t R_GetPrecipMobjTimeFrac(precipmobj_t *mo)
{
return R_CheckPrecipMobjInterpDist(mo) ? R_GetTimeFrac(RTF_LEVEL) : FRACUNIT;
}
enum viewcontext_e
{
+16 -5
View File
@@ -1262,7 +1262,7 @@ static void R_ProjectSprite(mobj_t *thing)
tx = FixedMul(tr_x, viewsin) - FixedMul(tr_y, viewcos); // sideways distance
// too far off the side?
if (!papersprite && abs(tx) > (INT64)FixedMul(tz, fovtan)<<2) // papersprite clipping is handled later
if (!papersprite && abs(tx) > (INT64)FixedMul(tz, fovtan) << 2) // papersprite clipping is handled later
return;
// aspect ratio stuff
@@ -1826,7 +1826,7 @@ static void R_ProjectSprite(mobj_t *thing)
#endif
vis->patch = static_cast<patch_t*>(W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE));
vis->precip = false;
vis->precip = NULL;
vis->vflip = vflip;
@@ -1873,7 +1873,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing)
interpmobjstate_t interp = {};
// do interpolation
R_InterpolatePrecipMobjState(thing, R_GetMobjTimeFrac((mobj_t*)thing), &interp);
R_InterpolatePrecipMobjState(thing, R_GetPrecipMobjTimeFrac(thing), &interp);
this_scale = interp.scale;
@@ -2014,7 +2014,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing)
// Fullbright
vis->colormap = colormaps;
vis->precip = true;
vis->precip = thing;
vis->vflip = false;
vis->isScaled = false;
}
@@ -2954,7 +2954,8 @@ fixed_t R_DoPlayerFade(mobj_t *thing)
return fadealpha;
}
boolean R_CheckInterpDist(mobj_t *thing)
template<typename T>
static boolean R_CheckInterpDist(T *thing)
{
if (!cv_maxinterpdist.value)
return true;
@@ -2967,6 +2968,16 @@ boolean R_CheckInterpDist(mobj_t *thing)
return (dist < cv_maxinterpdist.value);
}
boolean R_CheckPrecipMobjInterpDist(precipmobj_t *thing)
{
return R_CheckInterpDist(thing);
}
boolean R_CheckMobjInterpDist(mobj_t *thing)
{
return R_CheckInterpDist(thing);
}
boolean R_ThingIsFullBright(mobj_t *thing)
{
return ((thing->frame & FF_BRIGHTMASK) == FF_FULLBRIGHT);
+4 -2
View File
@@ -93,7 +93,8 @@ transnum_t R_GetThingTransTable(fixed_t alpha, transnum_t transmap);
boolean R_ThingVisible(mobj_t *thing);
boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist);
boolean R_CheckInterpDist(mobj_t *thing);
boolean R_CheckPrecipMobjInterpDist(precipmobj_t *thing);
boolean R_CheckMobjInterpDist(mobj_t *thing);
fixed_t R_DoPlayerFade(mobj_t *thing);
boolean R_ThingIsFullBright(mobj_t *thing);
@@ -170,7 +171,8 @@ typedef struct vissprite_s
INT16 *clipbot, *cliptop;
boolean precip;
precipmobj_t *precip;
boolean vflip; // Flip vertically
boolean isScaled;
INT32 dispoffset; // copy of info->dispoffset, affects ordering but not drawing