diff --git a/src/Sourcefile b/src/Sourcefile index 35f394dd8..fc2c1bedc 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -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 diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 04d388e81..1be176a42 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -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; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index e4a49c65c..9affc422f 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -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(*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; } diff --git a/src/p_local.h b/src/p_local.h index dbe96ae14..d428d59d1 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -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__ diff --git a/src/p_maputl.c b/src/p_maputl.cpp similarity index 98% rename from src/p_maputl.c rename to src/p_maputl.cpp index de88d4668..3209f6f51 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.cpp @@ -730,7 +730,8 @@ void P_UnsetPrecipThingPosition(precipmobj_t *thing) bnext->bprev = bprev; } -static void P_LinkToBlockMap(mobj_t *thing, mobj_t **bmap) +template +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(Z_Realloc(intercepts, sizeof (*intercepts) * max_intercepts, PU_STATIC, NULL)); intercept_p = intercepts + count; } diff --git a/src/p_maputl.h b/src/p_maputl.h index 22d269924..c6c1a9d13 100644 --- a/src/p_maputl.h +++ b/src/p_maputl.h @@ -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__ diff --git a/src/p_mobj.h b/src/p_mobj.h index 7718bda71..eed259ba3 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -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 diff --git a/src/r_fps.cpp b/src/r_fps.cpp index 764515bbf..d2665ac21 100644 --- a/src/r_fps.cpp +++ b/src/r_fps.cpp @@ -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; } diff --git a/src/r_fps.h b/src/r_fps.h index 8638f7e96..64903a5b5 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -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 { diff --git a/src/r_things.cpp b/src/r_things.cpp index 79165561e..1164072db 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -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(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 +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); diff --git a/src/r_things.h b/src/r_things.h index 605c1d269..9cba7340d 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -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