From b0f3b515d2b5a9f96b1a1b7606d30e48de9fe963 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 11 Feb 2024 14:53:16 +0100 Subject: [PATCH 01/27] Add cvar gr_maxinterpdist, which allows to control max distance on which mobjs will be interpolated --- src/hardware/hw_main.c | 14 ++++++++++---- src/hardware/hw_md2.c | 2 +- src/r_main.c | 10 ++++++++++ src/r_main.h | 1 + src/r_things.c | 4 ++-- src/r_things.h | 6 ++++++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 79d9e5085..68a0f7338 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4102,8 +4102,10 @@ static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts interpmobjstate_t interp = {0}; float basey, lowy; + INT32 dist = R_QuickCamDist(spr->mobj->x, spr->mobj->y); + // do interpolation - if (R_UsingFrameInterpolation() && !paused) + if (R_UsingFrameInterpolation() && !paused && (!cv_grmaxinterpdist.value || dist < cv_grmaxinterpdist.value)) { if (precip) { @@ -5315,7 +5317,9 @@ void HWR_ProjectSprite(mobj_t *thing) if (!thing) return; - if (R_UsingFrameInterpolation() && !paused) + INT32 dist = R_QuickCamDist(thing->x, thing->y); + + if (R_UsingFrameInterpolation() && !paused && (!cv_grmaxinterpdist.value || dist < cv_grmaxinterpdist.value)) { R_InterpolateMobjState(thing, rendertimefrac, &interp); } @@ -5655,12 +5659,14 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) if (!thing) return; - + + INT32 dist = R_QuickCamDist(thing->x, thing->y); + // uncapped/interpolation interpmobjstate_t interp = {0}; // do interpolation - if (R_UsingFrameInterpolation() && !paused) + if (R_UsingFrameInterpolation() && !paused && (!cv_grmaxinterpdist.value || dist < cv_grmaxinterpdist.value)) { R_InterpolatePrecipMobjState(thing, rendertimefrac, &interp); } diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index c64d77639..fd6cf4f16 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1157,7 +1157,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) angle_t ang; interpmobjstate_t interp; - if (R_UsingFrameInterpolation() && !paused) + if (R_UsingFrameInterpolation() && !paused && (!cv_grmaxinterpdist.value || R_QuickCamDist(spr->mobj->x, spr->mobj->y) < cv_grmaxinterpdist.value)) { R_InterpolateMobjState(spr->mobj, rendertimefrac, &interp); } diff --git a/src/r_main.c b/src/r_main.c index 44c388ec8..274ea079a 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -153,6 +153,12 @@ static CV_PossibleValue_t drawdist_precip_cons_t[] = { {3072, "3072"}, {0, "None"}, {0, NULL}}; +static CV_PossibleValue_t maxinterpdist_cons_t[] = { + /*{256, "256"},*/ {512, "512"}, {768, "768"}, + {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, + {3072, "3072"}, {4096, "4096"}, {6144, "6144"}, + {8192, "8192"}, {0, "Infinite"}, {0, NULL}}; + static CV_PossibleValue_t fov_cons_t[] = {{5*FRACUNIT, "MIN"}, {178*FRACUNIT, "MAX"}, {0, NULL}}; //static CV_PossibleValue_t precipdensity_cons_t[] = {{0, "None"}, {1, "Light"}, {2, "Moderate"}, {4, "Heavy"}, {6, "Thick"}, {8, "V.Thick"}, {0, NULL}}; @@ -201,6 +207,8 @@ consvar_t cv_drawdist_precip = {"drawdist_precip", "1024", CV_SAVE, drawdist_pre consvar_t cv_lessprecip = {"lessweathereffects", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //consvar_t cv_precipdensity = {"precipdensity", "Moderate", CV_SAVE, precipdensity_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grmaxinterpdist = {"gr_maxinterpdist", "Infinite", 0, maxinterpdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + // cap fov, fov too high tears software apart. consvar_t cv_fov = {"fov", "90", CV_FLOAT|CV_CALL|CV_SAVE, fov_cons_t, Fov_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -1885,6 +1893,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_maxportals); + CV_RegisterVar(&cv_grmaxinterpdist); + // Default viewheight is changeable, // initialized to standard viewheight //CV_RegisterVar(&cv_viewheight); diff --git a/src/r_main.h b/src/r_main.h index dadb1c9cf..f057db234 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -117,6 +117,7 @@ extern consvar_t /*cv_precipdensity,*/ cv_drawdist, /*cv_drawdist_nights,*/ cv_d extern consvar_t cv_fov; extern consvar_t cv_skybox; extern consvar_t cv_tailspickup; +extern consvar_t cv_grmaxinterpdist; // Called by startup code. void R_Init(void); diff --git a/src/r_things.c b/src/r_things.c index 6cc11b49f..1e9a116cc 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1357,7 +1357,7 @@ static void R_ProjectSprite(mobj_t *thing) interpmobjstate_t interp = {0}; // do interpolation - if (R_UsingFrameInterpolation() && !paused) + if (R_UsingFrameInterpolation() && !paused && (!cv_grmaxinterpdist.value || R_QuickCamDist(thing->x, thing->y) < cv_grmaxinterpdist.value)) { R_InterpolateMobjState(oldthing, rendertimefrac, &interp); } @@ -1881,7 +1881,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) interpmobjstate_t interp = {0}; // do interpolation - if (R_UsingFrameInterpolation() && !paused) + if (R_UsingFrameInterpolation() && !paused && (!cv_grmaxinterpdist.value || R_QuickCamDist(thing->x, thing->y) < cv_grmaxinterpdist.value)) { R_InterpolatePrecipMobjState(thing, rendertimefrac, &interp); } diff --git a/src/r_things.h b/src/r_things.h index 823bad9a8..e6470a952 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -32,6 +32,12 @@ #define FEETADJUST (4<>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) + // Constant arrays used for psprite clipping // and initializing clipping. extern INT16 negonearray[MAXVIDWIDTH]; From 4732f9578204832a84492a6d06d07aa400eadcc1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 11 Feb 2024 14:51:14 +0100 Subject: [PATCH 02/27] toggable mobj subsector interpolation honestly couldnt spot any difference at all but R_PointinSubsector is quite expensive so making a toggle seems cool --- src/r_fps.c | 12 ++++++++++-- src/r_fps.h | 1 + src/r_main.c | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index 041a51a05..efbf36564 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -39,6 +39,8 @@ consvar_t cv_fpscap = {"fpscap", "Match refresh rate", CV_SAVE, fpscap_cons_t, N consvar_t cv_precipinterp = {"precipinterpolation", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_mobjssector = {"mobjsubsectorinterp", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + UINT32 R_GetFramerateCap(void) { if (rendermode == render_none) @@ -315,7 +317,10 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) //out->spritexoffset = mobj->spritexoffset; //out->spriteyoffset = mobj->spriteyoffset; - out->subsector = R_PointInSubsector(out->x, out->y); + if (cv_mobjssector.value) + out->subsector = R_PointInSubsector(out->x, out->y); + else + out->subsector = mobj->subsector; if (mobj->player) { @@ -361,7 +366,10 @@ void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjst out->spritexoffset = mobj->spritexoffset; out->spriteyoffset = mobj->spriteyoffset; - out->subsector = R_PointInSubsector(out->x, out->y); + if (cv_mobjssector.value) + out->subsector = R_PointInSubsector(out->x, out->y); + else + out->subsector = mobj->subsector; out->angle = R_LerpAngle(mobj->old_angle, mobj->angle, frac); } diff --git a/src/r_fps.h b/src/r_fps.h index deb0c8788..35585517d 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -21,6 +21,7 @@ extern consvar_t cv_fpscap; extern consvar_t cv_precipinterp; +extern consvar_t cv_mobjssector; UINT32 R_GetFramerateCap(void); boolean R_UsingFrameInterpolation(void); diff --git a/src/r_main.c b/src/r_main.c index 274ea079a..e78e88982 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1902,4 +1902,5 @@ void R_RegisterEngineStuff(void) // Frame interpolation/uncapped CV_RegisterVar(&cv_fpscap); CV_RegisterVar(&cv_precipinterp); + CV_RegisterVar(&cv_mobjssector); } From 8ba926550cfeb739178920ccf0302cd062b1b028 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 11 Feb 2024 14:51:44 +0100 Subject: [PATCH 03/27] only interpolate pitch, roll, slopepitch and sloperoll when using sprite rotation --- src/r_fps.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index efbf36564..5a454c679 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -331,13 +331,23 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) out->angle = mobj->resetinterp ? mobj->angle : R_LerpAngle(mobj->old_angle, mobj->angle, frac); } - // pitch roll stuff - out->pitch = mobj->resetinterp ? mobj->pitch : R_LerpAngle(mobj->old_pitch, mobj->pitch, frac); - out->roll = mobj->resetinterp ? mobj->roll : R_LerpAngle(mobj->old_roll, mobj->roll, frac); + if (cv_spriteroll.value) // no need to interpolate this if its disabled + { + // pitch roll stuff + out->pitch = mobj->resetinterp ? mobj->pitch : R_LerpAngle(mobj->old_pitch, mobj->pitch, frac); + out->roll = mobj->resetinterp ? mobj->roll : R_LerpAngle(mobj->old_roll, mobj->roll, frac); - // and the slope stuff - out->slopepitch = mobj->resetinterp ? mobj->slopepitch : R_LerpAngle(mobj->old_slopepitch, mobj->slopepitch, frac); - out->sloperoll = mobj->resetinterp ? mobj->sloperoll : R_LerpAngle(mobj->old_sloperoll, mobj->sloperoll, frac); + // and the slope stuff + out->slopepitch = mobj->resetinterp ? mobj->slopepitch : R_LerpAngle(mobj->old_slopepitch, mobj->slopepitch, frac); + out->sloperoll = mobj->resetinterp ? mobj->sloperoll : R_LerpAngle(mobj->old_sloperoll, mobj->sloperoll, frac); + } + else + { + out->pitch = mobj->pitch; + out->roll = mobj->roll; + out->slopepitch = mobj->slopepitch; + out->sloperoll = mobj->sloperoll; + } } void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjstate_t *out) From 088426a654133afffe57f82832d202080847a3d5 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 11 Feb 2024 15:05:58 +0100 Subject: [PATCH 04/27] only interpolate those if we use the stuff that uses them --- src/r_fps.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index 5a454c679..7045e17ee 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -298,11 +298,29 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) out->x = R_LerpFixed(mobj->old_x, mobj->x, frac); out->y = R_LerpFixed(mobj->old_y, mobj->y, frac); out->z = R_LerpFixed(mobj->old_z, mobj->z, frac); - out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); - out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); - out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); - out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); - + + if (cv_gravstretch.value || cv_saltysquish.value) // for now we only use it for those two features so no need to interpolate this when we dont use stuff + { + out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); + out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); + } + else + { + out->spritexscale = mobj->spritexscale; + out->spriteyscale = mobj->spriteyscale; + } + + if (cv_saltyhop.value) // same here + { + out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); + out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); + } + else + { + out->spritexoffset = mobj->spritexoffset; + out->spriteyoffset = mobj->spriteyoffset; + } + if (mobj->scale == mobj->old_scale) // Tiny optimisation - scale is usually unchanging, so let's skip a lerp, two FixedMuls, and two FixedDivs { out->scale = mobj->scale; @@ -312,11 +330,6 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) out->scale = R_LerpFixed(mobj->old_scale, mobj->scale, frac); } - // Sprite offsets are not interpolated until we have a way to interpolate them explicitly in Lua. - // It seems existing mods visually break more often than not if it is interpolated. - //out->spritexoffset = mobj->spritexoffset; - //out->spriteyoffset = mobj->spriteyoffset; - if (cv_mobjssector.value) out->subsector = R_PointInSubsector(out->x, out->y); else From 242df89d0e12830299c48d4e473aa60dabaebdec Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 11 Feb 2024 15:10:16 +0100 Subject: [PATCH 05/27] forgor --- src/r_fps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r_fps.c b/src/r_fps.c index 7045e17ee..11c88a987 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -16,6 +16,7 @@ #include "r_main.h" #include "g_game.h" +#include "k_kart.h" // saltyhop stuffs #include "i_video.h" #include "r_plane.h" #include "p_spec.h" From 2ebb71fb6c55b94a1baa982b6d7ff15c9bb6c51f Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 11 Feb 2024 15:21:20 +0100 Subject: [PATCH 06/27] add stuff to menu --- src/m_menu.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 80e0ba5db..4cd99404d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1485,28 +1485,32 @@ static menuitem_t OP_ColorOptionsMenu[] = static menuitem_t OP_ExpOptionsMenu[] = { {IT_HEADER, NULL, "Experimental Options", NULL, 10}, - {IT_STRING | IT_CVAR, NULL, "Weather Interpolation", &cv_precipinterp, 25}, - {IT_STRING | IT_CVAR, NULL, "Less Weather Effects", &cv_lessprecip, 35}, + {IT_STRING|IT_CVAR, NULL, "Interpolation Distance", &cv_grmaxinterpdist, 25}, + {IT_STRING|IT_CVAR, NULL, "Mobj Subsector Interpolation", &cv_mobjssector, 35}, + {IT_STRING | IT_CVAR, NULL, "Weather Interpolation", &cv_precipinterp, 45}, + {IT_STRING | IT_CVAR, NULL, "Less Weather Effects", &cv_lessprecip, 55}, - {IT_STRING | IT_CVAR, NULL, "VHS effect", &cv_vhseffect, 55}, + {IT_STRING | IT_CVAR, NULL, "VHS effect", &cv_vhseffect, 75}, - {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 75}, - {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 85}, + {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 95}, + {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 105}, #ifdef HWRENDER - {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 75}, + {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 95}, - {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_grpalettedepth, 85}, + {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_grpalettedepth, 105}, - {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 105}, - {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 115}, - {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 125}, - {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 135}, + {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 125}, + {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 135}, + {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 145}, + {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 155}, #endif }; static const char* OP_ExpTooltips[] = { NULL, + "How far Mobj interpolation should take effect.", + "Toggles Mobj Subsector Interpolation.", "Should weather be interpolated? Weather should look about the\nsame but perform a bit better when disabled.", "When weather is on this will cut the object amount used in half.", "Show a VHS-like effect when the game is paused\n or youre rewinding replays.", @@ -1525,6 +1529,8 @@ static const char* OP_ExpTooltips[] = enum { op_exp_header, + op_exp_interpdist, + op_exp_mobjssector, op_exp_precipinter, op_exp_lessprecip, op_exp_vhs, From 2b1d192eddabb98fb1ab6b51c0a9a2e05cea05d0 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 15 Feb 2024 20:22:05 +0100 Subject: [PATCH 07/27] make this save --- src/r_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_main.c b/src/r_main.c index e78e88982..90c749d9a 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -207,7 +207,7 @@ consvar_t cv_drawdist_precip = {"drawdist_precip", "1024", CV_SAVE, drawdist_pre consvar_t cv_lessprecip = {"lessweathereffects", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //consvar_t cv_precipdensity = {"precipdensity", "Moderate", CV_SAVE, precipdensity_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grmaxinterpdist = {"gr_maxinterpdist", "Infinite", 0, maxinterpdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grmaxinterpdist = {"gr_maxinterpdist", "Infinite", CV_SAVE, maxinterpdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // cap fov, fov too high tears software apart. consvar_t cv_fov = {"fov", "90", CV_FLOAT|CV_CALL|CV_SAVE, fov_cons_t, Fov_OnChange, 0, NULL, NULL, 0, 0, NULL}; From 1a91060573dc2da1e76a02a263168a839383839c Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Feb 2024 21:04:35 +0100 Subject: [PATCH 08/27] dont interpolate unchanging things + remove unused dynslope interp code --- src/r_fps.c | 123 +++++++++++++++++++++++++++++++++++++++------------- src/r_fps.h | 2 +- 2 files changed, 94 insertions(+), 31 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index c9d862caf..f01730d50 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -98,7 +98,7 @@ static angle_t R_LerpAngle(angle_t from, angle_t to, fixed_t frac) return from + FixedMul(frac, to - from); } -static vector2_t *R_LerpVector2(const vector2_t *from, const vector2_t *to, fixed_t frac, vector2_t *out) +/*static vector2_t *R_LerpVector2(const vector2_t *from, const vector2_t *to, fixed_t frac, vector2_t *out) { FV2_SubEx(to, from, out); FV2_MulEx(out, frac, out); @@ -112,7 +112,7 @@ static vector3_t *R_LerpVector3(const vector3_t *from, const vector3_t *to, fixe FV3_MulEx(out, frac, out); FV3_AddEx(from, out, out); return out; -} +}*/ // recalc necessary stuff for mouseaiming // slopes are already calculated for the full possible view (which is 4*viewheight). @@ -255,7 +255,7 @@ void R_SetViewContext(enum viewcontext_e _viewcontext) } } -fixed_t R_InterpolateFixed(fixed_t from, fixed_t to) +/*fixed_t R_InterpolateFixed(fixed_t from, fixed_t to) { if (!R_UsingFrameInterpolation()) { @@ -273,7 +273,7 @@ angle_t R_InterpolateAngle(angle_t from, angle_t to) } return (R_LerpAngle(from, to, rendertimefrac)); -} +}*/ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) { @@ -296,14 +296,32 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) return; } - out->x = R_LerpFixed(mobj->old_x, mobj->x, frac); - out->y = R_LerpFixed(mobj->old_y, mobj->y, frac); - out->z = R_LerpFixed(mobj->old_z, mobj->z, frac); + if (mobj->x == mobj->old_x) + out->x = mobj->old_x; + else + out->x = R_LerpFixed(mobj->old_x, mobj->x, frac); + + if (mobj->y == mobj->old_y) + out->y = mobj->old_y; + else + out->y = R_LerpFixed(mobj->old_y, mobj->y, frac); + + if (mobj->z == mobj->old_z) + out->z = mobj->old_z; + else + out->z = R_LerpFixed(mobj->old_z, mobj->z, frac); if (cv_gravstretch.value || cv_saltysquish.value) // for now we only use it for those two features so no need to interpolate this when we dont use stuff { - out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); - out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); + if (mobj->spritexscale == mobj->old_spritexscale) + out->spritexscale = mobj->old_spritexscale; + else + out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); + + if (mobj->spriteyscale == mobj->old_spriteyscale) + out->spriteyscale = mobj->old_spriteyscale; + else + out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); } else { @@ -313,8 +331,15 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) if (cv_saltyhop.value) // same here { - out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); - out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); + if (mobj->spritexoffset == mobj->old_spritexoffset) + out->spritexoffset = mobj->old_spritexoffset; + else + out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); + + if (mobj->spriteyoffset == mobj->old_spriteyoffset) + out->spriteyoffset = mobj->old_spriteyoffset; + else + out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); } else { @@ -342,7 +367,10 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) } else { - out->angle = mobj->resetinterp ? mobj->angle : R_LerpAngle(mobj->old_angle, mobj->angle, frac); + if (mobj->angle == mobj->old_angle) + out->angle = mobj->old_angle; + else + out->angle = mobj->resetinterp ? mobj->angle : R_LerpAngle(mobj->old_angle, mobj->angle, frac); } if (cv_spriteroll.value) // no need to interpolate this if its disabled @@ -495,7 +523,7 @@ void R_CreateInterpolator_Polyobj(thinker_t *thinker, polyobj_t *polyobj) interp->polyobj.oldcy = interp->polyobj.bakcy = polyobj->centerPt.y; } -void R_CreateInterpolator_DynSlope(thinker_t *thinker, pslope_t *slope) +/*void R_CreateInterpolator_DynSlope(thinker_t *thinker, pslope_t *slope) { levelinterpolator_t *interp = CreateInterpolator(LVLINTERP_DynSlope, thinker); interp->dynslope.slope = slope; @@ -507,7 +535,7 @@ void R_CreateInterpolator_DynSlope(thinker_t *thinker, pslope_t *slope) FV2_Copy(&interp->dynslope.bakd, &slope->d); interp->dynslope.oldzdelta = interp->dynslope.bakzdelta = slope->zdelta; -} +}*/ void R_InitializeLevelInterpolators(void) { @@ -551,7 +579,7 @@ static void UpdateLevelInterpolatorState(levelinterpolator_t *interp) interp->polyobj.bakcx = interp->polyobj.polyobj->centerPt.x; interp->polyobj.bakcy = interp->polyobj.polyobj->centerPt.y; break; - case LVLINTERP_DynSlope: + /*case LVLINTERP_DynSlope: FV3_Copy(&interp->dynslope.oldo, &interp->dynslope.bako); FV2_Copy(&interp->dynslope.oldd, &interp->dynslope.bakd); interp->dynslope.oldzdelta = interp->dynslope.bakzdelta; @@ -559,7 +587,7 @@ static void UpdateLevelInterpolatorState(levelinterpolator_t *interp) FV3_Copy(&interp->dynslope.bako, &interp->dynslope.slope->o); FV2_Copy(&interp->dynslope.bakd, &interp->dynslope.slope->d); interp->dynslope.bakzdelta = interp->dynslope.slope->zdelta; - break; + break;*/ } } @@ -605,29 +633,56 @@ void R_ApplyLevelInterpolators(fixed_t frac) case LVLINTERP_SectorPlane: if (interp->sectorplane.ceiling) { - interp->sectorplane.sector->ceilingheight = R_LerpFixed(interp->sectorplane.oldheight, interp->sectorplane.bakheight, frac); + if (interp->sectorplane.sector->ceilingheight == interp->sectorplane.oldheight) + interp->sectorplane.sector->ceilingheight = interp->sectorplane.oldheight; + else + interp->sectorplane.sector->ceilingheight = R_LerpFixed(interp->sectorplane.oldheight, interp->sectorplane.bakheight, frac); } else { - interp->sectorplane.sector->floorheight = R_LerpFixed(interp->sectorplane.oldheight, interp->sectorplane.bakheight, frac); + if (interp->sectorplane.sector->floorheight == interp->sectorplane.oldheight) + interp->sectorplane.sector->floorheight = interp->sectorplane.oldheight; + else + interp->sectorplane.sector->floorheight = R_LerpFixed(interp->sectorplane.oldheight, interp->sectorplane.bakheight, frac); } interp->sectorplane.sector->moved = true; break; case LVLINTERP_SectorScroll: if (interp->sectorscroll.ceiling) { - interp->sectorscroll.sector->ceiling_xoffs = R_LerpFixed(interp->sectorscroll.oldxoffs, interp->sectorscroll.bakxoffs, frac); - interp->sectorscroll.sector->ceiling_yoffs = R_LerpFixed(interp->sectorscroll.oldyoffs, interp->sectorscroll.bakyoffs, frac); + if (interp->sectorscroll.sector->ceiling_xoffs == interp->sectorscroll.oldxoffs) + interp->sectorscroll.sector->ceiling_xoffs = interp->sectorscroll.oldxoffs; + else + interp->sectorscroll.sector->ceiling_xoffs = R_LerpFixed(interp->sectorscroll.oldxoffs, interp->sectorscroll.bakxoffs, frac); + + if (interp->sectorscroll.sector->ceiling_yoffs == interp->sectorscroll.oldyoffs) + interp->sectorscroll.sector->ceiling_yoffs = interp->sectorscroll.oldyoffs; + else + interp->sectorscroll.sector->ceiling_yoffs = R_LerpFixed(interp->sectorscroll.oldyoffs, interp->sectorscroll.bakyoffs, frac); } else { - interp->sectorscroll.sector->floor_xoffs = R_LerpFixed(interp->sectorscroll.oldxoffs, interp->sectorscroll.bakxoffs, frac); - interp->sectorscroll.sector->floor_yoffs = R_LerpFixed(interp->sectorscroll.oldyoffs, interp->sectorscroll.bakyoffs, frac); + if (interp->sectorscroll.sector->floor_xoffs == interp->sectorscroll.oldxoffs) + interp->sectorscroll.sector->floor_xoffs = interp->sectorscroll.oldxoffs; + else + interp->sectorscroll.sector->floor_xoffs = R_LerpFixed(interp->sectorscroll.oldxoffs, interp->sectorscroll.bakxoffs, frac); + + if (interp->sectorscroll.sector->floor_yoffs == interp->sectorscroll.oldyoffs) + interp->sectorscroll.sector->floor_yoffs = interp->sectorscroll.oldyoffs; + else + interp->sectorscroll.sector->floor_yoffs = R_LerpFixed(interp->sectorscroll.oldyoffs, interp->sectorscroll.bakyoffs, frac); } break; case LVLINTERP_SideScroll: - interp->sidescroll.side->textureoffset = R_LerpFixed(interp->sidescroll.oldtextureoffset, interp->sidescroll.baktextureoffset, frac); - interp->sidescroll.side->rowoffset = R_LerpFixed(interp->sidescroll.oldrowoffset, interp->sidescroll.bakrowoffset, frac); + if (interp->sidescroll.side->textureoffset == interp->sidescroll.oldtextureoffset) + interp->sidescroll.side->textureoffset = interp->sidescroll.oldtextureoffset; + else + interp->sidescroll.side->textureoffset = R_LerpFixed(interp->sidescroll.oldtextureoffset, interp->sidescroll.baktextureoffset, frac); + + if (interp->sidescroll.side->rowoffset == interp->sidescroll.oldrowoffset) + interp->sidescroll.side->rowoffset = interp->sidescroll.oldrowoffset; + else + interp->sidescroll.side->rowoffset = R_LerpFixed(interp->sidescroll.oldrowoffset, interp->sidescroll.bakrowoffset, frac); break; case LVLINTERP_Polyobj: for (ii = 0; ii < interp->polyobj.vertices_size; ii++) @@ -635,14 +690,22 @@ void R_ApplyLevelInterpolators(fixed_t frac) interp->polyobj.polyobj->vertices[ii]->x = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 ], interp->polyobj.bakvertices[ii * 2 ], frac); interp->polyobj.polyobj->vertices[ii]->y = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 + 1], interp->polyobj.bakvertices[ii * 2 + 1], frac); } - interp->polyobj.polyobj->centerPt.x = R_LerpFixed(interp->polyobj.oldcx, interp->polyobj.bakcx, frac); - interp->polyobj.polyobj->centerPt.y = R_LerpFixed(interp->polyobj.oldcy, interp->polyobj.bakcy, frac); + if (interp->polyobj.polyobj->centerPt.x == interp->polyobj.oldcx) + interp->polyobj.polyobj->centerPt.x = interp->polyobj.oldcx; + else + interp->polyobj.polyobj->centerPt.x = R_LerpFixed(interp->polyobj.oldcx, interp->polyobj.bakcx, frac); + + if (interp->polyobj.polyobj->centerPt.y == interp->polyobj.oldcy) + interp->polyobj.polyobj->centerPt.y = interp->polyobj.oldcy; + else + interp->polyobj.polyobj->centerPt.y = R_LerpFixed(interp->polyobj.oldcy, interp->polyobj.bakcy, frac); + break; - case LVLINTERP_DynSlope: + /*case LVLINTERP_DynSlope: R_LerpVector3(&interp->dynslope.oldo, &interp->dynslope.bako, frac, &interp->dynslope.slope->o); R_LerpVector2(&interp->dynslope.oldd, &interp->dynslope.bakd, frac, &interp->dynslope.slope->d); interp->dynslope.slope->zdelta = R_LerpFixed(interp->dynslope.oldzdelta, interp->dynslope.bakzdelta, frac); - break; + break;*/ } } } @@ -693,11 +756,11 @@ void R_RestoreLevelInterpolators(void) interp->polyobj.polyobj->centerPt.x = interp->polyobj.bakcx; interp->polyobj.polyobj->centerPt.y = interp->polyobj.bakcy; break; - case LVLINTERP_DynSlope: + /*case LVLINTERP_DynSlope: FV3_Copy(&interp->dynslope.slope->o, &interp->dynslope.bako); FV2_Copy(&interp->dynslope.slope->d, &interp->dynslope.bakd); interp->dynslope.slope->zdelta = interp->dynslope.bakzdelta; - break; + break;*/ } } } diff --git a/src/r_fps.h b/src/r_fps.h index 35585517d..1c0f1f884 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -78,7 +78,7 @@ typedef enum { LVLINTERP_SectorScroll, LVLINTERP_SideScroll, LVLINTERP_Polyobj, - LVLINTERP_DynSlope, + //LVLINTERP_DynSlope, } levelinterpolator_type_e; // Tagged union of a level interpolator From 1e50ecb2cdab42f7b8af9e49b497f250a6bda84d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Feb 2024 21:41:44 +0100 Subject: [PATCH 09/27] fix ternary hell for palette rendering lightlevels --- src/hardware/hw_main.c | 55 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a4c710420..f90d18450 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -53,6 +53,8 @@ #define ABS(x) ((x) < 0 ? -(x) : (x)) +#define SOFTLIGHT(llevel) HWR_ShouldUsePaletteRendering() ? ((llevel) >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : (llevel) + // ========================================================================== // the hardware driver object // ========================================================================== @@ -1129,7 +1131,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, { if (HWR_ShouldUsePaletteRendering()) { - lightnum = (pfloor->master->frontsector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(pfloor->master->frontsector->lightlevel); colormap = pfloor->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); }else{ @@ -1141,7 +1143,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, { if (HWR_ShouldUsePaletteRendering()) { - lightnum = (*list[i].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(*list[i].lightlevel); colormap = list[i].extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); }else{ @@ -1541,7 +1543,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (HWR_ShouldUsePaletteRendering()) { - lightnum = (gr_frontsector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(gr_frontsector->lightlevel); colormap = gr_frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); }else{ @@ -2489,7 +2491,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (HWR_ShouldUsePaletteRendering()) { - lightnum = (rover->master->frontsector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(rover->master->frontsector->lightlevel); colormap = rover->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); }else{ @@ -2640,7 +2642,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (HWR_ShouldUsePaletteRendering()) { - lightnum = (rover->master->frontsector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(rover->master->frontsector->lightlevel); colormap = rover->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); }else{ @@ -3479,12 +3481,12 @@ void HWR_Subsector(size_t num) light = R_GetPlaneLight(gr_frontsector, locFloorHeight, false); if (gr_frontsector->floorlightsec == -1) - floorlightlevel = HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel; + floorlightlevel = SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel); floorcolormap = gr_frontsector->lightlist[light].extra_colormap; light = R_GetPlaneLight(gr_frontsector, locCeilingHeight, false); if (gr_frontsector->ceilinglightsec == -1) - ceilinglightlevel = HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel;; + ceilinglightlevel = SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel); ceilingcolormap = gr_frontsector->lightlist[light].extra_colormap; } @@ -3559,16 +3561,13 @@ void HWR_Subsector(size_t num) light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - if (HWR_ShouldUsePaletteRendering()) - alpha = HWR_FogBlockAlpha((*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT, rover->master->frontsector->extra_colormap); - else - alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap); + alpha = HWR_FogBlockAlpha(SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), rover->master->frontsector->extra_colormap); HWR_AddTransparentFloor(0, &extrasubsectors[num], false, *rover->bottomheight, - HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, + SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), alpha, rover->master->frontsector, PF_Fog|PF_NoTexture, true, rover->master->frontsector->extra_colormap); } @@ -3579,7 +3578,7 @@ void HWR_Subsector(size_t num) &extrasubsectors[num], false, *rover->bottomheight, - HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, + SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), max(0, min(rover->alpha, 255)), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } @@ -3587,7 +3586,7 @@ void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[*rover->bottompic].lumpnum, R_NoEncore(gr_frontsector, false)); light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->bottompic].lumpnum, + HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), levelflats[*rover->bottompic].lumpnum, rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap); } } @@ -3613,17 +3612,14 @@ void HWR_Subsector(size_t num) UINT8 alpha; light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - - if (HWR_ShouldUsePaletteRendering()) - alpha = HWR_FogBlockAlpha((*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT, rover->master->frontsector->extra_colormap); - else - alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap); + + alpha = HWR_FogBlockAlpha(SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), rover->master->frontsector->extra_colormap); HWR_AddTransparentFloor(0, &extrasubsectors[num], true, *rover->topheight, - HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, + SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), alpha, rover->master->frontsector, PF_Fog|PF_NoTexture, true, rover->master->frontsector->extra_colormap); } @@ -3634,7 +3630,7 @@ void HWR_Subsector(size_t num) &extrasubsectors[num], true, *rover->topheight, - HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, + SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), max(0, min(rover->alpha, 255)), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } @@ -3642,7 +3638,7 @@ void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[*rover->toppic].lumpnum, R_NoEncore(gr_frontsector, true)); light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->toppic].lumpnum, + HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), levelflats[*rover->toppic].lumpnum, rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap); } } @@ -4316,7 +4312,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) // Start with the lightlevel and colormap from the top of the sprite - lightlevel = HWR_ShouldUsePaletteRendering() ? (*list[sector->numlights - 1].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *list[sector->numlights - 1].lightlevel; + lightlevel = SOFTLIGHT(*list[sector->numlights - 1].lightlevel); colormap = list[sector->numlights - 1].extra_colormap; i = 0; @@ -4333,7 +4329,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (h <= temp) { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i-1].lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (*list[i-1].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *list[i-1].lightlevel; + lightlevel = *list[i-1].lightlevel > 255 ? 255 : SOFTLIGHT(*list[i-1].lightlevel); colormap = list[i-1].extra_colormap; break; } @@ -4341,7 +4337,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) #else i = R_GetPlaneLight(sector, temp, false); if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i].lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (*list[i].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *list[i].lightlevel; + lightlevel = *list[i].lightlevel > 255 ? 255 : SOFTLIGHT(*list[i].lightlevel); colormap = list[i].extra_colormap; #endif @@ -4357,7 +4353,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (!(list[i].flags & FF_NOSHADE) && (list[i].flags & FF_CUTSPRITES)) { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i].lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (*list[i].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *list[i].lightlevel; + lightlevel = *list[i].lightlevel > 255 ? 255 : SOFTLIGHT(*list[i].lightlevel); colormap = list[i].extra_colormap; } @@ -4648,7 +4644,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) extracolormap_t *colormap = sector->extra_colormap; if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (sector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : sector->lightlevel; + lightlevel = sector->lightlevel > 255 ? 255 : SOFTLIGHT(sector->lightlevel); HWR_Lighting(&Surf, lightlevel, colormap); } @@ -4749,7 +4745,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); // Always use the light at the top instead of whatever I was doing before if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *sector->lightlist[light].lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (*sector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *sector->lightlist[light].lightlevel; + lightlevel = *sector->lightlist[light].lightlevel > 255 ? 255 : SOFTLIGHT(*sector->lightlist[light].lightlevel); if (sector->lightlist[light].extra_colormap) colormap = sector->lightlist[light].extra_colormap; @@ -4757,7 +4753,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) else { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (sector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : sector->lightlevel; + lightlevel = sector->lightlevel > 255 ? 255 : SOFTLIGHT(sector->lightlevel); if (sector->extra_colormap) colormap = sector->extra_colormap; @@ -4819,6 +4815,7 @@ static int CompareVisSprites(const void *p1, const void *p2) return -1; } +#undef SOFTLIGHT static void HWR_SortVisSprites(void) { From 65cb5b265c03795c65607416f4eed0ce27bace8f Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Feb 2024 21:41:44 +0100 Subject: [PATCH 10/27] fix ternary hell for palette rendering lightlevels --- src/hardware/hw_main.c | 55 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 13f819664..c7223d848 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -53,6 +53,8 @@ #define ABS(x) ((x) < 0 ? -(x) : (x)) +#define SOFTLIGHT(llevel) HWR_ShouldUsePaletteRendering() ? ((llevel) >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : (llevel) + // ========================================================================== // the hardware driver object // ========================================================================== @@ -1129,7 +1131,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, { if (HWR_ShouldUsePaletteRendering()) { - lightnum = (pfloor->master->frontsector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(pfloor->master->frontsector->lightlevel); colormap = pfloor->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); }else{ @@ -1141,7 +1143,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, { if (HWR_ShouldUsePaletteRendering()) { - lightnum = (*list[i].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(*list[i].lightlevel); colormap = list[i].extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); }else{ @@ -1541,7 +1543,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (HWR_ShouldUsePaletteRendering()) { - lightnum = (gr_frontsector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(gr_frontsector->lightlevel); colormap = gr_frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); }else{ @@ -2489,7 +2491,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (HWR_ShouldUsePaletteRendering()) { - lightnum = (rover->master->frontsector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(rover->master->frontsector->lightlevel); colormap = rover->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); }else{ @@ -2640,7 +2642,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (HWR_ShouldUsePaletteRendering()) { - lightnum = (rover->master->frontsector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT; + lightnum = SOFTLIGHT(rover->master->frontsector->lightlevel); colormap = rover->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); }else{ @@ -3479,12 +3481,12 @@ void HWR_Subsector(size_t num) light = R_GetPlaneLight(gr_frontsector, locFloorHeight, false); if (gr_frontsector->floorlightsec == -1) - floorlightlevel = HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel; + floorlightlevel = SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel); floorcolormap = gr_frontsector->lightlist[light].extra_colormap; light = R_GetPlaneLight(gr_frontsector, locCeilingHeight, false); if (gr_frontsector->ceilinglightsec == -1) - ceilinglightlevel = HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel;; + ceilinglightlevel = SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel); ceilingcolormap = gr_frontsector->lightlist[light].extra_colormap; } @@ -3559,16 +3561,13 @@ void HWR_Subsector(size_t num) light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - if (HWR_ShouldUsePaletteRendering()) - alpha = HWR_FogBlockAlpha((*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT, rover->master->frontsector->extra_colormap); - else - alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap); + alpha = HWR_FogBlockAlpha(SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), rover->master->frontsector->extra_colormap); HWR_AddTransparentFloor(0, &extrasubsectors[num], false, *rover->bottomheight, - HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, + SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), alpha, rover->master->frontsector, PF_Fog|PF_NoTexture, true, rover->master->frontsector->extra_colormap); } @@ -3579,7 +3578,7 @@ void HWR_Subsector(size_t num) &extrasubsectors[num], false, *rover->bottomheight, - HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, + SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), max(0, min(rover->alpha, 255)), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } @@ -3587,7 +3586,7 @@ void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[*rover->bottompic].lumpnum, R_NoEncore(gr_frontsector, false)); light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->bottompic].lumpnum, + HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), levelflats[*rover->bottompic].lumpnum, rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap); } } @@ -3613,17 +3612,14 @@ void HWR_Subsector(size_t num) UINT8 alpha; light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - - if (HWR_ShouldUsePaletteRendering()) - alpha = HWR_FogBlockAlpha((*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT, rover->master->frontsector->extra_colormap); - else - alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap); + + alpha = HWR_FogBlockAlpha(SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), rover->master->frontsector->extra_colormap); HWR_AddTransparentFloor(0, &extrasubsectors[num], true, *rover->topheight, - HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, + SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), alpha, rover->master->frontsector, PF_Fog|PF_NoTexture, true, rover->master->frontsector->extra_colormap); } @@ -3634,7 +3630,7 @@ void HWR_Subsector(size_t num) &extrasubsectors[num], true, *rover->topheight, - HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, + SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), max(0, min(rover->alpha, 255)), rover->master->frontsector, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Translucent, false, gr_frontsector->lightlist[light].extra_colormap); } @@ -3642,7 +3638,7 @@ void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[*rover->toppic].lumpnum, R_NoEncore(gr_frontsector, true)); light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, HWR_ShouldUsePaletteRendering() ? (*gr_frontsector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->toppic].lumpnum, + HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, SOFTLIGHT(*gr_frontsector->lightlist[light].lightlevel), levelflats[*rover->toppic].lumpnum, rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap); } } @@ -4314,7 +4310,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) // Start with the lightlevel and colormap from the top of the sprite - lightlevel = HWR_ShouldUsePaletteRendering() ? (*list[sector->numlights - 1].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *list[sector->numlights - 1].lightlevel; + lightlevel = SOFTLIGHT(*list[sector->numlights - 1].lightlevel); colormap = list[sector->numlights - 1].extra_colormap; i = 0; @@ -4331,7 +4327,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (h <= temp) { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i-1].lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (*list[i-1].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *list[i-1].lightlevel; + lightlevel = *list[i-1].lightlevel > 255 ? 255 : SOFTLIGHT(*list[i-1].lightlevel); colormap = list[i-1].extra_colormap; break; } @@ -4339,7 +4335,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) #else i = R_GetPlaneLight(sector, temp, false); if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i].lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (*list[i].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *list[i].lightlevel; + lightlevel = *list[i].lightlevel > 255 ? 255 : SOFTLIGHT(*list[i].lightlevel); colormap = list[i].extra_colormap; #endif @@ -4355,7 +4351,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) if (!(list[i].flags & FF_NOSHADE) && (list[i].flags & FF_CUTSPRITES)) { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i].lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (*list[i].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *list[i].lightlevel; + lightlevel = *list[i].lightlevel > 255 ? 255 : SOFTLIGHT(*list[i].lightlevel); colormap = list[i].extra_colormap; } @@ -4646,7 +4642,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) extracolormap_t *colormap = sector->extra_colormap; if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (sector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : sector->lightlevel; + lightlevel = sector->lightlevel > 255 ? 255 : SOFTLIGHT(sector->lightlevel); HWR_Lighting(&Surf, lightlevel, colormap); } @@ -4747,7 +4743,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); // Always use the light at the top instead of whatever I was doing before if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *sector->lightlist[light].lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (*sector->lightlist[light].lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : *sector->lightlist[light].lightlevel; + lightlevel = *sector->lightlist[light].lightlevel > 255 ? 255 : SOFTLIGHT(*sector->lightlist[light].lightlevel); if (sector->lightlist[light].extra_colormap) colormap = sector->lightlist[light].extra_colormap; @@ -4755,7 +4751,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) else { if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = sector->lightlevel > 255 ? 255 : HWR_ShouldUsePaletteRendering() ? (sector->lightlevel >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : sector->lightlevel; + lightlevel = sector->lightlevel > 255 ? 255 : SOFTLIGHT(sector->lightlevel); if (sector->extra_colormap) colormap = sector->extra_colormap; @@ -4817,6 +4813,7 @@ static int CompareVisSprites(const void *p1, const void *p2) return -1; } +#undef SOFTLIGHT static void HWR_SortVisSprites(void) { From c6e07015815c8f85b99e3d59de4398e70b87161d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Feb 2024 22:46:51 +0100 Subject: [PATCH 11/27] forgor those --- src/hardware/hw_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c7223d848..b2fea0c4f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2499,7 +2499,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom colormap = rover->master->frontsector->extra_colormap; } - Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); + Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(SOFTLIGHT(rover->master->frontsector->lightlevel), rover->master->frontsector->extra_colormap); if (gr_frontsector->numlights) HWR_SplitWall(gr_frontsector, wallVerts, 0, &Surf, rover->flags, rover, 0); @@ -2650,7 +2650,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom colormap = rover->master->frontsector->extra_colormap; } - Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); + Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(SOFTLIGHT(rover->master->frontsector->lightlevel), rover->master->frontsector->extra_colormap); if (gr_backsector->numlights) HWR_SplitWall(gr_backsector, wallVerts, 0, &Surf, rover->flags, rover, 0); From b96fe0a0223682895e977bf3fe2434311ea1455e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Feb 2024 22:53:04 +0100 Subject: [PATCH 12/27] those too --- src/hardware/hw_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b2fea0c4f..0da852f8a 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3314,13 +3314,13 @@ void HWR_AddPolyObjectPlanes(void) FSurfaceInfo Surf; FBITFIELD blendmode = HWR_TranstableToAlpha(po_ptrs[i]->translucency, &Surf); HWR_AddTransparentPolyobjectFloor(levelflats[polyobjsector->floorpic].lumpnum, po_ptrs[i], false, polyobjsector->floorheight, - polyobjsector->lightlevel, Surf.PolyColor.s.alpha, polyobjsector, blendmode, NULL); + SOFTLIGHT(polyobjsector->lightlevel), Surf.PolyColor.s.alpha, polyobjsector, blendmode, NULL); } else { HWR_GetFlat(levelflats[polyobjsector->floorpic].lumpnum, R_NoEncore(polyobjsector, false)); HWR_RenderPolyObjectPlane(po_ptrs[i], false, polyobjsector->floorheight, PF_Occlude, - polyobjsector->lightlevel, levelflats[polyobjsector->floorpic].lumpnum, + SOFTLIGHT(polyobjsector->lightlevel), levelflats[polyobjsector->floorpic].lumpnum, polyobjsector, 255, NULL); } } @@ -3336,13 +3336,13 @@ void HWR_AddPolyObjectPlanes(void) memset(&Surf, 0x00, sizeof(Surf)); blendmode = HWR_TranstableToAlpha(po_ptrs[i]->translucency, &Surf); HWR_AddTransparentPolyobjectFloor(levelflats[polyobjsector->ceilingpic].lumpnum, po_ptrs[i], true, polyobjsector->ceilingheight, - polyobjsector->lightlevel, Surf.PolyColor.s.alpha, polyobjsector, blendmode, NULL); + SOFTLIGHT(polyobjsector->lightlevel), Surf.PolyColor.s.alpha, polyobjsector, blendmode, NULL); } else { HWR_GetFlat(levelflats[polyobjsector->ceilingpic].lumpnum, R_NoEncore(polyobjsector, true)); HWR_RenderPolyObjectPlane(po_ptrs[i], true, polyobjsector->ceilingheight, PF_Occlude, - polyobjsector->lightlevel, levelflats[polyobjsector->ceilingpic].lumpnum, + SOFTLIGHT(polyobjsector->lightlevel), levelflats[polyobjsector->ceilingpic].lumpnum, polyobjsector, 255, NULL); } } From cd239b0f357a2d1003ac0d6186a28054ac870c61 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Feb 2024 23:26:18 +0100 Subject: [PATCH 13/27] fix conflicts --- src/hardware/hw_cache.c | 22 +++++++--------------- src/hardware/hw_glob.h | 3 +-- src/hardware/hw_main.c | 1 - 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index f4007b826..c32870fed 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -321,8 +321,7 @@ bpp = format2bpp(grMipmap->format); // Create a composite texture from patches, adapt the texture size to a power of 2 // height and width for the hardware texture cache. // -static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex, boolean noencore) -static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex) +static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex, boolean noencore) { UINT8 *block; texture_t *texture; @@ -560,11 +559,10 @@ void HWR_LoadTextures(size_t pnumtextures) // -------------------------------------------------------------------------- // Make sure texture is downloaded and set it as the source // -------------------------------------------------------------------------- -GLTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) -GLMapTexture_t *HWR_GetTexture(INT32 tex) +GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) { GLMapTexture_t *grtex; - + if (tex < 0 || tex >= (signed)gr_numtextures) { #ifdef PARANOIA @@ -572,20 +570,17 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex) #else tex = 0; #endif - grtex = &gr_textures[tex*2 + (encoremap && !noencore ? 0 : 1)]; } + + grtex = &gr_textures[tex*2 + (encoremap && !noencore ? 0 : 1)]; - grtex = &gr_textures[tex]; - - if (!grtex->mipmap.grInfo.data && !grtex->mipmap.downloaded) - HWR_GenerateTexture(tex, grtex, noencore); if (!grtex->mipmap.data && !grtex->mipmap.downloaded) - HWR_GenerateTexture(tex, grtex); + HWR_GenerateTexture(tex, grtex, noencore); // If hardware does not have the texture, then call pfnSetTexture to upload it if (!grtex->mipmap.downloaded) HWD.pfnSetTexture(&grtex->mipmap); - + HWR_SetCurrentTexture(&grtex->mipmap); // The system-memory data can be purged now. @@ -594,7 +589,6 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex) return grtex; } - static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) { #ifdef GLENCORE @@ -603,7 +597,6 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) #endif size_t size, pflatsize; - // setup the texture info grMipmap->format = GL_TEXFMT_P_8; grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; @@ -649,7 +642,6 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) #endif } - // Download a Doom 'flat' to the hardware cache and make it ready for use void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) { diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 60c3b1fae..742fd82ae 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -63,8 +63,7 @@ void HWR_FreeExtraSubsectors(void); void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap); // ^ some flats must NOT be remapped to encore, since we remap them as we cache them for ease, adding a toggle here seems wise. -GLMapTexture_t *HWR_GetTexture(INT32 tex); -GLTexture_t *HWR_GetTexture(INT32 tex, boolean noencore); +GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore); void HWR_GetPatch(GLPatch_t *gpatch); void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap); void HWR_MakePatch(patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e83349fcf..8403c6565 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5812,7 +5812,6 @@ void HWR_DrawSkyBackground(float fpov) dometransform.roll = atransform.roll; dometransform.splitscreen = splitscreen; - HWR_GetTexture(texturetranslation[skytexture]); if (HWR_UseShader()) HWD.pfnSetShader(HWR_GetShaderFromTarget(SHADER_SKY));// sky shader HWR_GetTexture(texturetranslation[skytexture], false); From 0b1add2988dc7d1cb25ab508704063d98f0226eb Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Feb 2024 23:27:26 +0100 Subject: [PATCH 14/27] one more --- src/hardware/hw_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 8403c6565..bb80441af 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5812,10 +5812,9 @@ void HWR_DrawSkyBackground(float fpov) dometransform.roll = atransform.roll; dometransform.splitscreen = splitscreen; + HWR_GetTexture(texturetranslation[skytexture], false); if (HWR_UseShader()) HWD.pfnSetShader(HWR_GetShaderFromTarget(SHADER_SKY));// sky shader - HWR_GetTexture(texturetranslation[skytexture], false); - HWD.pfnSetShader(7); // sky shader HWD.pfnRenderSkyDome(skytexture, textures[skytexture]->width, textures[skytexture]->height, dometransform); } From bee72c4646def39547de0bd721943120d4d82927 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Feb 2024 23:40:30 +0100 Subject: [PATCH 15/27] remove redundant check --- src/r_fps.c | 56 ++++++++++++++++------------------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index f01730d50..f29ffa88f 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -305,56 +305,36 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) out->y = mobj->old_y; else out->y = R_LerpFixed(mobj->old_y, mobj->y, frac); - + if (mobj->z == mobj->old_z) out->z = mobj->old_z; else out->z = R_LerpFixed(mobj->old_z, mobj->z, frac); - if (cv_gravstretch.value || cv_saltysquish.value) // for now we only use it for those two features so no need to interpolate this when we dont use stuff - { - if (mobj->spritexscale == mobj->old_spritexscale) - out->spritexscale = mobj->old_spritexscale; - else - out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); - - if (mobj->spriteyscale == mobj->old_spriteyscale) - out->spriteyscale = mobj->old_spriteyscale; - else - out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); - } + if (mobj->spritexscale == mobj->old_spritexscale) + out->spritexscale = mobj->old_spritexscale; else - { - out->spritexscale = mobj->spritexscale; - out->spriteyscale = mobj->spriteyscale; - } + out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); - if (cv_saltyhop.value) // same here - { - if (mobj->spritexoffset == mobj->old_spritexoffset) - out->spritexoffset = mobj->old_spritexoffset; - else - out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); - - if (mobj->spriteyoffset == mobj->old_spriteyoffset) - out->spriteyoffset = mobj->old_spriteyoffset; - else - out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); - } + if (mobj->spriteyscale == mobj->old_spriteyscale) + out->spriteyscale = mobj->old_spriteyscale; else - { - out->spritexoffset = mobj->spritexoffset; - out->spriteyoffset = mobj->spriteyoffset; - } + out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); + + if (mobj->spritexoffset == mobj->old_spritexoffset) + out->spritexoffset = mobj->old_spritexoffset; + else + out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); + + if (mobj->spriteyoffset == mobj->old_spriteyoffset) + out->spriteyoffset = mobj->old_spriteyoffset; + else + out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); if (mobj->scale == mobj->old_scale) // Tiny optimisation - scale is usually unchanging, so let's skip a lerp, two FixedMuls, and two FixedDivs - { out->scale = mobj->scale; - } else - { out->scale = mobj->resetinterp ? mobj->scale : R_LerpFixed(mobj->old_scale, mobj->scale, frac); - } if (cv_mobjssector.value) out->subsector = R_PointInSubsector(out->x, out->y); @@ -362,9 +342,7 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) out->subsector = mobj->subsector; if (mobj->player) - { out->angle = mobj->resetinterp ? mobj->player->frameangle : R_LerpAngle(mobj->player->old_frameangle, mobj->player->frameangle, frac); - } else { if (mobj->angle == mobj->old_angle) From 339aab8540b62a99e0add18f6631d09760c28840 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Feb 2024 23:45:26 +0100 Subject: [PATCH 16/27] use the current not old state also add dont interp precip angle if it doesent change --- src/r_fps.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index f29ffa88f..209886301 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -297,37 +297,37 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) } if (mobj->x == mobj->old_x) - out->x = mobj->old_x; + out->x = mobj->x; else out->x = R_LerpFixed(mobj->old_x, mobj->x, frac); if (mobj->y == mobj->old_y) - out->y = mobj->old_y; + out->y = mobj->y; else out->y = R_LerpFixed(mobj->old_y, mobj->y, frac); if (mobj->z == mobj->old_z) - out->z = mobj->old_z; + out->z = mobj->z; else out->z = R_LerpFixed(mobj->old_z, mobj->z, frac); if (mobj->spritexscale == mobj->old_spritexscale) - out->spritexscale = mobj->old_spritexscale; + out->spritexscale = mobj->spritexscale; else out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); if (mobj->spriteyscale == mobj->old_spriteyscale) - out->spriteyscale = mobj->old_spriteyscale; + out->spriteyscale = mobj->spriteyscale; else out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); if (mobj->spritexoffset == mobj->old_spritexoffset) - out->spritexoffset = mobj->old_spritexoffset; + out->spritexoffset = mobj->spritexoffset; else out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); if (mobj->spriteyoffset == mobj->old_spriteyoffset) - out->spriteyoffset = mobj->old_spriteyoffset; + out->spriteyoffset = mobj->spriteyoffset; else out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); @@ -346,7 +346,7 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) else { if (mobj->angle == mobj->old_angle) - out->angle = mobj->old_angle; + out->angle = mobj->angle; else out->angle = mobj->resetinterp ? mobj->angle : R_LerpAngle(mobj->old_angle, mobj->angle, frac); } @@ -401,7 +401,10 @@ void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjst else out->subsector = mobj->subsector; - out->angle = R_LerpAngle(mobj->old_angle, mobj->angle, frac); + if (mobj->angle == mobj->old_angle) + out->angle = mobj->angle; + else + out->angle = R_LerpAngle(mobj->old_angle, mobj->angle, frac); } static void AddInterpolator(levelinterpolator_t* interpolator) @@ -629,36 +632,36 @@ void R_ApplyLevelInterpolators(fixed_t frac) if (interp->sectorscroll.ceiling) { if (interp->sectorscroll.sector->ceiling_xoffs == interp->sectorscroll.oldxoffs) - interp->sectorscroll.sector->ceiling_xoffs = interp->sectorscroll.oldxoffs; + interp->sectorscroll.sector->ceiling_xoffs = interp->sectorscroll.bakxoffs; else interp->sectorscroll.sector->ceiling_xoffs = R_LerpFixed(interp->sectorscroll.oldxoffs, interp->sectorscroll.bakxoffs, frac); if (interp->sectorscroll.sector->ceiling_yoffs == interp->sectorscroll.oldyoffs) - interp->sectorscroll.sector->ceiling_yoffs = interp->sectorscroll.oldyoffs; + interp->sectorscroll.sector->ceiling_yoffs = interp->sectorscroll.bakyoffs; else interp->sectorscroll.sector->ceiling_yoffs = R_LerpFixed(interp->sectorscroll.oldyoffs, interp->sectorscroll.bakyoffs, frac); } else { if (interp->sectorscroll.sector->floor_xoffs == interp->sectorscroll.oldxoffs) - interp->sectorscroll.sector->floor_xoffs = interp->sectorscroll.oldxoffs; + interp->sectorscroll.sector->floor_xoffs = interp->sectorscroll.bakxoffs; else interp->sectorscroll.sector->floor_xoffs = R_LerpFixed(interp->sectorscroll.oldxoffs, interp->sectorscroll.bakxoffs, frac); if (interp->sectorscroll.sector->floor_yoffs == interp->sectorscroll.oldyoffs) - interp->sectorscroll.sector->floor_yoffs = interp->sectorscroll.oldyoffs; + interp->sectorscroll.sector->floor_yoffs = interp->sectorscroll.bakyoffs; else interp->sectorscroll.sector->floor_yoffs = R_LerpFixed(interp->sectorscroll.oldyoffs, interp->sectorscroll.bakyoffs, frac); } break; case LVLINTERP_SideScroll: if (interp->sidescroll.side->textureoffset == interp->sidescroll.oldtextureoffset) - interp->sidescroll.side->textureoffset = interp->sidescroll.oldtextureoffset; + interp->sidescroll.side->textureoffset = interp->sidescroll.baktextureoffset; else interp->sidescroll.side->textureoffset = R_LerpFixed(interp->sidescroll.oldtextureoffset, interp->sidescroll.baktextureoffset, frac); if (interp->sidescroll.side->rowoffset == interp->sidescroll.oldrowoffset) - interp->sidescroll.side->rowoffset = interp->sidescroll.oldrowoffset; + interp->sidescroll.side->rowoffset = interp->sidescroll.bakrowoffset; else interp->sidescroll.side->rowoffset = R_LerpFixed(interp->sidescroll.oldrowoffset, interp->sidescroll.bakrowoffset, frac); break; @@ -669,12 +672,12 @@ void R_ApplyLevelInterpolators(fixed_t frac) interp->polyobj.polyobj->vertices[ii]->y = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 + 1], interp->polyobj.bakvertices[ii * 2 + 1], frac); } if (interp->polyobj.polyobj->centerPt.x == interp->polyobj.oldcx) - interp->polyobj.polyobj->centerPt.x = interp->polyobj.oldcx; + interp->polyobj.polyobj->centerPt.x = interp->polyobj.bakcx; else interp->polyobj.polyobj->centerPt.x = R_LerpFixed(interp->polyobj.oldcx, interp->polyobj.bakcx, frac); if (interp->polyobj.polyobj->centerPt.y == interp->polyobj.oldcy) - interp->polyobj.polyobj->centerPt.y = interp->polyobj.oldcy; + interp->polyobj.polyobj->centerPt.y = interp->polyobj.bakcy; else interp->polyobj.polyobj->centerPt.y = R_LerpFixed(interp->polyobj.oldcy, interp->polyobj.bakcy, frac); From bcc15011b20f920e19a7c3d43380c90e2beb7d80 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 23 Feb 2024 01:27:52 +0100 Subject: [PATCH 17/27] forgor those aswell --- src/r_fps.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index 209886301..66441397e 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -351,23 +351,27 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) out->angle = mobj->resetinterp ? mobj->angle : R_LerpAngle(mobj->old_angle, mobj->angle, frac); } - if (cv_spriteroll.value) // no need to interpolate this if its disabled - { - // pitch roll stuff + // pitch roll stuff + if (mobj->pitch == mobj->old_pitch) + out->pitch = mobj->pitch; + else out->pitch = mobj->resetinterp ? mobj->pitch : R_LerpAngle(mobj->old_pitch, mobj->pitch, frac); + + if (mobj->roll == mobj->old_roll) + out->roll = mobj->roll; + else out->roll = mobj->resetinterp ? mobj->roll : R_LerpAngle(mobj->old_roll, mobj->roll, frac); - // and the slope stuff - out->slopepitch = mobj->resetinterp ? mobj->slopepitch : R_LerpAngle(mobj->old_slopepitch, mobj->slopepitch, frac); - out->sloperoll = mobj->resetinterp ? mobj->sloperoll : R_LerpAngle(mobj->old_sloperoll, mobj->sloperoll, frac); - } - else - { - out->pitch = mobj->pitch; - out->roll = mobj->roll; + // and the slope stuff + if (mobj->slopepitch == mobj->old_slopepitch) out->slopepitch = mobj->slopepitch; + else + out->slopepitch = mobj->resetinterp ? mobj->slopepitch : R_LerpAngle(mobj->old_slopepitch, mobj->slopepitch, frac); + + if (mobj->sloperoll == mobj->old_sloperoll) out->sloperoll = mobj->sloperoll; - } + else + out->sloperoll = mobj->resetinterp ? mobj->sloperoll : R_LerpAngle(mobj->old_sloperoll, mobj->sloperoll, frac); } void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjstate_t *out) @@ -615,14 +619,14 @@ void R_ApplyLevelInterpolators(fixed_t frac) if (interp->sectorplane.ceiling) { if (interp->sectorplane.sector->ceilingheight == interp->sectorplane.oldheight) - interp->sectorplane.sector->ceilingheight = interp->sectorplane.oldheight; + interp->sectorplane.sector->ceilingheight = interp->sectorplane.bakheight; else interp->sectorplane.sector->ceilingheight = R_LerpFixed(interp->sectorplane.oldheight, interp->sectorplane.bakheight, frac); } else { if (interp->sectorplane.sector->floorheight == interp->sectorplane.oldheight) - interp->sectorplane.sector->floorheight = interp->sectorplane.oldheight; + interp->sectorplane.sector->floorheight = interp->sectorplane.bakheight; else interp->sectorplane.sector->floorheight = R_LerpFixed(interp->sectorplane.oldheight, interp->sectorplane.bakheight, frac); } @@ -668,8 +672,15 @@ void R_ApplyLevelInterpolators(fixed_t frac) case LVLINTERP_Polyobj: for (ii = 0; ii < interp->polyobj.vertices_size; ii++) { - interp->polyobj.polyobj->vertices[ii]->x = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 ], interp->polyobj.bakvertices[ii * 2 ], frac); - interp->polyobj.polyobj->vertices[ii]->y = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 + 1], interp->polyobj.bakvertices[ii * 2 + 1], frac); + if (interp->polyobj.polyobj->vertices[ii]->x == interp->polyobj.oldvertices[ii * 2 ]) + interp->polyobj.polyobj->vertices[ii]->x = interp->polyobj.bakvertices[ii * 2 ]; + else + interp->polyobj.polyobj->vertices[ii]->x = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 ], interp->polyobj.bakvertices[ii * 2 ], frac); + + if (interp->polyobj.polyobj->vertices[ii]->y == interp->polyobj.oldvertices[ii * 2 + 1]) + interp->polyobj.polyobj->vertices[ii]->y = interp->polyobj.bakvertices[ii * 2 + 1]; + else + interp->polyobj.polyobj->vertices[ii]->y = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 + 1], interp->polyobj.bakvertices[ii * 2 + 1], frac); } if (interp->polyobj.polyobj->centerPt.x == interp->polyobj.oldcx) interp->polyobj.polyobj->centerPt.x = interp->polyobj.bakcx; From 9b4f05131237872f65b87e8394f11c0641a996e4 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 23 Feb 2024 01:35:49 +0100 Subject: [PATCH 18/27] this aswell --- src/r_fps.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/r_fps.c b/src/r_fps.c index 66441397e..33cd206c7 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -342,7 +342,12 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) out->subsector = mobj->subsector; if (mobj->player) - out->angle = mobj->resetinterp ? mobj->player->frameangle : R_LerpAngle(mobj->player->old_frameangle, mobj->player->frameangle, frac); + { + if (mobj->angle == mobj->player->old_frameangle) + out->angle = mobj->player->frameangle; + else + out->angle = mobj->resetinterp ? mobj->player->frameangle : R_LerpAngle(mobj->player->old_frameangle, mobj->player->frameangle, frac); + } else { if (mobj->angle == mobj->old_angle) From bd2c8969f1eafa232230763318abebe73e9f0be8 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 24 Feb 2024 17:23:41 +0100 Subject: [PATCH 19/27] Revert "Refactor Batching code" This reverts commit 3dcf4f6f6472b76fe8cd124c52ee5c35c3bac8e4. --- src/hardware/hw_batching.c | 569 +++++++++++++++++++------------------ src/hardware/hw_batching.h | 12 + 2 files changed, 306 insertions(+), 275 deletions(-) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 388bb2023..aa0e05375 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -15,54 +15,29 @@ #include "hw_main.h" #include "../i_system.h" -typedef struct -{ - FSurfaceInfo surf; // surf also has its own polyflags for some reason, but it seems unused - unsigned int vertsIndex; // location of verts in unsortedVertices - FUINT numVerts; - FBITFIELD polyFlags; - GLMipmap_t *texture; - int shader; - // this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls - boolean horizonSpecial; -} DrawCallInfo; - // The texture for the next polygon given to HWR_ProcessPolygon. // Set with HWR_SetCurrentTexture. GLMipmap_t *current_texture = NULL; boolean currently_batching = false; -// Dynamic arrays for: -// - unsorted draw calls -// - sorted order of draw calls -// - unsorted vertices -// - final (sorted) vertices -// - vertex indices for sorted vertices +FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu +UINT32* finalVertexIndexArray = NULL;// contains indexes for glDrawElements, taking into account fan->triangles conversion +// NOTE have this alloced as 3x finalVertexArray size +int finalVertexArrayAllocSize = 65536; +//GLubyte* colorArray = NULL;// contains color data to be sent to gpu, if needed +//int colorArrayAllocSize = 65536; +// not gonna use this for now, just sort by color and change state when it changes +// later maybe when using vertex attributes if it's needed -// contains the draw calls from DrawPolygon, waiting to be processed -DrawCallInfo* drawCalls = NULL; -int drawCallsSize = 0; -int drawCallsCapacity = 65536; +PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed +int polygonArraySize = 0; +UINT32* polygonIndexArray = NULL;// contains sorting pointers for polygonArray +int polygonArrayAllocSize = 65536; -// contains sorted order (array indices) for drawCalls -// (therefore size and capacity shared with it) -UINT32* drawCallOrder = NULL; - -// contains unsorted vertices and texture coordinates from DrawPolygon -FOutVector* unsortedVertices = NULL; -int unsortedVerticesSize = 0; -int unsortedVerticesCapacity = 65536; - -// contains subset of sorted vertices and texture coordinates to be sent to gpu -FOutVector* finalVertices = NULL; -int finalVerticesSize = 0; -int finalVerticesCapacity = 65536; - -// contains vertex indices into finalVertices for glDrawElements, -// taking into account fan->triangles conversion -UINT32* finalIndices = NULL; // this is alloced with 3x finalVertices size -int finalIndicesSize = 0; +FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon +int unsortedVertexArraySize = 0; +int unsortedVertexArrayAllocSize = 65536; // Enables batching mode. HWR_ProcessPolygon will collect polygons instead of passing them directly to the rendering backend. // Call HWR_RenderBatches to render all the collected geometry. @@ -72,13 +47,13 @@ void HWR_StartBatching(void) I_Error("Repeat call to HWR_StartBatching without HWR_RenderBatches"); // init arrays if that has not been done yet - if (!finalVertices) + if (!finalVertexArray) { - finalVertices = malloc(finalVerticesCapacity * sizeof(FOutVector)); - finalIndices = malloc(finalVerticesCapacity * 3 * sizeof(UINT32)); - drawCalls = malloc(drawCallsCapacity * sizeof(DrawCallInfo)); - drawCallOrder = malloc(drawCallsCapacity * sizeof(UINT32)); - unsortedVertices = malloc(unsortedVerticesCapacity * sizeof(FOutVector)); + finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); + finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); + polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); + polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32)); + unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); } currently_batching = true; @@ -89,55 +64,14 @@ void HWR_StartBatching(void) // Doing this was easier than getting a texture pointer to HWR_ProcessPolygon. void HWR_SetCurrentTexture(GLMipmap_t *texture) { - if (currently_batching) - current_texture = texture; - else - HWD.pfnSetTexture(texture); -} - -static void HWR_CollectDrawCallInfo(FSurfaceInfo *pSurf, FUINT iNumPts, FBITFIELD PolyFlags, int shader_target, boolean horizonSpecial) -{ - // make sure dynamic array has capacity - if (drawCallsSize == drawCallsCapacity) - { - DrawCallInfo* new_array; - // ran out of space, make new array double the size - drawCallsCapacity *= 2; - new_array = malloc(drawCallsCapacity * sizeof(DrawCallInfo)); - memcpy(new_array, drawCalls, drawCallsSize * sizeof(DrawCallInfo)); - free(drawCalls); - drawCalls = new_array; - // also need to redo the index array, dont need to copy it though - free(drawCallOrder); - drawCallOrder = malloc(drawCallsCapacity * sizeof(UINT32)); - } - // add entry to array - drawCalls[drawCallsSize].surf = *pSurf; - drawCalls[drawCallsSize].vertsIndex = unsortedVerticesSize; - drawCalls[drawCallsSize].numVerts = iNumPts; - drawCalls[drawCallsSize].polyFlags = PolyFlags; - drawCalls[drawCallsSize].texture = current_texture; - drawCalls[drawCallsSize].shader = (shader_target != -1) ? HWR_GetShaderFromTarget(shader_target) : shader_target; - drawCalls[drawCallsSize].horizonSpecial = horizonSpecial; - drawCallsSize++; -} - -static void HWR_CollectDrawCallVertices(FOutVector *pOutVerts, FUINT iNumPts) -{ - // make sure dynamic array has capacity - while (unsortedVerticesSize + (int)iNumPts > unsortedVerticesCapacity) - { - FOutVector* new_array; - // need more space for vertices in unsortedVertices - unsortedVerticesCapacity *= 2; - new_array = malloc(unsortedVerticesCapacity * sizeof(FOutVector)); - memcpy(new_array, unsortedVertices, unsortedVerticesSize * sizeof(FOutVector)); - free(unsortedVertices); - unsortedVertices = new_array; - } - // add vertices to array - memcpy(&unsortedVertices[unsortedVerticesSize], pOutVerts, iNumPts * sizeof(FOutVector)); - unsortedVerticesSize += iNumPts; + if (currently_batching) + { + current_texture = texture; + } + else + { + HWD.pfnSetTexture(texture); + } } // If batching is enabled, this function collects the polygon data and the chosen texture @@ -145,16 +79,48 @@ static void HWR_CollectDrawCallVertices(FOutVector *pOutVerts, FUINT iNumPts) // render the polygon immediately. void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader_target, boolean horizonSpecial) { - if (currently_batching) + if (currently_batching) { if (!pSurf) + I_Error("Got a null FSurfaceInfo in batching");// nulls should not come in the stuff that batching currently applies to + if (polygonArraySize == polygonArrayAllocSize) { - // handling null FSurfaceInfo is not implemented - I_Error("Got a null FSurfaceInfo in batching"); + PolygonArrayEntry* new_array; + // ran out of space, make new array double the size + polygonArrayAllocSize *= 2; + new_array = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); + memcpy(new_array, polygonArray, polygonArraySize * sizeof(PolygonArrayEntry)); + free(polygonArray); + polygonArray = new_array; + // also need to redo the index array, dont need to copy it though + free(polygonIndexArray); + polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32)); } - HWR_CollectDrawCallInfo(pSurf, iNumPts, PolyFlags, shader_target, horizonSpecial); - HWR_CollectDrawCallVertices(pOutVerts, iNumPts); + while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize) + { + FOutVector* new_array; + // need more space for vertices in unsortedVertexArray + unsortedVertexArrayAllocSize *= 2; + new_array = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); + memcpy(new_array, unsortedVertexArray, unsortedVertexArraySize * sizeof(FOutVector)); + free(unsortedVertexArray); + unsortedVertexArray = new_array; + } + + // add the polygon data to the arrays + + polygonArray[polygonArraySize].surf = *pSurf; + polygonArray[polygonArraySize].vertsIndex = unsortedVertexArraySize; + polygonArray[polygonArraySize].numVerts = iNumPts; + polygonArray[polygonArraySize].polyFlags = PolyFlags; + polygonArray[polygonArraySize].texture = current_texture; + polygonArray[polygonArraySize].shader = shader; + polygonArray[polygonArraySize].horizonSpecial = horizonSpecial; + polygonArraySize++; + + memcpy(&unsortedVertexArray[unsortedVertexArraySize], pOutVerts, iNumPts * sizeof(FOutVector)); + unsortedVertexArraySize += iNumPts; } else { @@ -163,12 +129,12 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt } } -static int compareDrawCalls(const void *p1, const void *p2) +static int comparePolygons(const void *p1, const void *p2) { - UINT32 index1 = *(const UINT32*)p1; - UINT32 index2 = *(const UINT32*)p2; - DrawCallInfo* poly1 = &drawCalls[index1]; - DrawCallInfo* poly2 = &drawCalls[index2]; + unsigned int index1 = *(const unsigned int*)p1; + unsigned int index2 = *(const unsigned int*)p2; + PolygonArrayEntry* poly1 = &polygonArray[index1]; + PolygonArrayEntry* poly2 = &polygonArray[index2]; int diff; INT64 diff64; UINT32 downloaded1 = 0; @@ -213,12 +179,12 @@ static int compareDrawCalls(const void *p1, const void *p2) return diff; } -static int compareDrawCallsNoShaders(const void *p1, const void *p2) +static int comparePolygonsNoShaders(const void *p1, const void *p2) { - UINT32 index1 = *(const UINT32*)p1; - UINT32 index2 = *(const UINT32*)p2; - DrawCallInfo* poly1 = &drawCalls[index1]; - DrawCallInfo* poly2 = &drawCalls[index2]; + unsigned int index1 = *(const unsigned int*)p1; + unsigned int index2 = *(const unsigned int*)p2; + PolygonArrayEntry* poly1 = &polygonArray[index1]; + PolygonArrayEntry* poly2 = &polygonArray[index2]; int diff; INT64 diff64; @@ -249,155 +215,60 @@ static int compareDrawCallsNoShaders(const void *p1, const void *p2) return 0; } -static void HWR_CollectVerticesIntoBatch(DrawCallInfo *drawCall) -{ - int firstVIndex; - int lastVIndex; - int numVerts = drawCall->numVerts; - // before writing, check if there is enough room - // using 'while' instead of 'if' here makes sure that there will *always* be enough room. - // probably never will this loop run more than once though - while (finalVerticesSize + numVerts > finalVerticesCapacity) - { - FOutVector* new_array; - UINT32* new_index_array; - finalVerticesCapacity *= 2; - new_array = malloc(finalVerticesCapacity * sizeof(FOutVector)); - memcpy(new_array, finalVertices, finalVerticesSize * sizeof(FOutVector)); - free(finalVertices); - finalVertices = new_array; - // also increase size of index array, 3x of vertex array since - // going from fans to triangles increases vertex count to 3x - new_index_array = malloc(finalVerticesCapacity * 3 * sizeof(UINT32)); - memcpy(new_index_array, finalIndices, finalIndicesSize * sizeof(UINT32)); - free(finalIndices); - finalIndices = new_index_array; - } - // write the vertices of the polygon - memcpy(&finalVertices[finalVerticesSize], &unsortedVertices[drawCall->vertsIndex], - numVerts * sizeof(FOutVector)); - // write the indexes, pointing to the fan vertexes but in triangles format - firstVIndex = finalVerticesSize; - lastVIndex = finalVerticesSize + numVerts; - finalVerticesSize += 2; - while (finalVerticesSize < lastVIndex) - { - finalIndices[finalIndicesSize++] = firstVIndex; - finalIndices[finalIndicesSize++] = finalVerticesSize - 1; - finalIndices[finalIndicesSize++] = finalVerticesSize++; - } -} - -static GLMipmap_t *HWR_GetDrawCallTexture(DrawCallInfo *dc) -{ - return (dc->polyFlags & PF_NoTexture) ? NULL : dc->texture; -} - -// flags returned by HWR_MarkStateChanges -#define SHADER_CHANGED 1 -#define TEXTURE_CHANGED 2 -#define POLYFLAGS_CHANGED 4 -#define SURFACEINFO_CHANGED 8 - -static unsigned int HWR_MarkStateChanges(DrawCallInfo *current, DrawCallInfo *next) -{ - unsigned int stateChanges = 0; - FSurfaceInfo *currentSI = ¤t->surf; - FSurfaceInfo *nextSI = &next->surf; - - // check if a state change is required and flag it to stateChanges - - if (current->shader != next->shader && cv_grshaders.value && gr_shadersavailable) - stateChanges |= SHADER_CHANGED; - if (HWR_GetDrawCallTexture(current) != HWR_GetDrawCallTexture(next)) - stateChanges |= TEXTURE_CHANGED; - if (current->polyFlags != next->polyFlags) - stateChanges |= POLYFLAGS_CHANGED; - if (cv_grshaders.value && gr_shadersavailable) - { - if (currentSI->PolyColor.rgba != nextSI->PolyColor.rgba || - currentSI->TintColor.rgba != nextSI->TintColor.rgba || - currentSI->FadeColor.rgba != nextSI->FadeColor.rgba || - currentSI->LightInfo.light_level != nextSI->LightInfo.light_level || - currentSI->LightInfo.fade_start != nextSI->LightInfo.fade_start || - currentSI->LightInfo.fade_end != nextSI->LightInfo.fade_end) - { - stateChanges |= SURFACEINFO_CHANGED; - } - } - else - { - if (currentSI->PolyColor.rgba != nextSI->PolyColor.rgba) - stateChanges |= SURFACEINFO_CHANGED; - } - - return stateChanges; -} - -static void HWR_ExecuteStateChanges(unsigned int stateChanges, DrawCallInfo *dc) -{ - if ((stateChanges & SHADER_CHANGED) && cv_grshaders.value && gr_shadersavailable) - { - HWD.pfnSetShader(dc->shader); - ps_hw_numshaders.value.i++; - } - if (stateChanges & TEXTURE_CHANGED) - { - // for PF_NoTexture the texture is set in DrawIndexedTriangles - if (!(dc->polyFlags & PF_NoTexture)) - { - // texture should be already ready for use from calls to - // SetTexture during batch collection - HWD.pfnSetTexture(dc->texture); - } - ps_hw_numtextures.value.i++; - } - // these two are just parameters to DrawIndexedTriangles - // (changes to polyflags states are tracked in r_opengl.c though) - if (stateChanges & POLYFLAGS_CHANGED) - ps_hw_numpolyflags.value.i++; - if (stateChanges & SURFACEINFO_CHANGED) - ps_hw_numcolors.value.i++; -} - - -static void HWR_InitBatchingStats(void) -{ - ps_hw_numpolys.value.i = drawCallsSize; - ps_hw_numcalls.value.i = ps_hw_numverts.value.i - = ps_hw_numshaders.value.i = ps_hw_numtextures.value.i - = ps_hw_numpolyflags.value.i = ps_hw_numcolors.value.i = 0; -} - -// This function organizes the geometry and draw calls collected by HWR_ProcessPolygon -// calls into batches and uses the rendering backend to draw them. +// This function organizes the geometry collected by HWR_ProcessPolygon calls into batches and uses +// the rendering backend to draw them. void HWR_RenderBatches(void) { - int drawCallReadPos = 0; // position in drawCallOrder + int finalVertexWritePos = 0;// position in finalVertexArray + int finalIndexWritePos = 0;// position in finalVertexIndexArray + + int polygonReadPos = 0;// position in polygonIndexArray + + int currentShader; + int nextShader = 0; + GLMipmap_t *currentTexture; + GLMipmap_t *nextTexture = NULL; + FBITFIELD currentPolyFlags = 0; + FBITFIELD nextPolyFlags = 0; + FSurfaceInfo currentSurfaceInfo; + FSurfaceInfo nextSurfaceInfo; + int i; - if (!currently_batching) + if (!currently_batching) I_Error("HWR_RenderBatches called without starting batching"); - currently_batching = false; // no longer collecting batches + nextSurfaceInfo.LightInfo.fade_end = 0; + nextSurfaceInfo.LightInfo.fade_start = 0; + nextSurfaceInfo.LightInfo.light_level = 0; - HWR_InitBatchingStats(); + currently_batching = false;// no longer collecting batches + if (!polygonArraySize) + { + ps_hw_numpolys.value.i = ps_hw_numcalls.value.i = ps_hw_numshaders.value.i + = ps_hw_numtextures.value.i = ps_hw_numpolyflags.value.i + = ps_hw_numcolors.value.i = 0; + return;// nothing to draw + } + // init stats vars + ps_hw_numpolys.value.i = polygonArraySize; + ps_hw_numcalls.value.i = ps_hw_numverts.value.i = 0; + ps_hw_numshaders.value.i = ps_hw_numtextures.value.i + = ps_hw_numpolyflags.value.i = ps_hw_numcolors.value.i = 1; + // init polygonIndexArray + for (i = 0; i < polygonArraySize; i++) + { + polygonIndexArray[i] = i; + } - if (!drawCallsSize) - return; // nothing to draw - - // init drawCallOrder - for (i = 0; i < drawCallsSize; i++) - drawCallOrder[i] = i; - - // sort the draw calls + // sort polygons PS_START_TIMING(ps_hw_batchsorttime); if (cv_grshaders.value && gr_shadersavailable) - qsort(drawCallOrder, drawCallsSize, sizeof(UINT32), compareDrawCalls); + qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons); else - qsort(drawCallOrder, drawCallsSize, sizeof(UINT32), compareDrawCallsNoShaders); + qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders); PS_STOP_TIMING(ps_hw_batchsorttime); - // sort grouping order + // sort order // 1. shader // 2. texture // 3. polyflags @@ -406,57 +277,205 @@ void HWR_RenderBatches(void) PS_START_TIMING(ps_hw_batchdrawtime); + currentShader = polygonArray[polygonIndexArray[0]].shader; + currentTexture = polygonArray[polygonIndexArray[0]].texture; + currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags; + currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf; + // For now, will sort and track the colors. Vertex attributes could be used instead of uniforms + // and a color array could replace the color calls. + // set state for first batch - HWR_ExecuteStateChanges(0xFFFF, &drawCalls[drawCallOrder[0]]); - // - iterate through draw calls - // - accumulate converted vertices and indices into finalVertices and finalIndices - // and send them as a combined draw call when a state change occurs - while (1) + if (cv_grshaders.value && gr_shadersavailable) { + HWD.pfnSetShader(currentShader); + } + + if (currentPolyFlags & PF_NoTexture) + currentTexture = NULL; + else + HWD.pfnSetTexture(currentTexture); + + while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons) + { + int firstIndex; + int lastIndex; + boolean stopFlag = false; - unsigned int stateChanges = 0; // flags defined above HWR_MarkStateChanges - DrawCallInfo *currentDrawCall = &drawCalls[drawCallOrder[drawCallReadPos++]]; - DrawCallInfo *nextDrawCall = NULL; + boolean changeState = false; + boolean changeShader = false; + boolean changeTexture = false; + boolean changePolyFlags = false; + boolean changeSurfaceInfo = false; - HWR_CollectVerticesIntoBatch(currentDrawCall); + // steps: + // write vertices + // check for changes or end, otherwise go back to writing + // changes will affect the next vars and the change bools + // end could set flag for stopping + // execute draw call + // could check ending flag here + // change states according to next vars and change bools, updating the current vars and reseting the bools + // reset write pos + // repeat loop - if (drawCallReadPos >= drawCallsSize) // was that the last draw call? + int index = polygonIndexArray[polygonReadPos++]; + int numVerts = polygonArray[index].numVerts; + // before writing, check if there is enough room + // using 'while' instead of 'if' here makes sure that there will *always* be enough room. + // probably never will this loop run more than once though + while (finalVertexWritePos + numVerts > finalVertexArrayAllocSize) + { + FOutVector* new_array; + unsigned int* new_index_array; + finalVertexArrayAllocSize *= 2; + new_array = malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); + memcpy(new_array, finalVertexArray, finalVertexWritePos * sizeof(FOutVector)); + free(finalVertexArray); + finalVertexArray = new_array; + // also increase size of index array, 3x of vertex array since + // going from fans to triangles increases vertex count to 3x + new_index_array = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); + memcpy(new_index_array, finalVertexIndexArray, finalIndexWritePos * sizeof(UINT32)); + free(finalVertexIndexArray); + finalVertexIndexArray = new_index_array; + } + // write the vertices of the polygon + memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[polygonArray[index].vertsIndex], + numVerts * sizeof(FOutVector)); + // write the indexes, pointing to the fan vertexes but in triangles format + firstIndex = finalVertexWritePos; + lastIndex = finalVertexWritePos + numVerts; + finalVertexWritePos += 2; + while (finalVertexWritePos < lastIndex) + { + finalVertexIndexArray[finalIndexWritePos++] = firstIndex; + finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos - 1; + finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos++; + } + + if (polygonReadPos >= polygonArraySize) { stopFlag = true; } else { - nextDrawCall = &drawCalls[drawCallOrder[drawCallReadPos]]; - stateChanges = HWR_MarkStateChanges(currentDrawCall, nextDrawCall); + // check if a state change is required, set the change bools and next vars + int nextIndex = polygonIndexArray[polygonReadPos]; + nextShader = polygonArray[nextIndex].shader; + nextTexture = polygonArray[nextIndex].texture; + nextPolyFlags = polygonArray[nextIndex].polyFlags; + nextSurfaceInfo = polygonArray[nextIndex].surf; + if (nextPolyFlags & PF_NoTexture) + nextTexture = 0; + if (currentShader != nextShader && cv_grshaders.value && gr_shadersavailable) + { + changeState = true; + changeShader = true; + } + if (currentTexture != nextTexture) + { + changeState = true; + changeTexture = true; + } + if (currentPolyFlags != nextPolyFlags) + { + changeState = true; + changePolyFlags = true; + } + if ((cv_grshaders.value && gr_shadersavailable) && (HWR_ShouldUsePaletteRendering())) + { + if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || + currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || + currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba || + currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level || + currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start || + currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end || + currentSurfaceInfo.LightTableId != nextSurfaceInfo.LightTableId) + { + changeState = true; + changeSurfaceInfo = true; + } + } + else if (cv_grshaders.value && gr_shadersavailable) + { + if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || + currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || + currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba || + currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level || + currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start || + currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end) + { + changeState = true; + changeSurfaceInfo = true; + } + } + else + { + if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba) + { + changeState = true; + changeSurfaceInfo = true; + } + } } - if (stateChanges || stopFlag) + if (changeState || stopFlag) { - // execute combined draw call - HWD.pfnDrawIndexedTriangles(¤tDrawCall->surf, finalVertices, - finalIndicesSize, currentDrawCall->polyFlags, finalIndices); + // execute draw call + HWD.pfnDrawIndexedTriangles(¤tSurfaceInfo, finalVertexArray, finalIndexWritePos, currentPolyFlags, finalVertexIndexArray); // update stats ps_hw_numcalls.value.i++; - ps_hw_numverts.value.i += finalIndicesSize; - // reset final geometry collection arrays - finalVerticesSize = 0; - finalIndicesSize = 0; + ps_hw_numverts.value.i += finalIndexWritePos; + // reset write positions + finalVertexWritePos = 0; + finalIndexWritePos = 0; } - else - continue; + else continue; // if we're here then either its time to stop or time to change state - if (stopFlag) - break; - else - HWR_ExecuteStateChanges(stateChanges, nextDrawCall); + if (stopFlag) break; + + // change state according to change bools and next vars, update current vars and reset bools + if (changeShader) + { + HWD.pfnSetShader(nextShader); + currentShader = nextShader; + changeShader = false; + + ps_hw_numshaders.value.i++; + } + if (changeTexture) + { + // texture should be already ready for use from calls to SetTexture during batch collection + HWD.pfnSetTexture(nextTexture); + currentTexture = nextTexture; + changeTexture = false; + + ps_hw_numtextures.value.i++; + } + if (changePolyFlags) + { + currentPolyFlags = nextPolyFlags; + changePolyFlags = false; + + ps_hw_numpolyflags.value.i++; + } + if (changeSurfaceInfo) + { + currentSurfaceInfo = nextSurfaceInfo; + changeSurfaceInfo = false; + + ps_hw_numcolors.value.i++; + } + // and that should be it? } // reset the arrays (set sizes to 0) - drawCallsSize = 0; - unsortedVerticesSize = 0; + polygonArraySize = 0; + unsortedVertexArraySize = 0; PS_STOP_TIMING(ps_hw_batchdrawtime); } + #endif // HWRENDER diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index b4e4bd9e3..bf0b7fc94 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -17,6 +17,18 @@ #include "hw_data.h" #include "hw_drv.h" +typedef struct +{ + FSurfaceInfo surf;// surf also has its own polyflags for some reason, but it seems unused + unsigned int vertsIndex;// location of verts in unsortedVertexArray + FUINT numVerts; + FBITFIELD polyFlags; + GLMipmap_t *texture; + int shader; + // this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls + boolean horizonSpecial; +} PolygonArrayEntry; + void HWR_StartBatching(void); void HWR_SetCurrentTexture(GLMipmap_t *texture); void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial); From 6db95fc37b60a4ec47599aa9e3d87ecf478bf233 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 24 Feb 2024 16:56:28 +0100 Subject: [PATCH 20/27] fix conflict --- src/hardware/hw_batching.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index aa0e05375..85cd1c62e 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -115,7 +115,7 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt polygonArray[polygonArraySize].numVerts = iNumPts; polygonArray[polygonArraySize].polyFlags = PolyFlags; polygonArray[polygonArraySize].texture = current_texture; - polygonArray[polygonArraySize].shader = shader; + polygonArray[polygonArraySize].shader = (shader_target != -1) ? HWR_GetShaderFromTarget(shader_target) : shader_target; polygonArray[polygonArraySize].horizonSpecial = horizonSpecial; polygonArraySize++; From 6b41cf676cc9f86776495367acf4fe100832a837 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 25 Feb 2024 19:42:21 +0100 Subject: [PATCH 21/27] connect loadingscreen should clear menus --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 248afd2f9..165d79942 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2581,7 +2581,6 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic // Call it only once by tic if (*oldtic != I_GetTime()) { - INT32 key; I_OsPolling(); @@ -2605,6 +2604,7 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic #ifdef CLIENT_LOADINGSCREEN if (client && cl_mode != CL_CONNECTED && cl_mode != CL_ABORTED) { + M_ClearMenus(false); F_TitleScreenTicker(true); F_TitleScreenDrawer(); CL_DrawConnectionStatus(); From 612bde4e9a0ba4c5b7231bfb6a490a5b0b583aa1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 25 Feb 2024 19:47:52 +0100 Subject: [PATCH 22/27] dont quit addon downloading with the mousewheel lmao --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 165d79942..4e66872d9 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2590,7 +2590,7 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic key = I_GetKey(); // Only ESC and non-keyboard keys abort connection - if (!modeattacking && (key == KEY_ESCAPE || key >= KEY_MOUSE1 || cl_mode == CL_ABORTED)) + if (!modeattacking && (key == KEY_ESCAPE || key == KEY_JOY1+1 || cl_mode == CL_ABORTED)) { CONS_Printf(M_GetText("Network game synchronization aborted.\n")); D_QuitNetGame(); From 05195f4116ae196f0189bd62772ed61cfd1ac66d Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 26 Feb 2024 01:29:31 +0100 Subject: [PATCH 23/27] Revert "connect loadingscreen should clear menus" This reverts commit 6b41cf676cc9f86776495367acf4fe100832a837. --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 4e66872d9..1749d9aea 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2581,6 +2581,7 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic // Call it only once by tic if (*oldtic != I_GetTime()) { + INT32 key; I_OsPolling(); @@ -2604,7 +2605,6 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic #ifdef CLIENT_LOADINGSCREEN if (client && cl_mode != CL_CONNECTED && cl_mode != CL_ABORTED) { - M_ClearMenus(false); F_TitleScreenTicker(true); F_TitleScreenDrawer(); CL_DrawConnectionStatus(); From 50023b0021043ae0c9c28abe060f69dae3ea2ba9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 26 Feb 2024 20:58:18 +0100 Subject: [PATCH 24/27] replace SCR_FPSflags with V_LocalTransFlag so we can actually display hud transparency stuff before the hud appears, since that doesent work with V_HUDTRANS --- src/screen.c | 16 +++------------- src/v_video.c | 6 ++++++ src/v_video.h | 2 ++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/screen.c b/src/screen.c index d7aa1407e..9cebb5de9 100644 --- a/src/screen.c +++ b/src/screen.c @@ -70,8 +70,6 @@ consvar_t cv_shittyscreen = {"televisionsignal", "Okay", CV_NOSHOWHELP, shittysc static void SCR_ChangeFullscreen (void); -static INT32 SCR_FPSflags(void); - consvar_t cv_fullscreen = {"fullscreen", "Yes", CV_SAVE|CV_CALL, CV_YesNo, SCR_ChangeFullscreen, 0, NULL, NULL, 0, 0, NULL}; // ========================================================================= @@ -437,14 +435,6 @@ void SCR_CalculateFPS(void) #endif } -// this is pretty dumb, but has to be done like this, otherwise the fps counter just disappears sometimes for no reason lol -static INT32 SCR_FPSflags(void) -{ - if (!cv_translucenthud.value) return V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS; // eee kinda works ig - - return (((10-cv_translucenthud.value)*V_10TRANS) & V_ALPHAMASK) | V_SNAPTOBOTTOM|V_SNAPTORIGHT; -} - void SCR_DisplayTicRate(void) { const UINT8 *ticcntcolor = NULL; @@ -452,7 +442,7 @@ void SCR_DisplayTicRate(void) UINT32 benchmark = (cap == 0) ? I_GetRefreshRate() : cap; INT32 x = 318; double fps = round(averageFPS); - INT32 fpsflags = SCR_FPSflags(); + INT32 fpsflags = V_LocalTransFlag()|V_SNAPTOBOTTOM|V_SNAPTORIGHT; const char *fps_string; INT32 ticcntcolor2 = 0; @@ -520,12 +510,12 @@ void SCR_DisplayTicRate(void) void SCR_DisplayLocalPing(void) { UINT32 ping = playerpingtable[consoleplayer]; // consoleplayer's ping is everyone's ping in a splitnetgame :P - INT32 fpsflags = SCR_FPSflags(); + INT32 pingflags = V_LocalTransFlag()|V_SNAPTOBOTTOM|V_SNAPTORIGHT; if (cv_showping.value == 1 || (cv_showping.value == 2 && ping > servermaxping)) // only show 2 (warning) if our ping is at a bad level { INT32 dispy = (cv_ticrate.value == 1) ? 165 : ((cv_ticrate.value == 2 || cv_ticrate.value == 4) ? 172 : ((cv_ticrate.value == 3) ? 163 : 181)); // absolute buttpain - HU_drawPing(308, dispy, ping, fpsflags); + HU_drawPing(308, dispy, ping, pingflags); } } diff --git a/src/v_video.c b/src/v_video.c index 0d0405208..db9b38081 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -477,6 +477,12 @@ static UINT8 hudplusalpha[11] = { 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0}; static UINT8 hudminusalpha[11] = { 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5}; UINT8 hudtrans = 0; +// this is pretty dumb, but has to be done like this, otherwise the fps counter just disappears sometimes for no reason lol +INT32 V_LocalTransFlag(void) +{ + return ((10-cv_translucenthud.value)*V_10TRANS); +} + static const UINT8 *v_colormap = NULL; static const UINT8 *v_translevel = NULL; diff --git a/src/v_video.h b/src/v_video.h index d65966731..bf98f6b11 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -61,6 +61,8 @@ extern RGBA_t *pLocalPalette; extern UINT8 hudtrans; +extern INT32 V_LocalTransFlag(void); + void V_CubeApply(UINT8 *red, UINT8 *green, UINT8 *blue); // Retrieve the ARGB value from a palette color index From 2d160cfc8936f6c09986fee6735aa2606328e7f7 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 27 Feb 2024 15:52:34 +0100 Subject: [PATCH 25/27] Toggle for R_Pointtoangle Ex or 64 Ex may perform better on 32bit clients and some cpus so lets just make it toggable --- src/hardware/hw_main.c | 37 +++++++++++++++++++++++++++++++------ src/m_menu.c | 5 +++++ src/r_bsp.c | 26 ++++++++++++++++++++++---- src/r_main.c | 33 ++++++++++++++++++++++++++++----- src/r_main.h | 1 + src/r_state.h | 2 ++ src/tables.h | 2 +- 7 files changed, 90 insertions(+), 16 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 19f63b6ef..e420119b3 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2880,8 +2880,16 @@ void HWR_AddLine(seg_t *line) } // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngle64(v1x, v1y); - angle2 = R_PointToAngle64(v2x, v2y); + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(v1x, v1y); + angle2 = R_PointToAngle64(v2x, v2y); + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, v1x, v1y); + angle2 = R_PointToAngleEx(viewx, viewy, v2x, v2y); + } // do an extra culling check when rendering portals // check if any line vertex is on the viewable side of the portal target line @@ -3076,8 +3084,17 @@ boolean HWR_CheckBBox(fixed_t *bspcoord) if (mindist > current_bsp_culling_distance) return false; } - angle1 = R_PointToAngle64(px1, py1); - angle2 = R_PointToAngle64(px2, py2); + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(px1, py1); + angle2 = R_PointToAngle64(px2, py2); + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, px1, py1); + angle2 = R_PointToAngleEx(viewx, viewy, px2, py2); + } + return gld_clipper_SafeCheckRange(angle2, angle1); } @@ -5958,8 +5975,16 @@ static void HWR_PortalClipping(gl_portal_t *portal) line_t *line = &lines[portal->clipline]; - angle1 = R_PointToAngle64(line->v1->x, line->v1->y); - angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(line->v1->x, line->v1->y); + angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); + } // clip things that are not inside the portal window from our viewpoint gld_clipper_SafeAddClipRange(angle2, angle1); diff --git a/src/m_menu.c b/src/m_menu.c index 44d87ba59..4886f788d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1413,6 +1413,8 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "VHS effect", &cv_vhseffect, 75}, + {IT_STRING | IT_CVAR, NULL, "Clipping R_PointToAngle Version", &cv_pointoangleexor64, 85}, + {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 95}, {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 105}, #ifdef HWRENDER @@ -1424,6 +1426,7 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 135}, {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 145}, {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 155}, + #endif }; @@ -1435,6 +1438,7 @@ static const char* OP_ExpTooltips[] = "Should weather be interpolated? Weather should look about the\nsame but perform a bit better when disabled.", "When weather is on this will cut the object amount used in half.", "Show a VHS-like effect when the game is paused\n or youre rewinding replays.", + "Which version of R_PointToAngle should\nbe used for Sector Clipping?\n64 may fix rendering issues on larger maps\nat the cost of performance.", "Hides 3DFloors which are not visible\npotentially resulting in a performance boost.", "Hides Sprites which are not visible\npotentially resulting in a performance boost.", #ifdef HWRENDER @@ -1455,6 +1459,7 @@ enum op_exp_precipinter, op_exp_lessprecip, op_exp_vhs, + op_exp_angleshit, op_exp_ffclip, op_exp_sprclip, #ifdef HWRENDER diff --git a/src/r_bsp.c b/src/r_bsp.c index 2de30d2ab..e0b8039af 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -410,8 +410,18 @@ static void R_AddLine(seg_t *line) return; // big room fix - angle1 = R_PointToAngle64(line->v1->x, line->v1->y); - angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(line->v1->x, line->v1->y); + angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); + } + curline = line; // Clip to view edges. @@ -613,8 +623,16 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) check = checkcoord[boxpos]; // big room fix - angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; - angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + if (cv_pointoangleexor64.value) + { + angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + } + else + { + angle1 = R_PointToAngleEx(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngleEx(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + } if ((signed)angle1 < (signed)angle2) { diff --git a/src/r_main.c b/src/r_main.c index ec1cd0bf9..8a975498d 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -145,8 +145,6 @@ static CV_PossibleValue_t drawdist_cons_t[] = { {3072, "3072"}, {4096, "4096"}, {6144, "6144"}, {8192, "8192"}, {0, "Infinite"}, {0, NULL}}; -//static CV_PossibleValue_t precipdensity_cons_t[] = {{0, "None"}, {1, "Light"}, {2, "Moderate"}, {4, "Heavy"}, {6, "Thick"}, {8, "V.Thick"}, {0, NULL}}; - static CV_PossibleValue_t drawdist_precip_cons_t[] = { {256, "256"}, {512, "512"}, {768, "768"}, {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, @@ -161,7 +159,6 @@ static CV_PossibleValue_t maxinterpdist_cons_t[] = { static CV_PossibleValue_t fov_cons_t[] = {{5*FRACUNIT, "MIN"}, {178*FRACUNIT, "MAX"}, {0, NULL}}; -//static CV_PossibleValue_t precipdensity_cons_t[] = {{0, "None"}, {1, "Light"}, {2, "Moderate"}, {4, "Heavy"}, {6, "Thick"}, {8, "V.Thick"}, {0, NULL}}; static CV_PossibleValue_t translucenthud_cons_t[] = {{0, "MIN"}, {10, "MAX"}, {0, NULL}}; static CV_PossibleValue_t maxportals_cons_t[] = {{0, "MIN"}, {12, "MAX"}, {0, NULL}}; // lmao rendering 32 portals, you're a card static CV_PossibleValue_t homremoval_cons_t[] = {{0, "No"}, {1, "Yes"}, {2, "Flash"}, {0, NULL}}; @@ -202,10 +199,8 @@ consvar_t cv_translucenthud = {"translucenthud", "10", CV_SAVE, translucenthud_c consvar_t cv_translucency = {"translucency", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_drawdist = {"drawdist", "Infinite", CV_SAVE, drawdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -//consvar_t cv_drawdist_nights = {"drawdist_nights", "2048", CV_SAVE, drawdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_drawdist_precip = {"drawdist_precip", "1024", CV_SAVE, drawdist_precip_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_lessprecip = {"lessweathereffects", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -//consvar_t cv_precipdensity = {"precipdensity", "Moderate", CV_SAVE, precipdensity_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grmaxinterpdist = {"gr_maxinterpdist", "Infinite", CV_SAVE, maxinterpdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -217,6 +212,9 @@ consvar_t cv_homremoval = {"homremoval", "Yes", CV_SAVE, homremoval_cons_t, NULL consvar_t cv_maxportals = {"maxportals", "2", CV_SAVE, maxportals_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t pointoangle_cons_t[] = {{0, "Ex"}, {1, "64"}, {0, NULL}}; +consvar_t cv_pointoangleexor64 = {"r_pointtoangle", "Ex", CV_SAVE, pointoangle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + void SplitScreen_OnChange(void) { UINT8 i; @@ -420,6 +418,29 @@ angle_t R_PointToAngle64(INT64 x, INT64 y) 0; } +angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1) +{ + INT64 dx = x1-x2; + INT64 dy = y1-y2; + if (dx < INT32_MIN || dx > INT32_MAX || dy < INT32_MIN || dy > INT32_MAX) + { + x1 = (int)(dx / 2 + x2); + y1 = (int)(dy / 2 + y2); + } + return (y1 -= y2, (x1 -= x2) || y1) ? + x1 >= 0 ? + y1 >= 0 ? + (x1 > y1) ? tantoangle[SlopeDivEx(y1,x1)] : // octant 0 + ANGLE_90-tantoangle[SlopeDivEx(x1,y1)] : // octant 1 + x1 > (y1 = -y1) ? 0-tantoangle[SlopeDivEx(y1,x1)] : // octant 8 + ANGLE_270+tantoangle[SlopeDivEx(x1,y1)] : // octant 7 + y1 >= 0 ? (x1 = -x1) > y1 ? ANGLE_180-tantoangle[SlopeDivEx(y1,x1)] : // octant 3 + ANGLE_90 + tantoangle[SlopeDivEx(x1,y1)] : // octant 2 + (x1 = -x1) > (y1 = -y1) ? ANGLE_180+tantoangle[SlopeDivEx(y1,x1)] : // octant 4 + ANGLE_270-tantoangle[SlopeDivEx(x1,y1)] : // octant 5 + 0; +} + angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) { return (y -= pviewy, (x -= pviewx) || y) ? @@ -1869,6 +1890,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_translucenthud); CV_RegisterVar(&cv_maxportals); + + CV_RegisterVar(&cv_pointoangleexor64); CV_RegisterVar(&cv_grmaxinterpdist); diff --git a/src/r_main.h b/src/r_main.h index 4767c38ea..63c7c3ab5 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -69,6 +69,7 @@ INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node); INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line); angle_t R_PointToAngle(fixed_t x, fixed_t y); angle_t R_PointToAngle64(INT64 x, INT64 y); +angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); fixed_t R_PointToDist(fixed_t x, fixed_t y); fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); diff --git a/src/r_state.h b/src/r_state.h index e37bdf52e..670f800d1 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -102,6 +102,8 @@ extern INT32 portalclipstart, portalclipend; extern consvar_t cv_allowmlook; extern consvar_t cv_maxportals; +extern consvar_t cv_pointoangleexor64; + extern angle_t clipangle; extern angle_t doubleclipangle; diff --git a/src/tables.h b/src/tables.h index beea392ec..353bf591f 100644 --- a/src/tables.h +++ b/src/tables.h @@ -86,7 +86,7 @@ extern angle_t tantoangle[SLOPERANGE+1]; // Utility function, called by R_PointToAngle. FUNCMATH unsigned SlopeDiv(unsigned num, unsigned den); // Only called by R_PointToAngleEx -UINT64 SlopeDivEx(unsigned int num, unsigned int den); +FUNCMATH UINT64 SlopeDivEx(unsigned int num, unsigned int den); // 360 - angle_t(ANGLE_45) = ANGLE_315 FUNCMATH FUNCINLINE static ATTRINLINE angle_t InvAngle(angle_t a) From 0b6796cad9a4794444d18556cbd351608e864bcf Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 27 Feb 2024 20:18:10 +0300 Subject: [PATCH 26/27] Add cvar joinrefusemessage for custom messages when allowjoin is Off --- src/d_clisrv.c | 4 +++- src/d_clisrv.h | 2 +- src/d_netcmd.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1749d9aea..e3edcd962 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3959,6 +3959,8 @@ consvar_t cv_netticbuffer = {"netticbuffer", "1", CV_SAVE, netticbuffer_cons_t, static void Joinable_OnChange(void); +consvar_t cv_joinrefusemessage = {"joinrefusemessage", "The server is not accepting\njoins for the moment.", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_allownewplayer = {"allowjoin", "On", CV_SAVE|CV_CALL, CV_OnOff, Joinable_OnChange, 0, NULL, NULL, 0, 0, NULL}; #ifdef VANILLAJOINNEXTROUND @@ -4586,7 +4588,7 @@ static void HandleConnect(SINT8 node) } else if (!cv_allownewplayer.value && node) { - SV_SendRefuse(node, M_GetText("The server is not accepting\njoins for the moment.")); + SV_SendRefuse(node, M_GetText(cv_joinrefusemessage.string)); } else if (connectedplayers >= maxplayers) { diff --git a/src/d_clisrv.h b/src/d_clisrv.h index b1bc9ffcc..a314057a2 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -567,7 +567,7 @@ extern consvar_t #ifdef VANILLAJOINNEXTROUND cv_joinnextround, #endif - cv_netticbuffer, cv_allownewplayer, cv_maxplayers, cv_resynchattempts, cv_blamecfail, cv_maxsend, cv_noticedownload, cv_downloadspeed; + cv_netticbuffer, cv_allownewplayer, cv_joinrefusemessage, cv_maxplayers, cv_resynchattempts, cv_blamecfail, cv_maxsend, cv_noticedownload, cv_downloadspeed; extern consvar_t cv_connectawaittime; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 21f60b7cd..46fe4509e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -778,6 +778,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_httpsource); #ifndef NONET CV_RegisterVar(&cv_allownewplayer); + CV_RegisterVar(&cv_joinrefusemessage); CV_RegisterVar(&cv_chatlogsize); #ifdef VANILLAJOINNEXTROUND CV_RegisterVar(&cv_joinnextround); From 0ef51011d40cfbd244582b649897dcd5b554f5c0 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 27 Feb 2024 20:26:18 +0300 Subject: [PATCH 27/27] Change default value for joinrefusemessage because cvars don't support newline characters --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index e3edcd962..06670e729 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3959,7 +3959,7 @@ consvar_t cv_netticbuffer = {"netticbuffer", "1", CV_SAVE, netticbuffer_cons_t, static void Joinable_OnChange(void); -consvar_t cv_joinrefusemessage = {"joinrefusemessage", "The server is not accepting\njoins for the moment.", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_joinrefusemessage = {"joinrefusemessage", "The server is not accepting joins for the moment.", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_allownewplayer = {"allowjoin", "On", CV_SAVE|CV_CALL, CV_OnOff, Joinable_OnChange, 0, NULL, NULL, 0, 0, NULL};