From 8de340edbe374e5bbe121792a563f81b62078891 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 23 May 2024 19:11:11 +0200 Subject: [PATCH 01/15] allow gamepad dpad to hold scroll shit in menu aaa absolute arsepain cant wait to see this breaking kek --- src/d_main.c | 39 +++++++++++++++++++++++++++++++++++++++ src/m_menu.c | 40 +++++++++++++++++++++++++++++++++++++++- src/m_menu.h | 5 +++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index 17325e904..f32c825f4 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -617,6 +617,7 @@ static void D_Display(void) // ========================================================================= tic_t rendergametic; +static int menuInputDelayTimer = 0; void D_SRB2Loop(void) { @@ -779,6 +780,44 @@ void D_SRB2Loop(void) } #endif + // this is absolutely awful and i hate it lmao + if (menuactive && (UPKEY || DOWNKEY || LEFTKEY || RIGHTKEY)) + { + event_t myev; + myev.type = ev_keydown; + + if (renderisnewtic) + { + menuInputDelayTimer++; + + if (menuInputDelayTimer >= 19) + { + if (UPKEY) + { + myev.data1 = KEY_UPARROW; + M_Responder(&myev); + } + else if (DOWNKEY) + { + myev.data1 = KEY_DOWNARROW; + M_Responder(&myev); + } + else if (LEFTKEY) + { + myev.data1 = KEY_LEFTARROW; + M_Responder(&myev); + } + else if (RIGHTKEY) + { + myev.data1 = KEY_RIGHTARROW; + M_Responder(&myev); + } + } + } + } + else + menuInputDelayTimer = 0; + // Fully completed frame made. finishprecise = I_GetPreciseTime(); if (!singletics) diff --git a/src/m_menu.c b/src/m_menu.c index cc7d45d33..2dd0a6a38 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3433,6 +3433,11 @@ static void Command_Manual_f(void) itemOn = 0; } +boolean UPKEY = false; +boolean DOWNKEY = false; +boolean LEFTKEY = false; +boolean RIGHTKEY = false; + // // M_Responder // @@ -3464,7 +3469,6 @@ boolean M_Responder(event_t *ev) { ch = ev->data1; - // added 5-2-98 remap virtual keys (mouse & joystick buttons) switch (ch) { case KEY_MOUSE1: @@ -3492,6 +3496,40 @@ boolean M_Responder(event_t *ev) ch = KEY_RIGHTARROW; break; } + + switch (ev->data1) + { + case KEY_HAT1: + UPKEY = true; + break; + case KEY_HAT1 + 1: + DOWNKEY = true; + break; + case KEY_HAT1 + 2: + LEFTKEY = true; + break; + case KEY_HAT1 + 3: + RIGHTKEY = true; + break; + } + } + else if (ev->type == ev_keyup) + { + switch (ev->data1) + { + case KEY_HAT1: + UPKEY = false; + break; + case KEY_HAT1 + 1: + DOWNKEY = false; + break; + case KEY_HAT1 + 2: + LEFTKEY = false; + break; + case KEY_HAT1 + 3: + RIGHTKEY = false; + break; + } } else if (menuactive) { diff --git a/src/m_menu.h b/src/m_menu.h index bba8d3db3..530622ffe 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -74,6 +74,11 @@ typedef enum } menumessagetype_t; void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtype); +extern boolean UPKEY; +extern boolean DOWNKEY; +extern boolean LEFTKEY; +extern boolean RIGHTKEY; + typedef enum { M_NOT_WAITING, From 9f692c1f6a9ba1fd8ca5b41f0a2ef214395f7c68 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 23 May 2024 19:25:04 +0200 Subject: [PATCH 02/15] change names to be less basic --- src/d_main.c | 12 ++++++------ src/m_menu.c | 28 ++++++++++++++-------------- src/m_menu.h | 8 ++++---- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index f32c825f4..bdfa7557d 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -781,7 +781,7 @@ void D_SRB2Loop(void) #endif // this is absolutely awful and i hate it lmao - if (menuactive && (UPKEY || DOWNKEY || LEFTKEY || RIGHTKEY)) + if (menuactive && (DPADUPSCROLL || DPADDOWNSCROLL || DPADLEFTSCROLL || DPADRIGHTSCROLL)) { event_t myev; myev.type = ev_keydown; @@ -790,24 +790,24 @@ void D_SRB2Loop(void) { menuInputDelayTimer++; - if (menuInputDelayTimer >= 19) + if (menuInputDelayTimer >= 19) // TICRATE * ( (k+2) (1 - [wz + h + j - q]^2 - [(gk + 2g + k + 1)(h + j) + h - z]^2 - [16(k + 1)^3(k + 2)(n + 1)^2 + 1 - f^2]^2 calculated by my butt { - if (UPKEY) + if (DPADUPSCROLL) { myev.data1 = KEY_UPARROW; M_Responder(&myev); } - else if (DOWNKEY) + else if (DPADDOWNSCROLL) { myev.data1 = KEY_DOWNARROW; M_Responder(&myev); } - else if (LEFTKEY) + else if (DPADLEFTSCROLL) { myev.data1 = KEY_LEFTARROW; M_Responder(&myev); } - else if (RIGHTKEY) + else if (DPADRIGHTSCROLL) { myev.data1 = KEY_RIGHTARROW; M_Responder(&myev); diff --git a/src/m_menu.c b/src/m_menu.c index 2dd0a6a38..d7dc233b1 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3433,10 +3433,10 @@ static void Command_Manual_f(void) itemOn = 0; } -boolean UPKEY = false; -boolean DOWNKEY = false; -boolean LEFTKEY = false; -boolean RIGHTKEY = false; +boolean DPADUPSCROLL = false; +boolean DPADDOWNSCROLL = false; +boolean DPADLEFTSCROLL = false; +boolean DPADRIGHTSCROLL = false; // // M_Responder @@ -3497,37 +3497,37 @@ boolean M_Responder(event_t *ev) break; } - switch (ev->data1) + switch (ev->data1) // if you pressed it set those to true { case KEY_HAT1: - UPKEY = true; + DPADUPSCROLL = true; break; case KEY_HAT1 + 1: - DOWNKEY = true; + DPADDOWNSCROLL = true; break; case KEY_HAT1 + 2: - LEFTKEY = true; + DPADLEFTSCROLL = true; break; case KEY_HAT1 + 3: - RIGHTKEY = true; + DPADRIGHTSCROLL = true; break; } } else if (ev->type == ev_keyup) { - switch (ev->data1) + switch (ev->data1) // if you let go of those set those to false { case KEY_HAT1: - UPKEY = false; + DPADUPSCROLL = false; break; case KEY_HAT1 + 1: - DOWNKEY = false; + DPADDOWNSCROLL = false; break; case KEY_HAT1 + 2: - LEFTKEY = false; + DPADLEFTSCROLL = false; break; case KEY_HAT1 + 3: - RIGHTKEY = false; + DPADRIGHTSCROLL = false; break; } } diff --git a/src/m_menu.h b/src/m_menu.h index 530622ffe..a01c2ddef 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -74,10 +74,10 @@ typedef enum } menumessagetype_t; void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtype); -extern boolean UPKEY; -extern boolean DOWNKEY; -extern boolean LEFTKEY; -extern boolean RIGHTKEY; +extern boolean DPADUPSCROLL; +extern boolean DPADDOWNSCROLL; +extern boolean DPADLEFTSCROLL; +extern boolean DPADRIGHTSCROLL; typedef enum { From 837746c0a99bf540b18ef36de0b527675456cd21 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 25 May 2024 00:01:58 +0200 Subject: [PATCH 03/15] =?UTF-8?q?declare=20outside=20of=20l=C3=B6=C3=B6p?= =?UTF-8?q?=20also=20add=20const=20in=20r=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hardware/hw_main.c | 9 ++++++--- src/r_bsp.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index aedf40f34..afddd9365 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3530,14 +3530,16 @@ static boolean HWR_PortalCheckBBox(const fixed_t *bspcoord) static void HWR_RenderBSPNode(INT32 bspnum) { + const node_t *bsp; + INT32 side; ps_numbspcalls.value.i++; while (!(bspnum & NF_SUBSECTOR)) // Found a subsector? { - const node_t *bsp = &nodes[bspnum]; + bsp = &nodes[bspnum]; // Decide which side the view point is on. - INT32 side = R_PointOnSide(viewx, viewy, bsp); + side = R_PointOnSide(viewx, viewy, bsp); // Recursively divide front space. if (HWR_PortalCheckBBox(bsp->bbox[side])) @@ -3553,7 +3555,8 @@ static void HWR_RenderBSPNode(INT32 bspnum) // PORTAL CULLING if (portalclipline && portalcullsector) { - if (portalcullsector != subsectors[bspnum & ~NF_SUBSECTOR].sector) + sector_t *sect = subsectors[bspnum & ~NF_SUBSECTOR].sector; + if (sect != portalcullsector) return; portalcullsector = NULL; } diff --git a/src/r_bsp.c b/src/r_bsp.c index 83f530f2a..81569186d 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -1311,7 +1311,7 @@ INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside) void R_RenderBSPNode(INT32 bspnum) { - node_t *bsp; + const node_t *bsp; INT32 side; ps_numbspcalls.value.i++; From d794de3e83ac0be660d0832fdc3f1584bd27140f Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 25 May 2024 02:21:04 +0200 Subject: [PATCH 04/15] Cull BSP behind a raised floor or lowered ceiling that covers the entire screen https://git.do.srb2.org/KartKrew/RingRacers/-/commit/7b8a564f69688515319ccd425f2b88ffe8b7b120 --- src/r_bsp.c | 25 +++++++++++++++++++------ src/r_bsp.h | 1 + src/r_segs.c | 25 ++++++++++++++----------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index 81569186d..02f4d8c83 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -39,6 +39,10 @@ drawseg_t *ds_p = NULL; // indicates doors closed wrt automap bugfix: INT32 doorclosed; +// A wall was drawn covering the whole screen, which means we +// can block off the BSP across that seg. +boolean g_walloffscreen; + boolean R_NoEncore(sector_t *sector, boolean ceiling) { boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 15); @@ -163,7 +167,7 @@ crunch: // Clips the given range of columns, but does not include it in the clip list. // Does handle windows, e.g. LineDefs with upper and lower texture. // -static inline void R_ClipPassWallSegment(INT32 first, INT32 last) +static inline void R_ClipPassWallSegment(INT32 first, INT32 last, boolean soliddontrender) { cliprange_t *start; @@ -178,12 +182,14 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last) if (last < start->first - 1) { // Post is entirely visible (above start). - R_StoreWallRange(first, last); + if (!soliddontrender) + R_StoreWallRange(first, last); return; } // There is a fragment above *start. - R_StoreWallRange(first, start->first - 1); + if (!soliddontrender) + R_StoreWallRange(first, start->first - 1); } // Bottom contained in start? @@ -193,7 +199,8 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last) while (last >= (start+1)->first - 1) { // There is a fragment between two posts. - R_StoreWallRange(start->last + 1, (start+1)->first - 1); + if (!soliddontrender) + R_StoreWallRange(start->last + 1, (start+1)->first - 1); start++; if (last <= start->last) @@ -201,7 +208,8 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last) } // There is a fragment after *next. - R_StoreWallRange(start->last + 1, last); + if (!soliddontrender) + R_StoreWallRange(start->last + 1, last); } // @@ -579,10 +587,15 @@ static void R_AddLine(seg_t *line) return; clippass: - R_ClipPassWallSegment(x1, x2 - 1); + g_walloffscreen = false; + if (g_walloffscreen) + R_ClipPassWallSegment(x1, x2 - 1, true); + else + R_ClipPassWallSegment(x1, x2 - 1, false); return; clipsolid: + g_walloffscreen = false; R_ClipSolidWallSegment(x1, x2 - 1); } diff --git a/src/r_bsp.h b/src/r_bsp.h index f0db9066f..2803a90e4 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -32,6 +32,7 @@ extern INT32 checkcoord[12][4]; extern drawseg_t *drawsegs; extern drawseg_t *ds_p; extern INT32 doorclosed; +extern boolean g_walloffscreen; // BSP? void R_ClearClipSegs(void); diff --git a/src/r_segs.c b/src/r_segs.c index 8325e0fa0..6dd66e40f 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2596,23 +2596,26 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (toptexture) { - pixhigh = (centeryfrac>>4) - FixedMul (worldhigh, rw_scale); - pixhighstep = -FixedMul (rw_scalestep,worldhigh); + fixed_t topfracend = (centeryfrac>>4) - FixedMul (worldhighslope, ds_p->scale2); - if (backsector->c_slope) { - fixed_t topfracend = (centeryfrac>>4) - FixedMul (worldhighslope, ds_p->scale2); - pixhighstep = (topfracend-pixhigh)/(range); - } + pixhigh = (centeryfrac>>4) - FixedMul (worldhigh, rw_scale); + pixhighstep = (topfracend-pixhigh)/(range); + + // If the lowest part of a ceiling stretching down covers the entire screen + if (min(pixhigh, topfracend)>>HEIGHTBITS >= viewheight-1) + g_walloffscreen = true; } if (bottomtexture) { + fixed_t bottomfracend = (centeryfrac>>4) - FixedMul (worldlowslope, ds_p->scale2); + pixlow = (centeryfrac>>4) - FixedMul (worldlow, rw_scale); - pixlowstep = -FixedMul (rw_scalestep,worldlow); - if (backsector->f_slope) { - fixed_t bottomfracend = (centeryfrac>>4) - FixedMul (worldlowslope, ds_p->scale2); - pixlowstep = (bottomfracend-pixlow)/(range); - } + pixlowstep = (bottomfracend-pixlow)/(range); + + // If the highest part of a floor stretching up covers the entire screen + if ((max(pixlow, bottomfracend)+HEIGHTUNIT-1)>>HEIGHTBITS <= 0) + g_walloffscreen = true; } { From 157c95a785ca006d710b5133e1623ae457ef1f2d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 25 May 2024 14:37:30 +0200 Subject: [PATCH 05/15] super smol optimization to R_DrawRepeatMaskedColumn only maths once not twice lul --- src/r_segs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 6dd66e40f..219b142e0 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -634,12 +634,15 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) // Loop through R_DrawMaskedColumn calls static void R_DrawRepeatMaskedColumn(column_t *col) { - while (sprtopscreen < sprbotscreen) { + INT64 z; + while (sprtopscreen < sprbotscreen) + { R_DrawMaskedColumn(col); - if (sprtopscreen + (INT64)dc_texheight*spryscale > (INT64)INT32_MAX) // prevent overflow + z = sprtopscreen + (INT64)dc_texheight*spryscale; + if (z > (INT64)INT32_MAX) // prevent overflow sprtopscreen = INT32_MAX; else - sprtopscreen += dc_texheight*spryscale; + sprtopscreen = z; } } From 518ac3ca280d24287a5c613c054efe03ee40d86c Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 25 May 2024 14:43:52 +0200 Subject: [PATCH 06/15] Turn of FBO downsampling when you turn off screen textures fbo downsampling needs those and if theyre disabled youre essentially seeing nothing at all lol --- src/hardware/hw_main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index afddd9365..24dd67a97 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -185,7 +185,12 @@ static void CV_screentextures_ONChange(void) { ONLY_IF_GL_LOADED if (cv_grscreentextures.value != 3) + { +#ifdef USE_FBO_OGL + CV_Set(&cv_grframebuffer, "Off"); +#endif CV_Set(&cv_grpaletterendering, "Off"); + } HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_grscreentextures.value); } From 8774b14fdf6645ead740befc08063b8343a8b3ba Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 25 May 2024 14:52:58 +0200 Subject: [PATCH 07/15] move some cvars to be registerrerd latur in ogl --- src/hardware/hw_main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 24dd67a97..0a922bbf3 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5995,9 +5995,6 @@ void HWR_TogglePaletteRendering(void) //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { -#ifdef USE_FBO_OGL - CV_RegisterVar(&cv_grframebuffer); -#endif CV_RegisterVar(&cv_grfiltermode); CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grsolvetjoin); @@ -6007,9 +6004,7 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_fofzfightfix); CV_RegisterVar(&cv_splitwallfix); CV_RegisterVar(&cv_slopepegfix); - - CV_RegisterVar(&cv_grscreentextures); - + CV_RegisterVar(&cv_grrenderdistance); CV_RegisterVar(&cv_grfakecontrast); @@ -6037,6 +6032,12 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grpaletterendering); CV_RegisterVar(&cv_grpalettedepth); CV_RegisterVar(&cv_grflashpal); + +#ifdef USE_FBO_OGL + CV_RegisterVar(&cv_grframebuffer); +#endif + + CV_RegisterVar(&cv_grscreentextures); } // -------------------------------------------------------------------------- From ddddc7a89804e3c3fe1cf2732ff3d2bacc63a9d5 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 00:52:09 +0200 Subject: [PATCH 08/15] draw a black screen instead of "nothing" during wipes on disabled screentextures should resolve the intense flashing that can occur --- src/hardware/hw_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 0a922bbf3..d2a5b8189 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6247,6 +6247,12 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) lumpnum_t lumpnum; size_t lsize; + if (cv_grscreentextures.value == 0) + { + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // just draw a black screen instead of flashing and crap + return; + } + if (wipenum > 99 || scrnnum > 99) // not a valid wipe number return; // shouldn't end up here really, the loop should've stopped running beforehand From 67aa71170fea7b5a7f006a589b02b5cb4bf8bce2 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 00:52:40 +0200 Subject: [PATCH 09/15] when not using screentextures draw kart bg on intermission screen --- src/hardware/hw_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d2a5b8189..fc137c109 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6238,7 +6238,12 @@ void HWR_EndScreenWipe(void) void HWR_DrawIntermissionBG(void) { - HWD.pfnDrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); + patch_t *bgpatch = W_CachePatchName("SRB2BACK", PU_CACHE); + + if (cv_grscreentextures.value != 3) + V_DrawPatchFill(bgpatch); // use the neato kart bg for intermission on disabled screen textures + else + HWD.pfnDrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); } void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) From 4847e4e3cb19a60c9b38a0e5bb2ad880e199f4c3 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 22:22:48 +0200 Subject: [PATCH 10/15] that should be there lul --- src/r_things.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_things.c b/src/r_things.c index dfe05dbdf..183b6b93e 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2029,6 +2029,7 @@ void R_AddPrecipitationSprites(void) INT32 xl, xh, yl, yh, bx, by; precipmobj_t *th, *next; + // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off if (drawdist == 0) { return; @@ -2036,7 +2037,6 @@ void R_AddPrecipitationSprites(void) R_GetRenderBlockMapDimensions(drawdist, &xl, &xh, &yl, &yh); - // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off for (bx = xl; bx <= xh; bx++) { for (by = yl; by <= yh; by++) From 455bbe47c283620d182e264b24931e814fcc7cc9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 22:38:20 +0200 Subject: [PATCH 11/15] smth smth encore magic numbers idk --- src/hardware/hw_cache.c | 8 +++++--- src/hardware/hw_main.c | 4 ++-- src/r_draw8.c | 4 ++-- src/r_main.h | 3 +++ src/r_plane.c | 4 ++-- src/r_segs.c | 16 ++++++++-------- src/r_things.c | 4 ++-- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 848f8243f..2a5ec4ff5 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -26,6 +26,7 @@ #include "../z_zone.h" #include "../v_video.h" #include "../r_draw.h" +#include "../r_main.h" #include "../r_patch.h" // patch rotation INT32 patchformat = GL_TEXFMT_AP_88; // use alpha for holes @@ -344,7 +345,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex, boolean noe #ifdef GLENCORE if (encoremap && !noencore) - grtex->mipmap.colormap += (256*32); + grtex->mipmap.colormap += COLORMAP_REMAPOFFSET; #endif blockwidth = texture->width; @@ -647,7 +648,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) #ifdef GLENCORE if (!noencoremap && encoremap) - grmip->colormap += (256*32); + grmip->colormap += COLORMAP_REMAPOFFSET; #endif if (!grmip->downloaded && !grmip->data) @@ -729,7 +730,8 @@ void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap) { GLMipmap_t *grmip, *newmip; - if (colormap == colormaps || colormap == NULL) + // Blatant hack for encore colormapping aside... + if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET)) { // Load the default (green) color in doom cache (temporary?) AND hardware cache HWR_GetPatch(gpatch); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index fc137c109..4893bd5f3 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5285,7 +5285,7 @@ void HWR_ProjectSprite(mobj_t *thing) vis->colormap = colormaps; #ifdef GLENCORE if (encoremap && !(thing->flags & MF_DONTENCOREMAP)) - vis->colormap += (256*32); + vis->colormap += COLORMAP_REMAPOFFSET; #endif } @@ -5416,7 +5416,7 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) #ifdef GLENCORE if (encoremap && !(thing->flags & MF_DONTENCOREMAP)) - vis->colormap += (256*32); + vis->colormap += COLORMAP_REMAPOFFSET; #endif // set top/bottom coords diff --git a/src/r_draw8.c b/src/r_draw8.c index 93a0796a3..f3ebf0ff9 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -1696,7 +1696,7 @@ void R_DrawColumnShadowed_8(void) { dc_colormap = dc_lightlist[i].rcolormap; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (solid && dc_yl < bheight) dc_yl = bheight; continue; @@ -1714,7 +1714,7 @@ void R_DrawColumnShadowed_8(void) dc_colormap = dc_lightlist[i].rcolormap; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } dc_yh = realyh; if (dc_yl <= realyh) diff --git a/src/r_main.h b/src/r_main.h index 56e351138..7c2249873 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -64,6 +64,9 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // There a 0-31, i.e. 32 LUT in the COLORMAP lump. #define NUMCOLORMAPS 32 +#define COLORMAP_SIZE (256*LIGHTLEVELS) +#define COLORMAP_REMAPOFFSET COLORMAP_SIZE + // Utility functions. INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *node); INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line); diff --git a/src/r_plane.c b/src/r_plane.c index f89e10330..6bd6f212d 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -295,7 +295,7 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2) ds_colormap = planezlight[pindex]; } if (encoremap && !currentplane->noencore) - ds_colormap += (256*32); + ds_colormap += COLORMAP_REMAPOFFSET; if (currentplane->extra_colormap) ds_colormap = currentplane->extra_colormap->colormap + (ds_colormap - colormaps); @@ -675,7 +675,7 @@ static void R_DrawSkyPlane(visplane_t *pl) // by INVUL inverse mapping. dc_colormap = colormaps; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_texturemid = skytexturemid; dc_texheight = textureheight[skytexture] >>FRACBITS; diff --git a/src/r_segs.c b/src/r_segs.c index 219b142e0..4a231938b 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -208,7 +208,7 @@ static void R_DrawWallSplats(void) pindex = MAXLIGHTSCALE - 1; dc_colormap = walllights[pindex]; if (encoremap && !(seg->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (frontsector->extra_colormap) dc_colormap = frontsector->extra_colormap->colormap + (dc_colormap - colormaps); @@ -573,7 +573,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) { dc_colormap = rlight->rcolormap; if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; continue; } @@ -594,7 +594,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) windowtop = windowbottom + 1; dc_colormap = rlight->rcolormap; if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } windowbottom = realbot; if (windowtop < windowbottom) @@ -612,7 +612,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) dc_colormap = walllights[pindex]; if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (frontsector->extra_colormap) dc_colormap = frontsector->extra_colormap->colormap + (dc_colormap - colormaps); @@ -1107,7 +1107,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { dc_colormap = rlight->rcolormap; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } if (solid && windowtop < bheight) windowtop = bheight; @@ -1139,7 +1139,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { dc_colormap = rlight->rcolormap; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } } windowbottom = sprbotscreen; @@ -1160,7 +1160,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) dc_colormap = walllights[pindex]; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (pfloor->flags & FF_FOG && pfloor->master->frontsector->extra_colormap) dc_colormap = pfloor->master->frontsector->extra_colormap->colormap + (dc_colormap - colormaps); @@ -1396,7 +1396,7 @@ static void R_RenderSegLoop (void) dc_colormap = walllights[pindex]; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_x = rw_x; dc_iscale = 0xffffffffu / (unsigned)rw_scale; diff --git a/src/r_things.c b/src/r_things.c index 183b6b93e..933181ce7 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -816,7 +816,7 @@ static void R_DrawVisSprite(vissprite_t *vis) dc_colormap = colormaps; if (encoremap && !vis->mobj->color && !(vis->mobj->flags & MF_DONTENCOREMAP)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_texturemid = vis->texturemid; dc_texheight = 0; @@ -939,7 +939,7 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) dc_colormap = colormaps; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_iscale = FixedDiv(FRACUNIT, vis->scale); dc_texturemid = vis->texturemid; From 37d3e2ae1a679f437c6333d7b58074d9e84801d1 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 20:02:54 +0200 Subject: [PATCH 12/15] scale sprite draw distance with mapobjscale --- src/hardware/hw_main.c | 8 ++++---- src/r_things.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 4893bd5f3..750b245fc 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4795,12 +4795,12 @@ void HWR_AddSprites(sector_t *sec) { // Use the smaller setting if (cv_drawdist.value) - limit_dist = min(current_bsp_culling_distance, cv_drawdist.value << FRACBITS); + limit_dist = min(current_bsp_culling_distance, (fixed_t)(cv_drawdist.value) * mapobjectscale); else limit_dist = current_bsp_culling_distance; } else - limit_dist = cv_drawdist.value << FRACBITS; + limit_dist = (fixed_t)(cv_drawdist.value) * mapobjectscale; // Handle all things in sector. // If a limit exists, handle things a tiny bit different. @@ -4903,9 +4903,9 @@ static void HWR_AddPrecipitationSprites(void) precipmobj_t *th; if (current_bsp_culling_distance) - drawdist = min(current_bsp_culling_distance, cv_drawdist_precip.value * mapobjectscale); + drawdist = min(current_bsp_culling_distance, (fixed_t)(cv_drawdist_precip.value) * mapobjectscale); else - drawdist = cv_drawdist_precip.value * mapobjectscale; + drawdist = (fixed_t)(cv_drawdist_precip.value) * mapobjectscale; // No to infinite precipitation draw distance. if (drawdist == 0) diff --git a/src/r_things.c b/src/r_things.c index 933181ce7..64468ffa9 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1932,7 +1932,7 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) // Handle all things in sector. // If a limit exists, handle things a tiny bit different. - if ((limit_dist = (fixed_t)(/*(maptol & TOL_NIGHTS) ? cv_drawdist_nights.value : */cv_drawdist.value) << FRACBITS)) + if ((limit_dist = (fixed_t)(cv_drawdist.value) * mapobjectscale)) { for (thing = sec->thinglist; thing; thing = thing->snext) { @@ -2024,7 +2024,7 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) // void R_AddPrecipitationSprites(void) { - const fixed_t drawdist = cv_drawdist_precip.value * mapobjectscale; + const fixed_t drawdist = (fixed_t)(cv_drawdist_precip.value) * mapobjectscale; INT32 xl, xh, yl, yh, bx, by; precipmobj_t *th, *next; From faa5dbd0e73057bb19cacfa7daa3a18d86f260ee Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 20:55:03 +0200 Subject: [PATCH 13/15] split sprite draw loops so crap doesent constantly check for papersprites on all sprites --- src/r_things.c | 61 ++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 64468ffa9..1ea932ac3 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -724,9 +724,7 @@ static void R_DrawFlippedMaskedColumn(column_t *column, INT32 texheight) static void R_DrawVisSprite(vissprite_t *vis) { column_t *column; -#ifdef RANGECHECK INT32 texturecolumn; -#endif fixed_t frac; patch_t *patch = vis->patch; fixed_t this_scale = vis->thingscale; @@ -874,12 +872,16 @@ static void R_DrawVisSprite(vissprite_t *vis) } #endif - for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) +#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) + + // Split drawing loops for paper and non-paper to reduce conditional checks per sprite + if (vis->scalestep) { fixed_t scalestep = FixedMul(vis->scalestep, vis->spriteyscale); - if (vis->scalestep) // currently papersprites only - { + // Papersprite drawing loop + for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) + { #ifndef RANGECHECK if ((frac>>FRACBITS) < 0 || (frac>>FRACBITS) >= SHORT(patch->width)) // if this doesn't work i'm removing papersprites break; @@ -887,22 +889,30 @@ static void R_DrawVisSprite(vissprite_t *vis) sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale)); dc_iscale = (0xffffffffu / (unsigned)spryscale); spryscale += scalestep; + + texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); + column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); + + if (vis->vflip) + R_DrawFlippedMaskedColumn(column, patch->height); + else + R_DrawMaskedColumn(column); } -#ifdef RANGECHECK - texturecolumn = frac>>FRACBITS; - - if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width)) - I_Error("R_DrawSpriteRange: bad texturecolumn"); - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); -#else - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[frac>>FRACBITS])); -#endif - if (vis->vflip) - R_DrawFlippedMaskedColumn(column, patch->height); - else - R_DrawMaskedColumn(column); } + else + { + for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) + { + texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); + column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); + if (vis->vflip) + R_DrawFlippedMaskedColumn(column, patch->height); + else + R_DrawMaskedColumn(column); + } + } +#undef CLAMP colfunc = basecolfunc; dc_hires = 0; @@ -914,9 +924,7 @@ static void R_DrawVisSprite(vissprite_t *vis) static void R_DrawPrecipitationVisSprite(vissprite_t *vis) { column_t *column; -#ifdef RANGECHECK INT32 texturecolumn; -#endif fixed_t frac; patch_t *patch; INT64 overflow_test; @@ -956,20 +964,15 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) if (vis->x2 >= vid.width) vis->x2 = vid.width-1; +#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) { -#ifdef RANGECHECK - texturecolumn = frac>>FRACBITS; - - if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width)) - I_Error("R_DrawPrecipitationSpriteRange: bad texturecolumn"); - + texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); -#else - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[frac>>FRACBITS])); -#endif + R_DrawMaskedColumn(column); } +#undef CLAMP colfunc = basecolfunc; } From 040ddb1f40b17c84427c95a241a102c0e8f633bb Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 30 May 2024 19:23:14 +0300 Subject: [PATCH 14/15] Revert "Revert "Don't traverse the entire HOME directory to find wads"" This reverts commit 443905ffb3dd8904c395c9c50570ccc17b42dd27. --- src/sdl/i_system.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 9574d6ec5..48e513afc 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -4039,12 +4039,16 @@ static const char *locateWad(void) #endif #ifndef NOHOME // find in $HOME - I_OutputMsg(",HOME"); + I_OutputMsg(",HOME/" DEFAULTDIR); if ((envstr = I_GetEnv("HOME")) != NULL) { + char *tmp = malloc(strlen(envstr) + sizeof(DEFAULTDIR)); + strcpy(tmp, envstr); + strcat(tmp, DEFAULTDIR); WadPath = searchWad(envstr); if (WadPath) return WadPath; + free(tmp); } #endif #ifdef DEFAULTSEARCHPATH1 From 6269c7c827feed85ef1bb246b4bed51c565bc6d5 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 30 May 2024 19:32:18 +0300 Subject: [PATCH 15/15] Use tmp variable for searchWad since envstr doesn't get changed --- src/sdl/i_system.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 48e513afc..7a5f79f58 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -4042,13 +4042,14 @@ static const char *locateWad(void) I_OutputMsg(",HOME/" DEFAULTDIR); if ((envstr = I_GetEnv("HOME")) != NULL) { - char *tmp = malloc(strlen(envstr) + sizeof(DEFAULTDIR)); + char *tmp = malloc(strlen(envstr) + sizeof(PATHSEP) + sizeof(DEFAULTDIR)); strcpy(tmp, envstr); + strcat(tmp, PATHSEP); strcat(tmp, DEFAULTDIR); - WadPath = searchWad(envstr); + WadPath = searchWad(tmp); + free(tmp); if (WadPath) return WadPath; - free(tmp); } #endif #ifdef DEFAULTSEARCHPATH1