From 821c061f82929b041c11bb3abd55067308c3b072 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 17 Nov 2025 20:07:04 +0100 Subject: [PATCH 01/28] Optimize: Use doomednum lookup also when (re)spawning mapthings not just for loading savegame thinkers Actually even provides slight runtime performance improvement, but mostly makes levelload faster --- src/p_local.h | 3 +++ src/p_mobj.c | 71 ++++++++++++++++++++++++++++----------------------- src/p_saveg.c | 19 -------------- src/p_setup.c | 4 +++ 4 files changed, 46 insertions(+), 51 deletions(-) diff --git a/src/p_local.h b/src/p_local.h index 4d8e8032d..4b6530eb9 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -272,6 +272,9 @@ extern consvar_t cv_gravity; void P_RespawnSpecials(void); +extern mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; +void CalculateDoomednumToMobjtype(void); + mobj_t *P_AllocateMobj(void); mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type); diff --git a/src/p_mobj.c b/src/p_mobj.c index fcc70ec8b..e59d087d8 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10448,6 +10448,21 @@ void P_PrecipitationEffects(void) } } +mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; + +void CalculateDoomednumToMobjtype(void) +{ + memset(g_doomednum_to_mobjtype, MT_NULL, sizeof(g_doomednum_to_mobjtype)); + + for (size_t i = MT_NULL+1; i < NUMMOBJTYPES; i++) + { + if (mobjinfo[i].doomednum > 0 && mobjinfo[i].doomednum <= UINT16_MAX) + { + g_doomednum_to_mobjtype[ mobjinfo[i].doomednum ] = i; + } + } +} + // // P_RespawnSpecials // @@ -10527,11 +10542,9 @@ void P_RespawnSpecials(void) ss = R_PointInSubsector(x, y); // find which type to spawn - for (i = 0; i < NUMMOBJTYPES; i++) - if (mthing->type == mobjinfo[i].doomednum) - break; + i = g_doomednum_to_mobjtype[mthing->type]; - if (i == NUMMOBJTYPES) // prevent creation of objects with this type -- Monster Iestyn 17/12/17 + if (i <= MT_NULL || i >= NUMMOBJTYPES) // prevent creation of objects with this type -- Monster Iestyn 17/12/17 { // 3D Mode start Thing is unlikely to be added to the que, // so don't bother checking for that specific type @@ -10972,11 +10985,9 @@ void P_SpawnMapThing(mapthing_t *mthing) if (objectplacing) { // find which type to spawn - for (i = 0; i < NUMMOBJTYPES; i++) - if (mthing->type == mobjinfo[i].doomednum) - break; + i = g_doomednum_to_mobjtype[mthing->type]; - if (i == NUMMOBJTYPES) + if (i <= MT_NULL || i >= NUMMOBJTYPES) { if (mthing->type == 3328) // 3D Mode start Thing return; @@ -11044,13 +11055,9 @@ void P_SpawnMapThing(mapthing_t *mthing) } // find which type to spawn - for (i = 0; i < NUMMOBJTYPES; i++) - { - if (mthing->type == mobjinfo[i].doomednum) - break; - } + i = g_doomednum_to_mobjtype[mthing->type]; - if (i == NUMMOBJTYPES) + if (i <= MT_NULL || i >= NUMMOBJTYPES) { if (mthing->type == 3328) // 3D Mode start Thing return; @@ -11743,32 +11750,32 @@ ML_NOCLIMB : Direction not controllable if (mobj->flags & MF_MONITOR) { // flag for strong/weak random boxes - if (mthing->type == mobjinfo[MT_SUPERRINGBOX].doomednum || mthing->type == mobjinfo[MT_PRUP].doomednum || - mthing->type == mobjinfo[MT_SNEAKERTV].doomednum || mthing->type == mobjinfo[MT_INV].doomednum || - mthing->type == mobjinfo[MT_WHITETV].doomednum || mthing->type == mobjinfo[MT_GREENTV].doomednum || - mthing->type == mobjinfo[MT_YELLOWTV].doomednum || mthing->type == mobjinfo[MT_BLUETV].doomednum || - mthing->type == mobjinfo[MT_BLACKTV].doomednum || mthing->type == mobjinfo[MT_PITYTV].doomednum || - mthing->type == mobjinfo[MT_RECYCLETV].doomednum || mthing->type == mobjinfo[MT_MIXUPBOX].doomednum) + if (i == MT_SUPERRINGBOX || i == MT_PRUP || + i == MT_SNEAKERTV || i == MT_INV || + i == MT_WHITETV || i == MT_GREENTV || + i == MT_YELLOWTV || i == MT_BLUETV || + i == MT_BLACKTV || i == MT_PITYTV || + i == MT_RECYCLETV || i == MT_MIXUPBOX) mobj->flags2 |= MF2_AMBUSH; } - - else if (mthing->type != mobjinfo[MT_AXIS].doomednum && - mthing->type != mobjinfo[MT_AXISTRANSFER].doomednum && - mthing->type != mobjinfo[MT_AXISTRANSFERLINE].doomednum && - mthing->type != mobjinfo[MT_NIGHTSBUMPER].doomednum && - mthing->type != mobjinfo[MT_STARPOST].doomednum) + else if ( + i != MT_AXIS && + i != MT_AXISTRANSFER && + i != MT_AXISTRANSFERLINE && + i != MT_NIGHTSBUMPER && + i != MT_STARPOST) mobj->flags2 |= MF2_AMBUSH; } if (mthing->options & MTF_OBJECTSPECIAL) { // flag for strong/weak random boxes - if (mthing->type == mobjinfo[MT_SUPERRINGBOX].doomednum || mthing->type == mobjinfo[MT_PRUP].doomednum || - mthing->type == mobjinfo[MT_SNEAKERTV].doomednum || mthing->type == mobjinfo[MT_INV].doomednum || - mthing->type == mobjinfo[MT_WHITETV].doomednum || mthing->type == mobjinfo[MT_GREENTV].doomednum || - mthing->type == mobjinfo[MT_YELLOWTV].doomednum || mthing->type == mobjinfo[MT_BLUETV].doomednum || - mthing->type == mobjinfo[MT_BLACKTV].doomednum || mthing->type == mobjinfo[MT_PITYTV].doomednum || - mthing->type == mobjinfo[MT_RECYCLETV].doomednum || mthing->type == mobjinfo[MT_MIXUPBOX].doomednum) + if (i == MT_SUPERRINGBOX || i == MT_PRUP || + i == MT_SNEAKERTV || i == MT_INV || + i == MT_WHITETV || i == MT_GREENTV || + i == MT_YELLOWTV || i == MT_BLUETV || + i == MT_BLACKTV || i == MT_PITYTV || + i == MT_RECYCLETV || i == MT_MIXUPBOX) mobj->flags2 |= MF2_STRONGBOX; // Requires you to be in bonus time to activate diff --git a/src/p_saveg.c b/src/p_saveg.c index 0dcac2083..64686dfd4 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1965,21 +1965,6 @@ FUNCINLINE static ATTRINLINE player_t *LoadPlayer(UINT32 player) // Loads a mobj_t from a save game // -static mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; - -static void CalculateDoomednumToMobjtype(void) -{ - memset(g_doomednum_to_mobjtype, MT_NULL, sizeof(g_doomednum_to_mobjtype)); - - for (size_t i = MT_NULL+1; i < NUMMOBJTYPES; i++) - { - if (mobjinfo[i].doomednum > 0 && mobjinfo[i].doomednum <= UINT16_MAX) - { - g_doomednum_to_mobjtype[ mobjinfo[i].doomednum ] = i; - } - } -} - static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) { mobj_t *mobj; @@ -2879,10 +2864,6 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) if (READUINT32(save->p) != ARCHIVEBLOCK_THINKERS) I_Error("Bad $$$.sav at archive block Thinkers"); - // Pre-calculate this lookup, because it was wasting - // a shit ton of time loading mobj thinkers. - CalculateDoomednumToMobjtype(); - // remove all the current thinkers for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = next) { diff --git a/src/p_setup.c b/src/p_setup.c index 2993bb5d2..5b4c2796b 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2863,6 +2863,10 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) P_ResetDynamicSlopes(); + // Pre-calculate this lookup, because it was wasting + // a shit ton of time loading mobj thinkers. + CalculateDoomednumToMobjtype(); + P_SpawnMapThings(); P_SpawnEmblems(!fromnetsave); From 59ff5e61bf320b4dfd3e62c30853c085c5181613 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Dec 2025 19:13:07 +0100 Subject: [PATCH 02/28] Revert "Fix use-after-free when mobj is removed while still playing sounds" This reverts commit 3bdc745bd15f5742c41f560c5f7c397bc5ca8a7a. --- src/p_setup.c | 2 -- src/s_sound.c | 7 +------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 5b4c2796b..bf40afe9d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -812,8 +812,6 @@ static void P_LoadSectors(UINT8 *data) ss->tag = SHORT(ms->tag); ss->flags |= SF_FLIPSPECIAL_FLOOR; - - ss->soundorg.thinker.function = (actionf_p1)P_MobjThinker; } // set the sky flat num diff --git a/src/s_sound.c b/src/s_sound.c index 651d579b8..5bc830252 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -772,14 +772,9 @@ void S_UpdateSounds(void) volume = c->volume; // 8 bits internal volume precision sep = NORM_SEP; - if (P_MobjWasRemoved(c->origin)) - { - // origin was removed, stop the music - S_StopChannel(cnum); - } // check non-local sounds for distance clipping // or modify their params - else + if (c->origin) { boolean itsUs = false; From 9a58eb3010a99370569240bcd519a94364b65b99 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Dec 2025 14:10:28 +0100 Subject: [PATCH 03/28] G_BuildLocalTiccmd: remove "moveinput" variable checking both cmd->buttons aswell as cmd->driftturn already handles those cases --- src/g_game.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index b76c1290a..5d48a62b5 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -800,6 +800,10 @@ static fixed_t forwardmove[2] = {25<>16, 50<>16}; static fixed_t sidemove[2] = {2<>16, 4<>16}; static fixed_t angleturn[3] = {KART_FULLTURN/2, KART_FULLTURN, KART_FULLTURN/4}; // + slow turn +// +// G_HandleLocalDriftturn +// Hack for Lua menus that check directional inputs with driftturn +// static void G_HandleLocalDriftturn(ticcmd_t *cmd, UINT8 ssplayer) { INT32 axis = 0; @@ -862,9 +866,8 @@ static void G_HandleLocalDriftturn(ticcmd_t *cmd, UINT8 ssplayer) // static void G_BuildLocalTiccmd(ticcmd_t *cmd, UINT8 ssplayer, boolean freecam) { - boolean moveinput = false; INT32 axis = 0; - const boolean usejoystick = (cv_usejoystick[(ssplayer-1)].value); + const boolean usejoystick = cv_usejoystick[(ssplayer-1)].value; // check for inputs and return button commands // for stuff like joining with item button, saltyhop, honking, etc. @@ -899,15 +902,11 @@ static void G_BuildLocalTiccmd(ticcmd_t *cmd, UINT8 ssplayer, boolean freecam) #undef CHECKINPUT - moveinput = (InputDown(gc_turnleft, ssplayer) || InputDown(gc_turnright, ssplayer) - || InputDown(gc_aimforward, ssplayer) || InputDown(gc_aimbackward, ssplayer) || - (usejoystick && JoyAxis(AXISAIM, ssplayer) != 0) || (usejoystick && JoyAxis(AXISTURN, ssplayer) != 0)); - axis = JoyAxis(AXISLOOKBACK, ssplayer); camspin[ssplayer-1] = (InputDown(gc_lookback, ssplayer) || (usejoystick && axis > 0)); // Reset to our spec player if we watch someone else. - if ((moveinput || cmd->buttons) + if ((cmd->driftturn || cmd->buttons) && displayplayers[0] != consoleplayer && ssplayer == 1) { if (cv_director.value) From 4ee468f5c6667c0a7d19b744bdf2bc4a46b7282a Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Dec 2025 14:26:49 +0100 Subject: [PATCH 04/28] Accessability: Add "Auto Acceleration" feature ported from hostmod --- src/d_netcmd.c | 2 ++ src/g_game.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++- src/g_game.h | 2 ++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 8fca12794..870ceba69 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -997,6 +997,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_litesteer[i]); + CV_RegisterVar(&cv_autoaccel[i]); + CV_RegisterVar(&cv_usejoystick[i]); CV_RegisterVar(&cv_joyscale[i]); CV_RegisterVar(&cv_rumble[i]); diff --git a/src/g_game.c b/src/g_game.c index 5d48a62b5..2d2a49461 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -454,6 +454,14 @@ consvar_t cv_litesteer[MAXSPLITSCREENPLAYERS] = { {"litesteer4", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL} }; +//static CV_PossibleValue_t autoaccelcons_t[] = {{0, "Off"}, {1, "Manual"}, {2, "Automatic"}, {0, NULL}}; +consvar_t cv_autoaccel[MAXSPLITSCREENPLAYERS] = { + {"autoaccel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"autoaccel2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"autoaccel3", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"autoaccel4", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL} +}; + static CV_PossibleValue_t driftsparkpulse_t[] = {{0, "MIN"}, {FRACUNIT*3, "MAX"}, {0, NULL}}; consvar_t cv_driftsparkpulse = {"driftsparkpulse", "1.4", CV_FLOAT | CV_SAVE, driftsparkpulse_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -918,6 +926,63 @@ static void G_BuildLocalTiccmd(ticcmd_t *cmd, UINT8 ssplayer, boolean freecam) } } +// +// G_HandleAutoAcceleration +// +static void G_HandleAutoAcceleration(ticcmd_t *cmd, player_t *player, UINT8 forplayer) +{ + if (!cv_autoaccel[forplayer].value) + return; + + if (gamestate != GS_LEVEL) + return; + + // dont accel before and during countdown + if (leveltime <= starttime) + return; + + // dont do this in menus or when console is onscreen + if (menuactive || CON_Ready()) + return; + + // gotta have a player that aint respawning + if (!player->mo || player->kartstuff[k_respawn]) + return; + + // dont need for "finished" players + if (player->exiting || (player->pflags & PF_TIMEOVER)) + return; + + // dont do during spinout + if (player->kartstuff[k_spinouttimer]) + return; + + // spectators and freecam dont need special handling, see G_BuildTiccmd + + if (cmd->buttons & BT_BRAKE) + { + if (cmd->buttons & BT_DRIFT || + player->kartstuff[k_sneakertimer] || + player->kartstuff[k_squishedtimer]) + { + cmd->forwardmove = (SINT8)forwardmove[0]; + cmd->buttons |= BT_ACCELERATE; + } + else + { + // allows us to drive backwards if we need to + if (cmd->forwardmove > 0) + cmd->forwardmove = 0; + cmd->buttons &= ~BT_ACCELERATE; + } + } + else + { + cmd->forwardmove = (SINT8)forwardmove[1]; + cmd->buttons |= BT_ACCELERATE; + } +} + // // G_BuildTiccmd // Builds a ticcmd from all of the available inputs @@ -1065,7 +1130,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) if (InputDown(gc_accelerate, ssplayer) || (gamepadjoystickmove && axis > 0) || player->kartstuff[k_sneakertimer]) { cmd->buttons |= BT_ACCELERATE; - forward = forwardmove[1]; // 50 + forward = forwardmove[1]; // 50 } else if (analogjoystickmove && axis > 0) { @@ -1146,6 +1211,8 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) cmd->sidemove = (SINT8)(cmd->sidemove + side); } + G_HandleAutoAcceleration(cmd, player, forplayer); + //{ SRB2kart - Drift support // Not grouped with the rest of turn stuff because it needs to know what buttons you're pressing for rubber-burn turn // limit turning to angleturn[1] to stop mouselook letting you look too fast diff --git a/src/g_game.h b/src/g_game.h index c3b89435d..509749c5f 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -74,6 +74,8 @@ extern consvar_t cv_ydeadzone[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_litesteer[MAXSPLITSCREENPLAYERS]; +extern consvar_t cv_autoaccel[MAXSPLITSCREENPLAYERS]; + extern consvar_t cv_ghost_besttime, cv_ghost_bestlap, cv_ghost_last, cv_ghost_guest, cv_ghost_staff; // Hud offsets From 4cea0c1414456af1383f861adbfc380683cb6097 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Dec 2025 16:43:59 +0300 Subject: [PATCH 05/28] Add autoaccel into accessibility menu --- src/m_menudefs.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/m_menudefs.c b/src/m_menudefs.c index 3d8d9549a..60af918dc 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -1652,6 +1652,13 @@ static menuitem_t OP_AccessibilityMenu[] = {IT_STRING|IT_CVAR, NULL, "Reverse L/R Channels", &stereoreverse, 85}, {IT_STRING|IT_CVAR, NULL, "Same Sound Limit", &cv_samesoundlimit, 90}, + + {IT_HEADER, NULL, "Controls", NULL, 100}, + + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P1)", &cv_autoaccel[0], 110}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P2)", &cv_autoaccel[1], 115}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P3)", &cv_autoaccel[2], 120}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P4)", &cv_autoaccel[3], 125}, }; static const char* OP_AccessibilityTooltips[] = @@ -1673,6 +1680,11 @@ static const char* OP_AccessibilityTooltips[] = NULL, "Reverse left and right channels of audio.", "Change how often the same Sound is allowed to play at once.", + NULL, + "Automatically hold acceleration button (Player 1).", + "Automatically hold acceleration button (Player 2).", + "Automatically hold acceleration button (Player 3).", + "Automatically hold acceleration button (Player 4).", }; static menuitem_t OP_SaturnMenu[] = From 44ba69cf539c3a3361e017d22fbf0d8686a218a4 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Dec 2025 17:35:35 +0300 Subject: [PATCH 06/28] Move lite steer and turn smoothing cvars into individual player controls menu --- src/m_menu.c | 59 +++++++++++++++++++++++++++++++++++------------- src/m_menu.h | 4 ++-- src/m_menudefs.c | 40 ++++++++++++++++---------------- 3 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index bfe2372bf..deeb74e0c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9358,29 +9358,32 @@ static void M_SetupControlsMenu(UINT8 pnum) break; } + OP_AllControlsMenu[2].itemaction = &cv_litesteer[pnum]; + OP_AllControlsMenu[3].itemaction = &cv_turnsmooth[pnum]; + if (pnum > 0) { // Hide P1-only controls - OP_AllControlsMenu[15].status = IT_GRAYEDOUT2; // Chat - OP_AllControlsMenu[16].status = IT_GRAYEDOUT2; // Rankings - OP_AllControlsMenu[17].status = IT_GRAYEDOUT2; // Pause - OP_AllControlsMenu[18].status = IT_GRAYEDOUT2; // Screenshot - OP_AllControlsMenu[19].status = IT_GRAYEDOUT2; // GIF - OP_AllControlsMenu[20].status = IT_GRAYEDOUT2; // System Menu - OP_AllControlsMenu[21].status = IT_GRAYEDOUT2; // Console - OP_AllControlsMenu[37].status = IT_GRAYEDOUT2; // Director + OP_AllControlsMenu[19].status = IT_GRAYEDOUT2; // Chat + OP_AllControlsMenu[10].status = IT_GRAYEDOUT2; // Rankings + OP_AllControlsMenu[21].status = IT_GRAYEDOUT2; // Pause + OP_AllControlsMenu[22].status = IT_GRAYEDOUT2; // Screenshot + OP_AllControlsMenu[23].status = IT_GRAYEDOUT2; // GIF + OP_AllControlsMenu[24].status = IT_GRAYEDOUT2; // System Menu + OP_AllControlsMenu[25].status = IT_GRAYEDOUT2; // Console + OP_AllControlsMenu[41].status = IT_GRAYEDOUT2; // Director } else { // Unhide P1-only controls - OP_AllControlsMenu[15].status = IT_CONTROL; // Chat - OP_AllControlsMenu[16].status = IT_CONTROL; // Rankings - OP_AllControlsMenu[17].status = IT_CONTROL; // Pause - OP_AllControlsMenu[18].status = IT_CONTROL; // Screenshot - OP_AllControlsMenu[19].status = IT_CONTROL; // GIF - OP_AllControlsMenu[20].status = IT_CONTROL; // System Menu - OP_AllControlsMenu[21].status = IT_CONTROL; // Console - OP_AllControlsMenu[37].status = IT_CONTROL; // Director + OP_AllControlsMenu[19].status = IT_CONTROL; // Chat + OP_AllControlsMenu[10].status = IT_CONTROL; // Rankings + OP_AllControlsMenu[21].status = IT_CONTROL; // Pause + OP_AllControlsMenu[22].status = IT_CONTROL; // Screenshot + OP_AllControlsMenu[23].status = IT_CONTROL; // GIF + OP_AllControlsMenu[24].status = IT_CONTROL; // System Menu + OP_AllControlsMenu[25].status = IT_CONTROL; // Console + OP_AllControlsMenu[41].status = IT_CONTROL; // Director } M_SetupNextMenu(&OP_AllControlsDef); @@ -9494,12 +9497,36 @@ static void M_DrawControl(void) else if ((currentMenu->menuitems[i].status == IT_HEADER) && (i != max-1)) V_DrawString(19, y+6, highlightflags|V_ALLOWLOWERCASE, currentMenu->menuitems[i].text); else if (currentMenu->menuitems[i].status & IT_STRING) + { V_DrawString(x, y, ((i == itemOn) ? highlightflags|V_ALLOWLOWERCASE : V_ALLOWLOWERCASE), currentMenu->menuitems[i].text); + if (currentMenu->menuitems[i].status & IT_CVAR) + { + consvar_t *cv = (consvar_t *)currentMenu->menuitems[i].itemaction; + + // IT_HEADER matches IT_CVAR, for some reason... + if (cv) + { + INT32 w = V_StringWidth(cv->string, 0); + V_DrawString(BASEVIDWIDTH - x - w, y, + ((cv->flags & CV_CHEAT) && !CV_IsSetToDefault(cv) ? warningflags : highlightflags)|MENUCAPS, cv->string); + if (i == itemOn) + { + V_DrawCharacter(BASEVIDWIDTH - x - 10 - w - (skullAnimCounter/5), y, + '\x1C' | highlightflags, false); // left arrow + V_DrawCharacter(BASEVIDWIDTH - x + 2 + (skullAnimCounter/5), y, + '\x1D' | highlightflags, false); // right arrow + } + } + } + } + y += SMALLLINEHEIGHT; } V_DrawScaledPatch(currentMenu->x - 20, cursory, 0, (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); + + M_DoToolTips(currentMenu); } #undef controlheight diff --git a/src/m_menu.h b/src/m_menu.h index 62f66f177..2b048fe90 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -398,7 +398,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na NULL\ } -#define CONTROLMENUSTYLE(source, prev)\ +#define CONTROLMENUSTYLE(source, prev, tooltip)\ {\ "M_CONTRO",\ sizeof (source)/sizeof (menuitem_t),\ @@ -409,7 +409,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na 26, 40,\ 0,\ NULL,\ - NULL\ + tooltip\ } #define IMAGEDEF(source)\ diff --git a/src/m_menudefs.c b/src/m_menudefs.c index 60af918dc..cbdaac587 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -648,17 +648,6 @@ static menuitem_t OP_ControlsMenu[] = {IT_SUBMENU | IT_STRING, NULL, "Mouse Options...", &OP_MouseOptionsDef, 55}, {IT_STRING | IT_CVAR, NULL, "Controls per key", &cv_controlperkey, 75}, - - {IT_STRING | IT_CVAR, NULL, "Digital turn easing (P1)", &cv_turnsmooth[0], 85}, - {IT_STRING | IT_CVAR, NULL, "Digital turn easing (P2)", &cv_turnsmooth[1], 95}, - {IT_STRING | IT_CVAR, NULL, "Digital turn easing (P3)", &cv_turnsmooth[2], 105}, - {IT_STRING | IT_CVAR, NULL, "Digital turn easing (P4)", &cv_turnsmooth[3], 115}, - - // i hate our menus sincerly - {IT_STRING | IT_CVAR, NULL, "Lite Steer (P1)", &cv_litesteer[0], 135}, - {IT_STRING | IT_CVAR, NULL, "Lite Steer (P2)", &cv_litesteer[1], 145}, - {IT_STRING | IT_CVAR, NULL, "Lite Steer (P3)", &cv_litesteer[2], 155}, - {IT_STRING | IT_CVAR, NULL, "Lite Steer (P4)", &cv_litesteer[3], 165}, }; static const char* OP_ControlsTooltips[] = @@ -669,15 +658,6 @@ static const char* OP_ControlsTooltips[] = "Setup player 4 controls.", "Options for mouse control.", "Allowed amount of controls per key.", - "Turn smoothing for non-analog turning (Player 1).", - "Turn smoothing for non-analog turning (Player 2).", - "Turn smoothing for non-analog turning (Player 3).", - "Turn smoothing for non-analog turning (Player 4).", - - "Hold DOWN on d-pad/keyboard for shallow turns (Player 1).", - "Hold DOWN on d-pad/keyboard for shallow turns (Player 2).", - "Hold DOWN on d-pad/keyboard for shallow turns (Player 3).", - "Hold DOWN on d-pad/keyboard for shallow turns (Player 4).", }; static menuitem_t OP_AllControlsMenu[] = @@ -685,6 +665,13 @@ static menuitem_t OP_AllControlsMenu[] = {IT_SUBMENU|IT_STRING, NULL, "Gamepad Options...", &OP_Joystick1Def, 0}, {IT_CALL|IT_STRING, NULL, "Reset to defaults", M_ResetControls, 8}, + {IT_HEADER, NULL, "Control Options", NULL, 0}, + {IT_SPACE, NULL, NULL, NULL, 0}, + + // Cvars are set in M_SetupControlsMenu + {IT_STRING|IT_CVAR, NULL, "Lite Steer", &cv_litesteer[0], 18}, + {IT_STRING|IT_CVAR, NULL, "Digital turn easing", &cv_turnsmooth[0], 26}, + //{IT_SPACE, NULL, NULL, NULL, 0}, {IT_HEADER, NULL, "Gameplay Controls", NULL, 0}, {IT_SPACE, NULL, NULL, NULL, 0}, @@ -733,6 +720,17 @@ static menuitem_t OP_AllControlsMenu[] = {IT_CONTROL, NULL, "Custom Action 3", M_ChangeControl, gc_custom3 }, }; +// Has to be same length as OP_AllControlsMenu, but otherwise its mostly empty +static const char* OP_AllControlsTooltips[sizeof(OP_AllControlsMenu)/sizeof(OP_AllControlsMenu[0])] = { + NULL, + NULL, + NULL, + NULL, + "Hold DOWN on d-pad/keyboard for shallow turns.", + "Turn smoothing for non-analog turning.", + // The rest is null, for now +}; + #define OP_JOYMENU(pnum) \ {IT_HEADER, NULL, "Gameplay Controls", NULL, 7}, \ {IT_STRING | IT_CVAR, NULL, "Aim Forward/Back" , &cv_aimaxis[pnum] , 15}, \ @@ -2492,7 +2490,7 @@ menu_t OP_MainDef = menu_t OP_ControlsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_ControlsMenu, &OP_MainDef, 40, 15, OP_ControlsTooltips); //WTF menu_t OP_MouseOptionsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_MouseOptionsMenu, &OP_ControlsDef, 60, 30, OP_MouseTooltips); -menu_t OP_AllControlsDef = CONTROLMENUSTYLE(OP_AllControlsMenu, &OP_ControlsDef); +menu_t OP_AllControlsDef = CONTROLMENUSTYLE(OP_AllControlsMenu, &OP_ControlsDef, OP_AllControlsTooltips); menu_t OP_Joystick1Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick1Menu, &OP_AllControlsDef, 30, 36, NULL); menu_t OP_Joystick2Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick2Menu, &OP_AllControlsDef, 30, 36, NULL); menu_t OP_Joystick3Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick3Menu, &OP_AllControlsDef, 30, 36, NULL); From 1c289d73cae3455782ee39a02b55b03461e521a0 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Dec 2025 17:54:03 +0300 Subject: [PATCH 07/28] Oopsie --- src/m_menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index deeb74e0c..3650853bc 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9358,8 +9358,8 @@ static void M_SetupControlsMenu(UINT8 pnum) break; } - OP_AllControlsMenu[2].itemaction = &cv_litesteer[pnum]; - OP_AllControlsMenu[3].itemaction = &cv_turnsmooth[pnum]; + OP_AllControlsMenu[4].itemaction = &cv_litesteer[pnum]; + OP_AllControlsMenu[5].itemaction = &cv_turnsmooth[pnum]; if (pnum > 0) { From 6ad344f65d14eb32c4e52ee855faa03243e700ff Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Dec 2025 18:19:00 +0100 Subject: [PATCH 08/28] findfile: let files added with "-file" look in addon/downloads folders first due to https://github.com/Indev450/SRB2Kart-Saturn/commit/956fc099adcd7f33993c43c8ee3aea64df3fe9b4 IWADS shouldnt use findfile anymore If there should be such case we can always expose the startupiwad count to check if were currently searching for iwads iirc --- src/d_netfil.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index d35bb09b3..57f0f0f6c 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1162,8 +1162,12 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet filestatus_t homecheck; // store result of last file search boolean badmd5 = false; // store whether md5 was bad from either of the first two searches (if nothing was found in the third) - // skip for startup, our mainwads wont be in there - if (loaded_config) + // see IdentifyVersion + // Iwads skip findfile due to passing fullpath to W_OpenWadFile +#if 0 + // skip for Iwads, as they wont be in there + if (!startupiwadcount) +#endif { if (cv_addons_option.value == 3 && *cv_addons_folder.string != '\0') { From 1ccd3e37bcb50157359bbc8644cb4ed898c72636 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Dec 2025 21:37:31 +0300 Subject: [PATCH 09/28] Init playerinfo[i].node to 255 so if playerinfo packet gets lost, server join screen doesn't display empty player names --- src/d_clisrv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 8f2cc5afb..cd04fb3a2 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3475,6 +3475,9 @@ void CL_Reset(void) memset(player_muted, 0, sizeof(player_muted)); + for (INT32 i = 0; i < MAXPLAYERS; ++i) + playerinfo[i].node = 255; + // D_StartTitle should get done now, but the calling function will handle it } @@ -4263,6 +4266,9 @@ void D_ClientServerInit(void) #endif D_LoadBan(false); + for (INT32 i = 0; i < MAXPLAYERS; ++i) + playerinfo[i].node = 255; + gametic = 0; localgametic = 0; From 2c7c9ec32ab91a07a2a413ee69c6c6f24eedfc42 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Dec 2025 20:10:01 +0100 Subject: [PATCH 10/28] fastcmp.h: mark fastcmp functions as pure this might let the compiler optimize aways subsequent calls in some cases strcmp etc from glibc also does it prayin nothin changes the locale at runtime lmao --- src/fastcmp.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fastcmp.h b/src/fastcmp.h index 0f7c24aaa..1b92e42e8 100644 --- a/src/fastcmp.h +++ b/src/fastcmp.h @@ -3,14 +3,14 @@ // returns false if s != c // returns true if s == c -FUNCINLINE static ATTRINLINE boolean fasticmp(const char *s, const char *c) +FUNCINLINE static ATTRINLINE PUREFUNC boolean fasticmp(const char *s, const char *c) { for (; *s && toupper(*s) == toupper(*c); s++, c++) ; return (*s == *c); // make sure both strings ended } // case-sensitive of the above -FUNCINLINE static ATTRINLINE boolean fastcmp(const char *s, const char *c) +FUNCINLINE static ATTRINLINE PUREFUNC boolean fastcmp(const char *s, const char *c) { for (; *s && *s == *c; s++, c++) ; return (*s == *c); // make sure both strings ended @@ -18,7 +18,7 @@ FUNCINLINE static ATTRINLINE boolean fastcmp(const char *s, const char *c) // length-limited of the above // only true if both strings are at least l characters long AND match, case-sensitively! -FUNCINLINE static ATTRINLINE boolean fastncmp(const char *s, const char *c, UINT16 l) +FUNCINLINE static ATTRINLINE PUREFUNC boolean fastncmp(const char *s, const char *c, UINT16 l) { for (; *s && *s == *c && --l; s++, c++) ; return !l; // make sure you reached the end From 3828a9f8e07e7cffaf9fbbe70a28a8f45382f1d3 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Dec 2025 22:58:06 +0300 Subject: [PATCH 11/28] Add flipcammode toggle for using local flipcam settings instead of player flags --- src/m_menudefs.c | 11 +++++++---- src/p_mobj.c | 17 ++++++++++++++++- src/r_main.cpp | 5 +++++ src/r_main.h | 1 + 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/m_menudefs.c b/src/m_menudefs.c index cbdaac587..e6129d2d8 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -1339,16 +1339,19 @@ static menuitem_t OP_CamOptionsMenu[] = {IT_STRING | IT_CVAR | IT_CV_BIGFLOAT, NULL, "Field of View",&cv_fov, 30}, - {IT_STRING | IT_SUBMENU, NULL, "Player 1 Camera options...", &OP_Player1CamOptionsDef, 50}, - {IT_STRING | IT_SUBMENU, NULL, "Player 2 Camera options...", &OP_Player2CamOptionsDef, 60}, - {IT_STRING | IT_SUBMENU, NULL, "Player 3 Camera options...", &OP_Player3CamOptionsDef, 70}, - {IT_STRING | IT_SUBMENU, NULL, "Player 4 Camera options...", &OP_Player4CamOptionsDef, 80}, + {IT_STRING | IT_CVAR, NULL, "Flipcam Mode", &cv_flipcammode, 40}, + + {IT_STRING | IT_SUBMENU, NULL, "Player 1 Camera options...", &OP_Player1CamOptionsDef, 60}, + {IT_STRING | IT_SUBMENU, NULL, "Player 2 Camera options...", &OP_Player2CamOptionsDef, 70}, + {IT_STRING | IT_SUBMENU, NULL, "Player 3 Camera options...", &OP_Player3CamOptionsDef, 80}, + {IT_STRING | IT_SUBMENU, NULL, "Player 4 Camera options...", &OP_Player4CamOptionsDef, 90}, }; static const char* OP_CamOptionsTooltips[] = { NULL, "Player field of view.", + "Change flipcam mode.\nDisplayplayer - use currently viewed player option.\nLocal - use local flipcam toggle option.", NULL, NULL, NULL, diff --git a/src/p_mobj.c b/src/p_mobj.c index e59d087d8..cd7d44a62 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3237,7 +3237,22 @@ void P_DestroyRobots(void) // the below is chasecam only, if you're curious. check out P_CalcPostImg in p_user.c for first person void P_CalcChasePostImg(player_t *player, camera_t *thiscam) { - const boolean flipcam = (player->pflags & PF_FLIPCAM && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP); + boolean player_flipcam = false; + + if (cv_flipcammode.value == 0) + player_flipcam = player->pflags & PF_FLIPCAM; + else + { + INT32 pnum = P_GetLocalPlayerNumForPlayer(player); + + // Shouldn't happen but just in case + if (pnum == -1) + pnum = 0; + + player_flipcam = cv_flipcam[pnum].value; + } + + const boolean flipcam = (player_flipcam && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP); UINT8 postimgtype = 0; if (encoremode) diff --git a/src/r_main.cpp b/src/r_main.cpp index 1ad8e8be9..fecfba580 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -182,6 +182,9 @@ consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS] = { {"flipcam4", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam4_OnChange, 0, NULL, NULL, 0, 0, NULL} }; +static CV_PossibleValue_t flipcammode_cons_t[] = {{0, "Displayplayer"}, {1, "Local"}, {0, NULL}}; +consvar_t cv_flipcammode = {"flipcammode", "Displayplayer", CV_SAVE, flipcammode_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_shadow = {"shadow", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_shadowoffs = {"offsetshadows", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skybox = {"skybox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -1546,6 +1549,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_flipcam[i]); } + CV_RegisterVar(&cv_flipcammode); + // Enough for dedicated server if (dedicated) return; diff --git a/src/r_main.h b/src/r_main.h index 36c8756f8..d33d67606 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -205,6 +205,7 @@ extern consvar_t cv_showhud, cv_translucenthud, cv_uncappedhud; extern consvar_t cv_homremoval; extern consvar_t cv_chasecam[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS]; +extern consvar_t cv_flipcammode; extern consvar_t cv_shadow, cv_shadowoffs; extern consvar_t cv_ffloorclip, cv_spriteclip; extern consvar_t cv_softcyancut; From 6c98440f27f14c26d70c468915feb1d5cbb461e9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 16 Dec 2025 17:52:03 +0100 Subject: [PATCH 12/28] Remove pure attribute from fasticmp While i assume this to be fine currently, i quite frankly dont trust the srb2 codebase enough aswell as preventing any future issues if there should ever be need to switch locales, since toupper WILL change behaviour in such cases which does not qualify as pure --- src/fastcmp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fastcmp.h b/src/fastcmp.h index 1b92e42e8..ea87bee4d 100644 --- a/src/fastcmp.h +++ b/src/fastcmp.h @@ -3,7 +3,7 @@ // returns false if s != c // returns true if s == c -FUNCINLINE static ATTRINLINE PUREFUNC boolean fasticmp(const char *s, const char *c) +FUNCINLINE static ATTRINLINE boolean fasticmp(const char *s, const char *c) { for (; *s && toupper(*s) == toupper(*c); s++, c++) ; return (*s == *c); // make sure both strings ended From 0540b5656a2d95c21011d2617214de18c30b9e81 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 19 Nov 2025 19:10:23 +0100 Subject: [PATCH 13/28] OpenGL: keep around our drawnodes memory no need to constantly reallocate new memory we dont have renderer switch, and the next level will render drawnodes anyways those wont grow super big also, so theres no big worry about wasting tons of memory yes i like ceepeepee vectors, how can you tell --- src/hardware/hw_main.cpp | 51 ++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 9f1a90769..b363069b6 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -14,6 +14,7 @@ #ifdef HWRENDER #include +#include #include "../doomstat.h" #include "../doomdef.h" @@ -4174,6 +4175,7 @@ static int CompareVisSprites(const void *p1, const void *p2) static void HWR_SortVisSprites(void) { UINT32 i; + for (i = 0; i < gl_visspritecount; i++) { gl_vsprorder[i] = HWR_GetVisSprite(i); @@ -4242,38 +4244,29 @@ typedef struct // initial size of drawnode array #define DRAWNODES_INIT_SIZE 64 -gl_drawnode_t *drawnodes = NULL; -INT32 numdrawnodes = 0; -INT32 alloceddrawnodes = 0; +// no reason to waste all the allocations since every map will have atleast one translucent thing +static std::vector drawnodes; static void *HWR_CreateDrawNode(gl_drawnode_type_t type) { - gl_drawnode_t *drawnode; + // if we didnt alloc anything yet, reserve atleast 64 nodes + // dont declare with it as we want our size to be 0! + drawnodes.reserve(DRAWNODES_INIT_SIZE); - if (!drawnodes) - { - alloceddrawnodes = DRAWNODES_INIT_SIZE; - drawnodes = static_cast(Z_Malloc(alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes)); - } - else if (numdrawnodes >= alloceddrawnodes) - { - alloceddrawnodes *= 2; - Z_Realloc(drawnodes, alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes); - } - - drawnode = &drawnodes[numdrawnodes++]; - drawnode->type = type; + drawnodes.emplace_back(); + drawnodes.back().type = type; // not sure if returning different pointers to a union is necessary switch (type) { case DRAWNODE_PLANE: - return &drawnode->u.plane; + return &drawnodes.back().u.plane; case DRAWNODE_POLYOBJECT_PLANE: - return &drawnode->u.polyplane; + return &drawnodes.back().u.polyplane; case DRAWNODE_WALL: - return &drawnode->u.wall; + return &drawnodes.back().u.wall; } + return NULL; } @@ -4337,11 +4330,15 @@ static int CompareDrawNodePlanes(const void *p1, const void *p2) // Sorts and renders the list of drawnodes for the scene being rendered. static void HWR_RenderDrawNodes(void) { - INT32 i = 0, run_start = 0; + size_t i = 0, run_start = 0; + static std::vector sortindex; + + sortindex.reserve(DRAWNODES_INIT_SIZE); // Array for storing the rendering order. // A list of indices into the drawnodes array. - INT32 *sortindex; + + const size_t numdrawnodes = drawnodes.size(); if (!numdrawnodes) return; @@ -4350,7 +4347,7 @@ static void HWR_RenderDrawNodes(void) PS_START_TIMING(ps_hw_nodesorttime); - sortindex = static_cast(Z_Malloc(sizeof(INT32) * numdrawnodes, PU_STATIC, NULL)); + sortindex.resize(numdrawnodes); // Reversed order for (i = 0; i < numdrawnodes; i++) @@ -4366,7 +4363,7 @@ static void HWR_RenderDrawNodes(void) if (drawnodes[sortindex[run_start]].type == DRAWNODE_PLANE) { // found it, now look for run end - INT32 run_end; // (inclusive) + size_t run_end; // (inclusive) for (i = run_start+1; i < numdrawnodes; i++) { @@ -4379,7 +4376,7 @@ static void HWR_RenderDrawNodes(void) if (run_end > run_start) // if there are multiple consecutive planes, not just one { // consecutive run of planes found, now sort it - qs22j(sortindex + run_start, run_end - run_start + 1, sizeof(INT32), CompareDrawNodePlanes); + qs22j(sortindex.data() + run_start, run_end - run_start + 1, sizeof(INT32), CompareDrawNodePlanes); } run_start = run_end + 1; // continue looking for runs coming right after this one @@ -4451,9 +4448,7 @@ static void HWR_RenderDrawNodes(void) PS_STOP_TIMING(ps_hw_nodedrawtime); - numdrawnodes = 0; - - Z_Free(sortindex); + drawnodes.clear(); // clear so our size is 0 again! } From 8b3d55fbc89ab0d20ab1c741442b34c8b5189639 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 9 Dec 2025 18:14:44 +0100 Subject: [PATCH 14/28] HWR_ProcessSeg: port softwares code to skip rendering inner sides that are "joined" to other fofs This seems to improve performance on maps with moderate to lots of fofs quite a bit. On maps with only a few fofs, this makes no difference or has very very little regression Need to test and check if there are any visual errors, but so far everything seems good --- src/hardware/hw_main.cpp | 104 +++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 26 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index b363069b6..afe899df2 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1881,6 +1881,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Used for height comparisons and etc across FOFs and slopes fixed_t high1, highslope1, low1, lowslope1; + fixed_t high2, highslope2, low2, lowslope2; INT32 texnum; @@ -1893,19 +1894,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_backsector->ffloors; rover; rover = rover->next) { - boolean bothsides = false; - // Skip if it exists on both sectors. - ffloor_t * r2; - for (r2 = gl_frontsector->ffloors; r2; r2 = r2->next) - if (rover->master == r2->master) - { - bothsides = true; - break; - } - - if (bothsides) - continue; - const ffloortype_e roverflags = rover->flags; if (!(roverflags & FF_EXISTS) || !(roverflags & FF_RENDERSIDES) || (roverflags & FF_INVERTSIDES)) @@ -1917,6 +1905,45 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((high1 < lowcut || highslope1 < lowcutslope) || (low1 > highcut || lowslope1 > highcutslope)) continue; + ffloor_t * r2; + for (r2 = gl_frontsector->ffloors; r2; r2 = r2->next) + { + if (r2->master == rover->master) // Skip if same control line. + break; + + const ffloortype_e r2flags = r2->flags; + + if (!(r2flags & FF_EXISTS) || !(r2flags & FF_RENDERSIDES)) + continue; + + if (rover->flags & FF_EXTRA) + { + if (!(r2flags & FF_CUTEXTRA)) + continue; + + if (r2flags & FF_EXTRA && (r2flags & (FF_TRANSLUCENT|FF_FOG)) != (rover->flags & (FF_TRANSLUCENT|FF_FOG))) + continue; + } + else + { + if (!(r2flags & FF_CUTSOLIDS)) + continue; + } + + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) + + if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) + continue; + if ((high1 > high2 || highslope1 > highslope2) || (low1 < low2 || lowslope1 < lowslope2)) + continue; + + break; + } + + if (r2) + continue; + side_t *side = R_GetFFloorSide(gl_curline->linedef, rover, gl_backsector); boolean do_texture_skew; @@ -2053,19 +2080,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_frontsector->ffloors; rover; rover = rover->next) { - boolean bothsides = false; - // Skip if it exists on both sectors. - ffloor_t * r2; - for (r2 = gl_backsector->ffloors; r2; r2 = r2->next) - if (rover->master == r2->master) - { - bothsides = true; - break; - } - - if (bothsides) - continue; - const ffloortype_e roverflags = rover->flags; if (!(roverflags & FF_EXISTS) || !(roverflags & FF_RENDERSIDES) || !(roverflags & FF_ALLSIDES)) @@ -2077,6 +2091,44 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((high1 < lowcut || highslope1 < lowcutslope) || (low1 > highcut || lowslope1 > highcutslope)) continue; + ffloor_t * r2; + for (r2 = gl_backsector->ffloors; r2; r2 = r2->next) + { + if (r2->master == rover->master) // Skip if same control line. + break; + + const ffloortype_e r2flags = r2->flags; + + if (!(r2flags & FF_EXISTS) || !(r2flags & FF_RENDERSIDES)) + continue; + + if (rover->flags & FF_EXTRA) + { + if (!(r2flags & FF_CUTEXTRA)) + continue; + + if (r2flags & FF_EXTRA && (r2flags & (FF_TRANSLUCENT|FF_FOG)) != (rover->flags & (FF_TRANSLUCENT|FF_FOG))) + continue; + } + else + { + if (!(r2flags & FF_CUTSOLIDS)) + continue; + } + + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) + + if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) + continue; + if ((high1 > high2 || highslope1 > highslope2) || (low1 < low2 || lowslope1 < lowslope2)) + continue; + + break; + } + if (r2) + continue; + side_t *side = R_GetFFloorSide(gl_curline->linedef, rover, gl_backsector); boolean do_texture_skew; From 860dc37fe476b2b9cf489cf88c83c12268a31d04 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 24 Nov 2025 20:51:53 +0100 Subject: [PATCH 15/28] Optimize: move a few strlen calls out of loops when applicable and the input does not get modified within the loop needs some testing incase i oversaw something --- src/command.c | 7 +++++-- src/d_clisrv.c | 6 ++++-- src/d_netfil.c | 11 ++++++----- src/hu_stuff.c | 41 ++++++++++++++++++++++++----------------- src/k_hud.c | 4 +++- src/m_menu.c | 3 ++- src/m_misc.c | 13 +++++++------ src/sdl/i_system.cpp | 9 +++++++-- src/v_video.c | 12 +++++++++--- 9 files changed, 67 insertions(+), 39 deletions(-) diff --git a/src/command.c b/src/command.c index 7e0c34d03..6b71dce73 100644 --- a/src/command.c +++ b/src/command.c @@ -237,10 +237,13 @@ void COM_ImmedExecute(const char *ptext) char line[1024] = ""; INT32 quotes; - while (i < strlen(ptext)) + const size_t txtlength = strlen(ptext); + + while (i < txtlength) { quotes = 0; - for (j = 0; i < strlen(ptext); i++,j++) + + for (j = 0; i < txtlength; i++,j++) { if (ptext[i] == '\"' && !quotes && i > 0 && ptext[i-1] != ' ') // Malformed command return; diff --git a/src/d_clisrv.c b/src/d_clisrv.c index cd04fb3a2..6cf50a4d3 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1457,12 +1457,14 @@ static inline void CL_DrawConnectionStatus(void) V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-58, dldlength, 8, 160); memset(tempname, 0, sizeof(tempname)); + // offset filename to just the name only part filename += strlen(filename) - nameonlylength(filename); + const size_t filenamelength = strlen(filename); - if (strlen(filename) > sizeof(tempname)-1) // too long to display fully + if (filenamelength > sizeof(tempname)-1) // too long to display fully { - size_t endhalfpos = strlen(filename)-10; + size_t endhalfpos = filenamelength-10; // display as first 14 chars + ... + last 10 chars // which should add up to 27 if our math(s) is correct snprintf(tempname, sizeof(tempname), "%.14s...%.10s", filename, filename+endhalfpos); diff --git a/src/d_netfil.c b/src/d_netfil.c index 57f0f0f6c..a4478fcc9 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1079,12 +1079,14 @@ void CloseNetFile(void) // Receiving a file? for (i = 0; i < MAX_WADFILES; i++) + { if (fileneeded[i].status == FS_DOWNLOADING && fileneeded[i].file) { fclose(fileneeded[i].file); // File is not complete delete it remove(fileneeded[i].filename); } + } // Remove PT_FILEFRAGMENT from acknowledge list Net_AbortPacketType(PT_FILEFRAGMENT); @@ -1098,17 +1100,16 @@ void nameonly(char *s) void *ns; for (j = strlen(s); j != (size_t)-1; j--) + { if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) { ns = &(s[j+1]); len = strlen(ns); -#if 0 - memcpy(s, ns, len+1); -#else - memmove(s, ns, len+1); -#endif + memmove(s, ns, len+1); + return; } + } } // Returns the length in characters of the last element of a path. diff --git a/src/hu_stuff.c b/src/hu_stuff.c index a61199b39..6cca391e9 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -596,12 +596,12 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) } // Only servers/admins can CSAY. - if(!server && !(IsPlayerAdmin(consoleplayer))) + if (!server && !(IsPlayerAdmin(consoleplayer))) flags &= ~HU_CSAY; // We handle HU_SERVER_SAY, not the caller. flags &= ~HU_SERVER_SAY; - if(dedicated && !(flags & HU_CSAY)) + if (dedicated && !(flags & HU_CSAY)) flags |= HU_SERVER_SAY; buf[0] = target; @@ -615,17 +615,20 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) strlcat(msg, COM_Argv(ix + usedargs), msgspace); } - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + const size_t msglength = strlen(msg); + + if (msglength > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { // what we're gonna do now is check if the node exists // with that logic, characters 4 and 5 are our numbers: const char *newmsg; INT32 spc = 1; // used if nodenum[1] is a space. - char *nodenum = (char*) malloc(3); + CLEANUP(pfree) char *nodenum = (char*) malloc(3); memcpy(nodenum, msg+3, 2); nodenum[2] = '\0'; + // check for undesirable characters in our "number" - if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) + if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) { // check if nodenum[1] is a space if (nodenum[1] == ' ') @@ -634,23 +637,21 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } + // I'm very bad at C, I swear I am, additional checks eww! if (spc != 0) { if (msg[5] != ' ') { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } target = atoi((const char*) nodenum); // turn that into a number - free(nodenum); //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -661,12 +662,13 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same return; } + buf[0] = target; newmsg = msg+5+spc; strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } - SendNetXCmd(XD_SAY, buf, strlen(msg) + 1 + msg-buf); + SendNetXCmd(XD_SAY, buf, msglength + 1 + msg-buf); } /** Send a message to everyone. @@ -917,10 +919,12 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) return; } + const size_t msglength = strlen(msg); + //check for invalid characters (0x80 or above) { size_t i; - const size_t j = strlen(msg); + const size_t j = msglength; for (i = 0; i < j; i++) { if (msg[i] & 0x80) @@ -967,7 +971,7 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) } // Handle "/me" actions, but only in messages to everyone. - if (target == 0 && strlen(msg) > 4 && strnicmp(msg, "/me ", 4) == 0) + if (target == 0 && msglength > 4 && strnicmp(msg, "/me ", 4) == 0) { msg += 4; action = true; @@ -1149,10 +1153,12 @@ static boolean HU_clearChatSpaces(void) size_t i = 0; // Used to just check our message char c; // current character we're iterating. boolean nothingbutspaces = true; + const size_t chatlength = strlen(w_chat_buf); - for (; i < strlen(w_chat_buf); i++) // iterate through message and eradicate all spaces that don't belong. + for (; i < chatlength; i++) // iterate through message and eradicate all spaces that don't belong. { c = w_chat_buf[i]; + if (!c) break; // if there's nothing, it's safe to assume our message has ended, so let's not waste any more time here. @@ -1161,6 +1167,7 @@ static boolean HU_clearChatSpaces(void) nothingbutspaces = false; } } + return nothingbutspaces; } @@ -1207,11 +1214,11 @@ static void HU_SendChatMessage(void) return; } - size_t len = strlen(msg); + const size_t msglength = strlen(msg); - if (len >= 5 && strnicmp(msg, "/mute", 5) == 0) // Used /mute + if (msglength >= 5 && strnicmp(msg, "/mute", 5) == 0) // Used /mute { - if (len > 6) + if (msglength > 6) DoMute(msg+6); else HU_AddChatText("\x82NOTICE: \x80Usage: /mute ", false); @@ -1219,7 +1226,7 @@ static void HU_SendChatMessage(void) return; } - if (len > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + if (msglength > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { INT32 spc = 1; // used if nodenum[1] is a space. const char *newmsg; @@ -1991,7 +1998,7 @@ static void HU_DrawChat(void) longest_name_length = max(longest_name_length, strlen(player_names[i])); } - for(i = 0; i < MAXPLAYERS; i++) + for (i = 0; i < MAXPLAYERS; i++) { if (!playeringame[i]) continue; diff --git a/src/k_hud.c b/src/k_hud.c index 59278a229..1d9b7fe5b 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -4468,7 +4468,9 @@ static void K_drawLapStartAnim(void) V_DrawFixedPatch(leftx, y, FRACUNIT, vflags, kp_lapanim_lap[min(progress/2, 6)], NULL); char *lapnum = va("%02d", stplyr->laps + 1); - for (int i = 0; i < (int)strlen(lapnum); i++) + const size_t laplength = strlen(lapnum); + + for (int i = 0; i < (int)laplength; i++) { int digit = lapnum[i] - '0'; int frame = min(2, progress/2 - 8 - (i*2)); diff --git a/src/m_menu.c b/src/m_menu.c index 3650853bc..c2978fe82 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2868,8 +2868,9 @@ static void M_DrawCenteredMenu(void) static inline size_t M_StringHeight(const char *string) { size_t h = 8, i; + const size_t strlength = strlen(string); - for (i = 0; i < strlen(string); i++) + for (i = 0; i < strlength; i++) if (string[i] == '\n') h += 8; diff --git a/src/m_misc.c b/src/m_misc.c index 655a28a24..cbc40d4e2 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1693,22 +1693,23 @@ char *M_GetToken(const char *inputString) } -const char * M_Ftrim (double f) +const char * M_Ftrim(double f) { static char dig[9];/* "0." + 6 digits (6 is printf's default) */ int i; + /* I know I said it's the default, but just in case... */ sprintf(dig, "%.6f", fabs(modf(f, &f))); + /* trim trailing zeroes */ for (i = strlen(dig)-1; dig[i] == '0'; --i) ; + if (dig[i] == '.')/* :NOTHING: */ return ""; - else - { - dig[i + 1] = '\0'; - return &dig[1];/* skip the 0 */ - } + + dig[i + 1] = '\0'; + return &dig[1];/* skip the 0 */ } /** Count bits in a number. diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 60e5108ac..8a9b8bd69 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -2315,12 +2315,17 @@ static void pathonly(char *s) size_t j; for (j = strlen(s); j != (size_t)-1; j--) + { if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) { - if (s[j] == ':') s[j+1] = 0; - else s[j] = 0; + if (s[j] == ':') + s[j+1] = 0; + else + s[j] = 0; + return; } + } } /** \brief search for srb2.srb in the given path diff --git a/src/v_video.c b/src/v_video.c index 213db7bfc..ac85715ef 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2992,7 +2992,9 @@ INT32 V_CreditStringWidth(const char *string) if (!string) return 0; - for (i = 0; i < strlen(string); i++) + const size_t strlength = strlen(string); + + for (i = 0; i < strlength; i++) { c = toupper(string[i]) - CRED_FONTSTART; if (c < 0 || c >= CRED_FONTSIZE) @@ -3070,7 +3072,9 @@ INT32 V_LevelNameWidth(const char *string) INT32 c, w = 0; size_t i; - for (i = 0; i < strlen(string); i++) + const size_t strlength = strlen(string); + + for (i = 0; i < strlength; i++) { c = toupper(string[i]) - LT_FONTSTART; if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) @@ -3089,7 +3093,9 @@ INT32 V_LevelNameHeight(const char *string) INT32 c, w = 0; size_t i; - for (i = 0; i < strlen(string); i++) + const size_t strlength = strlen(string); + + for (i = 0; i < strlength; i++) { c = toupper(string[i]) - LT_FONTSTART; if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) From a4af2546437b033693dc5fec2ece1a6535b0e3c9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 22 Dec 2025 20:16:04 +0100 Subject: [PATCH 16/28] Revert "dont call I_Quit from within "quit_handler", let it signal main loop to quit" This reverts commit a2feaa7fde4c2d3138cf21c40c2f8f671fac78ad. --- src/d_main.c | 3 --- src/dedicated/i_system.c | 12 ++---------- src/i_system.h | 3 +-- src/sdl/i_system.cpp | 20 +++++++++++--------- src/sdl/i_video.c | 3 +-- src/sdl/mixer_sound.c | 3 +-- 6 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index ab10af215..c46ef0c44 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -679,9 +679,6 @@ void D_SRB2Loop(void) for (;;) { - if (I_Interrupted()) - I_Quit(); - // capbudget is the minimum precise_t duration of a single loop iteration precise_t capbudget; precise_t elapsed; diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 5edb71a99..31eaf0346 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1075,19 +1075,11 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -static volatile sig_atomic_t interrupted = 0; - -boolean I_Interrupted(void) -{ - return interrupted; -} - -static void quit_handler(int num) +FUNCNORETURN static ATTRNORETURN void quit_handler(int num) { signal(num, SIG_DFL); //default signal action raise(num); - //I_Quit(); - interrupted = true; + I_Quit(); } #ifdef HAVE_LIBBACKTRACE diff --git a/src/i_system.h b/src/i_system.h index 68d51f022..7084c655f 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -29,6 +29,7 @@ extern "C" { */ #define MAX_QUIT_FUNCS 16 + /** \brief Graphic system had started up */ extern UINT8 graphics_started; @@ -190,8 +191,6 @@ INT32 I_StartupSystem(void); */ void I_ShutdownSystem(void); -boolean I_Interrupted(void); - /** \brief The I_GetDiskFreeSpace function \param freespace a INT64 pointer to hold the free space amount diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 8a9b8bd69..0c024a5bd 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1670,19 +1670,21 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -static volatile sig_atomic_t interrupted = 0; - -boolean I_Interrupted(void) +FUNCNORETURN static ATTRNORETURN void quit_handler(int num) { - return interrupted; -} +#ifdef HAVE_THREADS + if (g_main_thread_id != std::this_thread::get_id()) + { + // Do not attempt any sort of recovery if this signal triggers off the main thread + signal(num, SIG_DFL); + raise(num); + exit(-2); + } +#endif -static void quit_handler(int num) -{ signal(num, SIG_DFL); //default signal action raise(num); - //I_Quit(); - interrupted = true; + I_Quit(); } static void I_RegisterSignals(void) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index ae2691359..c2d87e3f1 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2012,8 +2012,7 @@ void I_ShutdownGraphics(void) SDL_DestroyWindow(window); window = NULL; - if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO) - SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_QuitSubSystem(SDL_INIT_VIDEO); framebuffer = SDL_FALSE; } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index c455aab01..529b47399 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -237,8 +237,7 @@ void I_ShutdownSound(void) Mix_Quit(); #endif - if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) - SDL_QuitSubSystem(SDL_INIT_AUDIO); + SDL_QuitSubSystem(SDL_INIT_AUDIO); #ifdef HAVE_LIBGME if (gme) From 7c848f4be561876c4b833f711fe8458cbeb66580 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 24 Dec 2025 00:54:39 +0300 Subject: [PATCH 17/28] Sort directories too in replay list --- src/m_menu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index c2978fe82..15309dd2d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4170,8 +4170,6 @@ static int ReplayListSortComparator(const void *entry1, const void *entry2) return -1; else if (demo2->type == MD_SUBDIR && demo1->type != MD_SUBDIR) return 1; - else if (demo1->type == MD_SUBDIR && demo2->type == MD_SUBDIR) - return 0; memcpy(filepath1, demo1->filepath, sizeof(filepath1)); memcpy(filepath2, demo2->filepath, sizeof(filepath2)); From 1c95e5f40e58dabf8b22d7221e863b789327583b Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 24 Dec 2025 01:23:20 +0300 Subject: [PATCH 18/28] Actually add filepath to directories to sort them --- src/m_menu.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 15309dd2d..9a8c8bfba 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4174,8 +4174,14 @@ static int ReplayListSortComparator(const void *entry1, const void *entry2) memcpy(filepath1, demo1->filepath, sizeof(filepath1)); memcpy(filepath2, demo2->filepath, sizeof(filepath2)); - nameonly(filepath1); - nameonly(filepath2); + // nameonly will make filepath's empty for directories since they may end with PATHSEP + // this is a lazy solution but if we don't do nameonly, dirs still will be sorted in correct only, + // just not very efficently + if (demo1->type != MD_SUBDIR) + { + nameonly(filepath1); + nameonly(filepath2); + } // Comparing in opposite order to move new replays to the top return strncmp(filepath2, filepath1, sizeof(filepath1)); @@ -4211,6 +4217,9 @@ static void PrepReplayList(boolean reset) { demolist_all[i].type = MD_SUBDIR; strncpy(demolist_all[i].title, dirmenu[i] + DIR_STRING, 64); + snprintf(demolist_all[i].filepath, sizeof(demolist_all[i].filepath), + // 255 = UINT8 limit. dirmenu entries are restricted to this length (see DIR_LEN). + "%s%.255s", menupath, dirmenu[i] + DIR_STRING); } else { From 2bf4c442597768e83790e0d6688393a3a746e1c4 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 24 Dec 2025 01:36:00 +0300 Subject: [PATCH 19/28] Revert "Actually add filepath to directories to sort them" This reverts commit 1c95e5f40e58dabf8b22d7221e863b789327583b. --- src/m_menu.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 9a8c8bfba..15309dd2d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4174,14 +4174,8 @@ static int ReplayListSortComparator(const void *entry1, const void *entry2) memcpy(filepath1, demo1->filepath, sizeof(filepath1)); memcpy(filepath2, demo2->filepath, sizeof(filepath2)); - // nameonly will make filepath's empty for directories since they may end with PATHSEP - // this is a lazy solution but if we don't do nameonly, dirs still will be sorted in correct only, - // just not very efficently - if (demo1->type != MD_SUBDIR) - { - nameonly(filepath1); - nameonly(filepath2); - } + nameonly(filepath1); + nameonly(filepath2); // Comparing in opposite order to move new replays to the top return strncmp(filepath2, filepath1, sizeof(filepath1)); @@ -4217,9 +4211,6 @@ static void PrepReplayList(boolean reset) { demolist_all[i].type = MD_SUBDIR; strncpy(demolist_all[i].title, dirmenu[i] + DIR_STRING, 64); - snprintf(demolist_all[i].filepath, sizeof(demolist_all[i].filepath), - // 255 = UINT8 limit. dirmenu entries are restricted to this length (see DIR_LEN). - "%s%.255s", menupath, dirmenu[i] + DIR_STRING); } else { From 7518a6f181e59de80e56e707c5972926447ee871 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 24 Dec 2025 01:36:02 +0300 Subject: [PATCH 20/28] Revert "Sort directories too in replay list" This reverts commit 7c848f4be561876c4b833f711fe8458cbeb66580. --- src/m_menu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/m_menu.c b/src/m_menu.c index 15309dd2d..c2978fe82 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4170,6 +4170,8 @@ static int ReplayListSortComparator(const void *entry1, const void *entry2) return -1; else if (demo2->type == MD_SUBDIR && demo1->type != MD_SUBDIR) return 1; + else if (demo1->type == MD_SUBDIR && demo2->type == MD_SUBDIR) + return 0; memcpy(filepath1, demo1->filepath, sizeof(filepath1)); memcpy(filepath2, demo2->filepath, sizeof(filepath2)); From c9afd4a2cd6005b0ad5308f386da39003a414cbb Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 24 Dec 2025 00:06:05 +0100 Subject: [PATCH 21/28] G_GetDemoDate: make safer and use static memory bunch of smaller issues before, no real checks for strltol and potential free on a null pointer lul also skips replays with shorter than 10 char names and handles errors better --- src/g_demo.c | 93 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/src/g_demo.c b/src/g_demo.c index a714f8e48..312e57530 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -55,6 +55,8 @@ #include "k_stats.h" // SRB2kart #include "r_fps.h" // frame interpolation/uncapped +#include + #ifdef HAVE_DISCORDRPC #include "discord.h" #endif @@ -2401,49 +2403,69 @@ static long G_GetCreationTime(char *filepath) static char *G_GetDemoDate(menudemo_t *pdemo) { - char *datetime; - datetime = malloc(sizeof(pdemo->date)); // mallocma balls - - // no mallocma balls... :c - if (!datetime) - { - return NULL; - } - + char *endPos = NULL; + static char datetime[11]; time_t file_time = 0; + const char *format = NULL; + struct tm *tm_buf = NULL; + CLEANUP(pfree) char *filename = NULL; // get le filepath - char *filename; filename = strdup(pdemo->filepath); -#if defined (_WIN32) if (!filename) { - // if we cant get a filename try just getting the file create time +#if defined (_WIN32) + // if we cant get a filename try just getting the file creation time file_time = G_GetCreationTime(pdemo->filepath); goto skipfilenametime; - } #else - if (!filename) - { - free(datetime); return NULL; - } #endif + } // get the actual filename Zzz... nameonly(filename); - // convert it to long Zzz.... - file_time = strtol(filename, NULL, 10); - free(filename); // dont need this anymore a + // the first 10 characters of a replay name usually is a unix timestamp + + // not long enough to contain a valid timestamp + if (strlen(filename) < 10) + { +#if defined (_WIN32) + // try to get file creation time + file_time = G_GetCreationTime(pdemo->filepath); + goto skipfilenametime; +#else + return NULL; +#endif + } + +#ifndef AVOID_ERRNO + errno = 0; +#endif + // get the timestamp as actual numbers lul + file_time = strtol(filename, &endPos, 10); + + if (endPos == filename // Empty string +#ifndef AVOID_ERRNO + || errno == ERANGE // Number out-of-range +#endif + || file_time < 0) // Number is not positive + { +#if defined (_WIN32) + // just try and get the creation time then + file_time = G_GetCreationTime(pdemo->filepath); +#else + return NULL; +#endif + } #if defined (_WIN32) skipfilenametime: #endif // then throw it into localtime to get an actual human readable format lmao - struct tm *tm_buf = NULL; tm_buf = localtime(&file_time); // cant believe we ended up in 1970 @@ -2456,14 +2478,10 @@ skipfilenametime: tm_buf = localtime(&file_time); if (tm_buf == NULL || tm_buf->tm_year <= 110) - { - free(datetime); return NULL; - } goto gotcreationtime; #else - free(datetime); return NULL; #endif } @@ -2472,17 +2490,27 @@ skipfilenametime: gotcreationtime: #endif - const char *format; - // US ppl are special (: if (cv_demodateformat.value == 2) format = "%m.%d.%Y"; else if (cv_demodateformat.value == 1) format = "%d.%m.%Y"; else - format = strstr(setlocale(LC_TIME, NULL), "en_US") ? "%m.%d.%Y" : "%d.%m.%Y"; + { + const char *locale = setlocale(LC_TIME, NULL); - strftime(datetime, sizeof(pdemo->date), format, tm_buf); + if (locale == NULL) + format = "%d.%m.%Y"; // fallback to non US format + else if (strstr(locale, "en_US")) + format = "%m.%d.%Y"; + else + format = "%d.%m.%Y"; + } + + if (strftime(datetime, sizeof(datetime), format, tm_buf) == 0) + { + return NULL; + } return datetime; } @@ -2491,6 +2519,7 @@ void G_LoadDemoTitle(menudemo_t *pdemo) { UINT8 infobuffer[96], *info_p; UINT16 pdemoversion; + char *demodate = NULL; size_t count; FILE *handle = fopen(pdemo->filepath, "rb"); @@ -2529,13 +2558,13 @@ void G_LoadDemoTitle(menudemo_t *pdemo) memcpy(pdemo->title, info_p, 64); // demo date - char *demodate; demodate = G_GetDemoDate(pdemo); if (demodate) - strncpy(pdemo->date, demodate, sizeof(pdemo->date)); + { + strlcpy(pdemo->date, demodate, sizeof(pdemo->date)); + } - free(demodate); break; #ifdef DEMO_COMPAT_100 case 0x0001: From 0fe3086a5ad41d9ec61609bebbe3c7ccdcfa0cf6 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Dec 2025 18:58:41 +0100 Subject: [PATCH 22/28] Fixup the doomednum lookup properly match the old linear lookup by returning the FIRST match for doomednum also shrinks the array, doomednum max is 4095, no need for such massive array, also fixed a off by should fix some join desynchs and desynchs on certain maps --- src/d_netcmd.c | 2 -- src/info.h | 2 ++ src/p_local.h | 2 +- src/p_mobj.c | 15 +++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 870ceba69..c669da59b 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4751,8 +4751,6 @@ static void Command_LocateLump_f(void) } } -#define MAXDOOMEDNUM 4095 - static void Command_ListDoomednums_f(void) { INT16 i, j, k = 0, l = 0; diff --git a/src/info.h b/src/info.h index 4ee851cee..c84d63214 100644 --- a/src/info.h +++ b/src/info.h @@ -19,6 +19,8 @@ #include "sounds.h" #include "m_fixed.h" +#define MAXDOOMEDNUM 4095 + // dehacked.c now has lists for the more named enums! PLEASE keep them up to date! // For great modding!! diff --git a/src/p_local.h b/src/p_local.h index 4b6530eb9..3c16b5c62 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -272,7 +272,7 @@ extern consvar_t cv_gravity; void P_RespawnSpecials(void); -extern mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; +extern mobjtype_t g_doomednum_to_mobjtype[MAXDOOMEDNUM+1]; void CalculateDoomednumToMobjtype(void); mobj_t *P_AllocateMobj(void); diff --git a/src/p_mobj.c b/src/p_mobj.c index cd7d44a62..ad7982d87 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10463,17 +10463,20 @@ void P_PrecipitationEffects(void) } } -mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; +mobjtype_t g_doomednum_to_mobjtype[MAXDOOMEDNUM+1] = {}; void CalculateDoomednumToMobjtype(void) { memset(g_doomednum_to_mobjtype, MT_NULL, sizeof(g_doomednum_to_mobjtype)); - for (size_t i = MT_NULL+1; i < NUMMOBJTYPES; i++) + for (size_t i = 0; i < NUMMOBJTYPES; i++) { - if (mobjinfo[i].doomednum > 0 && mobjinfo[i].doomednum <= UINT16_MAX) + const INT32 doomednum = mobjinfo[i].doomednum; + + if (doomednum > 0 && doomednum <= MAXDOOMEDNUM) { - g_doomednum_to_mobjtype[ mobjinfo[i].doomednum ] = i; + if (g_doomednum_to_mobjtype[doomednum] == MT_NULL) + g_doomednum_to_mobjtype[doomednum] = (mobjtype_t)i; } } } @@ -10551,7 +10554,7 @@ void P_RespawnSpecials(void) if (mthing) { - mobjtype_t i; + mobjtype_t i = MT_NULL; x = mthing->x << FRACBITS; y = mthing->y << FRACBITS; ss = R_PointInSubsector(x, y); @@ -10987,7 +10990,7 @@ INT32 numhuntemeralds = 0; // void P_SpawnMapThing(mapthing_t *mthing) { - mobjtype_t i; + mobjtype_t i = MT_NULL; mobj_t *mobj; fixed_t x, y, z; subsector_t *ss; From 25dd3b49762cc979f3ffe52395ff43446d3f0b5a Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 1 Dec 2025 23:00:22 +0100 Subject: [PATCH 23/28] Revert "Fix static memory being re-tagged as purgable" This reverts commit c544cf9a7cc5b6c21d20e71672273be02035df92. --- src/z_zone.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 549696bd7..9e5b4f41e 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -651,9 +651,6 @@ void Z_ChangeTag(void *ptr, INT32 tag) I_Error("Internal memory management error: " "tried to make block purgable but it has no owner"); - // No, please, don't make my PU_STATIC patch NULL! It supposed to be always valid! - if (block->tag < 10) return; - block->tag = tag; } From 40bd3e5e19d7dd853d65b0661e0bebece028cd82 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Dec 2025 23:18:19 +0100 Subject: [PATCH 24/28] simplify opengl vsync set --- src/sdl/i_video.c | 14 +++++++------- src/sdl/ogl_sdl.c | 10 +--------- src/sdl/ogl_sdl.h | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c2d87e3f1..6be6bf638 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1426,7 +1426,7 @@ void I_FinishUpdate(void) #ifdef HWRENDER if (rendermode == render_opengl) { - OglSdlFinishUpdate(cv_vidwait.value); + OglSdlFinishUpdate(); return; } #endif @@ -2028,17 +2028,17 @@ UINT32 I_GetRefreshRate(void) static void Impl_SetVsync(void) { -#if SDL_VERSION_ATLEAST(2,0,18) - if (renderer) - SDL_RenderSetVSync(renderer, cv_vidwait.value); -#endif #ifdef HWRENDER - if (!renderer && rendermode == render_opengl && - sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) + if (rendermode == render_opengl && + sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) { SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); } #endif +#if SDL_VERSION_ATLEAST(2,0,18) + if (renderer) + SDL_RenderSetVSync(renderer, cv_vidwait.value); +#endif } void I_SetBorderlessWindow(void) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 319acab4b..4177c121a 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -241,22 +241,14 @@ boolean OglSdlSurface(INT32 w, INT32 h) \return void */ -void OglSdlFinishUpdate(boolean waitvbl) +void OglSdlFinishUpdate(void) { - static boolean oldwaitvbl = false; int sdlw, sdlh; #ifdef USE_FBO_OGL const boolean usefbo = UseScreenFBO(); #endif - if (oldwaitvbl != waitvbl) - { - SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); - } - - oldwaitvbl = waitvbl; - SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); diff --git a/src/sdl/ogl_sdl.h b/src/sdl/ogl_sdl.h index 6d614cd22..8dd2b9e0e 100644 --- a/src/sdl/ogl_sdl.h +++ b/src/sdl/ogl_sdl.h @@ -20,7 +20,7 @@ boolean OglSdlSurface(INT32 w, INT32 h); -void OglSdlFinishUpdate(boolean vidwait); +void OglSdlFinishUpdate(void); boolean VID_LoadOGLAPI(void); extern SDL_Renderer *renderer; From 1af1e42daba79f343dc0b42ba3b5788a1079b434 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Dec 2025 23:20:30 +0100 Subject: [PATCH 25/28] FBO: remove nvidia xwayland hack this has been a non issue since a while now, so can remove this (we shouldnt work around driver bugs anyways) --- src/sdl/ogl_sdl.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 4177c121a..9e51efdc4 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -63,18 +63,9 @@ PFNglGetString pglGetString; #endif #ifdef USE_FBO_OGL - -#if defined (__unix__) -static boolean xwaylandcrap = false; -#endif - boolean UseScreenFBO(void) { - return ((supportFBO && cv_glframebuffer.value && downsample) -#if defined (__unix__) - || (supportFBO && xwaylandcrap) -#endif - ); + return (supportFBO && cv_glframebuffer.value && downsample); } #endif @@ -201,17 +192,6 @@ boolean OglSdlSurface(INT32 w, INT32 h) supportNPO2tex = true; glanisotropicmode_cons_t[1].value = maximumAnisotropy; - -#if defined (__unix__) -#ifdef USE_FBO_OGL - // TODO: delet this since nvidia fixed their shit on 575 - char videodriver[4] = {'S','D','L',0}; - if (supportFBO && strstr((const char*)gl_renderer, "NVIDIA") - && (*strncpy(videodriver, SDL_GetCurrentVideoDriver(), sizeof(videodriver)-1) != '\0') - && (strncasecmp("x11", videodriver, 4) == 0)) - xwaylandcrap = true; -#endif -#endif } SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); @@ -281,13 +261,6 @@ void OglSdlFinishUpdate(void) if (!I_CheckNativeRes() || WipeInAction) #endif HWR_DrawScreenFinalTexture(realwidth, realheight, false); - -#if defined (__unix__) -#ifdef USE_FBO_OGL - if (loaded_config) - xwaylandcrap = false; -#endif -#endif } #endif //HWRENDER From 7866b769cc542c6d9062cc022f4bf2d3afaa31e8 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 21 Dec 2025 21:37:57 +0100 Subject: [PATCH 26/28] Do not archive table values for nil keys --- src/lua_script.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 96ce94a22..2aa88cd52 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1064,9 +1064,13 @@ static void ArchiveTables(UINT8 **p) { // Write key e = ArchiveValue(p, TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. - if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) + if (e == 1) + n++; // the table contained a new table we'll have to archive. :( + else if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) { CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -2), luaL_typename(gL, -2), i); + lua_pop(gL, 1); + continue; } else if (e == 3) // nil key due to invalid userdata. NOT an error. { @@ -1077,15 +1081,12 @@ static void ArchiveTables(UINT8 **p) // Write value e = ArchiveValue(p, TABLESINDEX, -1); if (e == 1) - { n++; // the table contained a new table we'll have to archive. :( - } else if (e == 2) // invalid value type - { CONS_Alert(CONS_ERROR, "Type of value for table %d entry '%s' (%s) could not be archived!\n", i, lua_tostring(gL, -2), luaL_typename(gL, -1)); - } lua_pop(gL, 1); + } lua_pop(gL, 1); WRITEUINT8(*p, ARCH_TEND); @@ -1276,13 +1277,21 @@ static void UnArchiveTables(UINT8 **p, boolean network) UINT8 ret; ret = UnArchiveValue(p, TABLESINDEX, network); - if (ret == 3) + if (ret == 1) // End of table + break; + else if (ret == 2) // Key contains a new table + n++; + else if (ret == 3) { //CONS_Alert(CONS_WARNING,"Couldn't read mobj_t\n"); lua_pushnil(gL); } - else if (ret == 1) // read key - break; + + if (lua_isnil(gL, -1)) // If key is nil, skip this entry + { + lua_pop(gL, 1); + continue; + } ret = UnArchiveValue(p, TABLESINDEX, network); if (ret == 1) @@ -1291,21 +1300,15 @@ static void UnArchiveTables(UINT8 **p, boolean network) lua_pop(gL, 1); // Pop key break; } + else if (ret == 2) // read value + n++; else if (ret == 3) { //CONS_Alert(CONS_WARNING,"Couldn't read mobj_t\n"); lua_pushnil(gL); } - else if (ret == 2) // read value - n++; - if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) - { - CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); - lua_pop(gL, 2); // pop key and value instead of setting them in the table, to prevent Lua panic errors - } - else - lua_rawset(gL, -3); + lua_rawset(gL, -3); } lua_pop(gL, 1); From 35e4f35f6e9867b3b143755a6c276a5946dee617 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 10:31:45 +0100 Subject: [PATCH 27/28] fix some shadowed variables, enable -Wshadow by default --- src/Makefile.d/versions.mk | 5 +---- src/hardware/hw_cache.cpp | 7 ++----- src/hardware/hw_main.cpp | 6 +++--- src/p_polyobj.c | 3 +-- src/r_segs.cpp | 10 +++++----- src/r_things.cpp | 2 +- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 451ff72e7..48964c39f 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs +WFLAGS:=-Wall -Wno-trigraphs -Wshadow ifndef GCC295 #WFLAGS+=-Wno-packed endif @@ -37,9 +37,6 @@ WFLAGS+=-Wfloat-equal ifndef GCC295 WFLAGS+=-Wendif-labels endif -ifdef GCC41 - WFLAGS+=-Wshadow -endif #WFLAGS+=-Wlarger-than-%len% WFLAGS+=-Wpointer-arith CWFLAGS+=-Wbad-function-cast diff --git a/src/hardware/hw_cache.cpp b/src/hardware/hw_cache.cpp index c20d7e9bb..09f4f1a7b 100644 --- a/src/hardware/hw_cache.cpp +++ b/src/hardware/hw_cache.cpp @@ -619,7 +619,6 @@ static void HWR_PrecacheLevelFlats(void) // lookup for flats that may´ve been already loaded // too lazy to make a hashtable or smth so unordered set will do :carbuncle: std::unordered_set flatpresent; - lumpnum_t lump; size_t i, j; INT32 k; @@ -649,9 +648,8 @@ static void HWR_PrecacheLevelFlats(void) const INT32 pic = ceiling ? sec->ceilingpic : sec->floorpic; const levelflat_t *levelflat = &levelflats[pic]; - lump = levelflat->lumpnum; - load_flat(lump, R_NoEncore(sec, ceiling)); + load_flat(levelflat->lumpnum, R_NoEncore(sec, ceiling)); if (levelflat->speed) // is it an animated flat ? { @@ -672,9 +670,8 @@ static void HWR_PrecacheLevelFlats(void) for (i = 0; i < numlevelflats; i++) { const levelflat_t *levelflat = &levelflats[i]; - lump = levelflat->lumpnum; - load_flat(lump, false); + load_flat(levelflat->lumpnum, false); if (levelflat->speed) // is it an animated flat ? { diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index afe899df2..70a5a3a8d 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5538,7 +5538,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool player_t *viewplayer = &players[displayplayers[viewssnum]]; const float fpov = FixedToFloat(R_GetPlayerFov(viewplayer)); - auto reset_viewstate = [&](const float fpov) + auto reset_viewstate = [&]() { HWR_SetTransform(fpov); HWR_ClearSprites(); @@ -5558,7 +5558,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool currentportallist = &portallist; HWR_SetPortalState(GLPORTAL_SEARCH); - reset_viewstate(fpov); + reset_viewstate(); if (rootportal) { @@ -5584,7 +5584,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool // draw normal things in current frame in current incremented stencil buffer area HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); - reset_viewstate(fpov); + reset_viewstate(); if constexpr (Type == RenderViewpointType::kPortal) { diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 7b5135c9e..94c808b22 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1385,8 +1385,7 @@ static void Polyobj_rotateThings(polyobj_t *po, vector2_t origin, angle_t delta, if (mo->player) { - angle_t localangle = P_GetLocalAngle(mo->player); - P_ForceLocalAngle(mo->player, localangle + delta); + P_ForceLocalAngle(mo->player, P_GetLocalAngle(mo->player) + delta); } } } diff --git a/src/r_segs.cpp b/src/r_segs.cpp index c0aab2bfc..3fe8042ae 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -2229,12 +2229,12 @@ void R_StoreWallRange(INT32 start, INT32 stop) lowcutslope = std::max(worldbottomslope, worldlowslope) + viewz; highcutslope = std::min(worldtopslope, worldhighslope) + viewz; - auto check_fof_offscreen = [&](ffloor_t* rover, INT32 bottom, INT32 bottomslope, INT32 top, INT32 topslope) + auto check_fof_offscreen = [&](ffloor_t* rrover, INT32 bottom, INT32 bottomslope, INT32 top, INT32 topslope) { - return ((P_GetFFloorTopZAt (rover, segleft .x, segleft .y) <= bottom + viewz - && P_GetFFloorTopZAt (rover, segright.x, segright.y) <= bottomslope + viewz) - || ( P_GetFFloorBottomZAt (rover, segleft .x, segleft .y) >= top + viewz - && P_GetFFloorBottomZAt (rover, segright.x, segright.y) >= topslope + viewz)); + return ((P_GetFFloorTopZAt (rrover, segleft .x, segleft .y) <= bottom + viewz + && P_GetFFloorTopZAt (rrover, segright.x, segright.y) <= bottomslope + viewz) + || ( P_GetFFloorBottomZAt (rrover, segleft .x, segleft .y) >= top + viewz + && P_GetFFloorBottomZAt (rrover, segright.x, segright.y) >= topslope + viewz)); }; if (frontsector->ffloors && backsector->ffloors) diff --git a/src/r_things.cpp b/src/r_things.cpp index 489ce8911..b62d9e5d7 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1577,7 +1577,7 @@ static void R_ProjectSprite(mobj_t *thing) else blendmode = thing->blendmode; - if (thing->flags2 & MF2_SHADOW || thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) + if (thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) trans = tr_trans80; // because now the translucency is set through FF_TRANSMASK else if (thing->frame & FF_TRANSMASK) { From b0bf588c27363f192b14e2b795fa7f761fce297b Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 10:52:21 +0100 Subject: [PATCH 28/28] fix some null pointer dereferences and enable -Wnull-dereference by default --- src/Makefile.d/versions.mk | 2 +- src/m_misc.c | 9 +++++---- src/s_sound.c | 3 +++ src/w_wad.c | 19 ++++++++++++++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 48964c39f..149fb30fc 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wshadow +WFLAGS:=-Wall -Wno-trigraphs -Wshadow -Wnull-dereference ifndef GCC295 #WFLAGS+=-Wno-packed endif diff --git a/src/m_misc.c b/src/m_misc.c index cbc40d4e2..8c7b34163 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1346,14 +1346,15 @@ void M_MinimapGenerate(void) minigen = AM_MinimapGenerate(mul); if (minigen == NULL || minigen->buf == NULL) - goto failure; + { + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create %s\n"), filepath); + return; + } M_CreateScreenShotPalette(); ret = M_SavePNG(filepath, minigen->buf, minigen->w, minigen->h, screenshot_palette); -failure: - if (minigen->buf != NULL) - free(minigen->buf); + free(minigen->buf); if (ret) { diff --git a/src/s_sound.c b/src/s_sound.c index 5bc830252..e8075469c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1491,6 +1491,9 @@ musicdef_t *S_FindMusicCredit(const char *musname) { def = S_GetMusicCredit(i); + if (!def) + continue; + if (hash != def->hash) continue; diff --git a/src/w_wad.c b/src/w_wad.c index 640ee0367..9be91c8ea 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1997,6 +1997,9 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) rspr = (rotsprite_t *)W_GetCachedRotPatchPwad(WADFILENUM(num),LUMPNUM(num)); + if (rspr == NULL) + return W_CachePatchNum(W_GetNumForName("MISSING"), tag); + if (rspr->patches[idx] == NULL) { INT32 xpivot = 0, ypivot = 0; @@ -2612,6 +2615,9 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. UINT8 *wadData = (UINT8*)(W_CacheLumpNum(lumpnum, PU_LEVEL)); + if (wadData == NULL) + I_Error("vres_GetMap: Invalid WadData!\n"); + filelump_t *fileinfo = (filelump_t *)(wadData + LONG(((wadinfo_t *)wadData)->infotableofs)); i = LONG(((wadinfo_t *)wadData)->numlumps); @@ -2628,6 +2634,8 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) } vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); // Build the lumps, skipping over empty entries. for (i = 0, realentry = 0; i < numlumps; realentry++) @@ -2663,7 +2671,11 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) lumpnum_t lumppos = lumpnum + 1; for (i = LUMPNUM(lumppos); i < wadfiles[WADFILENUM(lumpnum)]->numlumps; i++, lumppos++, numlumps++) { - if (memcmp(W_CheckNameForNum(lumppos), "MAP", 3) == 0 || W_LumpLength(lumppos) == 0) + const char *name = W_CheckNameForNum(lumppos); + if (name == NULL) + continue; + + if (memcmp(name, "MAP", 3) == 0 || W_LumpLength(lumppos) == 0) { break; } @@ -2671,10 +2683,15 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) numlumps++; vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); + for (i = 0; i < numlumps; i++, lumpnum++) { // Check if it is map marker. It is not always first lump sadly, so we need to expect it anywhere const char *name = W_CheckNameForNum(lumpnum); + if (name == NULL) + continue; if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) {