From 43690c9b2c05258f02bffe35fc6c7b82d1086c2b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 00:07:58 +0200 Subject: [PATCH 001/166] fix sound bug lol --- src/p_mobj.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/p_mobj.h b/src/p_mobj.h index f6b27ae49..7a8151dc3 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -266,15 +266,15 @@ typedef struct mobj_s { // List: thinker links. thinker_t thinker; - - mobjtype_t type; - const mobjinfo_t *info; // &mobjinfo[mobj->type] // Info for drawing: position. fixed_t x, y, z; fixed_t old_x, old_y, old_z; // position interpolation fixed_t old_x2, old_y2, old_z2; + mobjtype_t type; + const mobjinfo_t *info; // &mobjinfo[mobj->type] + // More list: links in sector (if needed) struct mobj_s *bnext; struct mobj_s **bprev; // killough 8/11/98: change to ptr-to-ptr @@ -420,14 +420,14 @@ typedef struct precipmobj_s // List: thinker links. thinker_t thinker; - mobjtype_t type; - const mobjinfo_t *info; // &mobjinfo[mobj->type] - // Info for drawing: position. fixed_t x, y, z; fixed_t old_x, old_y, old_z; // position interpolation fixed_t old_x2, old_y2, old_z2; + mobjtype_t type; + const mobjinfo_t *info; // &mobjinfo[mobj->type] + // More list: links in sector (if needed) struct precipmobj_s *bnext; struct precipmobj_s **bprev; // killough 8/11/98: change to ptr-to-ptr From 5f7bf4164db633d4be0cd26e37c974f307b12295 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 00:19:33 +0200 Subject: [PATCH 002/166] dont run playerjoin hook on resynch --- src/d_clisrv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index b6eb9930b..a5899796a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4437,9 +4437,10 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) D_AddAutoloadFiles(); - LUAh_PlayerJoin(newplayernum); + if (!resendingsavegame[node]) + LUAh_PlayerJoin(newplayernum); - if (newplayernum == consoleplayer) + if (newplayernum == consoleplayer && !resendingsavegame[node]) LUAh_ServerJoin(); #ifdef HAVE_DISCORDRPC From 7ac9f0cbefbcfacd9bb2d756ee0e944dec113db1 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 00:44:58 +0200 Subject: [PATCH 003/166] dont rerun mapload hook on resynch --- src/p_setup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 4f55b4609..671ba92ac 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2948,7 +2948,8 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) G_CopyTiccmd(&players[i].cmd, &netcmds[buf][i], 1); } P_PreTicker(2); - LUAh_MapLoad(); + if (!reloadinggamestate) + LUAh_MapLoad(); } if (rendermode != render_none && !reloadinggamestate) From a9a3a0437909ed56ce247aa4fd7a8c8c0e035b9e Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 17 Sep 2024 17:16:35 +0300 Subject: [PATCH 004/166] Add proper skin search in skin command --- src/d_netcmd.c | 62 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3cd815dee..126018930 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1255,19 +1255,69 @@ void D_RegisterClientCommands(void) */ static void Skin_FindRealNameSkin(consvar_t *cvar) { - // Not the best way to implements this but it will do. + INT32 matches[MAXSKINS] = {0}; // Skin numbers of matching skins + INT32 matches_pos[MAXSKINS] = {0}; // Index of matching substring + INT32 nummatches = 0; - int i; + INT32 i; const char *value = cvar->string; + for (i = 0; i < numskins; i++) { - if (strncmp(value, skins[i].realname, sizeof skins[i].realname) == 0) - { - // Change the cvar to be the value of the name. - CV_StealthSet(cvar, skins[i].name); + // Perfect match with some skin name, no need to find matching realname + if (strncmp(value, skins[i].name, sizeof skins[i].name) == 0) return; + + const char *match = strcasestr(skins[i].realname, value); + if (match != NULL) + { + matches[nummatches] = i; + matches_pos[nummatches] = match - skins[i].realname; + ++nummatches; } } + + if (nummatches == 1) + { + // Change the cvar to be the value of the name. + CV_StealthSet(cvar, skins[matches[0]].name); + } + else if (nummatches > 1) + { + size_t query_length = strlen(value); + + char start[SKINNAMESIZE+1] = {0}; // Start of name, printed with normal color + char match[SKINNAMESIZE+1] = {0}; // Matching part of name, highlighted in red + const char *end = NULL; // End of the name, printed with normal color. Can be just a pointer into realname part + + CONS_Printf("\x86Multiple matches found:\n"); + + for (i = 0; i < nummatches; ++i) + { + const char *realname = skins[matches[i]].realname; + + if (matches_pos[i] == 0) + start[0] = 0; + else + { + memcpy(start, realname, matches_pos[i]); + start[matches_pos[i]] = 0; + } + + memcpy(match, realname+matches_pos[i], query_length); + match[matches_pos[i] + query_length] = 0; + + end = realname + matches_pos[i] + query_length; + + CONS_Printf("%s\x85%s\x80%s (%s)\n", start, match, end, skins[matches[i]].name); + } + + CONS_Printf("\x86Try be more specific\n"); + } + else + { + CONS_Printf("\x86Skin not found\n"); + } } From b1644d4817774634960b4b70c2cc60995d9ca215 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 17 Sep 2024 17:23:16 +0300 Subject: [PATCH 005/166] Ignore case here --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 126018930..baba42007 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1265,7 +1265,7 @@ static void Skin_FindRealNameSkin(consvar_t *cvar) for (i = 0; i < numskins; i++) { // Perfect match with some skin name, no need to find matching realname - if (strncmp(value, skins[i].name, sizeof skins[i].name) == 0) + if (strncasecmp(value, skins[i].name, sizeof skins[i].name) == 0) return; const char *match = strcasestr(skins[i].realname, value); From d867868854ddecd260ec16eeda43f71af909dc19 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 17 Sep 2024 16:43:25 +0200 Subject: [PATCH 006/166] Revert "dont run playerjoin hook on resynch" This reverts commit 5f7bf4164db633d4be0cd26e37c974f307b12295. --- src/d_clisrv.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index a5899796a..b6eb9930b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4437,10 +4437,9 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) D_AddAutoloadFiles(); - if (!resendingsavegame[node]) - LUAh_PlayerJoin(newplayernum); + LUAh_PlayerJoin(newplayernum); - if (newplayernum == consoleplayer && !resendingsavegame[node]) + if (newplayernum == consoleplayer) LUAh_ServerJoin(); #ifdef HAVE_DISCORDRPC From 8580451bceabaf8aeb09b0c838e509b6002854d5 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 17 Sep 2024 16:46:21 +0200 Subject: [PATCH 007/166] properly reset all splitscreen cameras on resynch also fix some casting --- src/d_clisrv.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index b6eb9930b..f14ba8009 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1993,14 +1993,13 @@ static void CL_ReloadReceivedSavegame(void) neededtic = gametic; maketic = neededtic; - // set camera angle to somewhat match where your player is turning + // we dont have P_ForceLocalAngle so were setting it manually here for (i = 0; i <= splitscreen; i++) { - localangle[i] = players[displayplayers[i]].cmd.angleturn<<16; + localangle[i] = (angle_t)(players[displayplayers[i]].cmd.angleturn<<16); + camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); } - camera->subsector = R_PointInSubsector(camera->x, camera->y); - cl_redownloadinggamestate = false; CONS_Printf(M_GetText("Game state reloaded\n")); From ff0dcafeeab6ec43daae1d928be5b8915367a30d Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 17 Sep 2024 16:47:24 +0200 Subject: [PATCH 008/166] make ticcmds on gamestateresend resynch will still stop making em should hopefully fix some weird issues where you might end up somewhere weird if the resend takes a little longer --- src/g_game.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 27758119b..430ae0c7b 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1197,11 +1197,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) // why build a ticcmd if we're paused? // Or, for that matter, if we're being reborn. // Kart, don't build a ticcmd if someone is resynching or the server is stopped too so we don't fly off course in bad conditions - if (paused || P_AutoPause() || (gamestate == GS_LEVEL && player->playerstate == PST_REBORN) || hu_resynching -#ifdef SATURNSYNCH - || hu_redownloadinggamestate -#endif - ) + if (paused || P_AutoPause() || (gamestate == GS_LEVEL && player->playerstate == PST_REBORN) || hu_resynching) { cmd->angleturn = (INT16)(lang >> 16); cmd->aiming = G_ClipAimingPitch(&laim); From 30024f234131be241cbab17e8635a9437f250535 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 17 Sep 2024 19:47:24 +0200 Subject: [PATCH 009/166] this is the correct value --- src/hardware/hw_main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ba11cd7c4..c0131ba93 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4357,9 +4357,7 @@ void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, boolean planeinfo->isceiling = isceiling; planeinfo->fixedheight = fixedheight; - - planeinfo->lightlevel = (HWR_ShouldUsePaletteRendering() && (planecolormap && (planecolormap->fog & 1))) ? 255 : lightlevel; - + planeinfo->lightlevel = (HWR_ShouldUsePaletteRendering() && (planecolormap && (planecolormap->fog & 2))) ? 255 : lightlevel; planeinfo->lumpnum = lumpnum; planeinfo->xsub = xsub; planeinfo->alpha = alpha; @@ -4377,9 +4375,7 @@ void HWR_AddTransparentPolyobjectFloor(lumpnum_t lumpnum, polyobj_t *polysector, polyplaneinfo->isceiling = isceiling; polyplaneinfo->fixedheight = fixedheight; - - polyplaneinfo->lightlevel = (HWR_ShouldUsePaletteRendering() && (planecolormap && (planecolormap->fog & 1))) ? 255 : lightlevel; - + polyplaneinfo->lightlevel = (HWR_ShouldUsePaletteRendering() && (planecolormap && (planecolormap->fog & 2))) ? 255 : lightlevel; polyplaneinfo->lumpnum = lumpnum; polyplaneinfo->polysector = polysector; polyplaneinfo->alpha = alpha; From f0a8c27829b2d60993cd4fd9726ac911fb392993 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 17 Sep 2024 20:58:23 +0200 Subject: [PATCH 010/166] Fix crash when trying to send to an unreachable client https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2232 --- src/i_tcp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 77f8aac0c..3baefb94d 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -100,6 +100,10 @@ #undef ETIMEDOUT #endif #define ETIMEDOUT WSAETIMEDOUT + #ifdef EHOSTUNREACH + #undef EHOSTUNREACH + #endif + #define EHOSTUNREACH WSAEHOSTUNREACH #ifndef IOC_VENDOR #define IOC_VENDOR 0x18000000 #endif @@ -853,7 +857,7 @@ static void SOCK_Send(void) if (c == ERRSOCKET) { int e = errno; // save error code so it can't be modified later - if (e != ECONNREFUSED && e != EWOULDBLOCK) + if (e != ECONNREFUSED && e != EWOULDBLOCK && e != EHOSTUNREACH) I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode, SOCK_GetNodeAddress(doomcom->remotenode), e, strerror(e)); } From f5f7b99479c19fb94ecc1049ca79d98e36478533 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 17 Sep 2024 21:02:05 +0200 Subject: [PATCH 011/166] Fix crash if a packet fails to reach the client https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2480 but keeps the returns; --- src/i_tcp.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 3baefb94d..d7b0d3374 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -104,6 +104,10 @@ #undef EHOSTUNREACH #endif #define EHOSTUNREACH WSAEHOSTUNREACH + #ifdef ENETUNREACH + #undef ENETUNREACH + #endif + #define ENETUNREACH WSAENETUNREACH #ifndef IOC_VENDOR #define IOC_VENDOR 0x18000000 #endif @@ -820,6 +824,8 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr return sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d); } +#define ALLOWEDERROR(x) ((x) == ECONNREFUSED || (x) == EWOULDBLOCK || (x) == EHOSTUNREACH || (x) == ENETUNREACH) + static void SOCK_Send(void) { ssize_t c = ERRSOCKET; @@ -835,7 +841,11 @@ static void SOCK_Send(void) for (j = 0; j < broadcastaddresses; j++) { if (myfamily[i] == broadcastaddress[j].any.sa_family) - SOCK_SendToAddr(mysockets[i], &broadcastaddress[j]); + { + c = SOCK_SendToAddr(mysockets[i], &broadcastaddress[j]); + if (c == ERRSOCKET && !ALLOWEDERROR(errno)) + break; + } } } return; @@ -845,7 +855,11 @@ static void SOCK_Send(void) for (i = 0; i < mysocketses; i++) { if (myfamily[i] == clientaddress[doomcom->remotenode].any.sa_family) - SOCK_SendToAddr(mysockets[i], &clientaddress[doomcom->remotenode]); + { + c = SOCK_SendToAddr(mysockets[i], &clientaddress[doomcom->remotenode]); + if (c == ERRSOCKET && !ALLOWEDERROR(errno)) + break; + } } return; } @@ -857,11 +871,12 @@ static void SOCK_Send(void) if (c == ERRSOCKET) { int e = errno; // save error code so it can't be modified later - if (e != ECONNREFUSED && e != EWOULDBLOCK && e != EHOSTUNREACH) + if (!ALLOWEDERROR(e)) I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode, SOCK_GetNodeAddress(doomcom->remotenode), e, strerror(e)); } } +#undef ALLOWEDERROR #endif #ifndef NONET From 8074bfacb65bf751cfb6c4b7493c3f774095e3eb Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 18 Sep 2024 00:58:37 +0200 Subject: [PATCH 012/166] this does nothing --- src/r_main.c | 50 ++++---------------------------------------------- 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 0e0e7020e..5a686fb3b 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -173,10 +173,6 @@ static CV_PossibleValue_t maxportals_cons_t[] = {{0, "MIN"}, {12, "MAX"}, {0, NU static CV_PossibleValue_t homremoval_cons_t[] = {{0, "No"}, {1, "Yes"}, {2, "Flash"}, {0, NULL}}; static void Fov_OnChange(void); -static void ChaseCam_OnChange(void); -static void ChaseCam2_OnChange(void); -static void ChaseCam3_OnChange(void); -static void ChaseCam4_OnChange(void); static void FlipCam_OnChange(void); static void FlipCam2_OnChange(void); static void FlipCam3_OnChange(void); @@ -189,10 +185,10 @@ void SendWeaponPref4(void); static void Precipstuff_OnChange(void); consvar_t cv_tailspickup = {"tailspickup", "On", CV_NETVAR|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_chasecam = {"chasecam", "On", CV_CALL, CV_OnOff, ChaseCam_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_chasecam2 = {"chasecam2", "On", CV_CALL, CV_OnOff, ChaseCam2_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_chasecam3 = {"chasecam3", "On", CV_CALL, CV_OnOff, ChaseCam3_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_chasecam4 = {"chasecam4", "On", CV_CALL, CV_OnOff, ChaseCam4_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chasecam = {"chasecam", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chasecam2 = {"chasecam2", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chasecam3 = {"chasecam3", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_chasecam4 = {"chasecam4", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_flipcam = {"flipcam", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_flipcam2 = {"flipcam2", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam2_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_flipcam3 = {"flipcam3", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam3_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -272,47 +268,9 @@ void SplitScreen_OnChange(void) } static void Fov_OnChange(void) { - // Shouldn't be needed with render parity? - //if ((netgame || multiplayer) && !cv_debug && cv_fov.value != 90*FRACUNIT) - // CV_Set(&cv_fov, cv_fov.defaultvalue); - R_SetViewSize(); } -static void ChaseCam_OnChange(void) -{ - /*if (!cv_chasecam.value || !cv_useranalog.value) - CV_SetValue(&cv_analog, 0); - else - CV_SetValue(&cv_analog, 1);*/ -} - -static void ChaseCam2_OnChange(void) -{ - if (botingame) - return; - /*if (!cv_chasecam2.value || !cv_useranalog2.value) - CV_SetValue(&cv_analog2, 0); - else - CV_SetValue(&cv_analog2, 1);*/ -} - -static void ChaseCam3_OnChange(void) -{ - /*if (!cv_chasecam3.value || !cv_useranalog3.value) - CV_SetValue(&cv_analog3, 0); - else - CV_SetValue(&cv_analog3, 1);*/ -} - -static void ChaseCam4_OnChange(void) -{ - /*if (!cv_chasecam4.value || !cv_useranalog4.value) - CV_SetValue(&cv_analog4, 0); - else - CV_SetValue(&cv_analog4, 1);*/ -} - static void FlipCam_OnChange(void) { SendWeaponPref(); From d6d19d5dabfa95d9dd8499fade965b103558ed95 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 18 Sep 2024 01:02:42 +0200 Subject: [PATCH 013/166] smol cleanup --- src/m_menu.c | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 5a53d11bb..c42c923e2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3327,8 +3327,6 @@ static void Newgametype_OnChange(void) } CV_SetValue(&cv_nextmap, M_FindFirstMap(value)); - //CV_AddValue(&cv_nextmap, -1); - //CV_AddValue(&cv_nextmap, 1); } } } @@ -4295,7 +4293,9 @@ void M_Drawer(void) { // now that's more readable with a faded background (yeah like Quake...) if (ShouldDrawMenuBG()) + { V_DrawFadeScreen(0xFF00, 16); + } if (currentMenu->drawroutine) { @@ -5608,27 +5608,13 @@ boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) switch (levellistmode) { case LLM_CREATESERVER: - // Should the map be hidden? - //if (mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU && mapnum+1 != gamemap) - //return false; - // Should the map be hidden? <-- well imma wanna toggle it, its just annoying being unable to select hell maps in mapselect if ((mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU && mapnum+1 != gamemap) && (gt == GT_RACE && (mapheaderinfo[mapnum]->typeoflevel & TOL_RACE))) // map hell - { - if (cv_showallmaps.value) - return true; - else - return false; - } + return cv_showallmaps.value; // same goes here, just show every map if i want to if (M_MapLocked(mapnum+1)) // not unlocked - { - if (cv_showallmaps.value) - return true; - else - return false; - } + return cv_showallmaps.value; if ((gt == GT_MATCH || gt == GT_TEAMMATCH) && (mapheaderinfo[mapnum]->typeoflevel & TOL_MATCH)) return true; @@ -5638,18 +5624,7 @@ boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) return false; - /*case LLM_LEVELSELECT: - if (mapheaderinfo[mapnum]->levelselect != maplistoption) - return false; - - if (M_MapLocked(mapnum+1)) - return false; // not unlocked - - return true;*/ case LLM_RECORDATTACK: - /*if (!(mapheaderinfo[mapnum]->menuflags & LF2_RECORDATTACK)) - return false;*/ - if (!(mapheaderinfo[mapnum]->typeoflevel & TOL_RACE)) return false; @@ -5662,12 +5637,6 @@ boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) if (mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU) return false; // map hell - /*if (mapheaderinfo[mapnum]->menuflags & LF2_NOVISITNEEDED) - return true; - - if (!mapvisited[mapnum]) - return false;*/ - return true; default: return false; @@ -11753,7 +11722,7 @@ static void M_SetupMultiPlayer4(INT32 choice) //change the y offsets of the menu depending on cvar settings SKINSELECTMENUEDIT - + sortSkinGrid(); MP_PlayerSetupDef.prevMenu = currentMenu; From f77f7361a9f71e7a1b59d446044e9fccd78ef9c7 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 18 Sep 2024 01:06:54 +0200 Subject: [PATCH 014/166] this also does nothing --- src/g_game.c | 138 ++++--------------------------------------------- src/hu_stuff.c | 17 ------ 2 files changed, 10 insertions(+), 145 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 430ae0c7b..83150ea94 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -357,10 +357,6 @@ consvar_t cv_demochangemap = {"netdemo_savemapchange", "Disabled", CV_SAVE, demo static UINT8 *savebuffer; // Analog Control -static void UserAnalog_OnChange(void); -static void UserAnalog2_OnChange(void); -static void UserAnalog3_OnChange(void); -static void UserAnalog4_OnChange(void); static void Analog_OnChange(void); static void Analog2_OnChange(void); static void Analog3_OnChange(void); @@ -446,10 +442,10 @@ consvar_t cv_analog = {"analog", "Off", CV_CALL, CV_OnOff, Analog_OnChange, 0, N consvar_t cv_analog2 = {"analog2", "Off", CV_CALL, CV_OnOff, Analog2_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_analog3 = {"analog3", "Off", CV_CALL, CV_OnOff, Analog3_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_analog4 = {"analog4", "Off", CV_CALL, CV_OnOff, Analog4_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_useranalog = {"useranalog", "Off", CV_SAVE|CV_CALL, CV_OnOff, UserAnalog_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_useranalog2 = {"useranalog2", "Off", CV_SAVE|CV_CALL, CV_OnOff, UserAnalog2_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_useranalog3 = {"useranalog3", "Off", CV_SAVE|CV_CALL, CV_OnOff, UserAnalog3_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_useranalog4 = {"useranalog4", "Off", CV_SAVE|CV_CALL, CV_OnOff, UserAnalog4_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_useranalog = {"useranalog", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_useranalog2 = {"useranalog2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_useranalog3 = {"useranalog3", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_useranalog4 = {"useranalog4", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_turnaxis = {"joyaxis_turn", "Left X", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_moveaxis = {"joyaxis_move", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -511,8 +507,8 @@ static CV_PossibleValue_t driftsparkpulse_t[] = {{0, "MIN"}, {FRACUNIT*3, "MAX"} consvar_t cv_driftsparkpulse = {"driftsparkpulse", "1.4", CV_FLOAT | CV_SAVE, driftsparkpulse_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t stretchfactor_t[] = { - {0, "Off"}, {FRACUNIT/8, "0.125"}, {FRACUNIT/4, "0.250"}, - {3*FRACUNIT/8, "0.375"}, {FRACUNIT/2, "0.500"}, {5*FRACUNIT/8, "0.625"}, + {0, "Off"}, {FRACUNIT/8, "0.125"}, {FRACUNIT/4, "0.250"}, + {3*FRACUNIT/8, "0.375"}, {FRACUNIT/2, "0.500"}, {5*FRACUNIT/8, "0.625"}, {3*FRACUNIT/4, "0.750"}, {7*FRACUNIT/8, "0.875"}, {FRACUNIT, "Max"}, {0, NULL}}; consvar_t cv_gravstretch = {"gravstretch", "0", CV_SAVE, stretchfactor_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -596,15 +592,6 @@ void G_ClearRecords(void) } } -// For easy retrieval of records -/*UINT32 G_GetBestScore(INT16 map) -{ - if (!mainrecords[map-1]) - return 0; - - return mainrecords[map-1]->score; -}*/ - tic_t G_GetBestTime(INT16 map) { if (!mainrecords[map-1] || mainrecords[map-1]->time <= 0) @@ -980,7 +967,7 @@ static INT32 Joy3Axis(axis_input_e axissel) } if (flp) retaxis = -retaxis; //flip it around return retaxis; - + } else { @@ -1000,7 +987,7 @@ static INT32 Joy3Axis(axis_input_e axissel) } if (flp) retaxis = -retaxis; //flip it around return retaxis; - + } } @@ -1075,7 +1062,7 @@ static INT32 Joy4Axis(axis_input_e axissel) } if (flp) retaxis = -retaxis; //flip it around return retaxis; - + } else { @@ -1095,7 +1082,7 @@ static INT32 Joy4Axis(axis_input_e axissel) } if (flp) retaxis = -retaxis; //flip it around return retaxis; - + } } @@ -1509,61 +1496,11 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) } -// User has designated that they want -// analog ON, so tell the game to stop -// fudging with it. -static void UserAnalog_OnChange(void) -{ - /*if (cv_useranalog.value) - CV_SetValue(&cv_analog, 1); - else - CV_SetValue(&cv_analog, 0);*/ -} - -static void UserAnalog2_OnChange(void) -{ - if (botingame) - return; - /*if (cv_useranalog2.value) - CV_SetValue(&cv_analog2, 1); - else - CV_SetValue(&cv_analog2, 0);*/ -} - -static void UserAnalog3_OnChange(void) -{ - if (botingame) - return; - /*if (cv_useranalog3.value) - CV_SetValue(&cv_analog3, 1); - else - CV_SetValue(&cv_analog3, 0);*/ -} - -static void UserAnalog4_OnChange(void) -{ - if (botingame) - return; - /*if (cv_useranalog4.value) - CV_SetValue(&cv_analog4, 1); - else - CV_SetValue(&cv_analog4, 0);*/ -} - static void Analog_OnChange(void) { if (!cv_cam_dist.string) return; - // cameras are not initialized at this point - - /* - if (!cv_chasecam.value && cv_analog.value) { - CV_SetValue(&cv_analog, 0); - return; - } - */ - SendWeaponPref(); } @@ -1572,15 +1509,6 @@ static void Analog2_OnChange(void) if (!(splitscreen || botingame) || !cv_cam2_dist.string) return; - // cameras are not initialized at this point - - /* - if (!cv_chasecam2.value && cv_analog2.value) { - CV_SetValue(&cv_analog2, 0); - return; - } - */ - SendWeaponPref2(); } @@ -1589,15 +1517,6 @@ static void Analog3_OnChange(void) if (splitscreen < 2 || !cv_cam3_dist.string) return; - // cameras are not initialized at this point - - /* - if (!cv_chasecam3.value && cv_analog3.value) { - CV_SetValue(&cv_analog3, 0); - return; - } - */ - SendWeaponPref3(); } @@ -1606,15 +1525,6 @@ static void Analog4_OnChange(void) if (splitscreen < 3 || !cv_cam4_dist.string) return; - // cameras are not initialized at this point - - /* - if (!cv_chasecam4.value && cv_analog4.value) { - CV_SetValue(&cv_analog4, 0); - return; - } - */ - SendWeaponPref4(); } @@ -2150,7 +2060,6 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) P_ResetCamera(&players[(*displayplayerp)], camerap); - // Make sure the viewport doesn't interpolate at all into // its new position -- just snap instantly into place. R_ResetViewInterpolation(viewd); @@ -2235,13 +2144,6 @@ void G_Ticker(boolean run) if (!(netgame || multiplayer) && G_GetRetryFlag()) { G_ClearRetryFlag(); - - // Costs a life to retry ... unless the player in question is dead already. - /*if (G_GametypeUsesLives() && players[consoleplayer].playerstate == PST_LIVE) - players[consoleplayer].lives -= 1; - - G_DoReborn(consoleplayer);*/ - D_MapChange(gamemap, gametype, cv_kartencore.value, true, 1, false, false); } @@ -3163,13 +3065,6 @@ const char *Gametype_Names[NUMGAMETYPES] = { "Race", // GT_RACE "Battle" // GT_MATCH - - /*"Co-op", // GT_COOP - "Competition", // GT_COMPETITION - "Team Match", // GT_TEAMMATCH - "Tag", // GT_TAG - "Hide and Seek", // GT_HIDEANDSEEK - "CTF" // GT_CTF*/ }; // @@ -3231,12 +3126,7 @@ boolean G_GametypeHasTeams(void) // boolean G_GametypeHasSpectators(void) { - // SRB2Kart: We don't have any exceptions to not being able to spectate yet. Maybe when SP & bots roll around. -#if 0 - return (gametype != GT_COOP && gametype != GT_COMPETITION && gametype != GT_RACE); -#else return (netgame || (multiplayer && demo.playback)); //true -#endif } // @@ -4271,14 +4161,11 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) Z_Free(savebuffer); save_p = savebuffer = NULL; -// gameaction = ga_nothing; -// G_SetGamestate(GS_LEVEL); displayplayers[0] = consoleplayer; multiplayer = false; splitscreen = 0; SplitScreen_OnChange(); // not needed? -// G_DeferedInitNew(sk_medium, G_BuildMapName(1), 0, 0, 1); if (setsizeneeded) R_ExecuteSetViewSize(); @@ -7858,9 +7745,6 @@ void G_AddGhost(char *defdemoname) case ATTACKING_RECORD: // 1 p += 8; // demo time, lap break; - /*case ATTACKING_NIGHTS: // 2 - p += 8; // demo time left, score - break;*/ default: // 3 break; } @@ -8536,7 +8420,6 @@ boolean G_DemoTitleResponder(event_t *ev) void G_SetGamestate(gamestate_t newstate) { gamestate = newstate; - #ifdef HAVE_DISCORDRPC DRPC_UpdatePresence(); #endif @@ -8609,4 +8492,3 @@ INT32 G_TicsToMilliseconds(tic_t tics) { return (INT32)((tics%TICRATE) * (1000.00f/TICRATE)); } - diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 0594d28cd..ba6bb72bc 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2801,18 +2801,6 @@ static void HU_DrawRankings(void) V_DrawCenteredString(256, 16, hilicol, va("%d", cv_pointlimit.value)); } } - /*else if (gametype == GT_COOP) - { - INT32 totalscore = 0; - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i]) - totalscore += players[i].score; - } - - V_DrawCenteredString(256, 8, 0, "TOTAL SCORE"); - V_DrawCenteredString(256, 16, 0, va("%u", totalscore)); - }*/ else { if (circuitmap) @@ -2885,12 +2873,7 @@ static void HU_DrawRankings(void) #endif } - /*if (G_GametypeHasTeams()) - HU_DrawTeamTabRankings(tab, whiteplayer); //separate function for Spazzo's silly request -- gotta fix this up later - else if (scorelines > 10)*/ HU_DrawTabRankings(((scorelines > 8) ? 32 : 40), 33, tab, scorelines, whiteplayer, hilicol); - /*else - HU_DrawDualTabRankings(32, 32, tab, scorelines, whiteplayer);*/ // draw spectators in a ticker across the bottom if (netgame && G_GametypeHasSpectators()) From 6fb804292c7e50d4ccae8fce09ff63ab8cd31596 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Sep 2024 13:53:53 +0200 Subject: [PATCH 015/166] Prevent integer div by 0 in curl progress callback --- src/d_netfil.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index 7bf862f90..9423a368d 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1205,23 +1205,51 @@ size_t curlwrite_data(void *ptr, size_t size, size_t nmemb, FILE *stream) #ifdef XFERINFOFUNCTION int curlprogress_callbackx(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { + time_t curtime; + (void)clientp; (void)ultotal; (void)ulnow; // Function prototype requires these but we won't use, so just discard + + curtime = time(NULL); + curl_dlnow = dlnow; curl_dltotal = dltotal; - getbytes = curl_dlnow / (time(NULL) - curl_starttime); // To-do: Make this more accurate??? + + if (curtime > curl_starttime) + { + getbytes = curl_dlnow / (curtime - curl_starttime); // To-do: Make this more accurate??? + } + else + { + getbytes = 0; + } + return 0; } #else int curlprogress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { + time_t curtime; + (void)clientp; (void)ultotal; (void)ulnow; // Function prototype requires these but we won't use, so just discard + + curtime = time(NULL); + curl_dlnow = dlnow; curl_dltotal = dltotal; - getbytes = curl_dlnow / (time(NULL) - curl_starttime); // To-do: Make this more accurate??? + + if (curtime > curl_starttime) + { + getbytes = curl_dlnow / (curtime - curl_starttime); // To-do: Make this more accurate??? + } + else + { + getbytes = 0; + } + return 0; } #endif From 14ea041c72b0ffb0ce489fb04ac8e1abda5a5588 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 18 Sep 2024 12:11:04 +0200 Subject: [PATCH 016/166] always reset cam subsector regardless of splitscreen --- src/d_clisrv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f14ba8009..f80715785 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1997,6 +1997,10 @@ static void CL_ReloadReceivedSavegame(void) for (i = 0; i <= splitscreen; i++) { localangle[i] = (angle_t)(players[displayplayers[i]].cmd.angleturn<<16); + } + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); } From f12b7fd7726ffc0e08d7b372d5d574371b7f6b85 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 19 Sep 2024 12:41:32 +0200 Subject: [PATCH 017/166] move this --- src/g_game.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 83150ea94..1242e26e6 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2456,21 +2456,6 @@ void G_PlayerReborn(INT32 player) bot = players[player].bot; pity = players[player].pity; - if (leveltime <= starttime) // man i really hope this crap works kek but need to reset this somehow at mapstart - { - for (i = 0; i < LAP__MAX; i++) - { - laptime[i] = 0; - } - } - else - { - for (i = 0; i < LAP__MAX; i++) - { - laptime[i] = players[player].laptime[i]; - } - } - // SRB2kart if (leveltime <= starttime || spectator == true) { @@ -2491,6 +2476,11 @@ void G_PlayerReborn(INT32 player) starpostnum = 0; respawnflip = 0; starpostangle = 0; + + for (i = 0; i < LAP__MAX; i++) + { + laptime[i] = 0; + } } else { @@ -2519,6 +2509,11 @@ void G_PlayerReborn(INT32 player) bumper = players[player].kartstuff[k_bumper]; comebackpoints = players[player].kartstuff[k_comebackpoints]; wanted = players[player].kartstuff[k_wanted]; + + for (i = 0; i < LAP__MAX; i++) + { + laptime[i] = players[player].laptime[i]; + } } spectatorreentry = players[player].spectatorreentry; From 231c17354506e6321157cd714c99278dd83ceaee Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 19 Sep 2024 12:41:32 +0200 Subject: [PATCH 018/166] move this so speccing resets your laptime --- src/g_game.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 83150ea94..1242e26e6 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2456,21 +2456,6 @@ void G_PlayerReborn(INT32 player) bot = players[player].bot; pity = players[player].pity; - if (leveltime <= starttime) // man i really hope this crap works kek but need to reset this somehow at mapstart - { - for (i = 0; i < LAP__MAX; i++) - { - laptime[i] = 0; - } - } - else - { - for (i = 0; i < LAP__MAX; i++) - { - laptime[i] = players[player].laptime[i]; - } - } - // SRB2kart if (leveltime <= starttime || spectator == true) { @@ -2491,6 +2476,11 @@ void G_PlayerReborn(INT32 player) starpostnum = 0; respawnflip = 0; starpostangle = 0; + + for (i = 0; i < LAP__MAX; i++) + { + laptime[i] = 0; + } } else { @@ -2519,6 +2509,11 @@ void G_PlayerReborn(INT32 player) bumper = players[player].kartstuff[k_bumper]; comebackpoints = players[player].kartstuff[k_comebackpoints]; wanted = players[player].kartstuff[k_wanted]; + + for (i = 0; i < LAP__MAX; i++) + { + laptime[i] = players[player].laptime[i]; + } } spectatorreentry = players[player].spectatorreentry; From 12ffca73740a99549b52bb07126ff906e0ffe7e7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 04:13:02 +0200 Subject: [PATCH 019/166] precalc automap and minimap stuff on mapload instead of every frame --- src/am_map.c | 24 +++++---------- src/k_kart.c | 85 ++++++++++++--------------------------------------- src/p_local.h | 12 ++++++++ src/p_setup.c | 57 ++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 83 deletions(-) diff --git a/src/am_map.c b/src/am_map.c index d94ec7262..ac8236b41 100644 --- a/src/am_map.c +++ b/src/am_map.c @@ -260,25 +260,15 @@ static inline void AM_restoreScaleAndLoc(void) */ static void AM_findMinMaxBoundaries(void) { - size_t i; - fixed_t a; - fixed_t b; + fixed_t a, b; - min_x = min_y = +INT32_MAX; - max_x = max_y = -INT32_MAX; + min_x = minimapinfo.min_x << MAPBITS; + max_x = minimapinfo.max_x << MAPBITS; + min_y = minimapinfo.min_y << MAPBITS; + max_y = minimapinfo.max_y << MAPBITS; - for (i = 0; i < numvertexes; i++) - { - if (vertexes[i].x < min_x) - min_x = vertexes[i].x; - else if (vertexes[i].x > max_x) - max_x = vertexes[i].x; - - if (vertexes[i].y < min_y) - min_y = vertexes[i].y; - else if (vertexes[i].y > max_y) - max_y = vertexes[i].y; - } + max_w = minimapinfo.map_w << MAPBITS; + max_h = minimapinfo.map_h << MAPBITS; max_w = (max_x >>= FRACTOMAPBITS) - (min_x >>= FRACTOMAPBITS); max_h = (max_y >>= FRACTOMAPBITS) - (min_y >>= FRACTOMAPBITS); diff --git a/src/k_kart.c b/src/k_kart.c index 03efb24c9..9ed535d3b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9622,7 +9622,7 @@ static void K_drawKartPlayerCheck(void) } } -static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, patch_t *AutomapPic) +static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags) { // amnum xpos & ypos are the icon's speed around the HUD. // The number being divided by is for how fast it moves. @@ -9637,60 +9637,17 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat fixed_t amnumxpos, amnumypos; INT32 amxpos, amypos; - node_t *bsp = &nodes[numnodes-1]; - fixed_t maxx, minx, maxy, miny; - - fixed_t mapwidth, mapheight; - fixed_t xoffset, yoffset; - fixed_t xscale, yscale, zoom; - if (mo->skin) - skin = ((skin_t*)((mo->localskin) ? mo->localskin : mo->skin))-((skinlocal) ? localskins : skins); + skin = ((skin_t*)(mo->localskin ? mo->localskin : mo->skin))-(skinlocal ? localskins : skins); - maxx = maxy = INT32_MAX; - minx = miny = INT32_MIN; - minx = bsp->bbox[0][BOXLEFT]; - maxx = bsp->bbox[0][BOXRIGHT]; - miny = bsp->bbox[0][BOXBOTTOM]; - maxy = bsp->bbox[0][BOXTOP]; - - if (bsp->bbox[1][BOXLEFT] < minx) - minx = bsp->bbox[1][BOXLEFT]; - if (bsp->bbox[1][BOXRIGHT] > maxx) - maxx = bsp->bbox[1][BOXRIGHT]; - if (bsp->bbox[1][BOXBOTTOM] < miny) - miny = bsp->bbox[1][BOXBOTTOM]; - if (bsp->bbox[1][BOXTOP] > maxy) - maxy = bsp->bbox[1][BOXTOP]; - - // You might be wondering why these are being bitshift here - // it's because mapwidth and height would otherwise overflow for maps larger than half the size possible... - // map boundaries and sizes will ALWAYS be whole numbers thankfully - // later calculations take into consideration that these are actually not in terms of FRACUNIT though - minx >>= FRACBITS; - maxx >>= FRACBITS; - miny >>= FRACBITS; - maxy >>= FRACBITS; - - mapwidth = maxx - minx; - mapheight = maxy - miny; - - // These should always be small enough to be bitshift back right now - xoffset = (minx + mapwidth/2)<width, mapwidth); - yscale = FixedDiv(AutomapPic->height, mapheight); - zoom = FixedMul(min(xscale, yscale), FRACUNIT-FRACUNIT/20); - - amnumxpos = (FixedMul(lerp(mo->old_x, mo->x), zoom) - FixedMul(xoffset, zoom)); - amnumypos = -(FixedMul(lerp(mo->old_y, mo->y), zoom) - FixedMul(yoffset, zoom)); + amnumxpos = (FixedMul(lerp(mo->old_x, mo->x), minimapinfo.zoom) - minimapinfo.offs_x); + amnumypos = -(FixedMul(lerp(mo->old_y, mo->y), minimapinfo.zoom) - minimapinfo.offs_y); if (encoremode) amnumxpos = -amnumxpos; - amxpos = amnumxpos + ((x + AutomapPic->width/2 - (((skinlocal) ? localfacemmapprefix : facemmapprefix)[skin]->width/2))<height/2 - (((skinlocal) ? localfacemmapprefix : facemmapprefix)[skin]->height/2))<width)-SHORT((skinlocal ? localfacemmapprefix : facemmapprefix)[skin]->width))/2)<height)-SHORT((skinlocal ? localfacemmapprefix : facemmapprefix)[skin]->height))/2)<color) // 'default' color V_DrawSciencePatch(amxpos, amypos, flags, ( (skinlocal) ? localfacemmapprefix : facemmapprefix )[skin], FRACUNIT); @@ -9728,8 +9685,6 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat static void K_drawKartMinimap(void) { - INT32 lumpnum; - patch_t *AutomapPic; INT32 i = 0; INT32 x, y; INT32 minimaptrans, splitflags; @@ -9744,17 +9699,15 @@ static void K_drawKartMinimap(void) if (stplyr != &players[displayplayers[0]]) return; - lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap))); - - if (lumpnum != -1) - AutomapPic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX); - else + if (minimapinfo.minimap_pic == NULL) + { return; // no pic, just get outta here + } drawinfo_t info; K_getMinimapDrawinfo(&info); - x = info.x - (AutomapPic->width/2); - y = info.y - (AutomapPic->height/2); + x = info.x - (SHORT(minimapinfo.minimap_pic->width)/2); + y = info.y - (SHORT(minimapinfo.minimap_pic->height)/2); splitflags = info.flags; @@ -9775,9 +9728,9 @@ static void K_drawKartMinimap(void) splitflags |= minimaptrans; if (encoremode) - V_DrawScaledPatch(x+(AutomapPic->width), y, splitflags|V_FLIP, AutomapPic); + V_DrawScaledPatch(x+SHORT(minimapinfo.minimap_pic->width), y, minimaptrans|V_FLIP, minimapinfo.minimap_pic); else - V_DrawScaledPatch(x, y, splitflags, AutomapPic); + V_DrawScaledPatch(x, y, splitflags, minimapinfo.minimap_pic); if (!(splitscreen == 2)) { @@ -9787,10 +9740,10 @@ static void K_drawKartMinimap(void) // let offsets transfer to the heads, too! if (encoremode) - x += SHORT(AutomapPic->leftoffset); + x += SHORT(minimapinfo.minimap_pic->leftoffset); else - x -= SHORT(AutomapPic->leftoffset); - y -= SHORT(AutomapPic->topoffset); + x -= SHORT(minimapinfo.minimap_pic->leftoffset); + y -= SHORT(minimapinfo.minimap_pic->topoffset); // initialize for (i = 0; i < 4; i++) @@ -9802,7 +9755,7 @@ static void K_drawKartMinimap(void) demoghost *g = ghosts; while (g) { - K_drawKartMinimapHead(g->mo, x, y, splitflags, AutomapPic); + K_drawKartMinimapHead(g->mo, x, y, splitflags); g = g->next; } @@ -9843,7 +9796,7 @@ static void K_drawKartMinimap(void) continue; } - K_drawKartMinimapHead(players[i].mo, x, y, splitflags, AutomapPic); + K_drawKartMinimapHead(players[i].mo, x, y, splitflags); } } @@ -9855,7 +9808,7 @@ static void K_drawKartMinimap(void) { if (i == -1) continue; // this doesn't interest us - K_drawKartMinimapHead(players[localplayers[i]].mo, x, y, splitflags, AutomapPic); + K_drawKartMinimapHead(players[localplayers[i]].mo, x, y, splitflags); } } diff --git a/src/p_local.h b/src/p_local.h index 0193ec09d..6916acc44 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -392,6 +392,18 @@ extern fixed_t bmaporgy; // origin of block map extern mobj_t **blocklinks; // for thing chains extern precipmobj_t **precipblocklinks; // special blockmap for precip rendering +extern struct minimapinfo +{ + patch_t *minimap_pic; + UINT8 mapthingcount; + INT32 min_x, min_y; + INT32 max_x, max_y; + INT32 map_w, map_h; + INT32 minimap_w, minimap_h; + fixed_t offs_x, offs_y; + fixed_t zoom; +} minimapinfo; + // // P_INTER // diff --git a/src/p_setup.c b/src/p_setup.c index 671ba92ac..17d050dc4 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2487,6 +2487,61 @@ static boolean P_CanSave(void) return false; // SRB2Kart: no SP, no saving. } +struct minimapinfo minimapinfo; +static void P_InitMinimapInfo(void) +{ + INT32 lumpnum; + fixed_t a; + fixed_t b; + node_t *bsp = &nodes[numnodes-1]; + lumpnum = W_CheckNumForName(va("%sR", G_BuildMapName(gamemap))); + + if (lumpnum != -1) + minimapinfo.minimap_pic = W_CachePatchName(va("%sR", G_BuildMapName(gamemap)), PU_HUDGFX); + + minimapinfo.mapthingcount = 0; + // TODO iterate over mapthings to look for possible user-defined bounds + minimapinfo.min_x = bsp->bbox[0][BOXLEFT]; + minimapinfo.max_x = bsp->bbox[0][BOXRIGHT]; + minimapinfo.min_y = bsp->bbox[0][BOXBOTTOM]; + minimapinfo.max_y = bsp->bbox[0][BOXTOP]; + if (bsp->bbox[1][BOXLEFT] < minimapinfo.min_x) + minimapinfo.min_x = bsp->bbox[1][BOXLEFT]; + if (bsp->bbox[1][BOXRIGHT] > minimapinfo.max_x) + minimapinfo.max_x = bsp->bbox[1][BOXRIGHT]; + if (bsp->bbox[1][BOXBOTTOM] < minimapinfo.min_y) + minimapinfo.min_y = bsp->bbox[1][BOXBOTTOM]; + if (bsp->bbox[1][BOXTOP] > minimapinfo.max_y) + minimapinfo.max_y = bsp->bbox[1][BOXTOP]; + // You might be wondering why these are being bitshift here + // it's because mapwidth and height would otherwise overflow for maps larger than half the size possible... + // map boundaries and sizes will ALWAYS be whole numbers thankfully + // later calculations take into consideration that these are actually not in terms of FRACUNIT though + minimapinfo.map_w = (minimapinfo.max_x >>= FRACBITS) - (minimapinfo.min_x >>= FRACBITS); + minimapinfo.map_h = (minimapinfo.max_y >>= FRACBITS) - (minimapinfo.min_y >>= FRACBITS); + minimapinfo.minimap_w = minimapinfo.minimap_h = 100; + a = FixedDiv(minimapinfo.minimap_w<>(FRACBITS-4); + minimapinfo.zoom = a; + } + else + { + if (a != b) + { + minimapinfo.minimap_w = FixedMul(b, minimapinfo.map_w)>>(FRACBITS-4); + } + minimapinfo.zoom = b; + } + minimapinfo.zoom >>= (FRACBITS-4); + minimapinfo.zoom -= (minimapinfo.zoom/20); + // These should always be small enough to be bitshift back right now + minimapinfo.offs_x = FixedMul((minimapinfo.min_x + minimapinfo.map_w/2) << FRACBITS, minimapinfo.zoom); + minimapinfo.offs_y = FixedMul((minimapinfo.min_y + minimapinfo.map_h/2) << FRACBITS, minimapinfo.zoom); +} + /** Loads a level from a lump or external wad. * * \param skipprecip If true, don't spawn precipitation. @@ -2738,6 +2793,8 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) P_SpawnSecretItems(loademblems); + P_InitMinimapInfo(); + for (numcoopstarts = 0; numcoopstarts < MAXPLAYERS; numcoopstarts++) if (!playerstarts[numcoopstarts]) break; From 26e8c2ca2bc8473fdd4c649ea0c86317c2fd609f Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Sep 2024 20:31:45 +0200 Subject: [PATCH 020/166] beta hud driftgauge eh needs some stuff for menu still also should replace driftgauge gfx sometime --- src/d_netcmd.c | 4 ++-- src/k_kart.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index baba42007..3e89a3285 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -537,11 +537,11 @@ consvar_t cv_nametagscore = {"kartnametagscore", "Off", CV_SAVE, CV_OnOff, NULL, consvar_t cv_shownametagfinish = {"kartshownametagfinished", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_shownametagspectator = {"kartshownametagspectator", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t driftgaugeoffset_cons_t[] = { {-FRACUNIT*128, "MIN"}, {FRACUNIT*128, "MAX"}, {0, NULL}}; - static CV_PossibleValue_t driftgaugestyle_cons_t[] = { - {1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {0, NULL}}; + {1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {5, "Extra"}, {0, NULL}}; consvar_t cv_driftgauge = {"kartdriftgauge", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_driftgaugeofs = {"kartdriftgaugeoffset", "-20", CV_FLOAT|CV_SAVE, driftgaugeoffset_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/k_kart.c b/src/k_kart.c index 9ed535d3b..1fbe36794 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8874,7 +8874,7 @@ static void K_drawKartSpeedometer(void) { UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); V_DrawStretchyFixedPatch((SPDM_X-1)<= driftval*4) // rainbow sparks From 0bb1efcd50342949dbe99c8490aad7b94e86e00a Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 04:14:31 +0200 Subject: [PATCH 021/166] extra check --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 1fbe36794..747966ce3 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9404,7 +9404,7 @@ skipcrap: case 5: if (driftgaugegfx) { - if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || cv_driftgaugestyle.value == 5) + if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || (cv_driftgaugestyle.value == 5 && xtra_speedo3)) { barx = basex - dup*23; BAR_WIDTH = dup*47; From a6de843c75cd1ae0d809926869519ea2f158ce10 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 16:01:23 +0200 Subject: [PATCH 022/166] cleanup r_draw8 --- src/r_draw8.c | 411 +++++++++++++++++++++----------------------------- 1 file changed, 168 insertions(+), 243 deletions(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index 57f5366aa..6aabdb6dd 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -94,12 +94,16 @@ void R_DrawColumn_8(void) *dest = colormap[source[(frac>>FRACBITS) & heightmask]]; dest += vid.width; frac += fracstep; + *dest = colormap[source[(frac>>FRACBITS) & heightmask]]; dest += vid.width; frac += fracstep; } + if (count & 1) + { *dest = colormap[source[(frac>>FRACBITS) & heightmask]]; + } } } } @@ -162,7 +166,9 @@ void R_Draw2sMultiPatchColumn_8(void) val = source[frac>>FRACBITS]; if (val != TRANSPARENTPIXEL) + { *dest = colormap[val]; + } dest += vid.width; @@ -182,20 +188,30 @@ void R_Draw2sMultiPatchColumn_8(void) { val = source[(frac>>FRACBITS) & heightmask]; if (val != TRANSPARENTPIXEL) + { *dest = colormap[val]; + } + dest += vid.width; frac += fracstep; + val = source[(frac>>FRACBITS) & heightmask]; if (val != TRANSPARENTPIXEL) + { *dest = colormap[val]; + } + dest += vid.width; frac += fracstep; } + if (count & 1) { val = source[(frac>>FRACBITS) & heightmask]; if (val != TRANSPARENTPIXEL) + { *dest = colormap[val]; + } } } } @@ -259,7 +275,9 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) val = source[frac>>FRACBITS]; if (val != TRANSPARENTPIXEL) + { *dest = *(transmap + (colormap[val]<<8) + (*dest)); + } dest += vid.width; @@ -279,20 +297,30 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) { val = source[(frac>>FRACBITS) & heightmask]; if (val != TRANSPARENTPIXEL) + { *dest = *(transmap + (colormap[val]<<8) + (*dest)); + } + dest += vid.width; frac += fracstep; + val = source[(frac>>FRACBITS) & heightmask]; if (val != TRANSPARENTPIXEL) + { *dest = *(transmap + (colormap[val]<<8) + (*dest)); + } + dest += vid.width; frac += fracstep; } + if (count & 1) { val = source[(frac>>FRACBITS) & heightmask]; if (val != TRANSPARENTPIXEL) + { *dest = *(transmap + (colormap[val]<<8) + (*dest)); + } } } } @@ -394,6 +422,7 @@ void R_DrawTranslucentColumn_8(void) // heightmask is the Tutti-Frutti fix *dest = *(transmap + (colormap[source[frac>>FRACBITS]]<<8) + (*dest)); dest += vid.width; + if ((frac += fracstep) >= heightmask) frac -= heightmask; } @@ -406,12 +435,16 @@ void R_DrawTranslucentColumn_8(void) *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); dest += vid.width; frac += fracstep; + *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); dest += vid.width; frac += fracstep; } + if (count & 1) + { *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); + } } } } @@ -461,10 +494,9 @@ void R_DrawTranslatedTranslucentColumn_8(void) // Re-map color indices from wall texture column // using a lighting/special effects LUT. // heightmask is the Tutti-Frutti fix - *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]<<8) + (*dest)); - dest += vid.width; + if ((frac += fracstep) >= heightmask) frac -= heightmask; } @@ -477,12 +509,16 @@ void R_DrawTranslatedTranslucentColumn_8(void) *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); dest += vid.width; frac += fracstep; + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); dest += vid.width; frac += fracstep; } + if (count & 1) + { *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); + } } } } @@ -536,6 +572,12 @@ void R_DrawTranslatedColumn_8(void) // SPANS // ========================================================================== +#define SPANSIZE 16 +#define INVSPAN 0.0625f + +// 4194303 = (2048x2048)-1 (2048x2048 is maximum flat size) +#define MAXFLATBYTES 4194303 + /** \brief The R_DrawSpan_8 function Draws the actual span. */ @@ -544,6 +586,7 @@ void R_DrawSpan_8 (void) fixed_t xposition; fixed_t yposition; fixed_t xstep, ystep; + UINT32 bit; UINT8 *source; UINT8 *colormap; @@ -551,6 +594,7 @@ void R_DrawSpan_8 (void) const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; size_t count = (ds_x2 - ds_x1 + 1); + size_t i; xposition = ds_xfrac; yposition = ds_yfrac; xstep = ds_xstep; ystep = ds_ystep; @@ -577,44 +621,23 @@ void R_DrawSpan_8 (void) // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // have the uber complicated math to calculate it now, so that was a memory write we didn't // need! - dest[0] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; - xposition += xstep; - yposition += ystep; + for (i = 0; i < 8; i++) + { + bit = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); + dest[i] = colormap[source[bit]]; - dest[1] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; - xposition += xstep; - yposition += ystep; - - dest[2] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; - xposition += xstep; - yposition += ystep; - - dest[3] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; - xposition += xstep; - yposition += ystep; - - dest[4] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; - xposition += xstep; - yposition += ystep; - - dest[5] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; - xposition += xstep; - yposition += ystep; - - dest[6] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; - xposition += xstep; - yposition += ystep; - - dest[7] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; - xposition += xstep; - yposition += ystep; + xposition += xstep; + yposition += ystep; + } dest += 8; count -= 8; } while (count-- && dest <= deststop) { - *dest++ = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; + bit = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); + *dest++ = colormap[source[bit]]; + xposition += xstep; yposition += ystep; } @@ -664,6 +687,7 @@ void R_DrawTiltedSpan_8(void) double izstep, uzstep, vzstep; double endz, endu, endv; UINT32 stepu, stepv; + UINT32 bit; iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); @@ -683,6 +707,7 @@ void R_DrawTiltedSpan_8(void) vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); dest = ylookup[ds_y] + columnofs[ds_x1]; + source = ds_source; //colormap = ds_colormap; @@ -695,18 +720,16 @@ void R_DrawTiltedSpan_8(void) u = (INT64)(uz*z) + viewx; v = (INT64)(vz*z) + viewy; + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); + *dest = colormap[source[bit]]; - *dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; dest++; iz += ds_szp->x; uz += ds_sup->x; vz += ds_svp->x; } while (--width >= 0); #else -#define SPANSIZE 16 -#define INVSPAN 0.0625f - startz = 1.f/iz; startu = uz*startz; startv = vz*startz; @@ -733,8 +756,10 @@ void R_DrawTiltedSpan_8(void) for (i = SPANSIZE-1; i >= 0; i--) { + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; + *dest = colormap[source[bit]]; + dest++; u += stepu; v += stepv; @@ -749,8 +774,9 @@ void R_DrawTiltedSpan_8(void) { u = (INT64)(startu); v = (INT64)(startv); + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; + *dest = colormap[source[bit]]; } else { @@ -770,8 +796,10 @@ void R_DrawTiltedSpan_8(void) for (; width != 0; width--) { + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; + *dest = colormap[source[bit]]; + dest++; u += stepu; v += stepv; @@ -800,6 +828,7 @@ void R_DrawTiltedTranslucentSpan_8(void) double izstep, uzstep, vzstep; double endz, endu, endv; UINT32 stepu, stepv; + UINT32 bit; iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); @@ -819,6 +848,7 @@ void R_DrawTiltedTranslucentSpan_8(void) vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); dest = ylookup[ds_y] + columnofs[ds_x1]; + source = ds_source; //colormap = ds_colormap; @@ -831,17 +861,16 @@ void R_DrawTiltedTranslucentSpan_8(void) u = (INT64)(uz*z) + viewx; v = (INT64)(vz*z) + viewy; + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); + *dest = *(ds_transmap + (colormap[source[bit]] << 8) + *dest); + dest++; iz += ds_szp->x; uz += ds_sup->x; vz += ds_svp->x; } while (--width >= 0); #else -#define SPANSIZE 16 -#define INVSPAN 0.0625f - startz = 1.f/iz; startu = uz*startz; startv = vz*startz; @@ -868,8 +897,10 @@ void R_DrawTiltedTranslucentSpan_8(void) for (i = SPANSIZE-1; i >= 0; i--) { + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); + *dest = *(ds_transmap + (colormap[source[bit]] << 8) + *dest); + dest++; u += stepu; v += stepv; @@ -884,8 +915,9 @@ void R_DrawTiltedTranslucentSpan_8(void) { u = (INT64)(startu); v = (INT64)(startv); + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); + *dest = *(ds_transmap + (colormap[source[bit]] << 8) + *dest); } else { @@ -905,8 +937,10 @@ void R_DrawTiltedTranslucentSpan_8(void) for (; width != 0; width--) { + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); + *dest = *(ds_transmap + (colormap[source[bit]] << 8) + *dest); + dest++; u += stepu; v += stepv; @@ -937,6 +971,7 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) double izstep, uzstep, vzstep; double endz, endu, endv; UINT32 stepu, stepv; + UINT32 bit; iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); @@ -957,6 +992,7 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) dest = ylookup[ds_y] + columnofs[ds_x1]; dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1; + source = ds_source; //colormap = ds_colormap; @@ -969,17 +1005,16 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) u = (INT64)(uz*z) + viewx; v = (INT64)(vz*z) + viewy; + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++); + *dest = *(ds_transmap + (colormap[source[bit]] << 8) + *dsrc++); + dest++; iz += ds_szp->x; uz += ds_sup->x; vz += ds_svp->x; } while (--width >= 0); #else -#define SPANSIZE 16 -#define INVSPAN 0.0625f - startz = 1.f/iz; startu = uz*startz; startv = vz*startz; @@ -1006,8 +1041,10 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) for (i = SPANSIZE-1; i >= 0; i--) { + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++); + *dest = *(ds_transmap + (colormap[source[bit]] << 8) + *dsrc++); + dest++; u += stepu; v += stepv; @@ -1022,8 +1059,9 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) { u = (INT64)(startu); v = (INT64)(startv); + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++); + *dest = *(ds_transmap + (colormap[source[bit]] << 8) + *dsrc++); } else { @@ -1043,8 +1081,10 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) for (; width != 0; width--) { + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++); + *dest = *(ds_transmap + (colormap[source[bit]] << 8) + *dsrc++); + dest++; u += stepu; v += stepv; @@ -1073,6 +1113,7 @@ void R_DrawTiltedSplat_8(void) double izstep, uzstep, vzstep; double endz, endu, endv; UINT32 stepu, stepv; + UINT32 bit; iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); @@ -1092,6 +1133,7 @@ void R_DrawTiltedSplat_8(void) vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); dest = ylookup[ds_y] + columnofs[ds_x1]; + source = ds_source; //colormap = ds_colormap; @@ -1104,20 +1146,20 @@ void R_DrawTiltedSplat_8(void) u = (INT64)(uz*z) + viewx; v = (INT64)(vz*z) + viewy; - colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); + val = source[bit]; - val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; if (val != TRANSPARENTPIXEL) + { + colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); *dest = colormap[val]; + } dest++; iz += ds_szp->x; uz += ds_sup->x; vz += ds_svp->x; } while (--width >= 0); #else -#define SPANSIZE 16 -#define INVSPAN 0.0625f - startz = 1.f/iz; startu = uz*startz; startv = vz*startz; @@ -1144,10 +1186,13 @@ void R_DrawTiltedSplat_8(void) for (i = SPANSIZE-1; i >= 0; i--) { - colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); + val = source[bit]; if (val != TRANSPARENTPIXEL) + { + colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); *dest = colormap[val]; + } dest++; u += stepu; v += stepv; @@ -1162,10 +1207,13 @@ void R_DrawTiltedSplat_8(void) { u = (INT64)(startu); v = (INT64)(startv); - colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); + val = source[bit]; if (val != TRANSPARENTPIXEL) + { + colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); *dest = colormap[val]; + } } else { @@ -1185,10 +1233,13 @@ void R_DrawTiltedSplat_8(void) for (; width != 0; width--) { - colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; + bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); + val = source[bit]; if (val != TRANSPARENTPIXEL) + { + colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); *dest = colormap[val]; + } dest++; u += stepu; v += stepv; @@ -1206,12 +1257,14 @@ void R_DrawSplat_8 (void) UINT32 xposition; UINT32 yposition; UINT32 xstep, ystep; + UINT32 bit; UINT8 *source; UINT8 *colormap; UINT8 *dest; size_t count; + size_t i; UINT32 val; // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest @@ -1236,80 +1289,29 @@ void R_DrawSplat_8 (void) // need! // // 4194303 = (2048x2048)-1 (2048x2048 is maximum flat size) - val = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); - val &= 4194303; - val = source[val]; - if (val != TRANSPARENTPIXEL) - dest[0] = colormap[val]; - xposition += xstep; - yposition += ystep; + for (i = 0; i < 8; i++) + { + bit = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); + bit &= MAXFLATBYTES; + val = source[bit]; + if (val != TRANSPARENTPIXEL) + dest[i] = colormap[val]; - val = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); - val &= 4194303; - val = source[val]; - if (val != TRANSPARENTPIXEL) - dest[1] = colormap[val]; - xposition += xstep; - yposition += ystep; - - val = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); - val &= 4194303; - val = source[val]; - if (val != TRANSPARENTPIXEL) - dest[2] = colormap[val]; - xposition += xstep; - yposition += ystep; - - val = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); - val &= 4194303; - val = source[val]; - if (val != TRANSPARENTPIXEL) - dest[3] = colormap[val]; - xposition += xstep; - yposition += ystep; - - val = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); - val &= 4194303; - val = source[val]; - if (val != TRANSPARENTPIXEL) - dest[4] = colormap[val]; - xposition += xstep; - yposition += ystep; - - val = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); - val &= 4194303; - val = source[val]; - if (val != TRANSPARENTPIXEL) - dest[5] = colormap[val]; - xposition += xstep; - yposition += ystep; - - val = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); - val &= 4194303; - val = source[val]; - if (val != TRANSPARENTPIXEL) - dest[6] = colormap[val]; - xposition += xstep; - yposition += ystep; - - val = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); - val &= 4194303; - val = source[val]; - if (val != TRANSPARENTPIXEL) - dest[7] = colormap[val]; - xposition += xstep; - yposition += ystep; + xposition += xstep; + yposition += ystep; + } dest += 8; count -= 8; } while (count--) { - val = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); - val &= 4194303; - val = source[val]; + bit = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); + val = source[bit]; if (val != TRANSPARENTPIXEL) + { *dest = colormap[val]; + } dest++; xposition += xstep; @@ -1325,12 +1327,14 @@ void R_DrawTranslucentSplat_8 (void) UINT32 xposition; UINT32 yposition; UINT32 xstep, ystep; + UINT32 bit; UINT8 *source; UINT8 *colormap; UINT8 *dest; size_t count; + size_t i; UINT8 val; // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest @@ -1353,60 +1357,24 @@ void R_DrawTranslucentSplat_8 (void) // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // have the uber complicated math to calculate it now, so that was a memory write we didn't // need! - val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; - if (val != TRANSPARENTPIXEL) - dest[0] = *(ds_transmap + (colormap[val] << 8) + dest[0]); - xposition += xstep; - yposition += ystep; + for (i = 0; i < 8; i++) + { + bit = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); + val = source[bit]; + if (val != TRANSPARENTPIXEL) + dest[i] = *(ds_transmap + (colormap[val] << 8) + dest[i]); - val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; - if (val != TRANSPARENTPIXEL) - dest[1] = *(ds_transmap + (colormap[val] << 8) + dest[1]); - xposition += xstep; - yposition += ystep; - - val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; - if (val != TRANSPARENTPIXEL) - dest[2] = *(ds_transmap + (colormap[val] << 8) + dest[2]); - xposition += xstep; - yposition += ystep; - - val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; - if (val != TRANSPARENTPIXEL) - dest[3] = *(ds_transmap + (colormap[val] << 8) + dest[3]); - xposition += xstep; - yposition += ystep; - - val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; - if (val != TRANSPARENTPIXEL) - dest[4] = *(ds_transmap + (colormap[val] << 8) + dest[4]); - xposition += xstep; - yposition += ystep; - - val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; - if (val != TRANSPARENTPIXEL) - dest[5] = *(ds_transmap + (colormap[val] << 8) + dest[5]); - xposition += xstep; - yposition += ystep; - - val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; - if (val != TRANSPARENTPIXEL) - dest[6] = *(ds_transmap + (colormap[val] << 8) + dest[6]); - xposition += xstep; - yposition += ystep; - - val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; - if (val != TRANSPARENTPIXEL) - dest[7] = *(ds_transmap + (colormap[val] << 8) + dest[7]); - xposition += xstep; - yposition += ystep; + xposition += xstep; + yposition += ystep; + } dest += 8; count -= 8; } while (count--) { - val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; + bit = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); + val = source[bit]; if (val != TRANSPARENTPIXEL) *dest = *(ds_transmap + (colormap[val] << 8) + *dest); @@ -1424,6 +1392,7 @@ void R_DrawTranslucentSpan_8 (void) fixed_t xposition; fixed_t yposition; fixed_t xstep, ystep; + UINT32 bit; UINT8 *source; UINT8 *colormap; @@ -1431,7 +1400,7 @@ void R_DrawTranslucentSpan_8 (void) const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; size_t count = (ds_x2 - ds_x1 + 1); - UINT32 val; + size_t i; xposition = ds_xfrac; yposition = ds_yfrac; xstep = ds_xstep; ystep = ds_ystep; @@ -1455,45 +1424,21 @@ void R_DrawTranslucentSpan_8 (void) // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // have the uber complicated math to calculate it now, so that was a memory write we didn't // need! - dest[0] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[0]); - xposition += xstep; - yposition += ystep; - - dest[1] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[1]); - xposition += xstep; - yposition += ystep; - - dest[2] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[2]); - xposition += xstep; - yposition += ystep; - - dest[3] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[3]); - xposition += xstep; - yposition += ystep; - - dest[4] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[4]); - xposition += xstep; - yposition += ystep; - - dest[5] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[5]); - xposition += xstep; - yposition += ystep; - - dest[6] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[6]); - xposition += xstep; - yposition += ystep; - - dest[7] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[7]); - xposition += xstep; - yposition += ystep; + for (i = 0; i < 8; i++) + { + bit = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); + dest[i] = *(ds_transmap + (colormap[source[bit]] << 8) + dest[i]); + xposition += xstep; + yposition += ystep; + } dest += 8; count -= 8; } while (count-- && dest <= deststop) { - val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); - *dest = *(ds_transmap + (colormap[source[val]] << 8) + *dest); + bit = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); + *dest = *(ds_transmap + (colormap[source[bit]] << 8) + *dest); dest++; xposition += xstep; yposition += ystep; @@ -1506,6 +1451,7 @@ void R_DrawTranslucentWaterSpan_8(void) UINT32 xposition; UINT32 yposition; UINT32 xstep, ystep; + UINT32 bit; UINT8 *source; UINT8 *colormap; @@ -1513,6 +1459,7 @@ void R_DrawTranslucentWaterSpan_8(void) UINT8 *dsrc; size_t count; + size_t i; // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest // can be used for the fraction part. This allows calculation of the memory address in the @@ -1535,44 +1482,22 @@ void R_DrawTranslucentWaterSpan_8(void) // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // have the uber complicated math to calculate it now, so that was a memory write we didn't // need! - dest[0] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; - xposition += xstep; - yposition += ystep; - - dest[1] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; - xposition += xstep; - yposition += ystep; - - dest[2] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; - xposition += xstep; - yposition += ystep; - - dest[3] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; - xposition += xstep; - yposition += ystep; - - dest[4] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; - xposition += xstep; - yposition += ystep; - - dest[5] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; - xposition += xstep; - yposition += ystep; - - dest[6] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; - xposition += xstep; - yposition += ystep; - - dest[7] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; - xposition += xstep; - yposition += ystep; + for (i = 0; i < 8; i++) + { + bit = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); + dest[i] = colormap[*(ds_transmap + (source[bit] << 8) + *dsrc++)]; + xposition += xstep; + yposition += ystep; + } dest += 8; count -= 8; } while (count--) { - *dest++ = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; + bit = ((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift); + *dest++ = colormap[*(ds_transmap + (source[bit] << 8) + *dsrc++)]; + xposition += xstep; yposition += ystep; } From 8dfa841a7b4a3a6043f7b27c2a87ef54b0727219 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 16:25:16 +0200 Subject: [PATCH 023/166] Load palette before map data --- src/d_main.c | 4 ++++ src/v_video.c | 8 +++----- src/v_video.h | 3 +++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index c437a9dcf..a57bf9eb2 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1677,6 +1677,10 @@ void D_SRB2Main(void) #undef PUSHSPEEDO memcpy(speedo_cons_t, speedo_cons_temp, sizeof(speedo_cons_t)); + // Do it before P_InitMapData because PNG patch + // conversion sometimes needs the palette + V_ReloadPalette(); + // // search for maps // diff --git a/src/v_video.c b/src/v_video.c index 202b5d288..5746d963e 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -528,7 +528,7 @@ const char *GetPalette(void) return "PLAYPAL"; } -static void LoadMapPalette(void) +void V_ReloadPalette(void) { LoadPalette(GetPalette()); } @@ -540,7 +540,7 @@ static void LoadMapPalette(void) void V_SetPalette(INT32 palettenum) { if (!pLocalPalette) - LoadMapPalette(); + V_ReloadPalette(); #ifdef HWRENDER if (rendermode == render_opengl) @@ -575,7 +575,7 @@ static void CV_palette_OnChange(void) if (loaded_config == false) return; // reload palette - LoadMapPalette(); + V_ReloadPalette(); V_SetPalette(0); } @@ -3373,8 +3373,6 @@ void V_Init(void) UINT8 *base = vid.buffer; const INT32 screensize = vid.rowbytes * vid.height; - LoadMapPalette(); - for (i = 0; i < NUMSCREENS; i++) screens[i] = NULL; diff --git a/src/v_video.h b/src/v_video.h index 77f628efb..b1d10af6a 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -49,6 +49,9 @@ extern UINT8 colorlookup[CLUTSIZE][CLUTSIZE][CLUTSIZE]; void InitColorLUT(void); +// Loads the correct palette into memory +void V_ReloadPalette(void); + // Set the current RGB palette lookup to use for palettized graphics void V_SetPalette(INT32 palettenum); From c14af4a136a5a56f2bc3bb4343ecb559f5aeb6a7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 16:53:25 +0200 Subject: [PATCH 024/166] clean up leveload a bit --- src/p_setup.c | 306 +++++++++++++++++++++++++------------------------- 1 file changed, 154 insertions(+), 152 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 17d050dc4..e4f3c6c3d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -578,6 +578,7 @@ FUNCINLINE static ATTRINLINE void P_LoadRawSubsectors(void *data) size_t numlevelflats; levelflat_t *levelflats; +levelflat_t *foundflats; //SoM: Other files want this info. size_t P_PrecacheLevelFlats(void) @@ -703,18 +704,9 @@ static void P_LoadRawSectors(UINT8 *data) { mapsector_t *ms = (mapsector_t *)data; sector_t *ss = sectors; - levelflat_t *foundflats; size_t i; - // Allocate a big chunk of memory as big as our MAXLEVELFLATS limit. - //Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty - foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats)); - if (foundflats == NULL) - I_Error("Ran out of memory while loading sectors\n"); - - numlevelflats = 0; - // For each counted sector, copy the sector raw data from our cache pointer ms, to the global table pointer ss. for (i = 0; i < numsectors; i++, ss++, ms++) { @@ -775,16 +767,6 @@ static void P_LoadRawSectors(UINT8 *data) ss->floorspeed = 0; ss->ceilspeed = 0; } - - // set the sky flat num - skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats); - - // copy table for global usage - levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t)); - free(foundflats); - - // search for animated flats and set up - P_SetupLevelFlatAnims(); } // @@ -1469,7 +1451,6 @@ static void P_LoadRawSideDefs2(void *data) break; } } - R_ClearTextureNumCache(true); } static boolean LineInBlock(fixed_t cx1, fixed_t cy1, fixed_t cx2, fixed_t cy2, fixed_t bx1, fixed_t by1) @@ -1986,12 +1967,32 @@ static void P_LoadMapData(const virtres_t* virt) lines = Z_Calloc(numlines * sizeof (*lines), PU_LEVEL, NULL); mapthings = Z_Calloc(nummapthings * sizeof (*mapthings), PU_LEVEL, NULL); + // Allocate a big chunk of memory as big as our MAXLEVELFLATS limit. + //Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty + foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats)); + if (foundflats == NULL) + I_Error("Ran out of memory while loading sectors\n"); + numlevelflats = 0; + // Strict map data P_LoadRawVertexes(virtvertexes->data); P_LoadRawSectors(virtsectors->data); P_LoadRawLineDefs(virtlinedefs->data); P_SetupLines(); P_LoadRawSideDefs2(virtsidedefs->data); + P_PrepareRawThings(virtthings->data); + + R_ClearTextureNumCache(true); + + // set the sky flat num + skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats); + + // copy table for global usage + levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t)); + free(foundflats); + + // search for animated flats and set up + P_SetupLevelFlatAnims(); } /** Sets up a sky texture to use for the level. @@ -2242,16 +2243,6 @@ static void P_LoadMapFromFile(void) P_PrepareRawThings(vres_Find(curmapvirt, "THINGS")->data); P_MakeMapMD5(curmapvirt, &mapmd5); - - // We do the following silly - // construction because vres_Free - // no-sells deletions of pointers - // that are == curmapvirt. - { - virtres_t *temp = curmapvirt; - curmapvirt = NULL; - vres_Free(temp); - } } static void P_RunLevelScript(const char *scriptname) @@ -2487,6 +2478,129 @@ static boolean P_CanSave(void) return false; // SRB2Kart: no SP, no saving. } +static void P_InitGametype(void) +{ + INT32 i; + + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + { + players[i].pflags &= ~PF_NIGHTSMODE; + + // Start players with pity shields if possible + players[i].pity = -1; + + if (!G_RaceGametype()) + { + players[i].mo = NULL; + G_DoReborn(i); + } + else // gametype is GT_COOP or GT_RACE + { + players[i].mo = NULL; + + if (players[i].starposttime) + { + G_SpawnPlayer(i, true); + } + else + G_SpawnPlayer(i, false); + } + } + + if (modeattacking == ATTACKING_RECORD && !demo.playback) + P_LoadRecordGhosts(); + + if (G_TagGametype()) + { + INT32 realnumplayers = 0; + INT32 playersactive[MAXPLAYERS]; + + //I just realized how problematic this code can be. + //D_NumPlayers() will not always cover the scope of the netgame. + //What if one player is node 0 and the other node 31? + //The solution? Make a temp array of all players that are currently playing and pick from them. + //Future todo? When a player leaves, shift all nodes down so D_NumPlayers() can be used as intended? + //Also, you'd never have to loop through all 32 players slots to find anything ever again. + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && !players[i].spectator) + { + playersactive[realnumplayers] = i; //stores the player's node in the array. + realnumplayers++; + } + } + + if (realnumplayers) //this should also fix the dedicated crash bug. You only pick a player if one exists to be picked. + { + i = P_RandomKey(realnumplayers); + players[playersactive[i]].pflags |= PF_TAGIT; //choose our initial tagger before map starts. + + // Taken and modified from G_DoReborn() + // Remove the player so he can respawn elsewhere. + // first dissasociate the corpse + if (players[playersactive[i]].mo) + P_RemoveMobj(players[playersactive[i]].mo); + + G_SpawnPlayer(playersactive[i], false); //respawn the lucky player in his dedicated spawn location. + } + else + CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n")); + + } + else if (G_RaceGametype() && server) + CV_StealthSetValue(&cv_numlaps, + ((netgame || multiplayer) && cv_basenumlaps.value + && (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) + || (mapheaderinfo[gamemap - 1]->numlaps > cv_basenumlaps.value))) + ? cv_basenumlaps.value + : mapheaderinfo[gamemap - 1]->numlaps); + + // Start recording replay in multiplayer with a temp filename + //Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays! + if (!demo.playback && multiplayer && D_NumPlayers()) { + static char buf[256]; + sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap)); + + I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755); + I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755); + G_RecordDemo(buf); + if (dedicated) + G_BeginRecording(); //this has to move here, since dedicated servers dont run got_mapcmd + } + + wantedcalcdelay = wantedfrequency*2; + indirectitemcooldown = 0; + hyubgone = 0; + mapreset = 0; + nospectategrief = 0; + thwompsactive = false; + spbplace = -1; + + startedInFreePlay = false; + { + UINT8 nump = 0; + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + { + continue; + } + + nump++; + if (nump == 2) + { + break; + } + } + + if (nump <= 1) + { + startedInFreePlay = true; + } + } +} + struct minimapinfo minimapinfo; static void P_InitMinimapInfo(void) { @@ -2822,131 +2936,19 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) // none of this needs to be done because it's not the beginning of the map when // a netgame save is being loaded, and could actively be harmful by messing with // the client's view of the data.) - if (fromnetsave) - goto netgameskip; - // ========== + if (!fromnetsave) + P_InitGametype(); - for (i = 0; i < MAXPLAYERS; i++) - if (playeringame[i]) - { - players[i].pflags &= ~PF_NIGHTSMODE; - - // Start players with pity shields if possible - players[i].pity = -1; - - if (!G_RaceGametype()) - { - players[i].mo = NULL; - G_DoReborn(i); - } - else // gametype is GT_COOP or GT_RACE - { - players[i].mo = NULL; - - if (players[i].starposttime) - { - G_SpawnPlayer(i, true); - } - else - G_SpawnPlayer(i, false); - } - } - - if (modeattacking == ATTACKING_RECORD && !demo.playback) - P_LoadRecordGhosts(); - - if (G_TagGametype()) + // Now safe to free. + // We do the following silly + // construction because vres_Free + // no-sells deletions of pointers + // that are == curmapvirt. { - INT32 realnumplayers = 0; - INT32 playersactive[MAXPLAYERS]; - - //I just realized how problematic this code can be. - //D_NumPlayers() will not always cover the scope of the netgame. - //What if one player is node 0 and the other node 31? - //The solution? Make a temp array of all players that are currently playing and pick from them. - //Future todo? When a player leaves, shift all nodes down so D_NumPlayers() can be used as intended? - //Also, you'd never have to loop through all 32 players slots to find anything ever again. - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i] && !players[i].spectator) - { - playersactive[realnumplayers] = i; //stores the player's node in the array. - realnumplayers++; - } - } - - if (realnumplayers) //this should also fix the dedicated crash bug. You only pick a player if one exists to be picked. - { - i = P_RandomKey(realnumplayers); - players[playersactive[i]].pflags |= PF_TAGIT; //choose our initial tagger before map starts. - - // Taken and modified from G_DoReborn() - // Remove the player so he can respawn elsewhere. - // first dissasociate the corpse - if (players[playersactive[i]].mo) - P_RemoveMobj(players[playersactive[i]].mo); - - G_SpawnPlayer(playersactive[i], false); //respawn the lucky player in his dedicated spawn location. - } - else - CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n")); - + virtres_t *temp = curmapvirt; + curmapvirt = NULL; + vres_Free(temp); } - else if (G_RaceGametype() && server) - CV_StealthSetValue(&cv_numlaps, - ((netgame || multiplayer) && cv_basenumlaps.value - && (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) - || (mapheaderinfo[gamemap - 1]->numlaps > cv_basenumlaps.value))) - ? cv_basenumlaps.value - : mapheaderinfo[gamemap - 1]->numlaps); - - // Start recording replay in multiplayer with a temp filename - //Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays! - if (!demo.playback && multiplayer && D_NumPlayers()) { - static char buf[256]; - sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap)); - - I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755); - I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755); - G_RecordDemo(buf); - if (dedicated) - G_BeginRecording(); //this has to move here, since dedicated servers dont run got_mapcmd - } - - wantedcalcdelay = wantedfrequency*2; - indirectitemcooldown = 0; - hyubgone = 0; - mapreset = 0; - nospectategrief = 0; - thwompsactive = false; - spbplace = -1; - - startedInFreePlay = false; - { - UINT8 nump = 0; - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] || players[i].spectator) - { - continue; - } - - nump++; - if (nump == 2) - { - break; - } - } - - if (nump <= 1) - { - startedInFreePlay = true; - } - } - - // =========== - // landing point for netgames. - netgameskip: if (!reloadinggamestate) { From 0bd9c696df0a6ca121a791308774c33b75656284 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 16:51:05 +0200 Subject: [PATCH 025/166] try to prevent unknown packet type spam when client attempt to connect while levelloading --- src/d_clisrv.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f80715785..33088b7ce 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5793,9 +5793,12 @@ static void GetPackets(void) { node = (SINT8)doomcom->remotenode; - if (netbuffer->packettype == PT_CLIENTJOIN && server && !levelloading) + if (netbuffer->packettype == PT_CLIENTJOIN && server) { - HandleConnect(node); + if (!levelloading) // Otherwise just ignore + { + HandleConnect(node); + } continue; } if (node == servernode && client && cl_mode != CL_SEARCHING) From ba5459eeb6ddac7062e790f97eae078d51c0c1b0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 17:52:26 +0200 Subject: [PATCH 026/166] Revert "clean up leveload a bit" This reverts commit c14af4a136a5a56f2bc3bb4343ecb559f5aeb6a7. --- src/p_setup.c | 306 +++++++++++++++++++++++++------------------------- 1 file changed, 152 insertions(+), 154 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index e4f3c6c3d..17d050dc4 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -578,7 +578,6 @@ FUNCINLINE static ATTRINLINE void P_LoadRawSubsectors(void *data) size_t numlevelflats; levelflat_t *levelflats; -levelflat_t *foundflats; //SoM: Other files want this info. size_t P_PrecacheLevelFlats(void) @@ -704,9 +703,18 @@ static void P_LoadRawSectors(UINT8 *data) { mapsector_t *ms = (mapsector_t *)data; sector_t *ss = sectors; + levelflat_t *foundflats; size_t i; + // Allocate a big chunk of memory as big as our MAXLEVELFLATS limit. + //Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty + foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats)); + if (foundflats == NULL) + I_Error("Ran out of memory while loading sectors\n"); + + numlevelflats = 0; + // For each counted sector, copy the sector raw data from our cache pointer ms, to the global table pointer ss. for (i = 0; i < numsectors; i++, ss++, ms++) { @@ -767,6 +775,16 @@ static void P_LoadRawSectors(UINT8 *data) ss->floorspeed = 0; ss->ceilspeed = 0; } + + // set the sky flat num + skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats); + + // copy table for global usage + levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t)); + free(foundflats); + + // search for animated flats and set up + P_SetupLevelFlatAnims(); } // @@ -1451,6 +1469,7 @@ static void P_LoadRawSideDefs2(void *data) break; } } + R_ClearTextureNumCache(true); } static boolean LineInBlock(fixed_t cx1, fixed_t cy1, fixed_t cx2, fixed_t cy2, fixed_t bx1, fixed_t by1) @@ -1967,32 +1986,12 @@ static void P_LoadMapData(const virtres_t* virt) lines = Z_Calloc(numlines * sizeof (*lines), PU_LEVEL, NULL); mapthings = Z_Calloc(nummapthings * sizeof (*mapthings), PU_LEVEL, NULL); - // Allocate a big chunk of memory as big as our MAXLEVELFLATS limit. - //Fab : FIXME: allocate for whatever number of flats - 512 different flats per level should be plenty - foundflats = calloc(MAXLEVELFLATS, sizeof (*foundflats)); - if (foundflats == NULL) - I_Error("Ran out of memory while loading sectors\n"); - numlevelflats = 0; - // Strict map data P_LoadRawVertexes(virtvertexes->data); P_LoadRawSectors(virtsectors->data); P_LoadRawLineDefs(virtlinedefs->data); P_SetupLines(); P_LoadRawSideDefs2(virtsidedefs->data); - P_PrepareRawThings(virtthings->data); - - R_ClearTextureNumCache(true); - - // set the sky flat num - skyflatnum = P_AddLevelFlat(SKYFLATNAME, foundflats); - - // copy table for global usage - levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t)); - free(foundflats); - - // search for animated flats and set up - P_SetupLevelFlatAnims(); } /** Sets up a sky texture to use for the level. @@ -2243,6 +2242,16 @@ static void P_LoadMapFromFile(void) P_PrepareRawThings(vres_Find(curmapvirt, "THINGS")->data); P_MakeMapMD5(curmapvirt, &mapmd5); + + // We do the following silly + // construction because vres_Free + // no-sells deletions of pointers + // that are == curmapvirt. + { + virtres_t *temp = curmapvirt; + curmapvirt = NULL; + vres_Free(temp); + } } static void P_RunLevelScript(const char *scriptname) @@ -2478,129 +2487,6 @@ static boolean P_CanSave(void) return false; // SRB2Kart: no SP, no saving. } -static void P_InitGametype(void) -{ - INT32 i; - - for (i = 0; i < MAXPLAYERS; i++) - if (playeringame[i]) - { - players[i].pflags &= ~PF_NIGHTSMODE; - - // Start players with pity shields if possible - players[i].pity = -1; - - if (!G_RaceGametype()) - { - players[i].mo = NULL; - G_DoReborn(i); - } - else // gametype is GT_COOP or GT_RACE - { - players[i].mo = NULL; - - if (players[i].starposttime) - { - G_SpawnPlayer(i, true); - } - else - G_SpawnPlayer(i, false); - } - } - - if (modeattacking == ATTACKING_RECORD && !demo.playback) - P_LoadRecordGhosts(); - - if (G_TagGametype()) - { - INT32 realnumplayers = 0; - INT32 playersactive[MAXPLAYERS]; - - //I just realized how problematic this code can be. - //D_NumPlayers() will not always cover the scope of the netgame. - //What if one player is node 0 and the other node 31? - //The solution? Make a temp array of all players that are currently playing and pick from them. - //Future todo? When a player leaves, shift all nodes down so D_NumPlayers() can be used as intended? - //Also, you'd never have to loop through all 32 players slots to find anything ever again. - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i] && !players[i].spectator) - { - playersactive[realnumplayers] = i; //stores the player's node in the array. - realnumplayers++; - } - } - - if (realnumplayers) //this should also fix the dedicated crash bug. You only pick a player if one exists to be picked. - { - i = P_RandomKey(realnumplayers); - players[playersactive[i]].pflags |= PF_TAGIT; //choose our initial tagger before map starts. - - // Taken and modified from G_DoReborn() - // Remove the player so he can respawn elsewhere. - // first dissasociate the corpse - if (players[playersactive[i]].mo) - P_RemoveMobj(players[playersactive[i]].mo); - - G_SpawnPlayer(playersactive[i], false); //respawn the lucky player in his dedicated spawn location. - } - else - CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n")); - - } - else if (G_RaceGametype() && server) - CV_StealthSetValue(&cv_numlaps, - ((netgame || multiplayer) && cv_basenumlaps.value - && (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) - || (mapheaderinfo[gamemap - 1]->numlaps > cv_basenumlaps.value))) - ? cv_basenumlaps.value - : mapheaderinfo[gamemap - 1]->numlaps); - - // Start recording replay in multiplayer with a temp filename - //Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays! - if (!demo.playback && multiplayer && D_NumPlayers()) { - static char buf[256]; - sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap)); - - I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755); - I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755); - G_RecordDemo(buf); - if (dedicated) - G_BeginRecording(); //this has to move here, since dedicated servers dont run got_mapcmd - } - - wantedcalcdelay = wantedfrequency*2; - indirectitemcooldown = 0; - hyubgone = 0; - mapreset = 0; - nospectategrief = 0; - thwompsactive = false; - spbplace = -1; - - startedInFreePlay = false; - { - UINT8 nump = 0; - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] || players[i].spectator) - { - continue; - } - - nump++; - if (nump == 2) - { - break; - } - } - - if (nump <= 1) - { - startedInFreePlay = true; - } - } -} - struct minimapinfo minimapinfo; static void P_InitMinimapInfo(void) { @@ -2936,19 +2822,131 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) // none of this needs to be done because it's not the beginning of the map when // a netgame save is being loaded, and could actively be harmful by messing with // the client's view of the data.) - if (!fromnetsave) - P_InitGametype(); + if (fromnetsave) + goto netgameskip; + // ========== - // Now safe to free. - // We do the following silly - // construction because vres_Free - // no-sells deletions of pointers - // that are == curmapvirt. + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + { + players[i].pflags &= ~PF_NIGHTSMODE; + + // Start players with pity shields if possible + players[i].pity = -1; + + if (!G_RaceGametype()) + { + players[i].mo = NULL; + G_DoReborn(i); + } + else // gametype is GT_COOP or GT_RACE + { + players[i].mo = NULL; + + if (players[i].starposttime) + { + G_SpawnPlayer(i, true); + } + else + G_SpawnPlayer(i, false); + } + } + + if (modeattacking == ATTACKING_RECORD && !demo.playback) + P_LoadRecordGhosts(); + + if (G_TagGametype()) { - virtres_t *temp = curmapvirt; - curmapvirt = NULL; - vres_Free(temp); + INT32 realnumplayers = 0; + INT32 playersactive[MAXPLAYERS]; + + //I just realized how problematic this code can be. + //D_NumPlayers() will not always cover the scope of the netgame. + //What if one player is node 0 and the other node 31? + //The solution? Make a temp array of all players that are currently playing and pick from them. + //Future todo? When a player leaves, shift all nodes down so D_NumPlayers() can be used as intended? + //Also, you'd never have to loop through all 32 players slots to find anything ever again. + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && !players[i].spectator) + { + playersactive[realnumplayers] = i; //stores the player's node in the array. + realnumplayers++; + } + } + + if (realnumplayers) //this should also fix the dedicated crash bug. You only pick a player if one exists to be picked. + { + i = P_RandomKey(realnumplayers); + players[playersactive[i]].pflags |= PF_TAGIT; //choose our initial tagger before map starts. + + // Taken and modified from G_DoReborn() + // Remove the player so he can respawn elsewhere. + // first dissasociate the corpse + if (players[playersactive[i]].mo) + P_RemoveMobj(players[playersactive[i]].mo); + + G_SpawnPlayer(playersactive[i], false); //respawn the lucky player in his dedicated spawn location. + } + else + CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n")); + } + else if (G_RaceGametype() && server) + CV_StealthSetValue(&cv_numlaps, + ((netgame || multiplayer) && cv_basenumlaps.value + && (!(mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) + || (mapheaderinfo[gamemap - 1]->numlaps > cv_basenumlaps.value))) + ? cv_basenumlaps.value + : mapheaderinfo[gamemap - 1]->numlaps); + + // Start recording replay in multiplayer with a temp filename + //Ensure dedis only record a replay if there is a player at the start of the map, otherwise we get invalid replays! + if (!demo.playback && multiplayer && D_NumPlayers()) { + static char buf[256]; + sprintf(buf, "replay"PATHSEP"online"PATHSEP"%d-%s", (int) (time(NULL)), G_BuildMapName(gamemap)); + + I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755); + I_mkdir(va("%s"PATHSEP"replay"PATHSEP"online", srb2home), 0755); + G_RecordDemo(buf); + if (dedicated) + G_BeginRecording(); //this has to move here, since dedicated servers dont run got_mapcmd + } + + wantedcalcdelay = wantedfrequency*2; + indirectitemcooldown = 0; + hyubgone = 0; + mapreset = 0; + nospectategrief = 0; + thwompsactive = false; + spbplace = -1; + + startedInFreePlay = false; + { + UINT8 nump = 0; + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + { + continue; + } + + nump++; + if (nump == 2) + { + break; + } + } + + if (nump <= 1) + { + startedInFreePlay = true; + } + } + + // =========== + // landing point for netgames. + netgameskip: if (!reloadinggamestate) { From e7e1fd711e2125817c735d9e675cf71369e3b1f2 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Sep 2024 22:16:11 +0200 Subject: [PATCH 027/166] dont check consistency/attempt to resend the gamestate while a client is currently getting the save resend perhaps that makes mass synchs less bad --- src/d_clisrv.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 33088b7ce..58179d4cd 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1790,6 +1790,18 @@ static boolean SV_SendServerConfig(INT32 node) #ifdef JOININGAME #define SAVEGAMESIZE (768*1024) +#ifdef SATURNSYNCH +static boolean SV_ResendingSavegameToAnyone(void) +{ + INT32 i; + + for (i = 0; i < MAXNETNODES; i++) + if (resendingsavegame[i]) + return true; + return false; +} +#endif + static void SV_SendSaveGame(INT32 node, boolean resending) { size_t length, compressedlen; @@ -5364,7 +5376,8 @@ static void HandlePacketFromPlayer(SINT8 node) if (((!can_receive_gamestate[node]) && realstart <= gametic && realstart > gametic - TICQUEUE+1 && gamestate == GS_LEVEL && consistancy[realstart%TICQUEUE] != SHORT(netbuffer->u.clientpak.consistancy)) || (can_receive_gamestate[node] && realstart <= gametic && realstart + TICQUEUE - 1 > gametic && gamestate == GS_LEVEL && consistancy[realstart%TICQUEUE] != SHORT(netbuffer->u.clientpak.consistancy) - && !resendingsavegame[node] && savegameresendcooldown[node] <= I_GetTime())) + && !resendingsavegame[node] && savegameresendcooldown[node] <= I_GetTime() + && !SV_ResendingSavegameToAnyone())) { // we need to send this so the client can tell us if it can receive the savegame netbuffer->packettype = PT_WILLRESENDGAMESTATE; From 892816dadfd112d1e01e60c5fcc3b6f3704c8c40 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 01:00:47 +0200 Subject: [PATCH 028/166] fix precip performance issuess on certain maps --- src/p_mobj.c | 67 +++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index c70f9816c..91cf6f388 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10205,9 +10205,8 @@ consvar_t cv_suddendeath = {"suddendeath", "Off", CV_NETVAR|CV_CHEAT|CV_NOSHOWHE void P_SpawnPrecipitation(void) { - INT32 i, j, k, mrand; - fixed_t basex, basey, x, y, z, height; - fixed_t precipscale = cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT; + INT32 i, mrand; + fixed_t basex, basey, j, x, y, z; subsector_t *precipsector = NULL; precipmobj_t *rainmo = NULL; @@ -10220,9 +10219,10 @@ void P_SpawnPrecipitation(void) basex = bmaporgx + (i % bmapwidth) * MAPBLOCKSIZE; basey = bmaporgy + (i / bmapwidth) * MAPBLOCKSIZE; - for (j = 0; j < FRACUNIT; j += precipscale) + for (j = 0; j < FRACUNIT; j += cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT) { - UINT16 numparticles = 0; + INT32 floorz; + INT32 ceilingz; x = ((cv_lessprecip.value ? basex*1.5 : basex) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); y = ((cv_lessprecip.value ? basey*1.5 : basey) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); @@ -10237,50 +10237,37 @@ void P_SpawnPrecipitation(void) // Not in a sector with visible sky? if (precipsector->sector->ceilingpic != skyflatnum) continue; - - height = precipsector->sector->ceilingheight - precipsector->sector->floorheight; - height = FixedDiv(height, precipscale); - // Exists, but is too small for reasonable precipitation. - if (height < 64<sector->floorheight <= precipsector->sector->ceilingheight - (32<sector->ceilingheight; - for (k = 0; k < numparticles; k++) + if (curWeather == PRECIP_SNOW) { - INT32 floorz; - INT32 ceilingz; + rainmo = P_SpawnPrecipMobj(x, y, z, MT_SNOWFLAKE); + mrand = M_RandomByte(); + if (mrand < 64) + P_SetPrecipMobjState(rainmo, S_SNOW3); + else if (mrand < 144) + P_SetPrecipMobjState(rainmo, S_SNOW2); + } + else // everything else. + rainmo = P_SpawnPrecipMobj(x, y, z, MT_RAIN); - if (curWeather == PRECIP_SNOW) - { - rainmo = P_SpawnPrecipMobj(x, y, z, MT_SNOWFLAKE); - mrand = M_RandomByte(); - if (mrand < 64) - P_SetPrecipMobjState(rainmo, S_SNOW3); - else if (mrand < 144) - P_SetPrecipMobjState(rainmo, S_SNOW2); - } - else // everything else. - rainmo = P_SpawnPrecipMobj(x, y, z, MT_RAIN); + floorz = rainmo->floorz >> FRACBITS; + ceilingz = rainmo->ceilingz >> FRACBITS; - floorz = rainmo->floorz >> FRACBITS; - ceilingz = rainmo->ceilingz >> FRACBITS; - - if (floorz < ceilingz) - { - // Randomly assign a height, now that floorz is set. - rainmo->z = M_RandomRange(floorz, ceilingz) << FRACBITS; - } - else - { - // ...except if the floor is above the ceiling. - rainmo->z = ceilingz << FRACBITS; - } + if (floorz < ceilingz) + { + // Randomly assign a height, now that floorz is set. + rainmo->z = M_RandomRange(floorz, ceilingz) << FRACBITS; + } + else + { + // ...except if the floor is above the ceiling. + rainmo->z = ceilingz << FRACBITS; } } } From c921ab463ca10fbbe7de72cea180ab6aaca06b09 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 01:02:04 +0200 Subject: [PATCH 029/166] dont count precip towards thinkers in perfstats --- src/m_perfstats.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/m_perfstats.c b/src/m_perfstats.c index a8f9550f4..52944faf2 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -573,7 +573,9 @@ static void PS_CountThinkers(void) ps_removecount.value.i = 0; for (thinker = thinkercap.next; thinker != &thinkercap; thinker = thinker->next) { - ps_thinkercount.value.i++; + if (thinker->function.acp1 != (actionf_p1)P_NullPrecipThinker) + ps_thinkercount.value.i++; + if (thinker->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) ps_removecount.value.i++; else if (thinker->function.acp1 == (actionf_p1)P_MobjThinker) From a4706e0785b5e88a7c52cafdf21f0c87ace39408 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 01:02:14 +0200 Subject: [PATCH 030/166] read precip row in perfstats 2 --- src/m_perfstats.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 52944faf2..30640b21c 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -10,6 +10,7 @@ /// \brief Performance measurement tools. #include "m_perfstats.h" +#include "p_mobj.h" #include "v_video.h" #include "i_video.h" #include "d_netcmd.h" @@ -58,6 +59,7 @@ static ps_metric_t ps_regularcount = {0}; static ps_metric_t ps_scenerycount = {0}; static ps_metric_t ps_nothinkcount = {0}; static ps_metric_t ps_otherthcount = {0}; +static ps_metric_t ps_precipcount = {0}; static ps_metric_t ps_removecount = {0}; ps_metric_t ps_checkposition_calls = {0}; @@ -171,6 +173,7 @@ perfstatrow_t thinkercount_rows[] = { {" regular", " Regular: ", &ps_regularcount, PS_LEVEL}, {" scenery", " Scenery: ", &ps_scenerycount, PS_LEVEL}, {" nothink", " Nothink: ", &ps_nothinkcount, PS_HIDE_ZERO|PS_LEVEL}, + {" precip ", " Precipitation: ", &ps_precipcount, PS_LEVEL}, {" other ", " Other: ", &ps_otherthcount, PS_LEVEL}, {" remove ", " Pending removal:", &ps_removecount, PS_LEVEL}, {0} @@ -569,6 +572,7 @@ static void PS_CountThinkers(void) ps_regularcount.value.i = 0; ps_scenerycount.value.i = 0; ps_nothinkcount.value.i = 0; + ps_precipcount.value.i = 0; ps_otherthcount.value.i = 0; ps_removecount.value.i = 0; for (thinker = thinkercap.next; thinker != &thinkercap; thinker = thinker->next) @@ -589,6 +593,8 @@ static void PS_CountThinkers(void) else ps_regularcount.value.i++; } + else if (thinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) + ps_precipcount.value.i++; else ps_otherthcount.value.i++; } From 43452e1af4dc05d79e3c4dbbcdea0cc29a90104c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 01:03:59 +0200 Subject: [PATCH 031/166] dont actually call Nullprecipthinker --- src/p_tick.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index ed7252dc6..9dbdd7ed5 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -287,7 +287,7 @@ mobj_t *P_SetTarget(mobj_t **mop, mobj_t *targ) { if (*mop) // If there was a target already, decrease its refcount (*mop)->thinker.references--; -if ((*mop = targ) != NULL) // Set new target and if non-NULL, increase its counter + if ((*mop = targ) != NULL) // Set new target and if non-NULL, increase its counter targ->thinker.references++; return targ; } @@ -318,8 +318,12 @@ static inline void P_RunThinkers(void) { for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1) - currentthinker->function.acp1(currentthinker); + if (currentthinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) + continue; +#ifdef PARANOIA + I_Assert(currentthinker->function.acp1 != NULL) +#endif + currentthinker->function.acp1(currentthinker); } } From cfe3f01b32d09668c6ac7956c0fc1b4452d28eba Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 01:34:41 +0200 Subject: [PATCH 032/166] Revert "extra check" This reverts commit 0bb1efcd50342949dbe99c8490aad7b94e86e00a. --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 747966ce3..1fbe36794 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9404,7 +9404,7 @@ skipcrap: case 5: if (driftgaugegfx) { - if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || (cv_driftgaugestyle.value == 5 && xtra_speedo3)) + if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || cv_driftgaugestyle.value == 5) { barx = basex - dup*23; BAR_WIDTH = dup*47; From eec93b801361edca8f9843b64c7681fa2265bf5b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 01:34:47 +0200 Subject: [PATCH 033/166] Revert "beta hud driftgauge" This reverts commit 26e8c2ca2bc8473fdd4c649ea0c86317c2fd609f. --- src/d_netcmd.c | 4 ++-- src/k_kart.c | 28 +++++++--------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3e89a3285..baba42007 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -537,11 +537,11 @@ consvar_t cv_nametagscore = {"kartnametagscore", "Off", CV_SAVE, CV_OnOff, NULL, consvar_t cv_shownametagfinish = {"kartshownametagfinished", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_shownametagspectator = {"kartshownametagspectator", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; - static CV_PossibleValue_t driftgaugeoffset_cons_t[] = { {-FRACUNIT*128, "MIN"}, {FRACUNIT*128, "MAX"}, {0, NULL}}; + static CV_PossibleValue_t driftgaugestyle_cons_t[] = { - {1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {5, "Extra"}, {0, NULL}}; + {1, "Default"}, {2, "Small"}, {3, "Big Numbers"}, {4, "Numbers Only"}, {0, NULL}}; consvar_t cv_driftgauge = {"kartdriftgauge", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_driftgaugeofs = {"kartdriftgaugeoffset", "-20", CV_FLOAT|CV_SAVE, driftgaugeoffset_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/k_kart.c b/src/k_kart.c index 1fbe36794..9ed535d3b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8874,7 +8874,7 @@ static void K_drawKartSpeedometer(void) { UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); V_DrawStretchyFixedPatch((SPDM_X-1)<= driftval*4) // rainbow sparks From 0dbae349984062d556595fcc6b68dadd6b18a2cb Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 15:53:05 +0200 Subject: [PATCH 034/166] completely forgor to revert this lol --- src/sdl/i_system.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 66ce038f5..444fbb370 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -47,11 +47,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); // May be incorrect for other platforms, but we don't currently have a way to // query the scheduler granularity. SDL will do what's needed to make this as // low as possible though. -#if defined(_WIN32) -#define MIN_SLEEP_DURATION_MS 1.6 -#else #define MIN_SLEEP_DURATION_MS 2.1 -#endif #include #include From 90745d91aaf9148fb5290c8db2c05a0a52b78c3c Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 23 Sep 2024 23:39:25 +0300 Subject: [PATCH 035/166] Add showdownloadprompt cvar, so addon download prompt can be disabled --- src/d_clisrv.c | 86 ++++++++++++++++++++++++++++---------------------- src/d_netcmd.c | 3 ++ src/d_netcmd.h | 1 + 3 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 58179d4cd..139817d1b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2197,6 +2197,33 @@ void CL_TimeoutServerList(void) } #endif // ifndef NONET +static void CL_ConfirmConnect(void) +{ + if (totalfilesrequestednum > 0) + { +#ifdef HAVE_CURL + if (http_source[0] == '\0' || curl_failedwebdownload) +#endif + { + if (CL_SendRequestFile()) + { + cl_mode = CL_DOWNLOADFILES; + } + else + { + cl_mode = CL_LEGACYREQUESTFAILED; + } + } +#ifdef HAVE_CURL + else + cl_mode = CL_PREPAREHTTPFILES; +#endif + } + else + cl_mode = CL_LOADFILES; + +} + static void M_ConfirmConnect(event_t *ev) { #ifndef NONET @@ -2204,28 +2231,7 @@ static void M_ConfirmConnect(event_t *ev) { if (ev->data1 == ' ' || ev->data1 == 'y' || ev->data1 == KEY_ENTER || ev->data1 == gamecontrol[gc_accelerate][0] || ev->data1 == gamecontrol[gc_accelerate][1]) { - if (totalfilesrequestednum > 0) - { -#ifdef HAVE_CURL - if (http_source[0] == '\0' || curl_failedwebdownload) -#endif - { - if (CL_SendRequestFile()) - { - cl_mode = CL_DOWNLOADFILES; - } - else - { - cl_mode = CL_LEGACYREQUESTFAILED; - } - } -#ifdef HAVE_CURL - else - cl_mode = CL_PREPAREHTTPFILES; -#endif - } - else - cl_mode = CL_LOADFILES; + CL_ConfirmConnect(); M_ClearMenus(true); } @@ -2355,24 +2361,30 @@ static boolean CL_FinishedFileList(void) downloadsize = Z_StrDup(va("%uK",totalfilesrequestedsize>>10)); #endif - if (serverisfull) - M_StartMessage(va(M_GetText( - "This server is full!\n" - "Download of %s additional content is required to join.\n" - "\n" - "You may download, load server addons, and wait for a slot.\n" - "\n" - "Press ACCEL to continue or BRAKE to cancel.\n\n" - ), downloadsize), M_ConfirmConnect, MM_EVENTHANDLER); + if (cv_showdownloadprompt.value) + { + if (serverisfull) + M_StartMessage(va(M_GetText( + "This server is full!\n" + "Download of %s additional content is required to join.\n" + "\n" + "You may download, load server addons, and wait for a slot.\n" + "\n" + "Press ACCEL to continue or BRAKE to cancel.\n\n" + ), downloadsize), M_ConfirmConnect, MM_EVENTHANDLER); + else + M_StartMessage(va(M_GetText( + "Download of %s additional content is required to join.\n" + "\n" + "Press ACCEL to continue or BRAKE to cancel.\n\n" + ), downloadsize), M_ConfirmConnect, MM_EVENTHANDLER); + + cl_mode = CL_CONFIRMCONNECT; + } else - M_StartMessage(va(M_GetText( - "Download of %s additional content is required to join.\n" - "\n" - "Press ACCEL to continue or BRAKE to cancel.\n\n" - ), downloadsize), M_ConfirmConnect, MM_EVENTHANDLER); + CL_ConfirmConnect(); Z_Free(downloadsize); - cl_mode = CL_CONFIRMCONNECT; } #ifdef HAVE_CURL else diff --git a/src/d_netcmd.c b/src/d_netcmd.c index baba42007..a1868ce0a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -493,6 +493,8 @@ consvar_t cv_showlapemblem = {"showlapemblem", "On", CV_SAVE, CV_OnOff, NULL, 0, consvar_t cv_showviewpointtext = {"showviewpointtext", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showdownloadprompt = {"showdownloadprompt", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; + // Intermission time Tails 04-19-2002 static CV_PossibleValue_t inttime_cons_t[] = {{0, "MIN"}, {3600, "MAX"}, {0, NULL}}; consvar_t cv_inttime = {"inttime", "20", CV_NETVAR, inttime_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -994,6 +996,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_showtrackaddon); CV_RegisterVar(&cv_showviewpointtext); + CV_RegisterVar(&cv_showdownloadprompt); CV_RegisterVar(&cv_director); CV_RegisterVar(&cv_kartdebugdirector); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index f4ca00214..01fb98243 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -166,6 +166,7 @@ extern consvar_t cv_minihead; extern consvar_t cv_showlapemblem; extern consvar_t cv_showviewpointtext; +extern consvar_t cv_showdownloadprompt; extern consvar_t cv_luaimmersion; extern consvar_t cv_fakelocalskin; extern consvar_t cv_showlocalskinmenus; From 91a9f20af7948bd48368c4db2fe6b94b6a335b9a Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 24 Sep 2024 00:08:48 +0300 Subject: [PATCH 036/166] Skip map marker in vres_GetMap --- src/w_wad.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 5e2f4ce10..118c5011f 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -2169,8 +2169,16 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) if (vsizecache[realentry] == 0) continue; vlumps[i].size = vsizecache[realentry]; + + const char *name = (fileinfo + realentry)->name; + if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) + { + numlumps--; // We skip map marker, so 1 of entries becomes empty + continue; // This will skip i++ so we will write to same entry + } + // Play it safe with the name in this case. - memcpy(vlumps[i].name, (fileinfo + realentry)->name, 8); + memcpy(vlumps[i].name, name, 8); vlumps[i].name[8] = '\0'; vlumps[i].data = Z_Malloc(vlumps[i].size, PU_LEVEL, NULL); // This is memory inefficient, sorry about that. memcpy(vlumps[i].data, wadData + LONG((fileinfo + realentry)->filepos), vlumps[i].size); @@ -2196,8 +2204,17 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) vlumps = Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL); 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 (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) + { + --i; // Decrement so on next iteration we write on same i, so we don't leave corrupted vlumps entry + numlumps--; // Just so we don't try to access the leftover vlumps entry + continue; + } + vlumps[i].size = W_LumpLength(lumpnum); - memcpy(vlumps[i].name, W_CheckNameForNum(lumpnum), 8); + memcpy(vlumps[i].name, name, 8); vlumps[i].name[8] = '\0'; vlumps[i].data = W_CacheLumpNum(lumpnum, PU_LEVEL); } From 26d8c05ce7bf334022dbd6c580ee55a1ad6af52b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 18:40:24 +0200 Subject: [PATCH 037/166] forgor some casting --- src/w_wad.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 5e2f4ce10..a7fc119d0 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -2145,11 +2145,11 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) size_t *vsizecache; // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. - UINT8 *wadData = W_CacheLumpNum(lumpnum, PU_LEVEL); + UINT8 *wadData = (UINT8*)(W_CacheLumpNum(lumpnum, PU_LEVEL)); filelump_t *fileinfo = (filelump_t *)(wadData + LONG(((wadinfo_t *)wadData)->infotableofs)); i = LONG(((wadinfo_t *)wadData)->numlumps); - vsizecache = Z_Malloc(sizeof(size_t)*i, PU_LEVEL, NULL); + vsizecache = (size_t*)(Z_Malloc(sizeof(size_t)*i, PU_LEVEL, NULL)); for (realentry = 0; realentry < i; realentry++) { @@ -2161,7 +2161,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) numlumps++; } - vlumps = Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL); + vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); // Build the lumps, skipping over empty entries. for (i = 0, realentry = 0; i < numlumps; realentry++) @@ -2172,7 +2172,9 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) // Play it safe with the name in this case. memcpy(vlumps[i].name, (fileinfo + realentry)->name, 8); vlumps[i].name[8] = '\0'; - vlumps[i].data = Z_Malloc(vlumps[i].size, PU_LEVEL, NULL); // This is memory inefficient, sorry about that. + vlumps[i].data = (UINT8*)( + Z_Malloc(vlumps[i].size, PU_LEVEL, NULL) // This is memory inefficient, sorry about that. + ); memcpy(vlumps[i].data, wadData + LONG((fileinfo + realentry)->filepos), vlumps[i].size); i++; } @@ -2193,16 +2195,16 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) } numlumps++; - vlumps = Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL); + vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); for (i = 0; i < numlumps; i++, lumpnum++) { vlumps[i].size = W_LumpLength(lumpnum); memcpy(vlumps[i].name, W_CheckNameForNum(lumpnum), 8); vlumps[i].name[8] = '\0'; - vlumps[i].data = W_CacheLumpNum(lumpnum, PU_LEVEL); + vlumps[i].data = (UINT8*)(W_CacheLumpNum(lumpnum, PU_LEVEL)); } } - vres = Z_Malloc(sizeof(virtres_t), PU_LEVEL, NULL); + vres = (virtres_t*)(Z_Malloc(sizeof(virtres_t), PU_LEVEL, NULL)); vres->vlumps = vlumps; vres->numlumps = numlumps; From 9a6c0a0280fe7b5d32d4b8a2f148fe8213fb2bd4 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 20:36:56 +0200 Subject: [PATCH 038/166] check vres data before freeing it --- src/w_wad.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/w_wad.c b/src/w_wad.c index a7fc119d0..17afd413a 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -2224,7 +2224,13 @@ void vres_Free(virtres_t* vres) } while (vres->numlumps--) - Z_Free(vres->vlumps[vres->numlumps].data); + { + if (vres->vlumps[vres->numlumps].data) + { + Z_Free(vres->vlumps[vres->numlumps].data); + } + } + Z_Free(vres->vlumps); Z_Free(vres); } From 725754c427575fe6209cd9aa0e01467922a3f143 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 24 Sep 2024 14:51:18 +0200 Subject: [PATCH 039/166] dont run director when you use spectator freecam --- src/k_director.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/k_director.c b/src/k_director.c index 952adf8da..3789afa75 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -17,6 +17,7 @@ #include "k_director.h" #include "d_netcmd.h" #include "p_local.h" +#include "st_stuff.h" #define SWITCHTIME TICRATE * 5 // cooldown between unforced switches #define BOREDOMTIME 3 * TICRATE / 2 // how long until players considered far apart? @@ -49,7 +50,7 @@ static fixed_t ScaleFromMap(fixed_t n, fixed_t scale) static boolean K_DirectorIsEnabled(void) { - return cv_director.value && !splitscreen && (gamestate == GS_LEVEL && (!playeringame[consoleplayer] || players[consoleplayer].spectator || (demo.playback && (!demo.title || !modeattacking)))); + return cv_director.value && !splitscreen && (gamestate == GS_LEVEL && (((stplyr && !stplyr->spectator) && (!playeringame[consoleplayer] || players[consoleplayer].spectator)) || (demo.playback && !demo.freecam && (!demo.title || !modeattacking)))); } void K_InitDirector(void) From e7c0f322ee5670b3d7bce66e06af766ce6134d0e Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 24 Sep 2024 15:00:45 +0200 Subject: [PATCH 040/166] dont show driftgauge when in replay freecam --- src/k_kart.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/k_kart.c b/src/k_kart.c index 9ed535d3b..5128093f6 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9370,6 +9370,9 @@ static void K_drawDriftGauge(void) 0, 31, 47, 63, 79, 95, 111, 119, 127, 143, 159, 175, 183, 191, 199, 207, 223, 247 }; + if (demo.playback && demo.freecam) + return; + if (!stplyr->mo || (!splitscreen && !camera->chase)) return; From b064c534d8c510482f02e8fbef93079c018faffe Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 24 Sep 2024 15:01:02 +0200 Subject: [PATCH 041/166] hide viewpoint text when in replay freecam --- src/st_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 983ce4007..18b6a4fa5 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -695,7 +695,7 @@ static void ST_overlayDrawer(void) V_DrawCenteredString((BASEVIDWIDTH/2), BASEVIDHEIGHT-32, V_SNAPTOBOTTOM|V_HUDTRANS|V_ALLOWLOWERCASE, player_names[stplyr-players]); } } - else if (!demo.title) + else if (!demo.title && !demo.freecam) { if (!splitscreen) { From 14eec0c902c6caa01195a699d9961820e892ba37 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 24 Sep 2024 15:02:32 +0200 Subject: [PATCH 042/166] dont show director text when in replay freecam --- src/st_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 18b6a4fa5..154504e38 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -662,7 +662,7 @@ static void ST_overlayDrawer(void) if (!hu_showscores) // hide the following if TAB is held { - if (cv_showdirectorhud.value && ((demo.playback && (!demo.title || !modeattacking)) || !P_IsLocalPlayer(stplyr)) && !splitscreen) + if (cv_showdirectorhud.value && ((demo.playback && !demo.freecam && (!demo.title || !modeattacking)) || !P_IsLocalPlayer(stplyr)) && !splitscreen) { char directortext[20] = {0}; From ff7f68f5b43a7f280fc41010c6b9b37bcd0239ae Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 24 Sep 2024 16:05:16 +0300 Subject: [PATCH 043/166] Expose demo.freecam as replayfreecam --- src/dehacked.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/dehacked.c b/src/dehacked.c index 80a8e0ec1..e1f3adba2 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9216,6 +9216,11 @@ int LUA_EnumLib(lua_State *L) lua_glib_push_bool_getter(L, &demo.playback); lua_call(L, 2, 0); + lua_pushcfunction(L, lua_glib_new_getter); + lua_pushliteral(L, "replayfreecam"); + lua_glib_push_bool_getter(L, &demo.freecam); + lua_call(L, 2, 0); + if (!mathlib) { lua_pushcfunction(L, lua_glib_new_getter); From 2e99636bb0395489a7be735884954e3636de1c27 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 24 Sep 2024 15:25:36 +0200 Subject: [PATCH 044/166] make director text disappear after 13 seconds, and in replays after 4 --- src/st_stuff.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 154504e38..a0b659f5f 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -668,14 +668,16 @@ static void ST_overlayDrawer(void) snprintf(directortext, 20, "Director: %s", cv_director.value ? "On" : "Off"); - if (directortoggletimer < 4*TICRATE) + if ((!demo.playback && directortoggletimer < 13*TICRATE) || (demo.playback && directortoggletimer < 4*TICRATE)) { - V_DrawString(1, BASEVIDHEIGHT-8-1, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_HUDTRANSHALF|V_ALLOWLOWERCASE, directortext); if (renderisnewtic) directortoggletimer++; + + if (directortoggletimer < 4*TICRATE) + V_DrawString(1, BASEVIDHEIGHT-8-1, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_HUDTRANSHALF|V_ALLOWLOWERCASE, directortext); + else if (cv_translucenthud.value != 0) + V_DrawString(1, BASEVIDHEIGHT-8-1, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_80TRANS|V_ALLOWLOWERCASE, directortext); // idk if V_80TRANS is good? } - else if (cv_translucenthud.value != 0) - V_DrawString(1, BASEVIDHEIGHT-8-1, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_80TRANS|V_ALLOWLOWERCASE, directortext); // idk if V_80TRANS is good? } else directortoggletimer = 0; From da769ce5245421424f261aacfd7c3a24bea8d9fb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 24 Sep 2024 16:57:20 +0200 Subject: [PATCH 045/166] only allow director toggling with button when you spec someone --- src/g_game.c | 1 - src/k_director.c | 5 +++++ src/st_stuff.c | 7 +++++++ src/st_stuff.h | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/g_game.c b/src/g_game.c index 1242e26e6..8311d7cbc 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1858,7 +1858,6 @@ boolean G_Responder(event_t *ev) || ev->data1 == gamecontrol[gc_director][1]) { K_ToggleDirector(); - directortoggletimer = 0; } return true; diff --git a/src/k_director.c b/src/k_director.c index 3789afa75..51406cf07 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -395,10 +395,15 @@ void K_UpdateDirector(void) void K_ToggleDirector(void) { + if (!directortextactive) + return; + if (!K_DirectorIsEnabled()) { directorinfo.cooldown = 0; // switch immediately } + directortoggletimer = 0; + COM_ImmedExecute("add director 1"); } diff --git a/src/st_stuff.c b/src/st_stuff.c index a0b659f5f..aa5e07ed6 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -155,6 +155,8 @@ static patch_t *envelope; player_t *stplyr; UINT8 stplyrnum; +boolean directortextactive = false; + // SRB2kart hudinfo_t hudinfo[NUMHUDITEMS] = @@ -668,6 +670,8 @@ static void ST_overlayDrawer(void) snprintf(directortext, 20, "Director: %s", cv_director.value ? "On" : "Off"); + directortextactive = true; + if ((!demo.playback && directortoggletimer < 13*TICRATE) || (demo.playback && directortoggletimer < 4*TICRATE)) { if (renderisnewtic) @@ -680,7 +684,10 @@ static void ST_overlayDrawer(void) } } else + { directortoggletimer = 0; + directortextactive = false; + } if (cv_showviewpointtext.value) { diff --git a/src/st_stuff.h b/src/st_stuff.h index 250db1e7f..308dae2a0 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -146,4 +146,6 @@ extern UINT16 objectsdrawn; extern consvar_t cv_lessflicker; extern consvar_t cv_stagetitle; +extern boolean directortextactive; + #endif From 0137f2254d1f5b1bc6866566badec65ea536ea26 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 24 Sep 2024 22:18:17 +0200 Subject: [PATCH 046/166] add toggle for water ripples Zzz... --- src/hardware/hw_main.c | 2 +- src/r_main.c | 4 ++++ src/r_main.h | 1 + src/r_plane.c | 53 ++++++++++++++++++++++++------------------ 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c0131ba93..a1bd98a62 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -846,7 +846,7 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc { if (PolyFlags & PF_Fog) shader = SHADER_FOG; - else if (PolyFlags & PF_Ripple) + else if (cv_ripplewater.value && (PolyFlags & PF_Ripple)) shader = SHADER_WATER; else shader = SHADER_FLOOR; diff --git a/src/r_main.c b/src/r_main.c index 5a686fb3b..ba2c3551e 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -213,6 +213,8 @@ consvar_t cv_mobjscaleprecip = {"scaleprecipmobjscale", "Off", CV_SAVE|CV_CALL|C consvar_t cv_grmaxinterpdist = {"gr_maxinterpdist", "Infinite", CV_SAVE, maxinterpdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ripplewater = {"waterripples", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + // cap fov, fov too high tears software apart. consvar_t cv_fov = {"fov", "90", CV_FLOAT|CV_CALL|CV_SAVE, fov_cons_t, Fov_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -1889,6 +1891,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_grmaxinterpdist); + CV_RegisterVar(&cv_ripplewater); + // Default viewheight is changeable, // initialized to standard viewheight //CV_RegisterVar(&cv_viewheight); diff --git a/src/r_main.h b/src/r_main.h index dbf1a141b..34fe686b5 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -124,6 +124,7 @@ extern consvar_t cv_fov; extern consvar_t cv_skybox; extern consvar_t cv_tailspickup; extern consvar_t cv_grmaxinterpdist; +extern consvar_t cv_ripplewater; // Called by startup code. void R_Init(void); diff --git a/src/r_plane.c b/src/r_plane.c index ec5aa90eb..208478440 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -910,34 +910,41 @@ void R_DrawSinglePlane(visplane_t *pl) INT32 top, bottom; UINT8 *scr; - planeripple.active = true; - - if (spanfunc == R_DrawTranslucentSpan_8) + if (cv_ripplewater.value) { - spanfunc = R_DrawTranslucentWaterSpan_8; + planeripple.active = true; - // Copy the current scene, ugh - top = pl->high-8; - bottom = pl->low+8; + if (spanfunc == R_DrawTranslucentSpan_8) + { + spanfunc = R_DrawTranslucentWaterSpan_8; - if (top < 0) - top = 0; - if (bottom > vid.height) - bottom = vid.height; + // Copy the current scene, ugh + top = pl->high-8; + bottom = pl->low+8; - if (splitscreen > 2 && viewplayer == &players[displayplayers[3]]) // Only copy the part of the screen we need - scr = (screens[0] + (top+(viewheight))*vid.width + viewwidth); - else if ((splitscreen == 1 && viewplayer == &players[displayplayers[1]]) - || (splitscreen > 1 && viewplayer == &players[displayplayers[2]])) - scr = (screens[0] + (top+(viewheight))*vid.width); - else if (splitscreen > 1 && viewplayer == &players[displayplayers[1]]) - scr = (screens[0] + ((top)*vid.width) + viewwidth); - else - scr = (screens[0] + ((top)*vid.width)); + if (top < 0) + top = 0; + if (bottom > vid.height) + bottom = vid.height; - VID_BlitLinearScreen(scr, screens[1]+((top)*vid.width), - vid.width, bottom-top, - vid.width, vid.width); + if (splitscreen > 2 && viewplayer == &players[displayplayers[3]]) // Only copy the part of the screen we need + scr = (screens[0] + (top+(viewheight))*vid.width + viewwidth); + else if ((splitscreen == 1 && viewplayer == &players[displayplayers[1]]) + || (splitscreen > 1 && viewplayer == &players[displayplayers[2]])) + scr = (screens[0] + (top+(viewheight))*vid.width); + else if (splitscreen > 1 && viewplayer == &players[displayplayers[1]]) + scr = (screens[0] + ((top)*vid.width) + viewwidth); + else + scr = (screens[0] + ((top)*vid.width)); + + VID_BlitLinearScreen(scr, screens[1]+((top)*vid.width), + vid.width, bottom-top, + vid.width, vid.width); + } + } + else + { + planeripple.active = false; } } #endif From d5c33326357555d012be71fa74a36e54682b4d87 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 24 Sep 2024 22:23:23 +0200 Subject: [PATCH 047/166] those can be static --- src/d_netfil.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index 9423a368d..2559cbcf1 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -65,10 +65,10 @@ static boolean SV_SendFile(INT32 node, const char *filename, UINT8 fileid); #ifdef HAVE_CURL size_t curlwrite_data(void *ptr, size_t size, size_t nmemb, FILE *stream); #if defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 35, 0) -int curlprogress_callbackx(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); +static int curlprogress_callbackx(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); #define XFERINFOFUNCTION #else -int curlprogress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); +static int curlprogress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); #endif #endif @@ -1203,7 +1203,7 @@ size_t curlwrite_data(void *ptr, size_t size, size_t nmemb, FILE *stream) } #ifdef XFERINFOFUNCTION -int curlprogress_callbackx(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) +static int curlprogress_callbackx(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { time_t curtime; @@ -1228,7 +1228,7 @@ int curlprogress_callbackx(void *clientp, curl_off_t dltotal, curl_off_t dlnow, return 0; } #else -int curlprogress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) +static int curlprogress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { time_t curtime; From d8da0a11a23988bfc629684632001c19a619b5d8 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Sep 2024 19:31:07 +0200 Subject: [PATCH 048/166] gamestate resend counter was never proper reset for nodes means it would carry over to the next person occupieing that node and made them have less chances to get the gamestate resent --- src/d_clisrv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 139817d1b..8165d6a1c 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4246,6 +4246,7 @@ static void ResetNode(INT32 node) resendingsavegame[node] = false; can_receive_gamestate[node] = false; savegameresendcooldown[node] = 0; + gamestate_resend_counter[node] = 0; #endif // } @@ -5431,6 +5432,7 @@ static void HandlePacketFromPlayer(SINT8 node) DEBFILE(va("player %d kicked (synch failure) [%u] %d!=%d\n", netconsole, realstart, consistancy[realstart%TICQUEUE], SHORT(netbuffer->u.clientpak.consistancy))); + gamestate_resend_counter[node] = 0 break; } } From 7a3ccec38ded7b3a4d7fc3db476a6fe4ccf8d683 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Sep 2024 18:18:34 +0200 Subject: [PATCH 049/166] ; --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 8165d6a1c..171d61b01 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5432,7 +5432,7 @@ static void HandlePacketFromPlayer(SINT8 node) DEBFILE(va("player %d kicked (synch failure) [%u] %d!=%d\n", netconsole, realstart, consistancy[realstart%TICQUEUE], SHORT(netbuffer->u.clientpak.consistancy))); - gamestate_resend_counter[node] = 0 + gamestate_resend_counter[node] = 0; break; } } From b3b2b65c5fc1f076e40ac0e85c4b52d25f8a8492 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 04:24:45 +0200 Subject: [PATCH 050/166] reformat this --- src/qs22j.c | 264 ++++++++++++++++++++++++++-------------------------- src/qs22j.h | 18 +++- 2 files changed, 148 insertions(+), 134 deletions(-) diff --git a/src/qs22j.c b/src/qs22j.c index 16dc217bd..24f5de44d 100644 --- a/src/qs22j.c +++ b/src/qs22j.c @@ -24,7 +24,9 @@ #define MEDOF3THRESH 50 // < this use median-of-3 as pivot // larger subfiles use med-of-3-medians +#ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif typedef int32_t WORD; typedef int64_t DWORD; @@ -37,242 +39,240 @@ typedef void *pref_typ; #define ASWAP(a, b, t) ((void)(t = a, a = b, b = t)) #define SWAP(a, b) if (swap_type) swapf(a, b, size);\ - else do {pref_typ t; ASWAP(*(pref_typ*)(a), *(pref_typ*)(b), t);} while (0) + else do {pref_typ t; ASWAP(*(pref_typ*)(a), *(pref_typ*)(b), t);} while (0) #define COMP(a, b) ((*compar)((void *)(a), (void *)(b))) static inline void swapbytes(void *a0, void *b0, size_t n) { - char *a = a0, *b = b0, t; - do {ASWAP(*a, *b, t); a++; b++;} while (--n); + char *a = a0, *b = b0, t; + do {ASWAP(*a, *b, t); a++; b++;} while (--n); } static inline void swapdword(void *a0, void *b0, size_t n) { - DWORD *a = a0, *b = b0, t; - ASWAP(*a, *b, t); - (void)n; + DWORD *a = a0, *b = b0, t; + ASWAP(*a, *b, t); + (void)n; } static inline void swapdwords(void *a0, void *b0, size_t n) { - DWORD *a = a0, *b = b0, t; - do {ASWAP(*a, *b, t); a++; b++;} while (n -= sizeof(DWORD)); + DWORD *a = a0, *b = b0, t; + do {ASWAP(*a, *b, t); a++; b++;} while (n -= sizeof(DWORD)); } static inline void swapword(void *a0, void *b0, size_t n) { - WORD *a = a0, *b = b0, t; - ASWAP(*a, *b, t); - (void)n; + WORD *a = a0, *b = b0, t; + ASWAP(*a, *b, t); + (void)n; } static inline void swapwords(void *a0, void *b0, size_t n) { - WORD *a = a0, *b = b0, t; - do {ASWAP(*a, *b, t); a++; b++;} while (n -= sizeof(WORD)); + WORD *a = a0, *b = b0, t; + do {ASWAP(*a, *b, t); a++; b++;} while (n -= sizeof(WORD)); } typedef void (*swapf_typ)(void *, void *, size_t); static inline char *med3(char *a, char *b, char *c, int (*compar)(const void *, const void *)) { - return COMP(a, b) < 0 ? - (COMP(b, c) < 0 ? b : COMP(a, c) < 0 ? c : a) : - (COMP(b, c) > 0 ? b : COMP(a, c) > 0 ? c : a); + return COMP(a, b) < 0 ? + (COMP(b, c) < 0 ? b : COMP(a, c) < 0 ? c : a) : + (COMP(b, c) > 0 ? b : COMP(a, c) > 0 ? c : a); } void qs22j(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) { - char *stack[2*8*sizeof(size_t)], **sp = stack; // stack and stack pointer - char *left = base; // set up char * base pointer - char *limit = left + nmemb * size; // pointer past end of array - char *i, *ii, *j, *jj; // scan pointers - int ki = 0, kj = 0; - int swap_type = 1; - swapf_typ swapf, vecswapf; + char *stack[2*8*sizeof(size_t)], **sp = stack; // stack and stack pointer + char *left = base; // set up char * base pointer + char *limit = left + nmemb * size; // pointer past end of array + char *i, *ii, *j, *jj; // scan pointers + int ki = 0, kj = 0; + int swap_type = 1; + swapf_typ swapf, vecswapf; - vecswapf = swapf = swapbytes; - if ((ptr_to_int(left) | size) % sizeof(WORD)) + vecswapf = swapf = swapbytes; + if ((ptr_to_int(left) | size) % sizeof(WORD)) { - ; // unaligned or not multple of WORD size; swap bytes - } + ; // unaligned or not multple of WORD size; swap bytes + } else if (size == sizeof(DWORD)) { - swapf = swapdword; - vecswapf = swapdwords; - if (size == sizeof(pref_typ)) - swap_type = 0; - } + swapf = swapdword; + vecswapf = swapdwords; + if (size == sizeof(pref_typ)) + swap_type = 0; + } else if (size == sizeof(WORD)) { - swapf = swapword; - vecswapf = swapwords; - if (size == sizeof(pref_typ)) - swap_type = 0; + swapf = swapword; + vecswapf = swapwords; + if (size == sizeof(pref_typ)) + swap_type = 0; } else if ((size % sizeof(DWORD)) == 0) { - swapf = vecswapf = swapdwords; - } + swapf = vecswapf = swapdwords; + } else if ((size % sizeof(WORD)) == 0) { - swapf = vecswapf = swapwords; - } - for (;;) + swapf = vecswapf = swapwords; + } + for (;;) { - nmemb = (limit - left) / size; - for (i = left + size; i < limit && COMP(i - size, i) <= 0; i += size) - ; + nmemb = (limit - left) / size; + for (i = left + size; i < limit && COMP(i - size, i) <= 0; i += size) + ; - if (i == limit) // if already in order - goto pop; + if (i == limit) // if already in order + goto pop; - if (nmemb >= INSORTTHRESH) // otherwise use insertion sort + if (nmemb >= INSORTTHRESH) // otherwise use insertion sort { - char *right = limit - size; - // best so far? fewer compares, a few more swaps - char *p = left + (nmemb / 2) * size; - if (nmemb >= MIDTHRESH) + char *right = limit - size; + // best so far? fewer compares, a few more swaps + char *p = left + (nmemb / 2) * size; + if (nmemb >= MIDTHRESH) { - char *pleft = left + size; - char *pright = right - size; + char *pleft = left + size; + char *pright = right - size; - if (nmemb >= MEDOF3THRESH) + if (nmemb >= MEDOF3THRESH) { - size_t k = (nmemb / 8) * size; - pleft = med3(pleft, left + k, left + k * 2, compar); - p = med3(p - k, p, p + k, compar); - pright = med3(right - k * 2, right - k, pright, compar); - } + size_t k = (nmemb / 8) * size; + pleft = med3(pleft, left + k, left + k * 2, compar); + p = med3(p - k, p, p + k, compar); + pright = med3(right - k * 2, right - k, pright, compar); + } - p = med3(pleft, p, pright, compar); - } + p = med3(pleft, p, pright, compar); + } - i = ii = left; // i scans left to right - j = jj = right; // j scans right to left + i = ii = left; // i scans left to right + j = jj = right; // j scans right to left for (;;) { - while (i <= j) { if (i != p && ((ki = COMP(i, p)) >= 0)) { - if (ki) - break; + if (ki) + break; if (ii == p) { - p = i; + p = i; } else if (i != ii) { - SWAP(i, ii); + SWAP(i, ii); } - ii += size; - } - i += size; - } + ii += size; + } + i += size; + } - while (i < j) + while (i < j) { - if (j != p && ((kj = COMP(j, p)) <= 0)) + if (j != p && ((kj = COMP(j, p)) <= 0)) { - if (kj) - break; + if (kj) + break; - if (jj == p) + if (jj == p) { - p = j; + p = j; } - else if (j != jj) + else if (j != jj) { - SWAP(j, jj); + SWAP(j, jj); } - jj -= size; - } - j -= size; - } + jj -= size; + } + j -= size; + } - if (i >= j) - break; + if (i >= j) + break; - SWAP(i, j); - i += size; - j -= size; - } + SWAP(i, j); + i += size; + j -= size; + } - if (p < i) - i -= size; + if (p < i) + i -= size; if (p != i) { SWAP(p, i); } - ptrdiff_t lessthan = i - ii; - size_t k = min(lessthan, ii - left); + ptrdiff_t lessthan = i - ii; + size_t k = min(lessthan, ii - left); - if (k) - vecswapf(left, i - k, k); + if (k) + vecswapf(left, i - k, k); - ptrdiff_t morethan = jj - i; - k = min(morethan, right - jj); + ptrdiff_t morethan = jj - i; + k = min(morethan, right - jj); - if (k) - vecswapf(i + size, limit - k, k); + if (k) + vecswapf(i + size, limit - k, k); - if (lessthan > morethan) + if (lessthan > morethan) { - if (lessthan > 1) + if (lessthan > 1) { - sp[0] = left; - sp[1] = left + lessthan; - sp += 2; // increment stack pointer - } + sp[0] = left; + sp[1] = left + lessthan; + sp += 2; // increment stack pointer + } - if (morethan <= 1) - goto pop; + if (morethan <= 1) + goto pop; - left = limit - morethan; + left = limit - morethan; } else { - if (morethan > 1) + if (morethan > 1) { - sp[0] = limit - morethan; - sp[1] = limit; - sp += 2; // increment stack pointer - } + sp[0] = limit - morethan; + sp[1] = limit; + sp += 2; // increment stack pointer + } - if (lessthan <= 1) - goto pop; + if (lessthan <= 1) + goto pop; - limit = left + lessthan; - } - - } + limit = left + lessthan; + } + } else // else subfile is small, use insertion sort { - for (i = left + size; i < limit; i += size) + for (i = left + size; i < limit; i += size) { - for (j = i; j != left && COMP(j - size, j) > 0; j -= size) + for (j = i; j != left && COMP(j - size, j) > 0; j -= size) { - SWAP(j - size, j); - } - } + SWAP(j - size, j); + } + } pop: - if (sp != stack) // if any entries on stack + if (sp != stack) // if any entries on stack { - sp -= 2; // pop the left and limit - left = sp[0]; - limit = sp[1]; - } - else // else stack empty, done - break; + sp -= 2; // pop the left and limit + left = sp[0]; + limit = sp[1]; + } + else // else stack empty, done + break; } } } diff --git a/src/qs22j.h b/src/qs22j.h index 95d1c1292..c388b9c46 100644 --- a/src/qs22j.h +++ b/src/qs22j.h @@ -1,7 +1,21 @@ +// License: 0BSD +// +// Copyright 2022 Raymond Gardner +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// + #ifndef __QS22J__ #define __QS22J__ - void qs22j(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); - #endif From c3b6121968d00376e8e50aa3f03e2b66580c2253 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 04:26:43 +0200 Subject: [PATCH 051/166] forgor this --- src/qs22j.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qs22j.c b/src/qs22j.c index 24f5de44d..17f2b7c2e 100644 --- a/src/qs22j.c +++ b/src/qs22j.c @@ -18,11 +18,11 @@ #include #include "qs22j.h" -#define INSORTTHRESH 5 // if n < this use insertion sort - // MUST be >= 2 -#define MIDTHRESH 20 // < this use middle as pivot -#define MEDOF3THRESH 50 // < this use median-of-3 as pivot - // larger subfiles use med-of-3-medians +#define INSORTTHRESH 5 // if n < this use insertion sort + // MUST be >= 2 +#define MIDTHRESH 20 // < this use middle as pivot +#define MEDOF3THRESH 50 // < this use median-of-3 as pivot + // larger subfiles use med-of-3-medians #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) @@ -41,7 +41,7 @@ typedef void *pref_typ; #define SWAP(a, b) if (swap_type) swapf(a, b, size);\ else do {pref_typ t; ASWAP(*(pref_typ*)(a), *(pref_typ*)(b), t);} while (0) -#define COMP(a, b) ((*compar)((void *)(a), (void *)(b))) +#define COMP(a, b) ((*compar)((void *)(a), (void *)(b))) static inline void swapbytes(void *a0, void *b0, size_t n) { @@ -51,9 +51,9 @@ static inline void swapbytes(void *a0, void *b0, size_t n) static inline void swapdword(void *a0, void *b0, size_t n) { + (void)n; DWORD *a = a0, *b = b0, t; ASWAP(*a, *b, t); - (void)n; } static inline void swapdwords(void *a0, void *b0, size_t n) @@ -64,9 +64,9 @@ static inline void swapdwords(void *a0, void *b0, size_t n) static inline void swapword(void *a0, void *b0, size_t n) { + (void)n; WORD *a = a0, *b = b0, t; ASWAP(*a, *b, t); - (void)n; } static inline void swapwords(void *a0, void *b0, size_t n) From 7a832df4d37a425ba8acfcb2aede213603225fef Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 15:05:31 +0200 Subject: [PATCH 052/166] cleanup + reformatting --- src/hardware/hw_main.c | 129 ++++++++++++++++++++--------------------- src/r_bsp.c | 3 +- src/v_video.c | 26 ++++----- 3 files changed, 75 insertions(+), 83 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a1bd98a62..0bb78bee5 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -195,7 +195,7 @@ static void CV_grshaders_OnChange(void) { ONLY_IF_GL_LOADED HWR_SetShaderState(); - if ((cv_grpaletterendering.value)) + if (cv_grpaletterendering.value) { // can't do palette rendering without shaders, so update the state if needed HWR_TogglePaletteRendering(); @@ -205,7 +205,6 @@ static void CV_grshaders_OnChange(void) static void CV_grpaletterendering_OnChange(void) { ONLY_IF_GL_LOADED - if (cv_grscreentextures.value != 2) // can't do palette rendering without screen textures CV_Set(&cv_grpaletterendering, "Off"); @@ -573,11 +572,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col Surface->LightInfo.light_level = light_level; Surface->LightInfo.fade_start = (colormap != NULL) ? colormap->fadestart : 0; Surface->LightInfo.fade_end = (colormap != NULL) ? colormap->fadeend : 31; - - if (HWR_ShouldUsePaletteRendering()) - Surface->LightTableId = HWR_GetLightTableID(colormap); - else - Surface->LightTableId = 0; + Surface->LightTableId = HWR_ShouldUsePaletteRendering() ? HWR_GetLightTableID(colormap) : 0; } UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if this can work @@ -3382,13 +3377,13 @@ static gr_vissprite_t gr_overflowsprite; static gr_vissprite_t *HWR_GetVisSprite(UINT32 num) { - UINT32 chunk = num >> VISSPRITECHUNKBITS; + UINT32 chunk = num >> VISSPRITECHUNKBITS; - // Allocate chunk if necessary - if (!gr_visspritechunks[chunk]) - Z_Malloc(sizeof(gr_vissprite_t) * VISSPRITESPERCHUNK, PU_LEVEL, &gr_visspritechunks[chunk]); + // Allocate chunk if necessary + if (!gr_visspritechunks[chunk]) + Z_Malloc(sizeof(gr_vissprite_t) * VISSPRITESPERCHUNK, PU_LEVEL, &gr_visspritechunks[chunk]); - return gr_visspritechunks[chunk] + (num & VISSPRITEINDEXMASK); + return gr_visspritechunks[chunk] + (num & VISSPRITEINDEXMASK); } static gr_vissprite_t *HWR_NewVisSprite(void) @@ -3764,15 +3759,13 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) HWR_RotateSpritePolyToAim(spr, baseWallVerts, false); // push it toward the camera to mitigate floor-clipping sprites + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); + float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; + for (i = 0; i < 4; i++) { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); - float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; - for (i = 0; i < 4; i++) - { - baseWallVerts[i].x += (gr_viewx - baseWallVerts[i].x)*distfact; - baseWallVerts[i].z += (gr_viewy - baseWallVerts[i].z)*distfact; - baseWallVerts[i].y += (gr_viewz - baseWallVerts[i].y)*distfact; - } + baseWallVerts[i].x += (gr_viewx - baseWallVerts[i].x)*distfact; + baseWallVerts[i].z += (gr_viewy - baseWallVerts[i].z)*distfact; + baseWallVerts[i].y += (gr_viewz - baseWallVerts[i].y)*distfact; } realtop = top = baseWallVerts[3].y; @@ -3957,6 +3950,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) FOutVector wallVerts[4]; GLPatch_t *gpatch; // sprite patch converted to hardware FSurfaceInfo Surf; + FBITFIELD blend = 0; INT32 shader = SHADER_NONE; @@ -4039,16 +4033,14 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) HWR_RotateSpritePolyToAim(spr, wallVerts, false); // push it toward the camera to mitigate floor-clipping sprites + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); + float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; + size_t i; + for (i = 0; i < 4; i++) { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); - float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; - size_t i; - for (i = 0; i < 4; i++) - { - wallVerts[i].x += (gr_viewx - wallVerts[i].x)*distfact; - wallVerts[i].z += (gr_viewy - wallVerts[i].z)*distfact; - wallVerts[i].y += (gr_viewz - wallVerts[i].y)*distfact; - } + wallVerts[i].x += (gr_viewx - wallVerts[i].x)*distfact; + wallVerts[i].z += (gr_viewy - wallVerts[i].z)*distfact; + wallVerts[i].y += (gr_viewz - wallVerts[i].y)*distfact; } // This needs to be AFTER the shadows so that the regular sprites aren't drawn completely black. @@ -4065,38 +4057,35 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) HWR_Lighting(&Surf, lightlevel, colormap); + if (!cv_translucency.value) // translucency disabled { - FBITFIELD blend = 0; - if (!cv_translucency.value) // translucency disabled - { - Surf.PolyColor.s.alpha = 0xFF; - blend = PF_Translucent|PF_Occlude; - } - else if (spr->mobj->flags2 & MF2_SHADOW) - { - Surf.PolyColor.s.alpha = 0x40; - blend = PF_Translucent; - } - else if (spr->mobj->frame & FF_TRANSMASK) - blend = HWR_TranstableToAlpha((spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); - else - { - // BP: i agree that is little better in environement but it don't - // work properly under glide nor with fogcolor to ffffff :( - // Hurdler: PF_Environement would be cool, but we need to fix - // the issue with the fog before - Surf.PolyColor.s.alpha = 0xFF; - blend = PF_Translucent|PF_Occlude; - } - - if (HWR_UseShader()) - { - shader = SHADER_SPRITE; - blend |= PF_ColorMapped; - } - - HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false); + Surf.PolyColor.s.alpha = 0xFF; + blend = PF_Translucent|PF_Occlude; } + else if (spr->mobj->flags2 & MF2_SHADOW) + { + Surf.PolyColor.s.alpha = 0x40; + blend = PF_Translucent; + } + else if (spr->mobj->frame & FF_TRANSMASK) + blend = HWR_TranstableToAlpha((spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); + else + { + // BP: i agree that is little better in environement but it don't + // work properly under glide nor with fogcolor to ffffff :( + // Hurdler: PF_Environement would be cool, but we need to fix + // the issue with the fog before + Surf.PolyColor.s.alpha = 0xFF; + blend = PF_Translucent|PF_Occlude; + } + + if (HWR_UseShader()) + { + shader = SHADER_SPRITE; + blend |= PF_ColorMapped; + } + + HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false); } // Sprite drawer for precipitation @@ -4467,8 +4456,9 @@ static void HWR_RenderDrawNodes(void) if (!(plane->blend & PF_NoTexture)) HWR_GetFlat(plane->lumpnum, R_NoEncore(plane->FOFSector, plane->isceiling)); + HWR_RenderPlane(NULL, plane->xsub, plane->isceiling, plane->fixedheight, plane->blend, plane->lightlevel, - plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap); + plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap); } else if (drawnode->type == DRAWNODE_POLYOBJECT_PLANE) { @@ -4479,8 +4469,9 @@ static void HWR_RenderDrawNodes(void) if (!(polyplane->blend & PF_NoTexture)) HWR_GetFlat(polyplane->lumpnum, R_NoEncore(polyplane->FOFSector, polyplane->isceiling)); + HWR_RenderPolyObjectPlane(polyplane->polysector, polyplane->isceiling, polyplane->fixedheight, polyplane->blend, polyplane->lightlevel, - polyplane->lumpnum, polyplane->FOFSector, polyplane->alpha, polyplane->planecolormap); + polyplane->lumpnum, polyplane->FOFSector, polyplane->alpha, polyplane->planecolormap); } else if (drawnode->type == DRAWNODE_WALL) { @@ -4488,8 +4479,9 @@ static void HWR_RenderDrawNodes(void) if (!(wall->blend & PF_NoTexture)) HWR_GetTexture(wall->texnum, wall->noencore); + HWR_RenderWall(wall->wallVerts, &wall->Surf, wall->blend, wall->fogwall, - wall->lightlevel, wall->wallcolormap); + wall->lightlevel, wall->wallcolormap); } } @@ -4799,8 +4791,8 @@ void HWR_ProjectSprite(mobj_t *thing) flip ^= (1<skin && ((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->flags & SF_HIRES) - this_scale *= FIXED_TO_FLOAT(((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->highresscale); + if (thing->skin && ((skin_t *)(thing->localskin ? thing->localskin : thing->skin))->flags & SF_HIRES) + this_scale *= FIXED_TO_FLOAT(((skin_t *)(thing->localskin ? thing->localskin : thing->skin))->highresscale); spr_width = spritecachedinfo[lumpoff].width; spr_height = spritecachedinfo[lumpoff].height; @@ -4921,6 +4913,7 @@ void HWR_ProjectSprite(mobj_t *thing) FIXED_TO_FLOAT(interp.z) >= FIXED_TO_FLOAT(sectors[heightsec].floorheight) : gzt < FIXED_TO_FLOAT(sectors[heightsec].floorheight)) return; + if (gr_viewz > FIXED_TO_FLOAT(sectors[phs].ceilingheight) ? gzt < FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) && gr_viewz >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) : FIXED_TO_FLOAT(interp.z) >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight)) @@ -5377,9 +5370,10 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe gl_portallist_t portallist; gl_portal_t *portal; gl_portal_t *gl_portal_temp; - portallist.base = portallist.cap = NULL; const boolean skybox = (skyboxmo[0] && cv_skybox.value); - boolean useportals = gr_maphasportals && cv_grportals.value && allow_portals; + const boolean useportals = cv_grportals.value && gr_maphasportals && allow_portals; + + portallist.base = portallist.cap = NULL; if (useportals && stencil_level < cv_maxportals.value) // if recursion limit is not reached { @@ -5388,6 +5382,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe gr_portal = GRPORTAL_SEARCH; HWR_ClearClipper(); + if (!rootportal) portalclipline = NULL; else @@ -5845,7 +5840,7 @@ void HWR_DoPostProcessor(player_t *player) // Armageddon Blast Flash! // Could this even be considered postprocessor? - if ((player->flashcount) && (!HWR_PalRenderFlashpal())) + if (!HWR_PalRenderFlashpal() && player->flashcount) { FOutVector v[4]; FSurfaceInfo Surf; diff --git a/src/r_bsp.c b/src/r_bsp.c index 54d6cada1..d1ceadbf4 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -1333,8 +1333,7 @@ void R_RenderBSPNode(INT32 bspnum) // PORTAL CULLING if (portalcullsector) { - sector_t *sect = subsectors[bspnum & ~NF_SUBSECTOR].sector; - if (sect != portalcullsector) + if (subsectors[bspnum & ~NF_SUBSECTOR].sector != portalcullsector) return; portalcullsector = NULL; } diff --git a/src/v_video.c b/src/v_video.c index 5746d963e..ee9cfa5f9 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1611,21 +1611,19 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength) } #endif - { - const UINT8 *fadetable = - (color > 0xFFF0) // Grab a specific colormap palette? - ? R_GetTranslationColormap(color | 0xFFFF0000, strength, GTC_CACHE) - : ((color & 0xFF00) // Color is not palette index? - ? ((UINT8 *)colormaps + strength*256) // Do COLORMAP fade. - : ((UINT8 *)transtables + ((9-strength)< 0xFFF0) // Grab a specific colormap palette? + ? R_GetTranslationColormap(color | 0xFFFF0000, strength, GTC_CACHE) + : ((color & 0xFF00) // Color is not palette index? + ? ((UINT8 *)colormaps + strength*256) // Do COLORMAP fade. + : ((UINT8 *)transtables + ((9-strength)< Date: Fri, 27 Sep 2024 05:19:52 +0200 Subject: [PATCH 053/166] use qs22j here again it is really faster thought it wasnt in this case --- src/d_net.c | 8 ++++---- src/hardware/hw_main.c | 3 +-- src/p_polyobj.c | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/d_net.c b/src/d_net.c index ad031a76b..a8602f567 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1446,13 +1446,13 @@ void Command_Ping_f(void) } } - if (f_width < 10) f_width = 1; + if (f_width < 10) f_width = 1; else if (f_width < 100) f_width = 2; - else f_width = 3; + else f_width = 3; - if (ms_width < 10) ms_width = 1; + if (ms_width < 10) ms_width = 1; else if (ms_width < 100) ms_width = 2; - else ms_width = 3; + else ms_width = 3; qsort(pingv, pingc, sizeof (struct pingcell), &pingcellcmp); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 0bb78bee5..30c6f7454 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -12,7 +12,6 @@ /// \brief hardware renderer, using the standard HardWareRender driver DLL for SRB2 #include -#include // qsort #include "../doomstat.h" @@ -4227,7 +4226,7 @@ static void HWR_SortVisSprites(void) gr_vsprorder[i] = HWR_GetVisSprite(i); } - qsort(gr_vsprorder, gr_visspritecount, sizeof(gr_vissprite_t*), CompareVisSprites); + qs22j(gr_vsprorder, gr_visspritecount, sizeof(gr_vissprite_t*), CompareVisSprites); } // A drawnode is something that points to a 3D floor, 3D side, or masked diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 7a21497e3..f890b0bd0 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -28,6 +28,7 @@ #include "r_main.h" #include "r_state.h" #include "r_defs.h" +#include "qs22j.h" /* @@ -580,7 +581,7 @@ static void Polyobj_findExplicit(polyobj_t *po) // sort the array if necessary if (numSegItems >= 2) - qsort(segitems, numSegItems, sizeof(segitem_t), Polyobj_segCompare); + qs22j(segitems, numSegItems, sizeof(segitem_t), Polyobj_segCompare); // second loop: put the sorted segs into the polyobject for (i = 0; i < numSegItems; ++i) From 1c6fce9339bfa25adae5eff9b65e4d7ba46fdedd Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 15:04:01 +0200 Subject: [PATCH 054/166] fix encore minimap --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 5128093f6..44497b0f2 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9731,7 +9731,7 @@ static void K_drawKartMinimap(void) splitflags |= minimaptrans; if (encoremode) - V_DrawScaledPatch(x+SHORT(minimapinfo.minimap_pic->width), y, minimaptrans|V_FLIP, minimapinfo.minimap_pic); + V_DrawScaledPatch(x+SHORT(minimapinfo.minimap_pic->width), y, splitflags|V_FLIP, minimapinfo.minimap_pic); else V_DrawScaledPatch(x, y, splitflags, minimapinfo.minimap_pic); From 48e71afec13d8a414fa8179791355eda956d8e68 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 18:21:17 +0200 Subject: [PATCH 055/166] update lzf compression to 1.6 --- src/lzf.c | 528 +++++++++++++++++++++++++++++++++++------------------- src/lzf.h | 4 +- 2 files changed, 346 insertions(+), 186 deletions(-) diff --git a/src/lzf.c b/src/lzf.c index f81c3ee0a..eb0d73b78 100644 --- a/src/lzf.c +++ b/src/lzf.c @@ -37,9 +37,8 @@ /* * Sacrifice very little compression quality in favour of compression speed. * This gives almost the same compression as the default code, and is - * (very roughly) 15% faster. This is the preferable mode of operation. + * (very roughly) 15% faster. This is the preferred mode of operation. */ - #ifndef VERY_FAST # define VERY_FAST 1 #endif @@ -48,7 +47,7 @@ * Sacrifice some more compression quality in favour of compression speed. * (roughly 1-2% worse compression for large blocks and * 9-10% for small, redundant, blocks and >>20% better speed in both cases) - * In INT16: when in need for speed, enable this for binary data, + * In short: when in need for speed, enable this for binary data, * possibly disable this for text data. */ #ifndef ULTRA_FAST @@ -66,21 +65,10 @@ #endif #endif -/* - * Use string functions to copy memory. - * this is usually a loss, even with glibc's optimized memcpy - */ -#ifndef USE_MEMCPY -#ifdef _MSC_VER -# define USE_MEMCPY 0 -#else -# define USE_MEMCPY 1 -#endif -#endif - /* * You may choose to pre-set the hash table (might be faster on some - * modern cpus and large (>>64k) blocks) + * modern cpus and large (>>64k) blocks, and also makes compression + * deterministic/repeatable when the configuration otherwise is the same). */ #ifndef INIT_HTAB # define INIT_HTAB 1 @@ -88,15 +76,15 @@ /* * Avoid assigning values to errno variable? for some embedding purposes - * (linux kernel for example), this is neccessary. NOTE: this breaks - * the documentation in lzf.h. + * (linux kernel for example), this is necessary. NOTE: this breaks + * the documentation in lzf.h. Avoiding errno has no speed impact. */ #ifndef AVOID_ERRNO # define AVOID_ERRNO 0 #endif /* - * Wether to pass the LZF_STATE variable as argument, or allocate it + * Whether to pass the LZF_STATE variable as argument, or allocate it * on the stack. For small-stack environments, define this to 1. * NOTE: this breaks the prototype in lzf.h. */ @@ -105,51 +93,109 @@ #endif /* - * Wether to add extra checks for input validity in lzf_decompress + * Whether to add extra checks for input validity in lzf_decompress * and return EINVAL if the input stream has been corrupted. This * only shields against overflowing the input buffer and will not * detect most corrupted streams. - * This check is not normally noticable on modern hardware + * This check is not normally noticeable on modern hardware * (<1% slowdown), but might slow down older cpus considerably. */ #ifndef CHECK_INPUT # define CHECK_INPUT 1 #endif +/* + * Whether the target CPU has a slow multiplication. This affects + * the default hash function for the compressor, and enables a slightly + * worse hash function that needs only shifts. + */ +#ifndef MULTIPLICATION_IS_SLOW +# define MULTIPLICATION_IS_SLOW 0 +#endif + +/* + * If defined, then this data type will be used for storing offsets. + * This can be useful if you want to use a huge hashtable, want to + * conserve memory, or both, and your data fits into e.g. 64kb. + * If instead you want to compress data > 4GB, then it's better to + * to "#define LZF_USE_OFFSETS 0" instead. + */ +/*#define LZF_HSLOT unsigned short*/ + +/* + * Whether to store pointers or offsets inside the hash table. On + * 64 bit architetcures, pointers take up twice as much space, + * and might also be slower. Default is to autodetect. + */ +/*#define LZF_USE_OFFSETS autodetect */ + +/* + * Whether to optimise code for size, at the expense of speed. Use + * this when you are extremely tight on memory, perhaps in combination + * with AVOID_ERRNO 1 and CHECK_INPUT 0. + */ +#ifndef OPTIMISE_SIZE +# ifdef __OPTIMIZE_SIZE__ +# define OPTIMISE_SIZE 1 +# else +# define OPTIMISE_SIZE 0 +# endif +#endif + /*****************************************************************************/ /* nothing should be changed below */ -typedef unsigned char u8; - -typedef const u8 *LZF_STATE[1 << (HLOG)]; - -#if !STRICT_ALIGN -/* for unaligned accesses we need a 16 bit datatype. */ +# include # include -# if USHRT_MAX == 65535 - typedef unsigned short u16; -# elif UINT_MAX == 65535 - typedef unsigned int u16; -# else -# undef STRICT_ALIGN -# define STRICT_ALIGN 1 -# endif -#endif #if ULTRA_FAST -# if defined(VERY_FAST) -# undef VERY_FAST +# undef VERY_FAST +#endif + +#ifndef LZF_USE_OFFSETS +# ifdef _WIN32 +# define LZF_USE_OFFSETS defined(_M_X64) +# else +# include +# define LZF_USE_OFFSETS (UINTPTR_MAX > 0xffffffffU) # endif #endif -#if USE_MEMCPY || INIT_HTAB -# ifdef __cplusplus -# include +typedef unsigned char u8; + +#ifdef LZF_HSLOT +# define LZF_HSLOT_BIAS ((const u8 *)in_data) +#else +# if LZF_USE_OFFSETS +# define LZF_HSLOT_BIAS ((const u8 *)in_data) + typedef unsigned int LZF_HSLOT; # else -# include +# define LZF_HSLOT_BIAS 0 + typedef const u8 *LZF_HSLOT; # endif #endif +#if USHRT_MAX == 65535 + typedef unsigned short u16; +#elif UINT_MAX == 65535 + typedef unsigned int u16; +#else +# undef STRICT_ALIGN +# define STRICT_ALIGN 1 +#endif + +#define LZF_MAX_LIT (1 << 5) +#define LZF_MAX_OFF (1 << 13) +#define LZF_MAX_REF ((1 << 8) + (1 << 3)) + +typedef LZF_HSLOT LZF_STATE[1 << (HLOG)]; + +typedef struct +{ + const u8 *first [1 << (6+8)]; /* most recent occurance of a match */ + u16 prev [LZF_MAX_OFF]; /* how many bytes to go backwards for the next match */ +} LZF_STATE_BEST[1]; + #endif @@ -164,14 +210,31 @@ typedef const u8 *LZF_STATE[1 << (HLOG)]; # define SET_ERRNO(n) errno = (n) #endif +#ifndef USE_REP_MOVSB +#if (defined (__i386) || defined (__amd64)) && __GNUC__ >= 3 +#define USE_REP_MOVSB 1 +#else +#define USE_REP_MOVSB 0 // Default to 0 if not defined elsewhere +#endif +#endif + +#if USE_REP_MOVSB /* small win on amd, big loss on intel */ +#if (defined (__i386) || defined (__amd64)) && __GNUC__ >= 3 +# define lzf_movsb(dst, src, len) \ + asm ("rep movsb" \ + : "=D" (dst), "=S" (src), "=c" (len) \ + : "0" (dst), "1" (src), "2" (len)); +#endif +#endif + size_t lzf_decompress (const void *const in_data, size_t in_len, - void *out_data, size_t out_len) + void *out_data, size_t out_len) { u8 const *ip = (const u8 *)in_data; - u8 *op = (u8 *)out_data; + u8 *op = (u8 *)out_data; u8 const *const in_end = ip + in_len; - u8 *const out_end = op + out_len; + u8 *const out_end = op + out_len; do { @@ -195,14 +258,23 @@ lzf_decompress (const void *const in_data, size_t in_len, } #endif -#if USE_MEMCPY - M_Memcpy (op, ip, ctrl); - op += ctrl; - ip += ctrl; -#else - do +#ifdef lzf_movsb + lzf_movsb (op, ip, ctrl); +#elif OPTIMISE_SIZE + while (ctrl--) *op++ = *ip++; - while (--ctrl); +#else + switch (ctrl) + { + case 32: *op++ = *ip++; case 31: *op++ = *ip++; case 30: *op++ = *ip++; case 29: *op++ = *ip++; + case 28: *op++ = *ip++; case 27: *op++ = *ip++; case 26: *op++ = *ip++; case 25: *op++ = *ip++; + case 24: *op++ = *ip++; case 23: *op++ = *ip++; case 22: *op++ = *ip++; case 21: *op++ = *ip++; + case 20: *op++ = *ip++; case 19: *op++ = *ip++; case 18: *op++ = *ip++; case 17: *op++ = *ip++; + case 16: *op++ = *ip++; case 15: *op++ = *ip++; case 14: *op++ = *ip++; case 13: *op++ = *ip++; + case 12: *op++ = *ip++; case 11: *op++ = *ip++; case 10: *op++ = *ip++; case 9: *op++ = *ip++; + case 8: *op++ = *ip++; case 7: *op++ = *ip++; case 6: *op++ = *ip++; case 5: *op++ = *ip++; + case 4: *op++ = *ip++; case 3: *op++ = *ip++; case 2: *op++ = *ip++; case 1: *op++ = *ip++; + } #endif } else /* back reference */ @@ -244,12 +316,49 @@ lzf_decompress (const void *const in_data, size_t in_len, return 0; } - *op++ = *ref++; - *op++ = *ref++; +#ifdef lzf_movsb + len += 2; + lzf_movsb (op, ref, len); +#elif OPTIMISE_SIZE + len += 2; do *op++ = *ref++; while (--len); +#else + switch (len) + { + default: + len += 2; + + if (op >= ref + len) + { + /* disjunct areas */ + memcpy (op, ref, len); + op += len; + } + else + { + /* overlapping, use octet by octet copying */ + do + *op++ = *ref++; + while (--len); + } + break; + + case 9: *op++ = *ref++; + case 8: *op++ = *ref++; + case 7: *op++ = *ref++; + case 6: *op++ = *ref++; + case 5: *op++ = *ref++; + case 4: *op++ = *ref++; + case 3: *op++ = *ref++; + case 2: *op++ = *ref++; + case 1: *op++ = *ref++; + case 0: *op++ = *ref++; /* two octets more */ + *op++ = *ref++; + } +#endif } } while (ip < in_end); @@ -266,23 +375,29 @@ lzf_decompress (const void *const in_data, size_t in_len, /* * don't play with this unless you benchmark! - * decompression is not dependent on the hash function - * the hashing function might seem strange, just believe me + * the data format is not dependent on the hash function. + * the hash function might seem strange, just believe me, * it works ;) */ #ifndef FRST # define FRST(p) (((p[0]) << 8) | p[1]) # define NEXT(v,p) (((v) << 8) | p[2]) -# define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1)) -#endif -/* - * IDX works because it is very similar to a multiplicative hash, e.g. - * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1)) - * the latter is also quite fast on newer CPUs, and sligthly better - * - * the next one is also quite good, albeit slow ;) - * (int)(cos(h & 0xffffff) * 1e6) +# if MULTIPLICATION_IS_SLOW +# if ULTRA_FAST +# define IDX(h) ((( h >> (3*8 - HLOG)) - h ) & (HSIZE - 1)) +# elif VERY_FAST +# define IDX(h) ((( h >> (3*8 - HLOG)) - h*5) & (HSIZE - 1)) +# else +# define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1)) +# endif +# else +/* this one was developed with sesse, + * and is very similar to the one in snappy. + * it does need a modern enough cpu with a fast multiplication. */ +# define IDX(h) (((h * 0x1e35a7bdU) >> (32 - HLOG - 8)) & (HSIZE - 1)) +# endif +#endif #if 0 /* original lzv-like hash function, much worse and thus slower */ @@ -291,177 +406,222 @@ lzf_decompress (const void *const in_data, size_t in_len, # define IDX(h) ((h) & (HSIZE - 1)) #endif -#define MAX_LIT (1 << 5) -#define MAX_OFF (1 << 13) -#define MAX_REF ((1 << 8) + (1 << 3)) +#if __GNUC__ >= 3 +# define expect(expr,value) __builtin_expect ((expr),(value)) +# define inline inline +#else +# define expect(expr,value) (expr) +# define inline static +#endif + +#define expect_false(expr) expect ((expr) != 0, 0) +#define expect_true(expr) expect ((expr) != 0, 1) /* * compressed format * - * 000LLLLL ; literal - * LLLooooo oooooooo ; backref L - * 111ooooo LLLLLLLL oooooooo ; backref L+7 + * 000LLLLL ; literal, L+1=1..33 octets + * LLLooooo oooooooo ; backref L+1=1..7 octets, o+1=1..4096 offset + * 111ooooo LLLLLLLL oooooooo ; backref L+8 octets, o+1=1..4096 offset * */ size_t -lzf_compress (const void *const in_data,size_t in_len, - void *out_data, size_t out_len +lzf_compress (const void *const in_data, size_t in_len, + void *out_data, size_t out_len #if LZF_STATE_ARG - , LZF_STATE *htab + , LZF_STATE htab #endif - ) + ) { #if !LZF_STATE_ARG LZF_STATE htab; #endif - const u8 **hslot; const u8 *ip = (const u8 *)in_data; - u8 *op = (u8 *)out_data; + u8 *op = (u8 *)out_data; const u8 *in_end = ip + in_len; - u8 *out_end = op + out_len; - const u8 *ref = NULL; + u8 *out_end = op + out_len; + const u8 *ref; - unsigned int hval = FRST (ip); - size_t off; - int lit = 0; + /* + * off requires a type wide enough to hold a general pointer difference. + * ISO C doesn't have that (size_t might not be enough and ptrdiff_t only + * works for differences within a single object). We also assume that + * no bit pattern traps. Since the only platform that is both non-POSIX + * and fails to support both assumptions is windows 64 bit, we make a + * special workaround for it. + */ +#if defined (_WIN32) && defined (_M_X64) + /* workaround for missing POSIX compliance */ +#if __GNUC__ + unsigned long long off; +#else + unsigned __int64 off; +#endif +#else + unsigned long off; +#endif + unsigned int hval; + int lit; + + if (!in_len || !out_len) + return 0; #if INIT_HTAB -# if USE_MEMCPY memset (htab, 0, sizeof (htab)); -# else - for (hslot = htab; hslot < htab + HSIZE; hslot++) - *hslot++ = ip; -# endif #endif - for (;;) + lit = 0; op++; /* start run */ + + hval = FRST (ip); + while (ip < in_end - 2) { - if (ip < in_end - 2) - { - hval = NEXT (hval, ip); - hslot = htab + IDX (hval); - ref = *hslot; *hslot = ip; + LZF_HSLOT *hslot; - if ( -#if INIT_HTAB && !USE_MEMCPY - ref < ip /* the next test will actually take care of this, but this is faster */ - && + hval = NEXT (hval, ip); + hslot = htab + IDX (hval); + ref = *hslot + LZF_HSLOT_BIAS; *hslot = ip - LZF_HSLOT_BIAS; + + if (1 +#if INIT_HTAB + && ref < ip /* the next test will actually take care of this, but this is faster */ #endif - (off = ip - ref - 1) < MAX_OFF - && ip + 4 < in_end - && ref > (const u8 *)in_data + && (off = ip - ref - 1) < LZF_MAX_OFF + && ref > (const u8 *)in_data + && ref[2] == ip[2] #if STRICT_ALIGN - && ref[0] == ip[0] - && ref[1] == ip[1] - && ref[2] == ip[2] + && ((ref[1] << 8) | ref[0]) == ((ip[1] << 8) | ip[0]) #else - && *(const u16 *)ref == *(const u16 *)ip - && ref[2] == ip[2] + && *(const u16 *)ref == *(const u16 *)ip #endif - ) - { - /* match found at *ref++ */ - unsigned int len = 2; - size_t maxlen = in_end - ip - len; - maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; + ) + { + /* match found at *ref++ */ + unsigned int len = 2; + unsigned int maxlen = in_end - ip - len; + maxlen = maxlen > LZF_MAX_REF ? LZF_MAX_REF : maxlen; - if (op + lit + 1 + 3 >= out_end) + if (expect_false (op + 3 + 1 >= out_end)) /* first a faster conservative test */ + if (op - !lit + 3 + 1 >= out_end) /* second the exact but rare test */ return 0; + op [- lit - 1] = lit - 1; /* stop run */ + op -= !lit; /* undo run if length is zero */ + + for (;;) + { + if (expect_true (maxlen > 16)) + { + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + } + do len++; while (len < maxlen && ref[len] == ip[len]); - if (lit) - { - *op++ = (u8)(lit - 1); - lit = -lit; - do - *op++ = ip[lit]; - while (++lit); - } + break; + } - len -= 2; - ip++; + len -= 2; /* len is now #octets - 1 */ + ip++; - if (len < 7) - { - *op++ = (u8)((off >> 8) + (len << 5)); - } - else - { - *op++ = (u8)((off >> 8) + ( 7 << 5)); - *op++ = (u8)(len - 7); - } + if (len < 7) + { + *op++ = (off >> 8) + (len << 5); + } + else + { + *op++ = (off >> 8) + ( 7 << 5); + *op++ = len - 7; + } - *op++ = (u8)off; + *op++ = off; + + lit = 0; op++; /* start run */ + + ip += len + 1; + + if (expect_false (ip >= in_end - 2)) + break; #if ULTRA_FAST || VERY_FAST - ip += len; -#if VERY_FAST && !ULTRA_FAST - --ip; -#endif - hval = FRST (ip); + --ip; +# if VERY_FAST && !ULTRA_FAST + --ip; +# endif + hval = FRST (ip); - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip - LZF_HSLOT_BIAS; + ip++; -#if VERY_FAST && !ULTRA_FAST - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; -#endif +# if VERY_FAST && !ULTRA_FAST + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip - LZF_HSLOT_BIAS; + ip++; +# endif #else - do - { - hval = NEXT (hval, ip); - htab[IDX (hval)] = ip; - ip++; - } - while (len--); -#endif - continue; + ip -= len + 1; + + do + { + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip - LZF_HSLOT_BIAS; + ip++; } + while (len--); +#endif } - else if (ip == in_end) - break; - - /* one more literal byte we must copy */ - lit++; - ip++; - - if (lit == MAX_LIT) + else { - if (op + 1 + MAX_LIT >= out_end) + /* one more literal byte we must copy */ + if (expect_false (op >= out_end)) return 0; - *op++ = MAX_LIT - 1; -#if USE_MEMCPY - M_Memcpy (op, ip - MAX_LIT, MAX_LIT); - op += MAX_LIT; - lit = 0; -#else - lit = -lit; - do - *op++ = ip[lit]; - while (++lit); -#endif + lit++; *op++ = *ip++; + + if (expect_false (lit == LZF_MAX_LIT)) + { + op [- lit - 1] = lit - 1; /* stop run */ + lit = 0; op++; /* start run */ + } } } - if (lit) - { - if (op + lit + 1 >= out_end) - return 0; + if (op + 3 > out_end) /* at most 3 bytes can be missing here */ + return 0; - *op++ = (u8)(lit - 1); - lit = -lit; - do - *op++ = ip[lit]; - while (++lit); + while (ip < in_end) + { + lit++; *op++ = *ip++; + + if (expect_false (lit == LZF_MAX_LIT)) + { + op [- lit - 1] = lit - 1; /* stop run */ + lit = 0; op++; /* start run */ + } } - return op - (u8 *) out_data; + op [- lit - 1] = lit - 1; /* end run */ + op -= !lit; /* undo run if length is zero */ + + return op - (u8 *)out_data; } diff --git a/src/lzf.h b/src/lzf.h index 85daf255e..dae8b131c 100644 --- a/src/lzf.h +++ b/src/lzf.h @@ -1,6 +1,6 @@ // SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- -// Copyright (C) 2000-2005 by Marc Alexander Lehmann +// Copyright (c) 2000-2010 Marc Alexander Lehmann // // This program is free software distributed under the // terms of the GNU General Public License, version 2. @@ -22,7 +22,7 @@ ** ***********************************************************************/ -#define LZF_VERSION 0x0105 /* 1.5 */ +#define LZF_VERSION 0x0106 /* 1.6 */ /* * Compress in_len bytes stored at the memory block starting at From b357c09171d52c891b1a829775d000bb9c3596b6 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 18:52:53 +0200 Subject: [PATCH 056/166] those should be size_t --- src/lzf.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/lzf.c b/src/lzf.c index eb0d73b78..28ba1b6cb 100644 --- a/src/lzf.c +++ b/src/lzf.c @@ -451,16 +451,8 @@ lzf_compress (const void *const in_data, size_t in_len, * and fails to support both assumptions is windows 64 bit, we make a * special workaround for it. */ -#if defined (_WIN32) && defined (_M_X64) - /* workaround for missing POSIX compliance */ -#if __GNUC__ - unsigned long long off; -#else - unsigned __int64 off; -#endif -#else - unsigned long off; -#endif + + size_t off; unsigned int hval; int lit; @@ -498,7 +490,7 @@ lzf_compress (const void *const in_data, size_t in_len, { /* match found at *ref++ */ unsigned int len = 2; - unsigned int maxlen = in_end - ip - len; + size_t maxlen = in_end - ip - len; maxlen = maxlen > LZF_MAX_REF ? LZF_MAX_REF : maxlen; if (expect_false (op + 3 + 1 >= out_end)) /* first a faster conservative test */ From a1d490cb4902989ba80424499374a8d19062d59b Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 20:18:21 +0200 Subject: [PATCH 057/166] R_DrawMaskedColumn: do not draw zero length column --- src/r_things.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 85fe49f63..981988933 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -614,7 +614,7 @@ void R_DrawMaskedColumn(column_t *column) if (dc_yh >= vid.height) dc_yh = vid.height - 1; - if (dc_yl <= dc_yh && dc_yh > 0) + if (dc_yl <= dc_yh && dc_yh > 0&& column->length != 0) { dc_source = (UINT8 *)column + 3; dc_texturemid = basetexturemid - (topdelta<= vid.height) dc_yh = vid.height - 1; - if (dc_yl <= dc_yh && dc_yh > 0) + if (dc_yl <= dc_yh && dc_yh > 0 && column->length != 0) { dc_source = ZZ_Alloc(column->length); for (s = (UINT8 *)column+2+column->length, d = dc_source; d < dc_source+column->length; --s) From 2622ba286e908b7cfc5fd0037e4af29b11119953 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 20:18:36 +0200 Subject: [PATCH 058/166] z --- 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 981988933..84d73d2a5 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -614,7 +614,7 @@ void R_DrawMaskedColumn(column_t *column) if (dc_yh >= vid.height) dc_yh = vid.height - 1; - if (dc_yl <= dc_yh && dc_yh > 0&& column->length != 0) + if (dc_yl <= dc_yh && dc_yh > 0 && column->length != 0) { dc_source = (UINT8 *)column + 3; dc_texturemid = basetexturemid - (topdelta< Date: Fri, 27 Sep 2024 22:28:57 +0200 Subject: [PATCH 059/166] this does nothing --- src/m_menu.c | 31 ++++++++++++++----------------- src/s_sound.c | 26 ++++---------------------- src/s_sound.h | 1 - 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index c42c923e2..2bfb3e1f1 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1598,7 +1598,20 @@ static menuitem_t OP_SoundOptionsMenu[] = //{IT_STRING|IT_CALL, NULL, "Restart Audio System", M_RestartAudio, 50}, #ifdef NO_MIDI {IT_STRING|IT_CVAR, NULL, "Reverse L/R Channels", &stereoreverse, 50}, - {IT_STRING|IT_CVAR, NULL, "Surround Sound", &surround, 60}, + + {IT_STRING|IT_CVAR, NULL, "Chat Notifications", &cv_chatnotifications, 65}, + {IT_STRING|IT_CVAR, NULL, "Character voices", &cv_kartvoices, 75}, + {IT_STRING|IT_CVAR, NULL, "Hit Em Delay", &cv_karthitemdialog, 85}, + {IT_STRING|IT_CVAR, NULL, "Powerup Warning", &cv_kartinvinsfx, 95}, + + {IT_KEYHANDLER|IT_STRING, NULL, "Sound Test", M_HandleSoundTest, 105}, + {IT_STRING|IT_CALL, NULL, "Music Test", M_MusicTest, 115}, + + {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 125}, + {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 135}, + {IT_STRING|IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 145} +#else + {IT_STRING|IT_CVAR, NULL, "Reverse L/R Channels", &stereoreverse, 60}, {IT_STRING|IT_CVAR, NULL, "Chat Notifications", &cv_chatnotifications, 75}, {IT_STRING|IT_CVAR, NULL, "Character voices", &cv_kartvoices, 85}, @@ -1611,21 +1624,6 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 135}, {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 145}, {IT_STRING|IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 155} -#else - {IT_STRING|IT_CVAR, NULL, "Reverse L/R Channels", &stereoreverse, 60}, - {IT_STRING|IT_CVAR, NULL, "Surround Sound", &surround, 70}, - - {IT_STRING|IT_CVAR, NULL, "Chat Notifications", &cv_chatnotifications, 85}, - {IT_STRING|IT_CVAR, NULL, "Character voices", &cv_kartvoices, 95}, - {IT_STRING|IT_CVAR, NULL, "Hit Em Delay", &cv_karthitemdialog, 105}, - {IT_STRING|IT_CVAR, NULL, "Powerup Warning", &cv_kartinvinsfx, 115}, - - {IT_KEYHANDLER|IT_STRING, NULL, "Sound Test", M_HandleSoundTest, 125}, - {IT_STRING|IT_CALL, NULL, "Music Test", M_MusicTest, 135}, - - {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 145}, - {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 155}, - {IT_STRING|IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 165} #endif }; @@ -1640,7 +1638,6 @@ static const char* OP_SoundTooltips[] = "Volume of Midi Music.", #endif "Reverse left and right channels of audio.", - "Surround Sound.", "Chat notification sound.", "Frequency of character voice lines.", "Play 'Hit Em' character line after other player's hurt line.", diff --git a/src/s_sound.c b/src/s_sound.c index f3450b6f4..ec5ebf00d 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -85,7 +85,6 @@ consvar_t cv_midimusicvolume = {"midimusicvolume", "18", CV_SAVE, soundvolume_co // number of channels available consvar_t cv_numChannels = {"snd_channels", "64", CV_SAVE|CV_CALL, CV_Unsigned, SetChannelsNum, 0, NULL, NULL, 0, 0, NULL}; -consvar_t surround = {"surround", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE|CV_NOSHOWHELP, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; // Sound system toggles, saved into the config @@ -163,10 +162,6 @@ consvar_t cv_amigatype = {"amigatype", "0", CV_SAVE|CV_CALL|CV_NOINIT, amigatype #define S_PITCH_PERTURB 1 #define S_STEREO_SWING (96*0x10000) -#ifdef SURROUND -#define SURROUND_SEP -128 -#endif - // percent attenuation from front to back #define S_IFRACVOL 30 @@ -272,7 +267,6 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&stereoreverse); CV_RegisterVar(&precachesound); - CV_RegisterVar(&surround); CV_RegisterVar(&cv_samplerate); //CV_RegisterVar(&cv_resetmusic); CV_RegisterVar(&cv_gamesounds); @@ -616,11 +610,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) } // Avoid channel reverse if surround - if (reverse -#ifdef SURROUND - && sep != SURROUND_SEP -#endif - ) + if (reverse) { sep = (~sep) & 255; } @@ -1102,18 +1092,10 @@ boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 if (reverse) angle = InvAngle(angle); -#ifdef SURROUND - // Produce a surround sound for angle from 105 till 255 - if (surround.value == 1 && (angle > ANG105 && angle < ANG255 )) - *sep = SURROUND_SEP; - else -#endif - { - angle >>= ANGLETOFINESHIFT; + angle >>= ANGLETOFINESHIFT; - // stereo separation - *sep = 128 - (FixedMul(S_STEREO_SWING, FINESINE(angle))>>FRACBITS); - } + // stereo separation + *sep = 128 - (FixedMul(S_STEREO_SWING, FINESINE(angle))>>FRACBITS); } // volume calculation diff --git a/src/s_sound.h b/src/s_sound.h index 8787ea5e5..6f4d03f09 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -32,7 +32,6 @@ extern consvar_t stereoreverse; extern consvar_t cv_soundvolume, cv_digmusicvolume;//, cv_midimusicvolume; extern consvar_t cv_numChannels; -extern consvar_t surround; extern consvar_t cv_audbuffersize; //extern consvar_t cv_resetmusic; extern consvar_t cv_gamedigimusic; From eb74f3525af05f3771c5559968df21a5b3d831db Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 22:36:48 +0200 Subject: [PATCH 060/166] consolidate this --- src/p_saveg.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index b8a517f0e..0bf03aa04 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3031,6 +3031,13 @@ static inline void P_FinishMobjs(void) } } +static inline mobj_t *RelinkMobj(mobj_t **ptr) +{ + UINT32 temp = (UINT32)(size_t)*ptr; + *ptr = NULL; + return P_SetTarget(ptr, P_FindNewPosition(temp)); +} + static void P_RelinkPointers(void) { thinker_t *currentthinker; @@ -3051,58 +3058,42 @@ static void P_RelinkPointers(void) if (mobj->tracer) { - temp = (UINT32)(size_t)mobj->tracer; - mobj->tracer = NULL; - if (!P_SetTarget(&mobj->tracer, P_FindNewPosition(temp))) + if (!RelinkMobj(&mobj->tracer)) CONS_Debug(DBG_GAMELOGIC, "tracer not found on %d\n", mobj->type); } if (mobj->target) { - temp = (UINT32)(size_t)mobj->target; - mobj->target = NULL; - if (!P_SetTarget(&mobj->target, P_FindNewPosition(temp))) + if (!RelinkMobj(&mobj->target)) CONS_Debug(DBG_GAMELOGIC, "target not found on %d\n", mobj->type); } if (mobj->hnext) { - temp = (UINT32)(size_t)mobj->hnext; - mobj->hnext = NULL; - if (!P_SetTarget(&mobj->hnext, P_FindNewPosition(temp))) + if (!RelinkMobj(&mobj->hnext)) CONS_Debug(DBG_GAMELOGIC, "hnext not found on %d\n", mobj->type); } if (mobj->hprev) { - temp = (UINT32)(size_t)mobj->hprev; - mobj->hprev = NULL; - if (!P_SetTarget(&mobj->hprev, P_FindNewPosition(temp))) + if (!RelinkMobj(&mobj->hprev)) CONS_Debug(DBG_GAMELOGIC, "hprev not found on %d\n", mobj->type); } if (mobj->player && mobj->player->capsule) { - temp = (UINT32)(size_t)mobj->player->capsule; - mobj->player->capsule = NULL; - if (!P_SetTarget(&mobj->player->capsule, P_FindNewPosition(temp))) + if (!RelinkMobj(&mobj->player->capsule)) CONS_Debug(DBG_GAMELOGIC, "capsule not found on %d\n", mobj->type); } if (mobj->player && mobj->player->axis1) { - temp = (UINT32)(size_t)mobj->player->axis1; - mobj->player->axis1 = NULL; - if (!P_SetTarget(&mobj->player->axis1, P_FindNewPosition(temp))) + if (!RelinkMobj(&mobj->player->axis1)) CONS_Debug(DBG_GAMELOGIC, "axis1 not found on %d\n", mobj->type); } if (mobj->player && mobj->player->axis2) { - temp = (UINT32)(size_t)mobj->player->axis2; - mobj->player->axis2 = NULL; - if (!P_SetTarget(&mobj->player->axis2, P_FindNewPosition(temp))) + if (!RelinkMobj(&mobj->player->axis2)) CONS_Debug(DBG_GAMELOGIC, "axis2 not found on %d\n", mobj->type); } if (mobj->player && mobj->player->awayviewmobj) { - temp = (UINT32)(size_t)mobj->player->awayviewmobj; - mobj->player->awayviewmobj = NULL; - if (!P_SetTarget(&mobj->player->awayviewmobj, P_FindNewPosition(temp))) + if (!RelinkMobj(&mobj->player->awayviewmobj)) CONS_Debug(DBG_GAMELOGIC, "awayviewmobj not found on %d\n", mobj->type); } } From 89965ad718f739b01ada206943057f5a55311a8d Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 22:40:08 +0200 Subject: [PATCH 061/166] forgor remove this --- src/p_saveg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 0bf03aa04..dc0276bb5 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3042,7 +3042,6 @@ static void P_RelinkPointers(void) { thinker_t *currentthinker; mobj_t *mobj; - UINT32 temp; // use info field (value = oldposition) to relink mobjs for (currentthinker = thinkercap.next; currentthinker != &thinkercap; From 1533e13d68a5b7c1842f531d1b64b62f518f222d Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 22:40:38 +0200 Subject: [PATCH 062/166] let player pointer be const in P_IsLocalPlayer and P_IsDisplayPlayer --- src/p_local.h | 5 +++-- src/p_user.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/p_local.h b/src/p_local.h index 6916acc44..ab078e8b5 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -164,8 +164,9 @@ void P_InitCameraCmd(void); boolean P_PlayerInPain(player_t *player); void P_DoPlayerPain(player_t *player, mobj_t *source, mobj_t *inflictor); void P_ResetPlayer(player_t *player); -boolean P_IsLocalPlayer(player_t *player); -boolean P_IsDisplayPlayer(player_t *player); +boolean P_IsLocalPlayer(const player_t *player); +boolean P_IsDisplayPlayer(const player_t *player); + boolean P_SpectatorJoinGame(player_t *player); boolean P_IsObjectInGoop(mobj_t *mo); diff --git a/src/p_user.c b/src/p_user.c index 7d9e0e21f..f09f8b1ef 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1041,7 +1041,7 @@ fixed_t P_GetPlayerSpinHeight(player_t *player) // Returns true if player is // on the local machine. // -boolean P_IsLocalPlayer(player_t *player) +boolean P_IsLocalPlayer(const player_t *player) { UINT8 i; @@ -1065,7 +1065,7 @@ boolean P_IsLocalPlayer(player_t *player) // Returns true if player is // currently being watched. // -boolean P_IsDisplayPlayer(player_t *player) +boolean P_IsDisplayPlayer(const player_t *player) { UINT8 i; From 01c9632025897fc1ad46e7d2e52c98aca8229f6e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 22:46:54 +0200 Subject: [PATCH 063/166] set those in P_SpawnGhostMobj too --- src/p_user.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_user.c b/src/p_user.c index f09f8b1ef..a9b1b6b72 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1179,6 +1179,7 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) ghost = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_GHOST); P_SetScale(ghost, mobj->scale); + ghost->scalespeed = mobj->scalespeed; ghost->destscale = mobj->scale; if (mobj->eflags & MFE_VERTICALFLIP) @@ -1230,6 +1231,7 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) ghost->old_roll = mobj->old_roll2; ghost->old_sloperoll = mobj->old_sloperoll2; ghost->old_slopepitch = mobj->old_slopepitch2; + ghost->old_scale = mobj->old_scale2; return ghost; } From b71870f57bf4f1b4aa2b0fcaff66c9ea22414337 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 23:45:52 +0200 Subject: [PATCH 064/166] this needs no dedi check actually --- src/d_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index a57bf9eb2..e0d427b01 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -866,7 +866,7 @@ void D_SRB2Loop(void) else menuInputDelayTimer = 0; - if (!dedicated && renderisnewtic) // idk does this need dedi check?? + if (renderisnewtic) // idk does this need dedi check?? D_DeviceLEDTick(); // Fully completed frame made. From 222f56d1b21ec7b50784e57d5c93de38eb145f54 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 28 Sep 2024 00:12:57 +0200 Subject: [PATCH 065/166] smol director stuffs --- src/k_director.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/k_director.c b/src/k_director.c index 51406cf07..3c5938713 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -23,7 +23,7 @@ #define BOREDOMTIME 3 * TICRATE / 2 // how long until players considered far apart? #define TRANSFERTIME TICRATE // how long to delay reaction shots? #define BREAKAWAYDIST 2000 // how *far* until players considered far apart? -#define WALKBACKDIST 600 // how close should a trailing player be before we switch? +#define WALKBACKDIST 400 // how close should a trailing player be before we switch? #define PINCHDIST 20000 // how close should the leader be to be considered "end of race"? struct directorinfo @@ -377,6 +377,12 @@ void K_UpdateDirector(void) break; } + // if this is a splitscreen player, try next pair + if (P_IsDisplayPlayer(&players[target])) + { + continue; + } + // if we're certain the back half of the pair is actually in this position, try to switch if (!players[target].kartstuff[k_positiondelay]) { From fd4833568880ea0db4d709e80aa021fda037a935 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 28 Sep 2024 01:30:14 +0200 Subject: [PATCH 066/166] Replace portalline boolean with g_portal pointer to current portal Beta --- src/r_bsp.c | 4 ++-- src/r_bsp.h | 4 +++- src/r_main.c | 20 +------------------- src/r_main.h | 21 +++++++++++++++++++++ src/r_segs.c | 2 +- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index d1ceadbf4..586aa3799 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -28,7 +28,7 @@ side_t *sidedef; line_t *linedef; sector_t *frontsector; sector_t *backsector; -boolean portalline; // is curline a portal seg? +portal_pair *g_portal; // is curline a portal seg? // very ugly realloc() of drawsegs at run-time, I upped it to 512 // instead of 256.. and someone managed to send me a level with @@ -417,7 +417,7 @@ static void R_AddLine(seg_t *line) angle_t angle1, angle2, span, tspan; static sector_t tempsec; - portalline = false; + g_portal = NULL; if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) return; diff --git a/src/r_bsp.h b/src/r_bsp.h index 2803a90e4..0d73c2bc4 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -18,12 +18,14 @@ #pragma interface #endif +#include "r_main.h" + extern seg_t *curline; extern side_t *sidedef; extern line_t *linedef; extern sector_t *frontsector; extern sector_t *backsector; -extern boolean portalline; // is curline a portal seg? +extern portal_pair *g_portal; // is curline a portal seg? // drawsegs are allocated on the fly... see r_segs.c diff --git a/src/r_main.c b/src/r_main.c index ba2c3551e..9b1787931 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -70,24 +70,6 @@ player_t *viewplayer; // You can thank and/or curse JTE for these. UINT8 portalrender; sector_t *portalcullsector; -typedef struct portal_pair -{ - INT32 line1; - INT32 line2; - UINT8 pass; - struct portal_pair *next; - - fixed_t viewx; - fixed_t viewy; - fixed_t viewz; - angle_t viewangle; - - INT32 start; - INT32 end; - INT16 *ceilingclip; - INT16 *floorclip; - fixed_t *frontscale; -} portal_pair; portal_pair *portal_base, *portal_cap; line_t *portalclipline; INT32 portalclipstart, portalclipend; @@ -1613,7 +1595,7 @@ void R_AddPortal(INT32 line1, INT32 line2, INT32 x1, INT32 x2) portal->start = x1; portal->end = x2; - portalline = true; // this tells R_StoreWallRange that curline is a portal seg + g_portal = portal; // this tells R_StoreWallRange that curline is a portal seg portal->viewx = viewx; portal->viewy = viewy; diff --git a/src/r_main.h b/src/r_main.h index 34fe686b5..8766ea65c 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -88,6 +88,27 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y); boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixed_t bottomh, fixed_t toph); void R_GetRenderBlockMapDimensions(fixed_t drawdist, INT32 *xl, INT32 *xh, INT32 *yl, INT32 *yh); + +typedef struct portal_pair +{ + INT32 line1; + INT32 line2; + UINT8 pass; + struct portal_pair *next; + + fixed_t viewx; + fixed_t viewy; + fixed_t viewz; + angle_t viewangle; + + INT32 start; + INT32 end; + INT16 *ceilingclip; + INT16 *floorclip; + fixed_t *frontscale; +} portal_pair; + + // Performance stats extern precise_t ps_prevframetime;// time when previous frame was rendered extern ps_metric_t ps_rendercalltime; diff --git a/src/r_segs.c b/src/r_segs.c index 07d217608..e89a10780 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2840,7 +2840,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) R_RenderSegLoop(); colfunc = wallcolfunc; - if (portalline) // if curline is a portal, set portalrender for drawseg + if (g_portal) // if curline is a portal, set portalrender for drawseg ds_p->portalpass = portalrender+1; else ds_p->portalpass = 0; From 4554bcc56545d52a2ab1d0d187fce4a3530ef788 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 28 Sep 2024 01:37:54 +0200 Subject: [PATCH 067/166] reset rumble on some conditions --- src/d_clisrv.c | 1 + src/d_netcmd.c | 2 ++ src/g_game.c | 4 ++++ src/g_input.c | 15 +++++++++++++++ src/g_input.h | 1 + 5 files changed, 23 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 171d61b01..cf6637edc 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3394,6 +3394,7 @@ void CL_Reset(void) curl_running = false; http_source[0] = '\0'; #endif + G_ResetAllDeviceRumbles(); // D_StartTitle should get done now, but the calling function will handle it } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a1868ce0a..c2e2c6fe1 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3228,6 +3228,8 @@ static void Got_Pause(UINT8 **cp, INT32 playernum) else S_ResumeAudio(); } + + G_ResetAllDeviceRumbles(); } static void Command_ReplayMarker(void) diff --git a/src/g_game.c b/src/g_game.c index 8311d7cbc..7906d10a9 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1600,6 +1600,8 @@ void G_DoLoadLevel(boolean resetplayer) // clear hud messages remains (usually from game startup) CON_ClearHUD(); + + G_ResetAllDeviceRumbles(); } static INT32 pausedelay = 0; @@ -3031,6 +3033,8 @@ void G_AddPlayer(INT32 playernum) void G_ExitLevel(void) { + G_ResetAllDeviceRumbles(); + if (gamestate == GS_LEVEL) { gameaction = ga_completed; diff --git a/src/g_input.c b/src/g_input.c index a4046350d..ad7758a7a 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -1013,6 +1013,21 @@ static void G_ResetPlayerDeviceRumble(INT32 player) I_GamepadRumble(device_id, 0, 0, 0); } +void G_ResetAllDeviceRumbles(void) +{ + int i; + int devices; + + devices = I_NumJoys(); + + for (i = 0; i < devices; i++) + { + INT32 device_id = G_GetDeviceForPlayer(i); + + I_GamepadRumble(device_id, 0, 0, 0); + } +} + void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength, UINT32 duration) { INT32 device_id; diff --git a/src/g_input.h b/src/g_input.h index 6799f6ca0..18fff51a4 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -138,6 +138,7 @@ UINT16 G_GetSkinColor(INT32 player); INT32 G_GetDeviceForPlayer(INT32 player); void G_SetPlayerGamepadIndicatorColor(INT32 player, UINT16 color); void G_PlayerDeviceRumble(INT32 player, UINT16 low_strength, UINT16 high_strength, UINT32 duration); +void G_ResetAllDeviceRumbles(void); // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); From 564838a4393e1d3fc2d2bc04fbc1f94013db157c Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Sep 2024 15:15:49 +0200 Subject: [PATCH 068/166] only draw lua hud stuff when patch exists --- src/lua_hudlib_drawlist.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 2ee9b8156..1cef45a87 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -632,12 +632,18 @@ void LUA_HUD_DrawList(huddrawlist_h list) switch (item->type) { case DI_Draw: + if (!item->patch || item->patch == NULL) + return; V_DrawFixedPatch(LERPS(x), LERPS(y), FRACUNIT, item->flags, item->patch, item->colormap); break; case DI_DrawScaled: + if (!item->patch || item->patch == NULL) + return; V_DrawFixedPatch(LERPS(x), LERPS(y), LERP(scale), item->flags, item->patch, item->colormap); break; case DI_DrawStretched: + if (!item->patch || item->patch == NULL) + return; V_DrawStretchyFixedPatch(LERPS(x), LERPS(y), LERP(hscale), LERP(vscale), item->flags, item->patch, item->colormap); break; case DI_DrawNum: From cadb67e6c909f25b7797114232e7fbcb8f5450dc Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Sep 2024 15:14:43 +0200 Subject: [PATCH 069/166] move this stuff so dont need check for renderisnewtic multiple times and dont need to check for menu and dpad stuff every single frame --- src/d_main.c | 72 ++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index e0d427b01..9ca370c2a 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -780,6 +780,37 @@ void D_SRB2Loop(void) doDisplay = true; } + +#define DPADSCROLLINPUT(INPUT)\ + {\ + myev.data1 = INPUT;\ + M_Responder(&myev);\ + } + // this is absolutely awful and i hate it lmao + if (menuactive && (DPADUPSCROLL || DPADDOWNSCROLL || DPADLEFTSCROLL || DPADRIGHTSCROLL)) + { + event_t myev; + myev.type = ev_keydown; + + menuInputDelayTimer++; + + 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 (DPADUPSCROLL) + DPADSCROLLINPUT(KEY_UPARROW) + else if (DPADDOWNSCROLL) + DPADSCROLLINPUT(KEY_DOWNARROW) + else if (DPADLEFTSCROLL) + DPADSCROLLINPUT(KEY_LEFTARROW) + else if (DPADRIGHTSCROLL) + DPADSCROLLINPUT(KEY_RIGHTARROW) + } + } + else + menuInputDelayTimer = 0; +#undef DPADSCROLLINPUT + + D_DeviceLEDTick(); } if (interp) @@ -828,47 +859,6 @@ void D_SRB2Loop(void) } #endif - // this is absolutely awful and i hate it lmao - if (menuactive && (DPADUPSCROLL || DPADDOWNSCROLL || DPADLEFTSCROLL || DPADRIGHTSCROLL)) - { - event_t myev; - myev.type = ev_keydown; - - if (renderisnewtic) - { - menuInputDelayTimer++; - - 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 (DPADUPSCROLL) - { - myev.data1 = KEY_UPARROW; - M_Responder(&myev); - } - else if (DPADDOWNSCROLL) - { - myev.data1 = KEY_DOWNARROW; - M_Responder(&myev); - } - else if (DPADLEFTSCROLL) - { - myev.data1 = KEY_LEFTARROW; - M_Responder(&myev); - } - else if (DPADRIGHTSCROLL) - { - myev.data1 = KEY_RIGHTARROW; - M_Responder(&myev); - } - } - } - } - else - menuInputDelayTimer = 0; - - if (renderisnewtic) // idk does this need dedi check?? - D_DeviceLEDTick(); - // Fully completed frame made. finishprecise = I_GetPreciseTime(); From d7b0726e424f70dc54c461f066563fe8d7b73434 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Sep 2024 21:51:31 +0200 Subject: [PATCH 070/166] no need to even traverse part of the blockmap when PRECIP_STORM_NORAIN and PRECIP_BLANK --- src/hardware/hw_main.c | 2 +- src/r_things.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 30c6f7454..db9846c07 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4601,7 +4601,7 @@ static void HWR_AddPrecipitationSprites(void) drawdist = (fixed_t)(cv_drawdist_precip.value) * precipscale; // No to infinite precipitation draw distance. - if (drawdist == 0) + if (drawdist == 0 || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) { return; } diff --git a/src/r_things.c b/src/r_things.c index 84d73d2a5..31c3dcbe4 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1987,7 +1987,7 @@ void R_AddPrecipitationSprites(void) precipmobj_t *th, *next; // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off - if (drawdist == 0) + if (drawdist == 0 || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) { return; } From 913426bfdbddd0bed7cf3d85c7a1ed11f1d6e3ab Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 29 Sep 2024 22:26:49 +0200 Subject: [PATCH 071/166] let SOC also use PRECIP_BLANK/ weather = 4 no idea why it couldnt doesent make any sense --- src/p_mobj.c | 6 ++---- src/p_spec.c | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 91cf6f388..3e94b3ec4 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10237,6 +10237,7 @@ void P_SpawnPrecipitation(void) // Not in a sector with visible sky? if (precipsector->sector->ceilingpic != skyflatnum) continue; + // Exists, but is too small for reasonable precipitation. if (!(precipsector->sector->floorheight <= precipsector->sector->ceilingheight - (32<>(FRACBITS+2)); } - if (volume < 0) - volume = 0; - else if (volume > 255) - volume = 255; + volume = CLAMP(volume, 0, 255); if (sounds_rain && (!leveltime || leveltime % 80 == 1)) S_StartSoundAtVolume(players[displayplayers[0]].mo, sfx_rainin, volume); diff --git a/src/p_spec.c b/src/p_spec.c index 133176db6..7066058fa 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5308,6 +5308,8 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) curWeather = PRECIP_STORM_NORAIN; else if (mapheaderinfo[gamemap-1]->weather == 6) // storm w/o lightning curWeather = PRECIP_STORM_NOSTRIKES; + else if (mapheaderinfo[gamemap-1]->weather == 4) // blank + curWeather = PRECIP_BLANK; else curWeather = PRECIP_NONE; From e1a65add5d86798fe4c506fe249e141e38491c6e Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 30 Sep 2024 10:35:27 +0300 Subject: [PATCH 072/166] Put all text input logic into separate file and use it for all text input fields --- src/Android.mk | 1 + src/CMakeLists.txt | 1104 ++++++++++++++++++++++---------------------- src/Makefile | 1 + src/console.c | 395 ++-------------- src/lua_script.c | 9 +- src/m_menu.c | 295 ++++++------ src/m_menu.h | 4 + src/m_textinput.c | 306 ++++++++++++ src/m_textinput.h | 23 + src/v_video.c | 29 +- src/v_video.h | 9 +- 11 files changed, 1108 insertions(+), 1068 deletions(-) create mode 100644 src/m_textinput.c create mode 100644 src/m_textinput.h diff --git a/src/Android.mk b/src/Android.mk index 035d48887..1d0603e6f 100644 --- a/src/Android.mk +++ b/src/Android.mk @@ -28,6 +28,7 @@ LOCAL_SRC_FILES := am_map.c \ m_cheat.c \ m_fixed.c \ m_menu.c \ + m_textinput.c \ m_misc.c \ m_queue.c \ m_random.c \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 258ff882c..adce10023 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,551 +1,553 @@ -# SRB2 Core - -# Core sources -set(SRB2_CORE_SOURCES - am_map.c - b_bot.c - command.c - comptime.c - console.c - d_clisrv.c - d_main.c - d_net.c - d_netcmd.c - d_netfil.c - d_protocol.c - dehacked.c - f_finale.c - f_wipe.c - filesrch.c - g_game.c - g_input.c - hu_stuff.c - i_tcp.c - info.c - lzf.c - m_aatree.c - m_anigif.c - m_argv.c - m_bbox.c - m_cheat.c - m_cond.c - m_fixed.c - m_menu.c - m_misc.c - m_perfstats.c - m_queue.c - m_random.c - md5.c - mserv.c - http-mserv.c - qs22j.c - s_sound.c - screen.c - sounds.c - st_stuff.c - #string.c - tables.c - v_video.c - w_wad.c - y_inter.c - z_zone.c -) - -set(SRB2_CORE_HEADERS - am_map.h - b_bot.h - byteptr.h - command.h - console.h - d_clisrv.h - d_event.h - d_main.h - d_net.h - d_netcmd.h - d_netfil.h - d_player.h - d_protocol.h - d_think.h - d_ticcmd.h - dehacked.h - doomdata.h - doomdef.h - doomstat.h - doomtype.h - endian.h - f_finale.h - fastcmp.h - filesrch.h - g_game.h - g_input.h - g_state.h - hu_stuff.h - i_joy.h - i_net.h - i_sound.h - i_system.h - i_tcp.h - i_time.h - i_video.h - info.h - keys.h - lzf.h - m_aatree.h - m_anigif.h - m_argv.h - m_bbox.h - m_cheat.h - m_cond.h - m_dllist.h - m_fixed.h - m_menu.h - m_misc.h - m_queue.h - m_perfstats.h - m_random.h - m_swap.h - md5.h - mserv.h - qs22j.h - s_sound.h - screen.h - sounds.h - st_stuff.h - tables.h - v_video.h - w_wad.h - y_inter.h - z_zone.h - - config.h.in -) - -set(SRB2_CORE_RENDER_SOURCES - r_bsp.c - r_data.c - r_draw.c - r_fps.c - r_main.c - r_patch.c - r_plane.c - r_segs.c - r_sky.c - r_splats.c - r_things.c - - r_bsp.h - r_data.h - r_defs.h - r_draw.h - r_fps.h - r_local.h - r_main.h - r_patch - r_plane.h - r_segs.h - r_sky.h - r_splats.h - r_state.h - r_things.h -) - -set(SRB2_CORE_GAME_SOURCES - p_ceilng.c - p_enemy.c - p_floor.c - p_inter.c - p_lights.c - p_map.c - p_maputl.c - p_mobj.c - p_polyobj.c - p_saveg.c - p_setup.c - p_sight.c - p_slopes.c - p_spec.c - p_telept.c - p_tick.c - p_user.c - k_director.c - k_kart.c - i_time.c - - p_local.h - p_maputl.h - p_mobj.h - p_polyobj.h - p_pspr.h - p_saveg.h - p_setup.h - p_slopes.h - p_spec.h - p_tick.h - k_director.h - k_kart.h -) - -if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - set(SRB2_CORE_SOURCES ${SRB2_CORE_SOURCES} string.c) -endif() - -prepend_sources(SRB2_CORE_SOURCES) -prepend_sources(SRB2_CORE_HEADERS) -prepend_sources(SRB2_CORE_RENDER_SOURCES) -prepend_sources(SRB2_CORE_GAME_SOURCES) - -set(SRB2_CORE_HEADERS ${SRB2_CORE_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/config.h) -source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) -source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES}) -source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES}) - -### Configuration -set(SRB2_CONFIG_HAVE_BLUA ON CACHE BOOL - "Enable Lua interpreter support") -set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL - "Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.") -set(SRB2_CONFIG_HAVE_ZLIB ON CACHE BOOL - "Enable zlib support.") -set(SRB2_CONFIG_HAVE_GME ON CACHE BOOL - "Enable GME support.") -set(SRB2_CONFIG_HAVE_OPENMPT ON CACHE BOOL - "Enable OpenMPT support.") -set(SRB2_CONFIG_HAVE_DISCORDRPC OFF CACHE BOOL - "Enable Discord rich presence support.") -set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL - "Enable curl support, used for downloading files via HTTP.") -set(SRB2_CONFIG_HWRENDER ON CACHE BOOL - "Enable hardware rendering through OpenGL.") -set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL - "Use statically linked OpenGL. NOT RECOMMENDED.") -set(SRB2_CONFIG_USE_FBO_OGL ON CACHE BOOL - "Enable OpenGL FBO Downsampling support.") - -### use internal libraries? -if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only - set(SRB2_CONFIG_USE_INTERNAL_LIBRARIES OFF CACHE BOOL - "Use SRB2Kart's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).") -endif() - -if(${SRB2_CONFIG_HAVE_BLUA}) - add_definitions(-DHAVE_BLUA) - set(SRB2_LUA_SOURCES - lua_baselib.c - lua_blockmaplib.c - lua_consolelib.c - lua_hooklib.c - lua_hudlib.c - lua_hudlib_drawlist.c - lua_infolib.c - lua_maplib.c - lua_mathlib.c - lua_mobjlib.c - lua_playerlib.c - lua_script.c - lua_skinlib.c - lua_thinkerlib.c - lua_udatalib.c - lua_glib.c - ) - set(SRB2_LUA_HEADERS - lua_hook.h - lua_hud.h - lua_hudlib_drawlist.h - lua_libs.h - lua_script.h - lua_udatalib.h - lua_glib.h - ) - - prepend_sources(SRB2_LUA_SOURCES) - prepend_sources(SRB2_LUA_HEADERS) - - source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS}) - - set(SRB2_BLUA_SOURCES - blua/lapi.c - blua/lauxlib.c - blua/lbaselib.c - blua/ldblib.c - blua/lcode.c - blua/ldebug.c - blua/ldo.c - blua/ldump.c - blua/lfunc.c - blua/lgc.c - blua/linit.c - blua/liolib.c - blua/llex.c - blua/lmem.c - blua/lobject.c - blua/lopcodes.c - blua/lparser.c - blua/lstate.c - blua/lstring.c - blua/lstrlib.c - blua/ltable.c - blua/ltablib.c - blua/ltm.c - blua/lundump.c - blua/lvm.c - blua/lzio.c - ) - set(SRB2_BLUA_HEADERS - blua/lapi.h - blua/lauxlib.h - blua/lcode.h - blua/ldebug.h - blua/ldo.h - blua/lfunc.h - blua/lgc.h - blua/llex.h - blua/llimits.h - blua/lmem.h - blua/lobject.h - blua/lopcodes.h - blua/lparser.h - blua/lstate.h - blua/lstring.h - blua/ltable.h - blua/ltm.h - blua/lua.h - blua/luaconf.h - blua/lualib.h - blua/lundump.h - blua/lvm.h - blua/lzio.h - ) - - prepend_sources(SRB2_BLUA_SOURCES) - prepend_sources(SRB2_BLUA_HEADERS) - - source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS}) -endif() - -if(${SRB2_CONFIG_HAVE_GME}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(GME_FOUND ON) - set(GME_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/gme/include) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win64 -lgme") - else() # 32-bit - set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win32 -lgme") - endif() - else() - find_package(GME) - endif() - if(${GME_FOUND}) - set(SRB2_HAVE_GME ON) - add_definitions(-DHAVE_LIBGME) - else() - message(WARNING "You have specified that GME is available but it was not found.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_DISCORDRPC}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(DISCORDRPC_FOUND ON) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/include) - set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/lib -ldiscord-rpc") - else() # 32-bit - set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/include) - set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/lib -ldiscord-rpc") - endif() - else() - find_package(DiscordRPC) - endif() - if(${DISCORDRPC_FOUND}) - set(SRB2_HAVE_DISCORDRPC ON) - add_definitions(-DHAVE_DISCORDRPC) - add_definitions(-DUSE_STUN) - set(SRB2_DISCORDRPC_SOURCES discord.c stun.c) - set(SRB2_DISCORDRPC_HEADERS discord.h stun.h) - prepend_sources(SRB2_DISCORDRPC_SOURCES) - prepend_sources(SRB2_DISCORDRPC_HEADERS) - source_group("Discord Rich Presence" FILES ${SRB2_DISCORDRPC_SOURCES} ${SRB2_DISCORDRPC_HEADERS}) - else() - message(WARNING "You have specified that Discord Rich Presence is available but it was not found.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_OPENMPT}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(OPENMPT_FOUND ON) - set(OPENMPT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/inc) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86_64/mingw -lopenmpt") - else() # 32-bit - set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86/mingw -lopenmpt") - endif() - else() - find_package(OPENMPT) - endif() - if(${OPENMPT_FOUND}) - set(SRB2_HAVE_OPENMPT ON) - add_definitions(-DHAVE_OPENMPT) - else() - message(WARNING "You have specified that OpenMPT is available but it was not found.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_ZLIB}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(ZLIB_FOUND ON) - set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/zlib) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz64") - else() # 32-bit - set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz32") - endif() - else() - find_package(ZLIB) - endif() - if(${ZLIB_FOUND}) - set(SRB2_HAVE_ZLIB ON) - add_definitions(-DHAVE_ZLIB) - else() - message(WARNING "You have specified that ZLIB is available but it was not found. SRB2Kart may not compile correctly.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) - if (${ZLIB_FOUND}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(PNG_FOUND ON) - set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libpng-src) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng64") - else() # 32-bit - set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng32") - endif() - else() - find_package(PNG) - endif() - if(${PNG_FOUND}) - set(SRB2_HAVE_PNG ON) - add_definitions(-DHAVE_PNG) - add_definitions(-D_LARGEFILE64_SOURCE) - set(SRB2_PNG_SOURCES apng.c) - set(SRB2_PNG_HEADERS apng.h) - prepend_sources(SRB2_PNG_SOURCES) - prepend_sources(SRB2_PNG_HEADERS) - source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS} - ${SRB2_PNG_SOURCES} ${SRB2_PNG_HEADERS}) - else() - message(WARNING "You have specified that PNG is available but it was not found. SRB2Kart may not compile correctly.") - endif() - endif() -endif() - -if(${SRB2_CONFIG_HAVE_CURL}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(CURL_FOUND ON) - set(CURL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/curl/include) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib64 -lcurl") - else() # 32-bit - set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib32 -lcurl") - endif() - else() - find_package(CURL) - endif() - if(${CURL_FOUND}) - set(SRB2_HAVE_CURL ON) - add_definitions(-DHAVE_CURL) - else() - message(WARNING "You have specified that CURL is available but it was not found. SRB2Kart may not compile correctly.") - endif() -endif() - -if(${SRB2_CONFIG_HWRENDER}) - add_definitions(-DHWRENDER) - set(SRB2_HWRENDER_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.c - ) - - set (SRB2_HWRENDER_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_drv.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.h - ) - - set(SRB2_R_OPENGL_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.c - ) - - set(SRB2_R_OPENGL_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.h - ) - -endif() - -if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) - find_package(OpenGL) - if(${OPENGL_FOUND}) - add_definitions(-DHWRENDER) - add_definitions(-DSTATIC_OPENGL) - else() - message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") - endif() -endif() - -if(${SRB2_CONFIG_HWRENDER}) - if(${SRB2_CONFIG_USE_FBO_OGL}) - set(SRB2_USE_FBO_OGL ON) - add_definitions(-DUSE_FBO_OGL) - endif() -endif() - -# Targets - -# Compatibility flag with later versions of GCC -# We should really fix our code to not need this -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) -endif() - -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) -endif() - -add_definitions(-DCMAKECONFIG) - -#add_library(SRB2Core STATIC -# ${SRB2_CORE_SOURCES} -# ${SRB2_CORE_HEADERS} -# ${SRB2_CORE_RENDER_SOURCES} -# ${SRB2_CORE_GAME_SOURCES} -# ${SRB2_LUA_SOURCES} -# ${SRB2_LUA_HEADERS} -# ${SRB2_BLUA_SOURCES} -# ${SRB2_BLUA_HEADERS} -#) - -add_subdirectory(sdl) - -if(NOT ${SRB2_SDL2_AVAILABLE} AND NOT ${SRB2_WIN32_AVAILABLE}) - message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") -endif() +# SRB2 Core + +# Core sources +set(SRB2_CORE_SOURCES + am_map.c + b_bot.c + command.c + comptime.c + console.c + d_clisrv.c + d_main.c + d_net.c + d_netcmd.c + d_netfil.c + d_protocol.c + dehacked.c + f_finale.c + f_wipe.c + filesrch.c + g_game.c + g_input.c + hu_stuff.c + i_tcp.c + info.c + lzf.c + m_aatree.c + m_anigif.c + m_argv.c + m_bbox.c + m_cheat.c + m_cond.c + m_fixed.c + m_menu.c + m_textinput.c + m_misc.c + m_perfstats.c + m_queue.c + m_random.c + md5.c + mserv.c + http-mserv.c + qs22j.c + s_sound.c + screen.c + sounds.c + st_stuff.c + #string.c + tables.c + v_video.c + w_wad.c + y_inter.c + z_zone.c +) + +set(SRB2_CORE_HEADERS + am_map.h + b_bot.h + byteptr.h + command.h + console.h + d_clisrv.h + d_event.h + d_main.h + d_net.h + d_netcmd.h + d_netfil.h + d_player.h + d_protocol.h + d_think.h + d_ticcmd.h + dehacked.h + doomdata.h + doomdef.h + doomstat.h + doomtype.h + endian.h + f_finale.h + fastcmp.h + filesrch.h + g_game.h + g_input.h + g_state.h + hu_stuff.h + i_joy.h + i_net.h + i_sound.h + i_system.h + i_tcp.h + i_time.h + i_video.h + info.h + keys.h + lzf.h + m_aatree.h + m_anigif.h + m_argv.h + m_bbox.h + m_cheat.h + m_cond.h + m_dllist.h + m_fixed.h + m_menu.h + m_textinput.h + m_misc.h + m_queue.h + m_perfstats.h + m_random.h + m_swap.h + md5.h + mserv.h + qs22j.h + s_sound.h + screen.h + sounds.h + st_stuff.h + tables.h + v_video.h + w_wad.h + y_inter.h + z_zone.h + + config.h.in +) + +set(SRB2_CORE_RENDER_SOURCES + r_bsp.c + r_data.c + r_draw.c + r_fps.c + r_main.c + r_patch.c + r_plane.c + r_segs.c + r_sky.c + r_splats.c + r_things.c + + r_bsp.h + r_data.h + r_defs.h + r_draw.h + r_fps.h + r_local.h + r_main.h + r_patch + r_plane.h + r_segs.h + r_sky.h + r_splats.h + r_state.h + r_things.h +) + +set(SRB2_CORE_GAME_SOURCES + p_ceilng.c + p_enemy.c + p_floor.c + p_inter.c + p_lights.c + p_map.c + p_maputl.c + p_mobj.c + p_polyobj.c + p_saveg.c + p_setup.c + p_sight.c + p_slopes.c + p_spec.c + p_telept.c + p_tick.c + p_user.c + k_director.c + k_kart.c + i_time.c + + p_local.h + p_maputl.h + p_mobj.h + p_polyobj.h + p_pspr.h + p_saveg.h + p_setup.h + p_slopes.h + p_spec.h + p_tick.h + k_director.h + k_kart.h +) + +if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + set(SRB2_CORE_SOURCES ${SRB2_CORE_SOURCES} string.c) +endif() + +prepend_sources(SRB2_CORE_SOURCES) +prepend_sources(SRB2_CORE_HEADERS) +prepend_sources(SRB2_CORE_RENDER_SOURCES) +prepend_sources(SRB2_CORE_GAME_SOURCES) + +set(SRB2_CORE_HEADERS ${SRB2_CORE_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/config.h) +source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) +source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES}) +source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES}) + +### Configuration +set(SRB2_CONFIG_HAVE_BLUA ON CACHE BOOL + "Enable Lua interpreter support") +set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL + "Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.") +set(SRB2_CONFIG_HAVE_ZLIB ON CACHE BOOL + "Enable zlib support.") +set(SRB2_CONFIG_HAVE_GME ON CACHE BOOL + "Enable GME support.") +set(SRB2_CONFIG_HAVE_OPENMPT ON CACHE BOOL + "Enable OpenMPT support.") +set(SRB2_CONFIG_HAVE_DISCORDRPC OFF CACHE BOOL + "Enable Discord rich presence support.") +set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL + "Enable curl support, used for downloading files via HTTP.") +set(SRB2_CONFIG_HWRENDER ON CACHE BOOL + "Enable hardware rendering through OpenGL.") +set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL + "Use statically linked OpenGL. NOT RECOMMENDED.") +set(SRB2_CONFIG_USE_FBO_OGL ON CACHE BOOL + "Enable OpenGL FBO Downsampling support.") + +### use internal libraries? +if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only + set(SRB2_CONFIG_USE_INTERNAL_LIBRARIES OFF CACHE BOOL + "Use SRB2Kart's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).") +endif() + +if(${SRB2_CONFIG_HAVE_BLUA}) + add_definitions(-DHAVE_BLUA) + set(SRB2_LUA_SOURCES + lua_baselib.c + lua_blockmaplib.c + lua_consolelib.c + lua_hooklib.c + lua_hudlib.c + lua_hudlib_drawlist.c + lua_infolib.c + lua_maplib.c + lua_mathlib.c + lua_mobjlib.c + lua_playerlib.c + lua_script.c + lua_skinlib.c + lua_thinkerlib.c + lua_udatalib.c + lua_glib.c + ) + set(SRB2_LUA_HEADERS + lua_hook.h + lua_hud.h + lua_hudlib_drawlist.h + lua_libs.h + lua_script.h + lua_udatalib.h + lua_glib.h + ) + + prepend_sources(SRB2_LUA_SOURCES) + prepend_sources(SRB2_LUA_HEADERS) + + source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS}) + + set(SRB2_BLUA_SOURCES + blua/lapi.c + blua/lauxlib.c + blua/lbaselib.c + blua/ldblib.c + blua/lcode.c + blua/ldebug.c + blua/ldo.c + blua/ldump.c + blua/lfunc.c + blua/lgc.c + blua/linit.c + blua/liolib.c + blua/llex.c + blua/lmem.c + blua/lobject.c + blua/lopcodes.c + blua/lparser.c + blua/lstate.c + blua/lstring.c + blua/lstrlib.c + blua/ltable.c + blua/ltablib.c + blua/ltm.c + blua/lundump.c + blua/lvm.c + blua/lzio.c + ) + set(SRB2_BLUA_HEADERS + blua/lapi.h + blua/lauxlib.h + blua/lcode.h + blua/ldebug.h + blua/ldo.h + blua/lfunc.h + blua/lgc.h + blua/llex.h + blua/llimits.h + blua/lmem.h + blua/lobject.h + blua/lopcodes.h + blua/lparser.h + blua/lstate.h + blua/lstring.h + blua/ltable.h + blua/ltm.h + blua/lua.h + blua/luaconf.h + blua/lualib.h + blua/lundump.h + blua/lvm.h + blua/lzio.h + ) + + prepend_sources(SRB2_BLUA_SOURCES) + prepend_sources(SRB2_BLUA_HEADERS) + + source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS}) +endif() + +if(${SRB2_CONFIG_HAVE_GME}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(GME_FOUND ON) + set(GME_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/gme/include) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win64 -lgme") + else() # 32-bit + set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win32 -lgme") + endif() + else() + find_package(GME) + endif() + if(${GME_FOUND}) + set(SRB2_HAVE_GME ON) + add_definitions(-DHAVE_LIBGME) + else() + message(WARNING "You have specified that GME is available but it was not found.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_DISCORDRPC}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(DISCORDRPC_FOUND ON) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/include) + set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/lib -ldiscord-rpc") + else() # 32-bit + set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/include) + set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/lib -ldiscord-rpc") + endif() + else() + find_package(DiscordRPC) + endif() + if(${DISCORDRPC_FOUND}) + set(SRB2_HAVE_DISCORDRPC ON) + add_definitions(-DHAVE_DISCORDRPC) + add_definitions(-DUSE_STUN) + set(SRB2_DISCORDRPC_SOURCES discord.c stun.c) + set(SRB2_DISCORDRPC_HEADERS discord.h stun.h) + prepend_sources(SRB2_DISCORDRPC_SOURCES) + prepend_sources(SRB2_DISCORDRPC_HEADERS) + source_group("Discord Rich Presence" FILES ${SRB2_DISCORDRPC_SOURCES} ${SRB2_DISCORDRPC_HEADERS}) + else() + message(WARNING "You have specified that Discord Rich Presence is available but it was not found.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_OPENMPT}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(OPENMPT_FOUND ON) + set(OPENMPT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/inc) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86_64/mingw -lopenmpt") + else() # 32-bit + set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86/mingw -lopenmpt") + endif() + else() + find_package(OPENMPT) + endif() + if(${OPENMPT_FOUND}) + set(SRB2_HAVE_OPENMPT ON) + add_definitions(-DHAVE_OPENMPT) + else() + message(WARNING "You have specified that OpenMPT is available but it was not found.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_ZLIB}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(ZLIB_FOUND ON) + set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/zlib) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz64") + else() # 32-bit + set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz32") + endif() + else() + find_package(ZLIB) + endif() + if(${ZLIB_FOUND}) + set(SRB2_HAVE_ZLIB ON) + add_definitions(-DHAVE_ZLIB) + else() + message(WARNING "You have specified that ZLIB is available but it was not found. SRB2Kart may not compile correctly.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) + if (${ZLIB_FOUND}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(PNG_FOUND ON) + set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libpng-src) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng64") + else() # 32-bit + set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng32") + endif() + else() + find_package(PNG) + endif() + if(${PNG_FOUND}) + set(SRB2_HAVE_PNG ON) + add_definitions(-DHAVE_PNG) + add_definitions(-D_LARGEFILE64_SOURCE) + set(SRB2_PNG_SOURCES apng.c) + set(SRB2_PNG_HEADERS apng.h) + prepend_sources(SRB2_PNG_SOURCES) + prepend_sources(SRB2_PNG_HEADERS) + source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS} + ${SRB2_PNG_SOURCES} ${SRB2_PNG_HEADERS}) + else() + message(WARNING "You have specified that PNG is available but it was not found. SRB2Kart may not compile correctly.") + endif() + endif() +endif() + +if(${SRB2_CONFIG_HAVE_CURL}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(CURL_FOUND ON) + set(CURL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/curl/include) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib64 -lcurl") + else() # 32-bit + set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib32 -lcurl") + endif() + else() + find_package(CURL) + endif() + if(${CURL_FOUND}) + set(SRB2_HAVE_CURL ON) + add_definitions(-DHAVE_CURL) + else() + message(WARNING "You have specified that CURL is available but it was not found. SRB2Kart may not compile correctly.") + endif() +endif() + +if(${SRB2_CONFIG_HWRENDER}) + add_definitions(-DHWRENDER) + set(SRB2_HWRENDER_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.c + ) + + set (SRB2_HWRENDER_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_drv.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.h + ) + + set(SRB2_R_OPENGL_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.c + ) + + set(SRB2_R_OPENGL_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.h + ) + +endif() + +if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) + find_package(OpenGL) + if(${OPENGL_FOUND}) + add_definitions(-DHWRENDER) + add_definitions(-DSTATIC_OPENGL) + else() + message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") + endif() +endif() + +if(${SRB2_CONFIG_HWRENDER}) + if(${SRB2_CONFIG_USE_FBO_OGL}) + set(SRB2_USE_FBO_OGL ON) + add_definitions(-DUSE_FBO_OGL) + endif() +endif() + +# Targets + +# Compatibility flag with later versions of GCC +# We should really fix our code to not need this +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) +endif() + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) +endif() + +add_definitions(-DCMAKECONFIG) + +#add_library(SRB2Core STATIC +# ${SRB2_CORE_SOURCES} +# ${SRB2_CORE_HEADERS} +# ${SRB2_CORE_RENDER_SOURCES} +# ${SRB2_CORE_GAME_SOURCES} +# ${SRB2_LUA_SOURCES} +# ${SRB2_LUA_HEADERS} +# ${SRB2_BLUA_SOURCES} +# ${SRB2_BLUA_HEADERS} +#) + +add_subdirectory(sdl) + +if(NOT ${SRB2_SDL2_AVAILABLE} AND NOT ${SRB2_WIN32_AVAILABLE}) + message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") +endif() diff --git a/src/Makefile b/src/Makefile index 4668518b9..e7fb4d60b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -529,6 +529,7 @@ OBJS:=$(i_main_o) \ $(OBJDIR)/m_fixed.o \ $(OBJDIR)/m_menu.o \ $(OBJDIR)/m_misc.o \ + $(OBJDIR)/m_textinput.o \ $(OBJDIR)/m_perfstats.o \ $(OBJDIR)/m_random.o \ $(OBJDIR)/m_queue.o \ diff --git a/src/console.c b/src/console.c index 5c2e04eb3..dbeb2b42b 100644 --- a/src/console.c +++ b/src/console.c @@ -32,6 +32,7 @@ #include "i_threads.h" #include "d_main.h" #include "m_menu.h" +#include "m_textinput.h" #include "filesrch.h" #ifdef HWRENDER @@ -97,9 +98,7 @@ static char inputlines[32][CON_MAXPROMPTCHARS]; // hold last 32 prompt lines static INT32 inputline; // current input line number static INT32 inputhist; // line number of history input line to restore -static size_t input_cur; // position of cursor in line -static size_t input_sel; // position of selection marker (I.E.: anything between this and input_cur is "selected") -static size_t input_len; // length of current line, used to bound cursor and such +static textinput_t input; // notice: input does NOT include the "$" at the start of the line. - 11/3/16 // protos. @@ -458,7 +457,8 @@ static void CON_InputInit(void) // prepare the first prompt line memset(inputlines, 0, sizeof (inputlines)); inputline = 0; - input_cur = input_sel = input_len = 0; + + M_TextInputInit(&input, inputlines[inputline], CON_MAXPROMPTCHARS); Unlock_state(); } @@ -802,178 +802,6 @@ void CON_Ticker(void) Unlock_state(); } -// -// ---- -// -// Shortcuts for adding and deleting characters, strings, and sections -// Necessary due to moving cursor -// - -static void CON_InputClear(void) -{ - Lock_state(); - - memset(inputlines[inputline], 0, CON_MAXPROMPTCHARS); - input_cur = input_sel = input_len = 0; - - Unlock_state(); -} - -static void CON_InputSetString(const char *c) -{ - Lock_state(); - - memset(inputlines[inputline], 0, CON_MAXPROMPTCHARS); - strcpy(inputlines[inputline], c); - input_cur = input_sel = input_len = strlen(c); - - Unlock_state(); -} - -static void CON_InputAddString(const char *c) -{ - size_t csize = strlen(c); - - Lock_state(); - - if (input_len + csize > CON_MAXPROMPTCHARS-1) - { - Unlock_state(); - return; - } - if (input_cur != input_len) - memmove(&inputlines[inputline][input_cur+csize], &inputlines[inputline][input_cur], input_len-input_cur); - memcpy(&inputlines[inputline][input_cur], c, csize); - input_len += csize; - input_sel = (input_cur += csize); - - Unlock_state(); -} - -static void CON_InputDel(size_t start, size_t end) -{ - size_t len; - - Lock_state(); - - len = (end - start); - - if (end != input_len) - memmove(&inputlines[inputline][start], &inputlines[inputline][end], input_len-end); - memset(&inputlines[inputline][input_len - len], 0, len); - - input_len -= len; - - if (input_sel >= end) - input_sel -= len; - else if (input_sel > start) - input_sel = start; - - if (input_cur >= end) - input_cur -= len; - else if (input_cur > start) - input_cur = start; - - Unlock_state(); -} - -static void CON_InputDelSelection(void) -{ - size_t start, end; - - Lock_state(); - - if (input_cur > input_sel) - { - start = input_sel; - end = input_cur; - } - else - { - start = input_cur; - end = input_sel; - } - - CON_InputDel(start, end); - - input_sel = input_cur = start; - - Unlock_state(); -} - -static void CON_ToWordEnd(boolean move_sel) -{ - Lock_state(); - - // Skip spaces - while (input_cur < input_len && isspace(inputlines[inputline][input_cur])) - ++input_cur; - - // Skip word - while (input_cur < input_len && !isspace(inputlines[inputline][input_cur])) - ++input_cur; - - if (move_sel) input_sel = input_cur; - - Unlock_state(); -} - -static void CON_ToWordBegin(boolean move_sel) -{ - Lock_state(); - - // Hack, always move back 1 character if possible so if we press ctrl-left at a word beginning - // we move to previous word - if (input_cur) --input_cur; - - // Skip spaces - while (input_cur && isspace(inputlines[inputline][input_cur])) - --input_cur; - - // Skip word - while (input_cur && !isspace(inputlines[inputline][input_cur])) - --input_cur; - - // Unless we reached beginning of line, we're pointing at a space before word, so move cursor - // forward to fix that - if (input_cur) ++input_cur; - - if (move_sel) input_sel = input_cur; - - Unlock_state(); -} - -static void CON_InputAddChar(char c) -{ - if (input_len >= CON_MAXPROMPTCHARS-1) - return; - - Lock_state(); - - if (input_cur != input_len) - memmove(&inputlines[inputline][input_cur+1], &inputlines[inputline][input_cur], input_len-input_cur); - inputlines[inputline][input_cur++] = c; - inputlines[inputline][++input_len] = 0; - input_sel = input_cur; - - Unlock_state(); -} - -static void CON_InputDelChar(void) -{ - if (!input_cur) - return; - - Lock_state(); - - if (input_cur != input_len) - memmove(&inputlines[inputline][input_cur-1], &inputlines[inputline][input_cur], input_len-input_cur); - inputlines[inputline][--input_len] = 0; - input_sel = --input_cur; - - Unlock_state(); -} - // // ---- // @@ -1054,6 +882,10 @@ boolean CON_Responder(event_t *ev) } } + Lock_state(); + M_TextInputHandle(&input, key); + Unlock_state(); + // Always eat ctrl/shift/alt if console open, so the menu doesn't get ideas if (key == KEY_LSHIFT || key == KEY_RSHIFT || key == KEY_LCTRL || key == KEY_RCTRL @@ -1069,9 +901,9 @@ boolean CON_Responder(event_t *ev) if (!completion[0]) { - if (!input_len || input_len >= 40 || strchr(inputlines[inputline], ' ')) + if (!input.length || input.length >= 40 || strchr(input.buffer, ' ')) return true; - strcpy(completion, inputlines[inputline]); + strcpy(completion, input.buffer); comskips = varskips = 0; } @@ -1092,74 +924,9 @@ boolean CON_Responder(event_t *ev) return true; } - if (key == 'x' || key == 'X') - { - if (input_sel > input_cur) - I_ClipboardCopy(&inputlines[inputline][input_cur], input_sel-input_cur); - else - I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel); - CON_InputDelSelection(); + // Those are already handled in M_TextInputHandle, but they do extra logic... Maybe textinput_t should have some sort of callbacks? + if (key == 'x' || key == 'X' || key == 'v' || key == 'V') completion[0] = 0; - return true; - } - else if (key == 'c' || key == 'C') - { - if (input_sel > input_cur) - I_ClipboardCopy(&inputlines[inputline][input_cur], input_sel-input_cur); - else - I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel); - return true; - } - else if (key == 'v' || key == 'V') - { - const char *paste = I_ClipboardPaste(); - if (input_sel != input_cur) - CON_InputDelSelection(); - if (paste != NULL) - CON_InputAddString(paste); - completion[0] = 0; - return true; - } - else if (key == 'w' || key == 'W') - { - size_t word_start, word_end, i; - word_end = i = input_cur; - - // Unless we're pointing at the beginning of line, decrement i so we only start - // removing symbols that come before the cursor - if (i) --i; - - // We might be pointing to spaces, skip them first - while (i && isspace(inputlines[inputline][i])) - --i; - - // Now skip the "word" - while (i && !isspace(inputlines[inputline][i])) - --i; - - // Unless we reached beginning of line, i is pointing at first space that was found - // before word start, and we don't want to remove it - if (i) ++i; - - word_start = i; - - if (word_start != word_end) - CON_InputDel(word_start, word_end); - - return true; - } - else if (key == KEY_RIGHTARROW) - CON_ToWordEnd(!shiftdown); - else if (key == KEY_LEFTARROW) - CON_ToWordBegin(!shiftdown); - - // Select all - if (key == 'a' || key == 'A') - { - input_sel = 0; - input_cur = input_len; - return true; - } // ...why shouldn't it eat the key? if it doesn't, it just means you // can control Sonic from the console, which is silly @@ -1174,9 +941,9 @@ boolean CON_Responder(event_t *ev) // remember typing for several completions (a-la-4dos) if (!completion[0]) { - if (!input_len || input_len >= 40 || strchr(inputlines[inputline], ' ')) + if (!input.length || input.length >= 40 || strchr(input.buffer, ' ')) return true; - strcpy(completion, inputlines[inputline]); + strcpy(completion, input.buffer); comskips = varskips = 0; } else @@ -1207,7 +974,11 @@ boolean CON_Responder(event_t *ev) cmd = CV_CompleteVar(completion, varskips); if (cmd) - CON_InputSetString(va("%s ", cmd)); + { + Lock_state(); + M_TextInputSetString(&input, va("%s ", cmd)); + Unlock_state(); + } else { if (comskips > 0) @@ -1233,37 +1004,6 @@ boolean CON_Responder(event_t *ev) return true; } - if (key == KEY_LEFTARROW) - { - if (input_cur != 0) - --input_cur; - if (!shiftdown) - input_sel = input_cur; - return true; - } - else if (key == KEY_RIGHTARROW) - { - if (input_cur < input_len) - ++input_cur; - if (!shiftdown) - input_sel = input_cur; - return true; - } - else if (key == KEY_HOME) - { - input_cur = 0; - if (!shiftdown) - input_sel = input_cur; - return true; - } - else if (key == KEY_END) - { - input_cur = input_len; - if (!shiftdown) - input_sel = input_cur; - return true; - } - // At this point we're messing with input // Clear completion completion[0] = 0; @@ -1271,45 +1011,29 @@ boolean CON_Responder(event_t *ev) // command enter if (key == KEY_ENTER) { - if (!input_len) + if (!input.length) return true; // push the command - COM_BufAddText(inputlines[inputline]); + COM_BufAddText(input.buffer); COM_BufAddText("\n"); CONS_Printf("\x86""%c""\x80""%s\n", CON_PROMPTCHAR, inputlines[inputline]); + Lock_state(); + // Only add command to history if it differs from previous one - if (strcmp(inputlines[inputline], inputlines[(inputline-1) & 31])) + if (strcmp(input.buffer, inputlines[(inputline-1) & 31])) + { inputline = (inputline+1) & 31; + M_TextInputInit(&input, inputlines[inputline], CON_MAXPROMPTCHARS); + } inputhist = inputline; - CON_InputClear(); + M_TextInputClear(&input); - return true; - } + Unlock_state(); - // backspace and delete command prompt - if (input_sel != input_cur) - { - if (key == KEY_BACKSPACE || key == KEY_DEL) - { - CON_InputDelSelection(); - return true; - } - } - else if (key == KEY_BACKSPACE) - { - CON_InputDelChar(); - return true; - } - else if (key == KEY_DEL) - { - if (input_cur == input_len) - return true; - ++input_cur; - CON_InputDelChar(); return true; } @@ -1326,7 +1050,9 @@ boolean CON_Responder(event_t *ev) if (inputhist == inputline) inputhist = (inputline + 1) & 31; - CON_InputSetString(inputlines[inputhist]); + Lock_state(); + M_TextInputSetString(&input, inputlines[inputhist]); + Unlock_state(); return true; } @@ -1340,41 +1066,16 @@ boolean CON_Responder(event_t *ev) while (inputhist != inputline && !inputlines[inputhist][0]); // back to currentline + Lock_state(); if (inputhist == inputline) - CON_InputClear(); + M_TextInputClear(&input); else - CON_InputSetString(inputlines[inputhist]); + M_TextInputSetString(&input, inputlines[inputhist]); + Unlock_state(); + return true; } - // allow people to use keypad in console (good for typing IP addresses) - Calum - if (key >= KEY_KEYPAD7 && key <= KEY_KPADDEL) - { - char keypad_translation[] = {'7','8','9','-', - '4','5','6','+', - '1','2','3', - '0','.'}; - - key = keypad_translation[key - KEY_KEYPAD7]; - } - else if (key == KEY_KPADSLASH) - key = '/'; - - // same capslock code as hu_stuff.c's HU_responder. Check there for details. - key = CON_ShiftChar(key); - - // enter a char into the command prompt - if (key < 32 || key > 127) - return true; - - // add key to cmd line here - if (key >= 'A' && key <= 'Z' && !(shiftdown ^ capslock)) //this is only really necessary for dedicated servers - key = key + 'a' - 'A'; - - if (input_sel != input_cur) - CON_InputDelSelection(); - CON_InputAddChar(key); - return true; } @@ -1656,16 +1357,16 @@ static void CON_DrawInput(void) clen = con_width-13; - if (input_len <= clen) + if (input.length <= clen) { c = 0; - clen = input_len; + clen = input.length; } else // input line scrolls left if it gets too long { clen -= 2; // There will always be some extra truncation -- but where is what we'll find out - if (input_cur <= clen/2) + if (input.cursor <= clen/2) { // Close enough to right edge to show all c = 0; @@ -1676,15 +1377,15 @@ static void CON_DrawInput(void) { // Cursor in the middle (or right side) of input // Move over for the ellipsis - c = input_cur - (clen/2) + 2; + c = input.cursor - (clen/2) + 2; x += charwidth*2; lellip = 1; - if (c + clen >= input_len) + if (c + clen >= input.length) { // Cursor in the right side of input // We were too far over, so move back - c = input_len - clen; + c = input.length - clen; } else { @@ -1698,7 +1399,7 @@ static void CON_DrawInput(void) if (lellip) { x -= charwidth*3; - if (input_sel < c) + if (input.select < c) V_DrawFill(x, y, charwidth*3, (10 * con_scalefactor), 107 | V_NOSCALESTART); for (i = 0; i < 3; ++i, x += charwidth) V_DrawCharacter(x, y, '.' | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, !cv_allcaps.value); @@ -1708,7 +1409,7 @@ static void CON_DrawInput(void) for (cend = c + clen; c < cend; ++c, x += charwidth) { - if ((input_sel > c && input_cur <= c) || (input_sel <= c && input_cur > c)) + if ((input.select > c && input.cursor <= c) || (input.select <= c && input.cursor > c)) { V_DrawFill(x, y, charwidth, (10 * con_scalefactor), 107 | V_NOSCALESTART); V_DrawCharacter(x, y, p[c] | cv_constextsize.value | V_YELLOWMAP | V_NOSCALESTART, !cv_allcaps.value); @@ -1716,14 +1417,14 @@ static void CON_DrawInput(void) else V_DrawCharacter(x, y, p[c] | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); - if (c == input_cur && con_tick >= 4) + if (c == input.cursor && con_tick >= 4) V_DrawCharacter(x, y + (con_scalefactor*2), '_' | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); } - if (cend == input_cur && con_tick >= 4) + if (cend == input.cursor && con_tick >= 4) V_DrawCharacter(x, y + (con_scalefactor*2), '_' | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); if (rellip) { - if (input_sel > cend) + if (input.select > cend) V_DrawFill(x, y, charwidth*3, (10 * con_scalefactor), 107 | V_NOSCALESTART); for (i = 0; i < 3; ++i, x += charwidth) V_DrawCharacter(x, y, '.' | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, !cv_allcaps.value); diff --git a/src/lua_script.c b/src/lua_script.c index 9d5bef4a7..e1bf03f4c 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1589,8 +1589,13 @@ void LUA_Step(void) { if (!gL) return; - lua_settop(gL, 0); - lua_gc(gL, LUA_GCSTEP, 1); + + if (lua_gettop(gL) != 0) + { + CONS_Alert(CONS_WARNING, "Eek, there is garbage on lua stack!\n"); + lua_settop(gL, 0); + lua_gc(gL, LUA_GCSTEP, 1); + } } void LUA_Archive(void) diff --git a/src/m_menu.c b/src/m_menu.c index c42c923e2..cc8bf39a6 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -30,6 +30,7 @@ #include "g_game.h" #include "g_input.h" #include "m_argv.h" +#include "m_textinput.h" // Data. #include "sounds.h" @@ -159,6 +160,9 @@ boolean fromlevelselect = false; boolean menu_text_input = false; +char menu_text_input_buf[MAXSTRINGLENGTH]; +static textinput_t menuinput; + static INT32 coolalphatimer = 9; typedef enum @@ -245,6 +249,7 @@ menu_t SR_MainDef, SR_UnlockChecklistDef; // Misc. Main Menu static void M_Options(INT32 choice); +static void M_Multiplayer(INT32 choice); static void M_LocalSkinMenu(INT32 choice); static void M_LocalSkinChange(INT32 choice); static void M_Manual(INT32 choice); @@ -591,7 +596,7 @@ static menuitem_t MainMenu[] = { {IT_SUBMENU|IT_STRING, NULL, "Extras", &SR_MainDef, 76}, {IT_CALL |IT_STRING, NULL, "Time Attack", M_TimeAttack, 84}, - {IT_SUBMENU|IT_STRING, NULL, "Multiplayer", &MP_MainDef, 92}, + {IT_CALL |IT_STRING, NULL, "Multiplayer", M_Multiplayer, 92}, {IT_CALL |IT_STRING, NULL, "Options", M_Options, 100}, {IT_CALL |IT_STRING, NULL, "Addons", M_Addons, 108}, {IT_CALL |IT_STRING, NULL, "Quit Game", M_QuitSRB2, 116}, @@ -3502,46 +3507,15 @@ static void M_ChangeCvar(INT32 choice) static boolean M_ChangeStringCvar(INT32 choice) { consvar_t *cv = (consvar_t *)currentMenu->menuitems[itemOn].itemaction; - char buf[MAXSTRINGLENGTH]; - size_t len; - choice = M_ShiftChar(choice); - - switch (choice) + if (M_TextInputHandle(&menuinput, choice)) { - case KEY_BACKSPACE: - len = strlen(cv->string); - if (len > 0) - { - S_StartSound(NULL,sfx_menu1); // Tails - M_Memcpy(buf, cv->string, len); - buf[len-1] = 0; - CV_Set(cv, buf); - } - return true; - case KEY_DEL: - if (cv->string[0]) - { - S_StartSound(NULL,sfx_menu1); // Tails - CV_Set(cv, ""); - } - return true; - default: - if ((cv_keyboardlayout.value != 3 && choice >= 32 && choice <= 127) || (cv_keyboardlayout.value == 3 && choice >= 32 && choice <= 141)) - { - len = strlen(cv->string); - if (len < MAXSTRINGLENGTH - 1) - { - S_StartSound(NULL,sfx_menu1); // Tails - M_Memcpy(buf, cv->string, len); - buf[len++] = (char)choice; - buf[len] = 0; - CV_Set(cv, buf); - } - return true; - } - break; + S_StartSound(NULL,sfx_menu1); // Tails + CV_Set(cv, menuinput.buffer); + + return true; } + return false; } @@ -3569,6 +3543,19 @@ static void M_NextOpt(void) else itemOn++; } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); + + if (itemOn < currentMenu->numitems && (currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_STRING) + { + consvar_t *cv = (consvar_t *)currentMenu->menuitems[itemOn].itemaction; + + // Just in case + memset(menu_text_input_buf, 0, sizeof menu_text_input_buf); + M_TextInputInit(&menuinput, menu_text_input_buf, sizeof menu_text_input_buf); + + M_TextInputSetString(&menuinput, cv->string); + + CONS_Printf("Set input string to %s\n", cv->string); + } } static void M_PrevOpt(void) @@ -3942,7 +3929,6 @@ boolean M_Responder(event_t *ev) if ((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_STRING) { menu_text_input = true; - ch = M_ShiftChar(ch); if (M_ChangeStringCvar(ch)) return true; else @@ -4942,6 +4928,28 @@ void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 fla V_DrawFill(x+5, y+5, width*8+6, boxlines*8+6, 239|flags); } +void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) +{ + V_DrawString(x, y, V_ALLOWLOWERCASE|flags, input->buffer); + + // draw text cursor for name + if (input->length && skullAnimCounter < 4) // blink cursor + V_DrawCharacter(x+V_SubStringWidth(input->buffer, input->cursor, V_ALLOWLOWERCASE), y+3, '_'|flags, false); + + // draw selection + if (input->select != input->cursor) + { + size_t start = min(input->select, input->cursor); + size_t end = max(input->select, input->cursor); + + size_t len = end - start; + + INT32 startx = V_SubStringWidth(input->buffer, start, V_ALLOWLOWERCASE); + + V_DrawFill(x+startx, y, V_SubStringWidth(input->buffer+start, len, V_ALLOWLOWERCASE), 8, 103|V_TRANSLUCENT|flags); + } +} + // horizontally centered text static void M_CentreText(INT32 y, const char *string) { @@ -5143,7 +5151,7 @@ static void M_DrawGenericMenu(void) break; case IT_CV_STRING: M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); + V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, menuinput.buffer); if (skullAnimCounter < 4 && i == itemOn) V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, '_' | 0x80, false); @@ -6648,11 +6656,11 @@ I_mutex replayquerymutex; #define MAXREPLAYQUERY 40 -char replayqueryinput[MAXREPLAYQUERY+1]; // The input typed -size_t replayquerypos = 0; // Position in input window +static char replayqueryinput_buffer[MAXREPLAYQUERY+1]; // The input typed +static textinput_t replayqueryinput; -size_t replayqueryfound = 0; // Number of checked replay entries -size_t replayquerycheck = 0; // Index of next replay entry to check in demolist_all +static size_t replayqueryfound = 0; // Number of checked replay entries +static size_t replayquerycheck = 0; // Index of next replay entry to check in demolist_all #define DF_ENCORE 0x40 static INT16 replayScrollTitle = 0; @@ -6707,8 +6715,8 @@ static void LoadReplayNames(void) static void ResetReplayQuery(void) { - memset(replayqueryinput, 0, MAXREPLAYQUERY); - replayquerypos = 0; + memset(replayqueryinput_buffer, 0, MAXREPLAYQUERY); + M_TextInputInit(&replayqueryinput, replayqueryinput_buffer, MAXREPLAYQUERY); replayqueryfound = 0; replayquerycheck = 0; @@ -6732,7 +6740,7 @@ static void M_HutCheckReplays(size_t maxnum) return; // If we don't have any query, just copy all demos and consider them checked - if (replayquerypos == 0) + if (replayqueryinput.length == 0) { // Mark as done replayqueryfound = replayquerycheck = sizedirmenu; @@ -6756,7 +6764,7 @@ static void M_HutCheckReplays(size_t maxnum) case MD_NOTLOADED: case MD_OUTDATED: case MD_LOADED: - if (demolist_all[replayquerycheck].title[0] && strcasestr(demolist_all[replayquerycheck].title, replayqueryinput) != NULL) + if (demolist_all[replayquerycheck].title[0] && strcasestr(demolist_all[replayquerycheck].title, replayqueryinput.buffer) != NULL) AddCheckedReplay(); // It matches, add it! else replayquerycheck++; // Doesn't match, moving on... @@ -6855,41 +6863,23 @@ void M_ReplayHut(INT32 choice) static boolean M_HandleReplayHutQuery(INT32 choice) { - switch (choice) + // Yea gonna copy buffer and check if it changed, thats better than checking for specific keys i think + char tmp[MAXREPLAYQUERY+1]; + memcpy(tmp, replayqueryinput_buffer, MAXREPLAYQUERY+1); + + if (M_TextInputHandle(&replayqueryinput, choice)) { - case KEY_BACKSPACE: - if (replayquerypos == 0) - break; - - S_StartSound(NULL,sfx_menu1); - - replayquerypos--; - replayqueryinput[replayquerypos] = 0; + S_StartSound(NULL,sfx_menu1); + // Restart search only if we actually modified input and not just moved in it + if (memcmp(tmp, replayqueryinput_buffer, MAXREPLAYQUERY+1)) + { preparefilemenu(false, true); dir_on[menudepthleft] = 0; PrepReplayList(false); + } - return true; - - default: - if (choice < 32 || choice > 127) - break; - - if (replayquerypos < MAXREPLAYQUERY) - { - S_StartSound(NULL,sfx_menu1); - - replayqueryinput[replayquerypos] = choice; - replayqueryinput[replayquerypos+1] = 0; - ++replayquerypos; - - preparefilemenu(false, true); - dir_on[menudepthleft] = 0; - PrepReplayList(false); - } - - return true; + return true; } return false; @@ -7320,15 +7310,11 @@ static void M_DrawReplayHut(void) // Draw search query M_DrawTextBoxFlags(x, 200 - 22, MAXREPLAYQUERY, 1, V_SNAPTOBOTTOM); - if (replayquerypos) - V_DrawString(x + 8, 200 - 14, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, replayqueryinput); + if (replayqueryinput.length) + M_DrawTextInput(x + 8, 200 - 14, &replayqueryinput, V_SNAPTOBOTTOM); else V_DrawString(x + 8, 200 - 14, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, "\x86Type to search..."); - // draw text cursor for name - if (replayquerypos && skullAnimCounter < 4) // blink cursor - V_DrawCharacter(x + 8 + V_StringWidth(replayqueryinput, V_ALLOWLOWERCASE), 200 - 14, '_'|V_SNAPTOBOTTOM, false); - if (replaynamesloaded && replayquerycheck < sizedirmenu) V_DrawString(x + 8, 200 - 30, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, va("Searching %u/%u...", (unsigned)replayquerycheck, (unsigned)sizedirmenu)); } @@ -8906,9 +8892,11 @@ void M_DrawTimeAttackMenu(void) if (currentMenu->menuitems[i].status & IT_CV_STRING) { M_DrawTextBox(x + 32, y - 8, MAXPLAYERNAME, 1); - V_DrawString(x + 40, y, V_ALLOWLOWERCASE, cv->string); - if (itemOn == i && skullAnimCounter < 4) // blink cursor - V_DrawCharacter(x + 40 + V_StringWidth(cv->string, V_ALLOWLOWERCASE), y, '_',false); + + if (itemOn != i) + V_DrawString(x + 40, y, V_ALLOWLOWERCASE, cv->string); + else + M_DrawTextInput(x + 40, y, &menuinput, 0); } else { @@ -10185,7 +10173,19 @@ static void M_StartServerMenu(INT32 choice) // ============== static char setupm_ip[28]; +static textinput_t setupm_input_ip; #endif + +void M_Multiplayer(INT32 choice) +{ + (void)choice; +#ifndef NONET + memset(setupm_ip, 0, 28); + M_TextInputInit(&setupm_input_ip, setupm_ip, 28); +#endif + M_SetupNextMenu(&MP_MainDef); +} + static UINT8 setupm_pselect = 1; // Draw the funky Connect IP menu. Tails 11-19-2002 @@ -10219,12 +10219,10 @@ Update the maxplayers label... V_DrawFill(x+5, y+4+5, /*16*8 + 6,*/ BASEVIDWIDTH - 2*(x+5), 8+6, 239); // draw name string - V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip); - - // draw text cursor for name - if (itemOn == 9 - && skullAnimCounter < 4) //blink cursor - V_DrawCharacter(x+8+V_StringWidth(setupm_ip, V_ALLOWLOWERCASE),y+12,'_',false); + if (itemOn != 9) + V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip); + else + M_DrawTextInput(x+8, y+12, &setupm_input_ip, 0); #endif // character bar, ripped off the color bar :V @@ -10412,7 +10410,6 @@ static void M_ConnectLastServer(INT32 choice) // Tails 11-19-2002 static void M_HandleConnectIP(INT32 choice) { - size_t l; boolean exitmenu = false; // exit to previous menu and send name change switch (choice) @@ -10437,41 +10434,21 @@ static void M_HandleConnectIP(INT32 choice) exitmenu = true; break; + case KEY_LEFTARROW: + case KEY_RIGHTARROW: case KEY_BACKSPACE: - if ((l = strlen(setupm_ip)) != 0) - { - S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[l-1] = 0; - } - break; - case KEY_DEL: - if (setupm_ip[0]) - { + if (M_TextInputHandle(&setupm_input_ip, choice)) S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[0] = 0; - } break; default: - l = strlen(setupm_ip); - if (l >= 28-1) - break; - // Rudimentary number and period enforcing - also allows letters so hostnames can be used instead - if ((choice >= '-' && choice <= ':') || (choice >= 'A' && choice <= 'Z') || (choice >= 'a' && choice <= 'z')) + if ((choice >= '-' && choice <= ':') || (choice >= 'A' && choice <= 'Z') || (choice >= 'a' && choice <= 'z') + || (choice >= 199 && choice <= 211 && choice != 202 && choice != 206)) //numpad too! { - S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[l] = (char)choice; - setupm_ip[l+1] = 0; - } - else if (choice >= 199 && choice <= 211 && choice != 202 && choice != 206) //numpad too! - { - char keypad_translation[] = {'7','8','9','-','4','5','6','+','1','2','3','0','.'}; - choice = keypad_translation[choice - 199]; - S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[l] = (char)choice; - setupm_ip[l+1] = 0; + if (M_TextInputHandle(&setupm_input_ip, choice)) + S_StartSound(NULL,sfx_menu1); // Tails } break; } @@ -10496,14 +10473,15 @@ static state_t *multi_state; // this is set before entering the MultiPlayer setup menu, // for either player 1 or 2 -static char setupm_name[MAXPLAYERNAME+1]; -static player_t *setupm_player; -static consvar_t *setupm_cvskin; -static consvar_t *setupm_cvcolor; -static consvar_t *setupm_cvname; -static UINT8 setupm_skinxpos; -static INT32 setupm_fakeskin; -static INT32 setupm_fakecolor; +static char setupm_name[MAXPLAYERNAME+1]; +static textinput_t setupm_input; +static player_t *setupm_player; +static consvar_t *setupm_cvskin; +static consvar_t *setupm_cvcolor; +static consvar_t *setupm_cvname; +static UINT8 setupm_skinxpos; +static INT32 setupm_fakeskin; +static INT32 setupm_fakecolor; //variables used for other skin select menus static UINT8 setupm_skinypos; @@ -10579,11 +10557,11 @@ static void M_DrawSetupMultiPlayerMenu(void) } M_DrawTextBox(mx + 32, my - 8 + nameboxaddy, MAXPLAYERNAME, 1); - V_DrawString(mx + 40, my + nameboxaddy, V_ALLOWLOWERCASE, setupm_name); - // draw text cursor for name - if (!itemOn && skullAnimCounter < 4) // blink cursor - V_DrawCharacter(mx + 40 + V_StringWidth(setupm_name, V_ALLOWLOWERCASE), my + nameboxaddy, '_', false); + if (itemOn != 0) + V_DrawString(mx + 40, my + nameboxaddy, V_ALLOWLOWERCASE, setupm_input.buffer); + else + M_DrawTextInput(mx + 40, my + nameboxaddy, &setupm_input, 0); // draw skin string st = V_StringWidth(skins[setupm_fakeskin].realname, 0); @@ -11182,7 +11160,6 @@ static void M_DrawSetupMultiPlayerMenu(void) // Handle 1P/2P MP Setup static void M_HandleSetupMultiPlayer(INT32 choice) { - size_t l; boolean exitmenu = false; // exit to previous menu and send name change if ((choice == gamecontrol[gc_fire][0] || choice == gamecontrol[gc_fire][1]) && itemOn == 2) @@ -11304,7 +11281,12 @@ static void M_HandleSetupMultiPlayer(INT32 choice) break; case KEY_LEFTARROW: - if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) + if (itemOn == 0) + { + M_TextInputHandle(&setupm_input, choice); + S_StartSound(NULL,sfx_menu1); // Tails + } + else if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) { if (setupm_skinlockedselect) { @@ -11358,7 +11340,12 @@ static void M_HandleSetupMultiPlayer(INT32 choice) break; case KEY_RIGHTARROW: - if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) + if (itemOn == 0) + { + M_TextInputHandle(&setupm_input, choice); + S_StartSound(NULL,sfx_menu1); // Tails + } + else if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) { if (setupm_skinlockedselect) { @@ -11389,7 +11376,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else if (cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED){ if (setupm_skinselect >= ((setupm_skinypos-1)+SKINGRIDHEIGHT)*8+24 && setupm_skinypos < (ROUNDSKINSUPTO8/8)-SKINGRIDHEIGHT+24) - setupm_skinypos++; + setupm_skinypos++; } } else @@ -11427,11 +11414,8 @@ static void M_HandleSetupMultiPlayer(INT32 choice) BREAKWHENLOCKED if (itemOn == 0) { - if ((l = strlen(setupm_name))!=0) - { - S_StartSound(NULL,sfx_menu1); // Tails - setupm_name[l-1] =0; - } + M_TextInputHandle(&setupm_input, choice); + S_StartSound(NULL,sfx_menu1); // Tails } else if ((cv_skinselectmenu.value == SKINMENUTYPE_GRID || cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED) && itemOn == 1) { @@ -11456,10 +11440,10 @@ static void M_HandleSetupMultiPlayer(INT32 choice) case KEY_DEL: if (cv_skinselectmenu.value) BREAKWHENLOCKED - if (itemOn == 0 && (l = strlen(setupm_name))!=0) + if (itemOn == 0) { + M_TextInputHandle(&setupm_input, choice); S_StartSound(NULL,sfx_menu1); // Tails - setupm_name[0] = 0; } break; @@ -11496,17 +11480,10 @@ static void M_HandleSetupMultiPlayer(INT32 choice) break; default: - if (choice < 32 || choice > 127) - break; if (itemOn == 0) { - l = strlen(setupm_name); - if (l < MAXPLAYERNAME) - { + if (M_TextInputHandle(&setupm_input, choice)) S_StartSound(NULL,sfx_menu1); // Tails - setupm_name[l] =(char)choice; - setupm_name[l+1] =0; - } } break; } @@ -11571,7 +11548,9 @@ static void M_SetupMultiPlayer(INT32 choice) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics*FRACUNIT; - strcpy(setupm_name, cv_playername.string); + + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, cv_playername.string); // set for player 1 setupm_player = &players[consoleplayer]; @@ -11613,7 +11592,9 @@ static void M_SetupMultiPlayer2(INT32 choice) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics*FRACUNIT; - strcpy (setupm_name, cv_playername2.string); + + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, cv_playername2.string); // set for splitscreen secondary player setupm_player = &players[displayplayers[1]]; @@ -11654,7 +11635,9 @@ static void M_SetupMultiPlayer3(INT32 choice) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics; - strcpy(setupm_name, cv_playername3.string); + + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, cv_playername3.string); // set for splitscreen third player setupm_player = &players[displayplayers[2]]; @@ -11695,7 +11678,9 @@ static void M_SetupMultiPlayer4(INT32 choice) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics; - strcpy(setupm_name, cv_playername4.string); + + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, cv_playername4.string); // set for splitscreen fourth player setupm_player = &players[displayplayers[3]]; diff --git a/src/m_menu.h b/src/m_menu.h index bd0cd0e69..486b5b869 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -64,6 +64,10 @@ void M_DrawTextBox(INT32 x, INT32 y, INT32 width, INT32 boxlines); // Same but with extra flags applied void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 flags); +// Draw text input +typedef struct textinput_s textinput_t; +void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags); + // Used in d_netcmd to restart time attack void M_ModeAttackRetry(INT32 choice); diff --git a/src/m_textinput.c b/src/m_textinput.c new file mode 100644 index 000000000..48ef7d203 --- /dev/null +++ b/src/m_textinput.c @@ -0,0 +1,306 @@ +#include "m_textinput.h" +#include "i_system.h" +#include "keys.h" +#include "console.h" + +static void M_TextInputDel(textinput_t *input, size_t start, size_t end) +{ + size_t len; + + len = (end - start); + + if (end != input->length) + memmove(&input->buffer[start], &input->buffer[end], input->length-end); + memset(&input->buffer[input->length - len], 0, len); + + input->length -= len; + + if (input->select >= end) + input->select -= len; + else if (input->select > start) + input->select = start; + + if (input->cursor >= end) + input->cursor -= len; + else if (input->cursor > start) + input->cursor = start; +} + +static void M_TextInputDelSelection(textinput_t *input) +{ + size_t start, end; + + if (input->cursor > input->select) + { + start = input->select; + end = input->cursor; + } + else + { + start = input->cursor; + end = input->select; + } + + M_TextInputDel(input, start, end); + + input->select = input->cursor = start; +} + +static void M_TextInputAddString(textinput_t *input, const char *c) +{ + size_t csize = strlen(c); + + if (input->length + csize > input->buffer_size-1) + return; + + if (input->cursor != input->length) + memmove(&input->buffer[input->cursor+csize], &input->buffer[input->cursor], input->length-input->cursor); + memcpy(&input->buffer[input->cursor], c, csize); + input->length += csize; + input->select = (input->cursor += csize); +} + +static void M_TextInputAddChar(textinput_t *input, char c) +{ + if (input->length >= input->buffer_size-1) + return; + + if (input->cursor != input->length) + memmove(&input->buffer[input->cursor+1], &input->buffer[input->cursor], input->length-input->cursor); + input->buffer[input->cursor++] = c; + input->buffer[++input->length] = 0; + input->select = input->cursor; +} + +static void M_TextInputDelChar(textinput_t *input) +{ + if (!input->cursor) + return; + + if (input->cursor != input->length) + memmove(&input->buffer[input->cursor-1], &input->buffer[input->cursor], input->length-input->cursor); + input->buffer[--input->length] = 0; + input->select = --input->cursor; +} + +static void M_TextInputToWordEnd(textinput_t *input, boolean move_sel) +{ + // Skip spaces + while (input->cursor < input->length && isspace(input->buffer[input->cursor])) + ++input->cursor; + + // Skip word + while (input->cursor < input->length && !isspace(input->buffer[input->cursor])) + ++input->cursor; + + if (move_sel) input->select = input->cursor; +} + +static void M_TextInputToWordBegin(textinput_t *input, boolean move_sel) +{ + // Hack, always move back 1 character if possible so if we press ctrl-left at a word beginning + // we move to previous word + if (input->cursor) --input->cursor; + + // Skip spaces + while (input->cursor && isspace(input->buffer[input->cursor])) + --input->cursor; + + // Skip word + while (input->cursor && !isspace(input->buffer[input->cursor])) + --input->cursor; + + // Unless we reached beginning of line, we're pointing at a space before word, so move cursor + // forward to fix that + if (input->cursor) ++input->cursor; + + if (move_sel) input->select = input->cursor; +} + +void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size) +{ + input->buffer = buffer; + input->buffer_size = buffer_size; + + M_TextInputClear(input); +} + +void M_TextInputClear(textinput_t *input) +{ + input->cursor = 0; + input->select = 0; + input->length = 0; +} + +void M_TextInputSetString(textinput_t *input, const char *c) +{ + memset(input->buffer, 0, input->buffer_size); + strcpy(input->buffer, c); + input->cursor = input->select = input->length = strlen(c); +} + +boolean M_TextInputHandle(textinput_t *input, INT32 key) +{ + if (key == KEY_LSHIFT || key == KEY_RSHIFT + || key == KEY_LCTRL || key == KEY_RCTRL + || key == KEY_LALT || key == KEY_RALT) + return false; + + if ((cv_keyboardlayout.value != 3 && ctrldown) || (cv_keyboardlayout.value == 3 && ctrldown && !altdown)) + { + if (key == 'x' || key == 'X') + { + if (input->select > input->cursor) + I_ClipboardCopy(&input->buffer[input->cursor], input->select-input->cursor); + else + I_ClipboardCopy(&input->buffer[input->select], input->cursor-input->select); + M_TextInputDelSelection(input); + return true; + } + else if (key == 'c' || key == 'C') + { + if (input->select > input->cursor) + I_ClipboardCopy(&input->buffer[input->cursor], input->select-input->cursor); + else + I_ClipboardCopy(&input->buffer[input->select], input->cursor-input->select); + return true; + } + else if (key == 'v' || key == 'V') + { + const char *paste = I_ClipboardPaste(); + if (input->select != input->cursor) + M_TextInputDelSelection(input); + if (paste != NULL) + M_TextInputAddString(input, paste); + return true; + } + else if (key == 'w' || key == 'W') + { + size_t word_start, word_end, i; + word_end = i = input->cursor; + + // Unless we're pointing at the beginning of line, decrement i so we only start + // removing symbols that come before the cursor + if (i) --i; + + // We might be pointing to spaces, skip them first + while (i && isspace(input->buffer[i])) + --i; + + // Now skip the "word" + while (i && !isspace(input->buffer[i])) + --i; + + // Unless we reached beginning of line, i is pointing at first space that was found + // before word start, and we don't want to remove it + if (i) ++i; + + word_start = i; + + if (word_start != word_end) + M_TextInputDel(input, word_start, word_end); + + return true; + } + else if (key == KEY_RIGHTARROW) + M_TextInputToWordEnd(input, !shiftdown); + else if (key == KEY_LEFTARROW) + M_TextInputToWordBegin(input, !shiftdown); + + // Select all + if (key == 'a' || key == 'A') + { + input->select = 0; + input->cursor = input->length; + return true; + } + + // ...why shouldn't it eat the key? if it doesn't, it just means you + // can control Sonic from the console, which is silly + return true; + } + + if (key == KEY_LEFTARROW) + { + if (input->cursor != 0) + --input->cursor; + if (!shiftdown) + input->select = input->cursor; + return true; + } + else if (key == KEY_RIGHTARROW) + { + if (input->cursor < input->length) + ++input->cursor; + if (!shiftdown) + input->select = input->cursor; + return true; + } + else if (key == KEY_HOME) + { + input->cursor = 0; + if (!shiftdown) + input->select = input->cursor; + return true; + } + else if (key == KEY_END) + { + input->cursor = input->length; + if (!shiftdown) + input->select = input->cursor; + return true; + } + + // backspace and delete command prompt + if (input->select != input->cursor) + { + if (key == KEY_BACKSPACE || key == KEY_DEL) + { + M_TextInputDelSelection(input); + return true; + } + } + else if (key == KEY_BACKSPACE) + { + M_TextInputDelChar(input); + return true; + } + else if (key == KEY_DEL) + { + if (input->cursor == input->length) + return true; + ++input->cursor; + M_TextInputDelChar(input); + return true; + } + + // allow people to use keypad in console (good for typing IP addresses) - Calum + if (key >= KEY_KEYPAD7 && key <= KEY_KPADDEL) + { + char keypad_translation[] = {'7','8','9','-', + '4','5','6','+', + '1','2','3', + '0','.'}; + + key = keypad_translation[key - KEY_KEYPAD7]; + } + else if (key == KEY_KPADSLASH) + key = '/'; + + // same capslock code as hu_stuff.c's HU_responder. Check there for details. + key = CON_ShiftChar(key); + + // enter a char into the command prompt + if (key < 32 || key > 127) + return false; + + // add key to cmd line here + if (key >= 'A' && key <= 'Z' && !(shiftdown ^ capslock)) //this is only really necessary for dedicated servers + key = key + 'a' - 'A'; + + if (input->select != input->cursor) + M_TextInputDelSelection(input); + M_TextInputAddChar(input, key); + + return true; +} diff --git a/src/m_textinput.h b/src/m_textinput.h new file mode 100644 index 000000000..aad5e94ab --- /dev/null +++ b/src/m_textinput.h @@ -0,0 +1,23 @@ +#ifndef __M_TEXTINPUT__ +#define __M_TEXTINPUT__ + +#include "doomtype.h" + +typedef struct textinput_s { + size_t cursor; + size_t select; + size_t length; + + char *buffer; + size_t buffer_size; +} textinput_t; + +void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size); + +void M_TextInputClear(textinput_t *input); + +void M_TextInputSetString(textinput_t *input, const char *c); + +boolean M_TextInputHandle(textinput_t *input, INT32 key); + +#endif diff --git a/src/v_video.c b/src/v_video.c index 5746d963e..492a75004 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2845,11 +2845,14 @@ INT32 V_LevelNameHeight(const char *string) // // Find string width from hu_font chars // -INT32 V_StringWidth(const char *string, INT32 option) +INT32 V_SubStringWidth(const char *string, INT32 length, INT32 option) { INT32 c, w = 0; INT32 spacewidth = 4, charwidth = 0; - size_t i; + ssize_t i; + + if (length < 0) + length = strlen(string); switch (option & V_SPACINGMASK) { @@ -2865,7 +2868,7 @@ INT32 V_StringWidth(const char *string, INT32 option) break; } - for (i = 0; i < strlen(string); i++) + for (i = 0; string[i] && i < length; i++) { c = string[i]; if ((UINT8)c >= 0x80 && (UINT8)c <= 0x8F) //color parsing! -Inuyasha 2.16.09 @@ -2884,11 +2887,14 @@ INT32 V_StringWidth(const char *string, INT32 option) // // Find string width from hu_font chars, 0.5x scale // -INT32 V_SmallStringWidth(const char *string, INT32 option) +INT32 V_SmallSubStringWidth(const char *string, INT32 length, INT32 option) { INT32 c, w = 0; INT32 spacewidth = 2, charwidth = 0; - size_t i; + ssize_t i; + + if (length < 0) + length = strlen(string); switch (option & V_SPACINGMASK) { @@ -2904,7 +2910,7 @@ INT32 V_SmallStringWidth(const char *string, INT32 option) break; } - for (i = 0; i < strlen(string); i++) + for (i = 0; string[i] && i < length; i++) { c = string[i]; if ((UINT8)c >= 0x80 && (UINT8)c <= 0x8F) //color parsing! -Inuyasha 2.16.09 @@ -2923,12 +2929,15 @@ INT32 V_SmallStringWidth(const char *string, INT32 option) // // Find string width from tny_font chars // -INT32 V_ThinStringWidth(const char *string, INT32 option) +INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option) { INT32 c, w = 0; INT32 spacewidth = 2, charwidth = 0; boolean lowercase = (option & V_ALLOWLOWERCASE); - size_t i; + ssize_t i; + + if (length < 0) + length = strlen(string); switch (option & V_SPACINGMASK) { @@ -2945,7 +2954,7 @@ INT32 V_ThinStringWidth(const char *string, INT32 option) break; } - for (i = 0; i < strlen(string); i++) + for (i = 0; string[i] && i < length; i++) { c = string[i]; if ((UINT8)c >= 0x80 && (UINT8)c <= 0x8F) //color parsing! -Inuyasha 2.16.09 @@ -2963,7 +2972,7 @@ INT32 V_ThinStringWidth(const char *string, INT32 option) else { w += (charwidth ? charwidth - : ((option & V_6WIDTHSPACE && i < strlen(string)-1) ? max(1, SHORT(tny_font[c]->width)-1) // Reuse this flag for the alternate bunched-up spacing + : ((option & V_6WIDTHSPACE && i < length-1) ? max(1, SHORT(tny_font[c]->width)-1) // Reuse this flag for the alternate bunched-up spacing : SHORT(tny_font[c]->width))); } } diff --git a/src/v_video.h b/src/v_video.h index b1d10af6a..0dae04aaa 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -237,11 +237,14 @@ void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string); INT32 V_CreditStringWidth(const char *string); // Find string width from hu_font chars -INT32 V_StringWidth(const char *string, INT32 option); +INT32 V_SubStringWidth(const char *string, INT32 length, INT32 option); +#define V_StringWidth(string, option) V_SubStringWidth(string, -1, option) // Find string width from hu_font chars, 0.5x scale -INT32 V_SmallStringWidth(const char *string, INT32 option); +INT32 V_SmallSubStringWidth(const char *string, INT32 length, INT32 option); +#define V_SmallStringWidth(string, option) V_SmallSubStringWidth(string, -1, option) // Find string width from tny_font chars -INT32 V_ThinStringWidth(const char *string, INT32 option); +INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option); +#define V_ThinStringWidth(string, option) V_ThinSubStringWidth(string, -1, option) char V_GetSkincolorChar(INT32 color); From e2367d26d195bbf3b080cb310f24d4ab9a3e136b Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 30 Sep 2024 12:08:21 +0300 Subject: [PATCH 073/166] Use same keyboardlayout code as in chat for textinput, also add a null terminator after ctrl-v just in case string is not always zeroed out already --- src/m_textinput.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/m_textinput.c b/src/m_textinput.c index 48ef7d203..8b608cc9a 100644 --- a/src/m_textinput.c +++ b/src/m_textinput.c @@ -58,6 +58,7 @@ static void M_TextInputAddString(textinput_t *input, const char *c) memcpy(&input->buffer[input->cursor], c, csize); input->length += csize; input->select = (input->cursor += csize); + input->buffer[input->length] = 0; } static void M_TextInputAddChar(textinput_t *input, char c) @@ -288,7 +289,7 @@ boolean M_TextInputHandle(textinput_t *input, INT32 key) key = '/'; // same capslock code as hu_stuff.c's HU_responder. Check there for details. - key = CON_ShiftChar(key); + key = cv_keyboardlayout.value == 3 ? CON_ShitAndAltGrChar(key) : CON_ShiftChar(key); // enter a char into the command prompt if (key < 32 || key > 127) From ff2b28ac73e88101132a5602a55b2030bdbc0b55 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 30 Sep 2024 12:13:25 +0300 Subject: [PATCH 074/166] Use m_textinput for chat too --- src/hu_stuff.c | 395 ++++++++++++++++++------------------------------- 1 file changed, 140 insertions(+), 255 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index ba6bb72bc..b864e14b6 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -49,6 +49,8 @@ #include "s_sound.h" // song credits #include "k_kart.h" +#include "m_textinput.h" + #ifdef HWRENDER #include "hardware/hw_main.h" #endif @@ -86,8 +88,8 @@ patch_t *frameslash; // framerate stuff. Used in screen.c static player_t *plr; boolean chat_on; // entering a chat message? -static char w_chat[HU_MAXMSGLEN + 1]; -static size_t c_input = 0; // let's try to make the chat input less shitty. +static char w_chat_buf[HU_MAXMSGLEN + 1]; +static textinput_t w_chat; static boolean headsupactive = false; boolean hu_showscores; // draw rankings static char hu_tick; @@ -1143,71 +1145,6 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) #endif } -// Handles key input and string input -// -static inline boolean HU_keyInChatString(char *s, char ch) -{ - size_t l; - - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) - || ch == ' ') // Allow spaces, of course - { - l = strlen(s); - if (l < HU_MAXMSGLEN - 1) - { - if (c_input >= strlen(s)) // don't do anything complicated - { - s[l++] = ch; - s[l]=0; - } - else - { - // move everything past c_input for new characters: - size_t m = HU_MAXMSGLEN-1; - while (m>=c_input) - { - if (s[m]) - s[m+1] = (s[m]); - if (m == 0) // prevent overflow - break; - m--; - } - s[c_input] = ch; // and replace this. - } - c_input++; - return true; - } - return false; - } - else if (ch == KEY_BACKSPACE) - { - size_t i = c_input; - - if (c_input <= 0) - return false; - - if (!s[i-1]) - return false; - - if (i >= strlen(s)-1) - { - s[strlen(s)-1] = 0; - c_input--; - return false; - } - - for (; (i < HU_MAXMSGLEN); i++) - { - s[i-1] = s[i]; - } - c_input--; - } - else if (ch != KEY_ENTER) - return false; // did not eat key - - return true; // ate the key -} - #endif // @@ -1280,9 +1217,9 @@ static boolean HU_clearChatSpaces(void) char c; // current character we're iterating. boolean nothingbutspaces = true; - for (; i < strlen(w_chat); i++) // iterate through message and eradicate all spaces that don't belong. + for (; i < strlen(w_chat_buf); i++) // iterate through message and eradicate all spaces that don't belong. { - c = w_chat[i]; + 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. @@ -1294,128 +1231,110 @@ static boolean HU_clearChatSpaces(void) return nothingbutspaces; } -// -// -static void HU_queueChatChar(INT32 c) +static void HU_SendChatMessage(void) { - // send automaticly the message (no more chat char) - if (c == KEY_ENTER) + char buf[2 + HU_MAXMSGLEN + 1]; + char *msg = &buf[2]; + size_t ci = 2; + INT32 target = 0; + char c; + + if (HU_clearChatSpaces()) // Avoids being able to send empty messages, or something. + return; // If this returns true, that means our message was NOTHING but spaces, so don't send it period. + + do { + c = w_chat_buf[-2+ci++]; + if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. + buf[ci-1]=c; + } while (c); + + M_TextInputClear(&w_chat); + + // last minute mute check + if (CHAT_MUTE) { - char buf[2 + HU_MAXMSGLEN + 1]; - char *msg = &buf[2]; - size_t i; - size_t ci = 2; - INT32 target = 0; + HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); + return; + } - if (HU_clearChatSpaces()) // Avoids being able to send empty messages, or something. - return; // If this returns true, that means our message was NOTHING but spaces, so don't send it period. + if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + { + INT32 spc = 1; // used if nodenum[1] is a space. + char *nodenum = (char*) malloc(3); + const char *newmsg; - do { - c = w_chat[-2+ci++]; - if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. - buf[ci-1]=c; - } while (c); - i = 0; - for (;(iERROR: The chat is muted. You can't say anything.", "\x85"), false); + HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false); return; } - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + 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'))) { - INT32 spc = 1; // used if nodenum[1] is a space. - char *nodenum = (char*) malloc(3); - const char *newmsg; - - // what we're gonna do now is check if the node exists - // with that logic, characters 4 and 5 are our numbers: - - // teamtalk can't send PMs, just don't send it, else everyone would be able to see it, and no one wants to see your sex RP sicko. - if (teamtalk) - { - HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false); - return; - } - - 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'))) - { - // check if nodenum[1] is a space - if (nodenum[1] == ' ') - spc = 0; - // let it slide - 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! - if (target < MAXPLAYERS && playeringame[target]) // player exists - target++; // even though playernums are from 0 to 31, target is 1 to 32, so up that by 1 to have it work! + // check if nodenum[1] is a space + if (nodenum[1] == ' ') + spc = 0; + // let it slide else { - HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + free(nodenum); return; } - - // we need to get rid of the /pm - newmsg = msg+5+spc; - strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } - if (ci > 3) // don't send target+flags+empty message. + // I'm very bad at C, I swear I am, additional checks eww! + if (spc != 0) { - if (teamtalk) - buf[0] = -1; // target - else - buf[0] = target; - - buf[1] = 0; // flags - SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); + if (msg[5] != ' ') + { + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + free(nodenum); + return; + } } - 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! + if (target < MAXPLAYERS && playeringame[target]) // player exists + target++; // even though playernums are from 0 to 31, target is 1 to 32, so up that by 1 to have it work! + else + { + HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same + return; + } + + // we need to get rid of the /pm + newmsg = msg+5+spc; + strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); + } + if (ci > 3) // don't send target+flags+empty message. + { + if (teamtalk) + buf[0] = -1; // target + else + buf[0] = target; + + buf[1] = 0; // flags + SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); } } #endif void HU_clearChatChars(void) { - size_t i = 0; - for (;idata1 != gamecontrol[gc_talkkey][1])) return false; - c = cv_keyboardlayout.value == 3 ? CON_ShitAndAltGrChar(c) : CON_ShiftChar(c); + M_TextInputHandle(&w_chat, c); - // pasting. pasting is cool. chat is a bit limited, though :( - if (((c == 'v' || c == 'V') && ctrldown) && !CHAT_MUTE) - { - const char *paste = I_ClipboardPaste(); - size_t chatlen; - size_t pastelen; - - // create a dummy string real quickly - - if (paste == NULL) - return true; - - chatlen = strlen(w_chat); - pastelen = strlen(paste); - if (chatlen+pastelen > HU_MAXMSGLEN) - return true; // we can't paste this!! - - if (c_input >= strlen(w_chat)) // add it at the end of the string. - { - memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that. - c_input += pastelen; - /*size_t i = 0; - for (;i= c_input) - { - if (w_chat[i]) - w_chat[i+pastelen] = w_chat[i]; - if (i == 0) // prevent overflow - break; - i--; - } - memcpy(&w_chat[c_input], paste, pastelen); // copy all of that. - c_input += pastelen; - return true; - } - } - - if (!CHAT_MUTE && HU_keyInChatString(w_chat,c)) - { - HU_queueChatChar(c); - } if (c == KEY_ENTER) { chat_on = false; - c_input = 0; // reset input cursor chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :) + HU_SendChatMessage(); } else if (c == KEY_ESCAPE || ((c == gamecontrol[gc_talkkey][0] || c == gamecontrol[gc_talkkey][1] @@ -1561,7 +1433,6 @@ boolean HU_Responder(event_t *ev) && c >= KEY_MOUSE1)) // If it's not a keyboard key, then the chat button is used as a toggle. { chat_on = false; - c_input = 0; // reset input cursor } else if ((c == KEY_UPARROW || c == KEY_MOUSEWHEELUP) && chat_scroll > 0 && !OLDCHAT) // CHAT SCROLLING YAYS! { @@ -1575,10 +1446,6 @@ boolean HU_Responder(event_t *ev) justscrolleddown = true; chat_scrolltime = 4; } - else if (c == KEY_LEFTARROW && c_input != 0 && !OLDCHAT) // i said go back - c_input--; - else if (c == KEY_RIGHTARROW && c_input < strlen(w_chat) && !OLDCHAT) // don't need to check for admin or w/e here since the chat won't ever contain anything if it's muted. - c_input++; return true; } #endif @@ -1932,8 +1799,9 @@ static void HU_DrawChat(void) INT32 charwidth = 4, charheight = 6; INT32 boxw = cv_chatwidth.value; INT32 t = 0, c = 0, y = chaty - (typelines*charheight); - UINT32 i = 0, saylen = strlen(w_chat); // You learn new things everyday! + UINT32 i = 0, saylen = strlen(w_chat_buf); // You learn new things everyday! INT32 cflag = 0; + size_t select_start = 0, select_end = 0; const char *ntalk = "Say: ", *ttalk = "Team: "; const char *talk = ntalk; const char *mute = "Chat has been muted."; @@ -1995,13 +1863,19 @@ static void HU_DrawChat(void) i = 0; typelines = 1; - if ((strlen(w_chat) == 0 || c_input == 0) && hu_tick < 4) - V_DrawChatCharacter(chatx + 2 + c, y+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, !cv_allcaps.value, NULL); + if ((w_chat.cursor == 0 || w_chat.length == 0) && hu_tick < 4) + V_DrawChatCharacter(chatx+2+c+charwidth*w_chat.cursor, y+1, '_'|V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, !cv_allcaps.value, NULL); - while (w_chat[i]) + if (w_chat.select != w_chat.cursor) + { + select_start = min(w_chat.select, w_chat.cursor); + select_end = max(w_chat.select, w_chat.cursor); + } + + while (w_chat_buf[i]) { boolean skippedline = false; - if (c_input == (i+1)) + if (w_chat.cursor == (i+1)) { INT32 cursorx = (c+charwidth < boxw-charwidth) ? (chatx + 2 + c+charwidth) : (chatx+1); // we may have to go down. INT32 cursory = (cursorx != chatx+1) ? (y) : (y+charheight); @@ -2016,10 +1890,14 @@ static void HU_DrawChat(void) } //Hurdler: isn't it better like that? - if (w_chat[i] < HU_FONTSTART) - ++i; - else - V_DrawChatCharacter(chatx + c + 2, y, w_chat[i++] | V_SNAPTOBOTTOM|V_SNAPTOLEFT | t, !cv_allcaps.value, NULL); + if (w_chat_buf[i] >= HU_FONTSTART) + V_DrawChatCharacter(chatx + c + 2, y, w_chat_buf[i] | V_SNAPTOBOTTOM|V_SNAPTOLEFT | t, !cv_allcaps.value, NULL); + + // Draw selection + if (i >= select_start && i < select_end) + V_DrawFill(chatx + c + 2, y-1, charwidth, charheight, 103|V_TRANSLUCENT|V_SNAPTOBOTTOM|V_SNAPTOLEFT|t); + + ++i; c += charwidth; if (c > boxw-(charwidth*2) && !skippedline) @@ -2031,7 +1909,7 @@ static void HU_DrawChat(void) } // handle /pm list. It's messy, horrible and I don't care. - if (strnicmp(w_chat, "/pm", 3) == 0 && vid.width >= 400 && !teamtalk) // 320x200 unsupported kthxbai + if (strnicmp(w_chat_buf, "/pm", 3) == 0 && vid.width >= 400 && !teamtalk) // 320x200 unsupported kthxbai { INT32 count = 0; INT32 p_dispy = chaty - charheight -1; @@ -2051,38 +1929,38 @@ static void HU_DrawChat(void) { // filter: (code needs optimization pls help I'm bad with C) - if (w_chat[3]) + if (w_chat_buf[3]) { char *nodenum; UINT32 n; - // right, that's half important: (w_chat[4] may be a space since /pm0 msg is perfectly acceptable!) - if ( ( ((w_chat[3] != 0) && ((w_chat[3] < '0') || (w_chat[3] > '9'))) || ((w_chat[4] != 0) && (((w_chat[4] < '0') || (w_chat[4] > '9'))))) && (w_chat[4] != ' ')) + // right, that's half important: (w_chat_buf[4] may be a space since /pm0 msg is perfectly acceptable!) + if ( ( ((w_chat_buf[3] != 0) && ((w_chat_buf[3] < '0') || (w_chat_buf[3] > '9'))) || ((w_chat_buf[4] != 0) && (((w_chat_buf[4] < '0') || (w_chat_buf[4] > '9'))))) && (w_chat_buf[4] != ' ')) break; nodenum = (char*) malloc(3); - memcpy(nodenum, w_chat+3, 2); + memcpy(nodenum, w_chat_buf+3, 2); nodenum[2] = '\0'; n = atoi((const char*) nodenum); // turn that into a number free(nodenum); // special cases: - if ((n == 0) && !(w_chat[4] == '0')) + if ((n == 0) && !(w_chat_buf[4] == '0')) { if (!(i<10)) continue; } - else if ((n == 1) && !(w_chat[3] == '0')) + else if ((n == 1) && !(w_chat_buf[3] == '0')) { if (!((i == 1) || ((i >= 10) && (i <= 19)))) continue; } - else if ((n == 2) && !(w_chat[3] == '0')) + else if ((n == 2) && !(w_chat_buf[3] == '0')) { if (!((i == 2) || ((i >= 20) && (i <= 29)))) continue; } - else if ((n == 3) && !(w_chat[3] == '0')) + else if ((n == 3) && !(w_chat_buf[3] == '0')) { if (!((i == 3) || ((i >= 30) && (i <= 31)))) continue; @@ -2121,6 +1999,7 @@ static void HU_DrawChat_Old(void) size_t i = 0; const char *ntalk = "Say: ", *ttalk = "Say-Team: "; const char *talk = ntalk; + size_t select_start = 0, select_end = 0; INT32 charwidth = 8 * con_scalefactor; //SHORT(hu_font['A'-HU_FONTSTART]->width) * con_scalefactor; INT32 charheight = 8 * con_scalefactor; //SHORT(hu_font['A'-HU_FONTSTART]->height) * con_scalefactor; if (teamtalk) @@ -2149,14 +2028,19 @@ static void HU_DrawChat_Old(void) c += charwidth; } - if ((strlen(w_chat) == 0 || c_input == 0) && hu_tick < 4) - V_DrawCharacter(HU_INPUTX+c, y+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, !cv_allcaps.value); + if ((w_chat.cursor == 0 || w_chat.length == 0) && hu_tick < 4) + V_DrawCharacter(HU_INPUTX+c+charwidth*w_chat.cursor, y+2*con_scalefactor, '_'|cv_constextsize.value|V_NOSCALESTART|t, !cv_allcaps.value); + + if (w_chat.select != w_chat.cursor) + { + select_start = min(w_chat.select, w_chat.cursor); + select_end = max(w_chat.select, w_chat.cursor); + } i = 0; - while (w_chat[i]) + while (w_chat_buf[i]) { - - if (c_input == (i+1) && hu_tick < 4) + if (w_chat.cursor == (i+1) && hu_tick < 4) { INT32 cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down. INT32 cursory = (cursorx != HU_INPUTX) ? (y) : (y+charheight); @@ -2164,17 +2048,18 @@ static void HU_DrawChat_Old(void) } //Hurdler: isn't it better like that? - if (w_chat[i] < HU_FONTSTART) - { - ++i; - //charwidth = 4 * con_scalefactor; - } - else + if (w_chat_buf[i] >= HU_FONTSTART) { //charwidth = SHORT(hu_font[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; - V_DrawCharacter(HU_INPUTX + c, y, w_chat[i++] | cv_constextsize.value | V_NOSCALESTART | t, !cv_allcaps.value); + V_DrawCharacter(HU_INPUTX + c, y, w_chat_buf[i] | cv_constextsize.value | V_NOSCALESTART | t, !cv_allcaps.value); } + // Draw selection + if (i >= select_start && i < select_end) + V_DrawFill(HU_INPUTX + c, y, charwidth, charheight, 103|V_TRANSLUCENT|cv_constextsize.value|V_NOSCALESTART|t); + + ++i; + c += charwidth; if (c >= vid.width) { From f051e33a0c34cc0ac3ca3e9b2058826d9677ce3b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 23:00:25 +0200 Subject: [PATCH 075/166] cv_showdirectorhud didnt save Zzz... --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index c2e2c6fe1..46a2a2ba7 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -569,7 +569,7 @@ consvar_t cv_ps_descriptor = {"ps_descriptor", "Average", 0, ps_descriptor_cons_ consvar_t cv_director = {"director", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_kartdebugdirector = {"debugdirector", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showdirectorhud = {"showdirectorhud", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showdirectorhud = {"showdirectorhud", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_showtrackaddon = {"showtrackaddon", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; From b24caf397aa6d4f95522e458d34dc201871d57ca Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 14:49:37 +0200 Subject: [PATCH 076/166] add "map ?" shortcut for random map --- src/g_game.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/g_game.c b/src/g_game.c index 7906d10a9..f6b7d562c 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4621,6 +4621,8 @@ INT32 G_FindMapByNameOrCode(const char *mapname, char **realmapnamep) { if (mapname[0] == '*') // current map return gamemap; + else if (mapname[0] == '?') + return G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, false, NULL); else if (mapname[0] == '+' && mapheaderinfo[gamemap-1]) // next map { newmapnum = mapheaderinfo[gamemap-1]->nextlevel; From 0deff73a460c89431566e1b931fb482df7d62a1a Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 05:17:44 +0200 Subject: [PATCH 077/166] make a function for the music level start stuff --- src/k_kart.c | 10 ++-------- src/p_user.c | 5 +---- src/s_sound.c | 23 +++++++++++++++++++---- src/s_sound.h | 1 + 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 44497b0f2..fcb373782 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5361,11 +5361,8 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) K_UpdateInvincibilitySounds(player); // Also thanks, VAda! // Plays the music after the starting countdown. - if (P_IsLocalPlayer(player) && leveltime == (starttime + (TICRATE/2))) - { - S_ChangeMusic(mapmusname, mapmusflags, true); - S_ShowMusicCredit(); - } + if (P_IsLocalPlayer(player)) + M_Start(); } void K_KartPlayerAfterThink(player_t *player) @@ -6553,10 +6550,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) if ((leveltime == starttime-(3*TICRATE)) || (leveltime == starttime-(2*TICRATE)) || (leveltime == starttime-TICRATE)) S_StartSound(NULL, sfx_s3ka7); if (leveltime == starttime) - { S_StartSound(NULL, sfx_s3kad); - S_StopMusic(); // The GO! sound stops the level start ambience - } } // Start charging once you're given the opportunity. diff --git a/src/p_user.c b/src/p_user.c index a9b1b6b72..a6e4791e6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -742,10 +742,7 @@ void P_RestoreMusic(player_t *player) if (P_EndingMusic(player)) return; - // Event - Level Start - if (leveltime < (starttime + (TICRATE/2))) - S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); - else // see also where time overs are handled - search for "lives = 2" in this file + if (leveltime > (starttime + (TICRATE/2))) { INT32 wantedmus = 0; // 0 is level music, 1 is invincibility, 2 is grow diff --git a/src/s_sound.c b/src/s_sound.c index ec5ebf00d..855026111 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2169,13 +2169,28 @@ void S_Start(void) mapmusresume = 0; } - //if (cv_resetmusic.value) // Starting ambience should always be restarted - S_StopMusic(); + S_StopMusic(); if (leveltime < (starttime + (TICRATE/2))) // SRB2Kart - S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); - else + S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); + //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); +} + +void M_Start(void) +{ + if (leveltime > (starttime + (TICRATE/2))) + return; + + // The GO! sound stops the level start ambience + if (leveltime == starttime) + S_StopMusic(); + + // Plays the music after the starting countdown. + if (leveltime == (starttime + (TICRATE/2))) + { S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); + S_ShowMusicCredit(); + } } void S_RestartMusic(void) diff --git a/src/s_sound.h b/src/s_sound.h index 6f4d03f09..75c59dbc8 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -101,6 +101,7 @@ void S_InitSfxChannels(INT32 sfxVolume); void S_StopSounds(void); void S_ClearSfx(void); void S_Start(void); +void M_Start(void); // Stops music and restarts it from same position. Used for instant applying changes to amiga filters. void S_RestartMusic(void); From 0d150e4b08c1a923cc290f1f91e831a016708d9d Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 06:28:02 +0200 Subject: [PATCH 078/166] add some basics of what i wanna have for music stuff - basic keepmusic implementation (currently checks for if the song changes instead of the map, idk if i keep this, since this allows certain maps to change the music on start, ex abstract avenue or wandering balls) - Toggle to ignore any kind of music change during the level (includes intermission music, depends on how custom intermission music works) -toggle to start map music instantly on levelload and skip the intro fanfare (also skips any linedef executed sound so some map intros dont interfere with this) --- src/p_spec.c | 7 +++++++ src/p_user.c | 3 +++ src/s_sound.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 7066058fa..0fbd16ee4 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2127,6 +2127,9 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 413: // Change music + //if (ignoremusicchanges) + //return; + // console player only unless NOCLIMB is set if ((line->flags & ML_NOCLIMB) || (mo && mo->player && P_IsLocalPlayer(mo->player))) { @@ -2209,6 +2212,10 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { INT32 sfxnum; + //dont play any funky sound intros that may interfere with the music + //if (cv_skipintromusic.value && (leveltime < (starttime + (TICRATE/2)))) + //return; + sfxnum = sides[line->sidenum[0]].toptexture; //P_AproxDistance(line->dx, line->dy)>>FRACBITS; if (sfxnum == sfx_None) diff --git a/src/p_user.c b/src/p_user.c index a6e4791e6..f5de9b704 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -650,6 +650,9 @@ boolean P_EndingMusic(player_t *player) INT32 bestlocalpos; player_t *bestlocalplayer; + //if (!ignoremusicchanges) + //return false; + if (!P_IsLocalPlayer(player)) // Only applies to a local player return false; diff --git a/src/s_sound.c b/src/s_sound.c index 855026111..a7845ce24 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2149,6 +2149,28 @@ boolean S_FadeOutStopMusic(UINT32 ms) return I_FadeSong(0, ms, &S_StopMusic); } + +static boolean S_KeepMusic(const char *mapmusicname) +{ + //if (!cv_keepmusic.value) + //return false; + + // should i compare songs or maps? + // comparing songs makes this alot easier honestly + static char oldmusname[7] = ""; + + if (strcmp(music_name, mapmusicname) != 0) + return false; + + if (strcmp(oldmusname, mapmusicname) == 0) + return true; + + strncpy(oldmusname, mapmusicname, 7); + oldmusname[6] = '\0'; + + return false; +} + /// ------------------------ /// Init & Others /// ------------------------ @@ -2169,6 +2191,16 @@ void S_Start(void) mapmusresume = 0; } + if (S_KeepMusic(mapmusname)) + return; + + /*if (cv_skipintromusic.value) + { + S_StopMusic(); + S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); + return; + }*/ + S_StopMusic(); if (leveltime < (starttime + (TICRATE/2))) // SRB2Kart @@ -2178,7 +2210,21 @@ void S_Start(void) void M_Start(void) { - if (leveltime > (starttime + (TICRATE/2))) + // need to be after race starts so "certain" maps don´t break Zzz... + //ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); + + //no need to constantly run this after race has started + //but let it run atleast half a tic after map music started to let shit update lmao + if (leveltime > (starttime + TICRATE)) + return; + + /*if (cv_skipintromusic.value && leveltime == (starttime + (TICRATE/2))) + { + S_ShowMusicCredit(); + return; + }*/ + + if (S_KeepMusic(mapmusname)) return; // The GO! sound stops the level start ambience @@ -2193,6 +2239,7 @@ void M_Start(void) } } + void S_RestartMusic(void) { S_StopMusic(); From e958e43b4976092932c2b1f85476ac2152ab5d52 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 06:31:43 +0200 Subject: [PATCH 079/166] update comments a little --- src/s_sound.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index a7845ce24..829a6a6da 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2156,7 +2156,6 @@ static boolean S_KeepMusic(const char *mapmusicname) //return false; // should i compare songs or maps? - // comparing songs makes this alot easier honestly static char oldmusname[7] = ""; if (strcmp(music_name, mapmusicname) != 0) @@ -2201,6 +2200,8 @@ void S_Start(void) return; }*/ + // Starting ambience should always be restarted + // lug: but not when we keep the map music lol S_StopMusic(); if (leveltime < (starttime + (TICRATE/2))) // SRB2Kart From 07f9756bc83466d3163aa94c4a635532e8a4e91c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 06:38:29 +0200 Subject: [PATCH 080/166] forgor about encore music --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 0fbd16ee4..8c1e9b5da 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2127,7 +2127,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 413: // Change music - //if (ignoremusicchanges) + //if (ignoremusicchanges && (leveltime < (starttime + (TICRATE/2)))) //why check for starttime? cause encore music Zzz... //return; // console player only unless NOCLIMB is set From 42d957e21bcc876845d5887ce614647bd65db84c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 11:45:33 +0200 Subject: [PATCH 081/166] change how keepmusic works compare map and encore instead of the music itself --- src/g_game.c | 1 + src/s_sound.c | 47 ++++++++++++++++++++++++++++++++++++++++------- src/s_sound.h | 2 ++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index f6b7d562c..d4d358431 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4368,6 +4368,7 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool else { LUAh_MapChange(gamemap); + S_KeepMusic(); G_DoLoadLevel(resetplayer); } diff --git a/src/s_sound.c b/src/s_sound.c index 829a6a6da..169dee2a0 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2149,8 +2149,7 @@ boolean S_FadeOutStopMusic(UINT32 ms) return I_FadeSong(0, ms, &S_StopMusic); } - -static boolean S_KeepMusic(const char *mapmusicname) +/*static boolean S_KeepMusic(void) { //if (!cv_keepmusic.value) //return false; @@ -2158,16 +2157,50 @@ static boolean S_KeepMusic(const char *mapmusicname) // should i compare songs or maps? static char oldmusname[7] = ""; - if (strcmp(music_name, mapmusicname) != 0) + if (strcmp(music_name, mapmusname) != 0) return false; - if (strcmp(oldmusname, mapmusicname) == 0) + if (strcmp(oldmusname, mapmusname) == 0) return true; - strncpy(oldmusname, mapmusicname, 7); + strncpy(oldmusname, mapmusname, 7); oldmusname[6] = '\0'; return false; +}*/ + +static INT16 oldmap = 0; +static INT32 oldencore = 0; +static boolean keepmusic = false; + +void S_KeepMusic(void) +{ + //if (!cv_keepmusic.value) + //return false; + + //this one compares map and encoremode instead of the music itself + //makes tunes work and stuff + + keepmusic = false; + + //dont keep the intro "sound" lmao + if (strcmp(music_name, (encoremode ? "estart" : "kstart")) == 0) + return; + + if (oldencore != cv_kartencore.value) + { + oldencore = cv_kartencore.value; + return; + } + + // we on the same map? keep it + if (oldmap == gamemap) + { + keepmusic = true; + return; + } + + oldmap = gamemap; } /// ------------------------ @@ -2190,7 +2223,7 @@ void S_Start(void) mapmusresume = 0; } - if (S_KeepMusic(mapmusname)) + if (keepmusic) return; /*if (cv_skipintromusic.value) @@ -2225,7 +2258,7 @@ void M_Start(void) return; }*/ - if (S_KeepMusic(mapmusname)) + if (keepmusic) return; // The GO! sound stops the level start ambience diff --git a/src/s_sound.h b/src/s_sound.h index 75c59dbc8..687054ee1 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -103,6 +103,8 @@ void S_ClearSfx(void); void S_Start(void); void M_Start(void); +void S_KeepMusic(void); + // Stops music and restarts it from same position. Used for instant applying changes to amiga filters. void S_RestartMusic(void); From f363663b3ebbe8c7a752cfcd4324f000611d851a Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 12:50:49 +0200 Subject: [PATCH 082/166] fix up everything and make stuff work i hope lmao --- src/p_spec.c | 16 +++++++++--- src/p_user.c | 4 +-- src/s_sound.c | 69 +++++++++++++++++++++++++-------------------------- src/s_sound.h | 7 ++++++ 4 files changed, 55 insertions(+), 41 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 8c1e9b5da..762540622 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -99,6 +99,8 @@ typedef struct thinker_t **thinkers; } thinkerlist_t; +static boolean fromlapexec = false; + static void P_SearchForDisableLinedefs(void); static void P_SpawnScrollers(void); static void P_SpawnFriction(void); @@ -1340,6 +1342,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller fixed_t dist = P_AproxDistance(triggerline->dx, triggerline->dy)>>FRACBITS; size_t i, linecnt, sectori; INT16 specialtype = triggerline->special; + fromlapexec = false; ///////////////////////////////////////////////// // Distance-checking/sector trigger conditions // @@ -1461,6 +1464,8 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller if (lap != (sides[triggerline->sidenum[0]].textureoffset >> FRACBITS)) return false; } + + fromlapexec = true; } // If we were not triggered by a sector type especially for the purpose, // a Linedef Executor linedef trigger is not handling sector triggers properly, return. @@ -2127,8 +2132,11 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 413: // Change music - //if (ignoremusicchanges && (leveltime < (starttime + (TICRATE/2)))) //why check for starttime? cause encore music Zzz... - //return; + if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... + return; + + if (ignoremusicchanges && !fromlapexec) // keep lap music intanct tho + return; // console player only unless NOCLIMB is set if ((line->flags & ML_NOCLIMB) || (mo && mo->player && P_IsLocalPlayer(mo->player))) @@ -2213,8 +2221,8 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 sfxnum; //dont play any funky sound intros that may interfere with the music - //if (cv_skipintromusic.value && (leveltime < (starttime + (TICRATE/2)))) - //return; + if (cv_skipintromusic.value && (leveltime < (starttime + (TICRATE/2)))) + return; sfxnum = sides[line->sidenum[0]].toptexture; //P_AproxDistance(line->dx, line->dy)>>FRACBITS; diff --git a/src/p_user.c b/src/p_user.c index f5de9b704..093143e95 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -650,8 +650,8 @@ boolean P_EndingMusic(player_t *player) INT32 bestlocalpos; player_t *bestlocalplayer; - //if (!ignoremusicchanges) - //return false; + if (ignoremusicchanges) + return false; if (!P_IsLocalPlayer(player)) // Only applies to a local player return false; diff --git a/src/s_sound.c b/src/s_sound.c index 169dee2a0..0380a2788 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -117,6 +117,14 @@ consvar_t cv_resume = {"resume", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0 consvar_t cv_fading = {"fading", "Off", CV_SAVE|CV_CALL, CV_OnOff, Bird_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_birdmusic = {"birdmusicstuff", "No", CV_SAVE|CV_CALL, CV_YesNo, Bird_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_keepmusic = {"keepmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_skipintromusic = {"skipintromusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +boolean ignoremusicchanges = false; +boolean keepmusic = false; + #ifdef HAVE_OPENMPT openmpt_module *openmpt_mhandle = NULL; @@ -294,6 +302,10 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_fading); CV_RegisterVar(&cv_birdmusic); + CV_RegisterVar(&cv_keepmusic); + CV_RegisterVar(&cv_skipintromusic); + CV_RegisterVar(&cv_ignoremusicchanges); + COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); COM_AddCommand("restartmusic", Command_RestartMusic_f); @@ -2170,36 +2182,21 @@ boolean S_FadeOutStopMusic(UINT32 ms) }*/ static INT16 oldmap = 0; -static INT32 oldencore = 0; -static boolean keepmusic = false; +static boolean oldencore = 0; void S_KeepMusic(void) { - //if (!cv_keepmusic.value) - //return false; + if (!cv_keepmusic.value) + { + keepmusic = false; + return; + } //this one compares map and encoremode instead of the music itself //makes tunes work and stuff + keepmusic = (strcmp(music_name, (encoremode ? "estart" : "kstart")) != 0 && oldmap == gamemap && oldencore == encoremode); // we on the same map and intro sound aint playin? keep it - keepmusic = false; - - //dont keep the intro "sound" lmao - if (strcmp(music_name, (encoremode ? "estart" : "kstart")) == 0) - return; - - if (oldencore != cv_kartencore.value) - { - oldencore = cv_kartencore.value; - return; - } - - // we on the same map? keep it - if (oldmap == gamemap) - { - keepmusic = true; - return; - } - + oldencore = encoremode; oldmap = gamemap; } @@ -2226,18 +2223,18 @@ void S_Start(void) if (keepmusic) return; - /*if (cv_skipintromusic.value) + if (cv_skipintromusic.value) { S_StopMusic(); S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); return; - }*/ + } // Starting ambience should always be restarted // lug: but not when we keep the map music lol S_StopMusic(); - if (leveltime < (starttime + (TICRATE/2))) // SRB2Kart + if (leveltime < starttime) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); } @@ -2245,28 +2242,30 @@ void S_Start(void) void M_Start(void) { // need to be after race starts so "certain" maps don´t break Zzz... - //ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); + ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); //no need to constantly run this after race has started //but let it run atleast half a tic after map music started to let shit update lmao if (leveltime > (starttime + TICRATE)) return; - /*if (cv_skipintromusic.value && leveltime == (starttime + (TICRATE/2))) - { - S_ShowMusicCredit(); - return; - }*/ - if (keepmusic) return; + if (cv_skipintromusic.value) + { + if (leveltime == (starttime + (TICRATE/2))) + S_ShowMusicCredit(); + return; + } + // The GO! sound stops the level start ambience if (leveltime == starttime) S_StopMusic(); - + else if (leveltime < starttime) // SRB2Kart + S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); // Plays the music after the starting countdown. - if (leveltime == (starttime + (TICRATE/2))) + else if (leveltime == (starttime + (TICRATE/2))) { S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); S_ShowMusicCredit(); diff --git a/src/s_sound.h b/src/s_sound.h index 687054ee1..2367d7729 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -67,6 +67,13 @@ extern consvar_t cv_resume; extern consvar_t cv_fading; extern consvar_t cv_birdmusic; +extern consvar_t cv_keepmusic; +extern consvar_t cv_skipintromusic; +extern consvar_t cv_ignoremusicchanges; + +extern boolean ignoremusicchanges; +extern boolean keepmusic; + extern consvar_t precachesound; typedef enum From b4b206f57565954f4bbd2b3074fe5c007d11cb56 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 13:05:44 +0200 Subject: [PATCH 083/166] encoremusic... --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 762540622..decea017d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2135,7 +2135,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... return; - if (ignoremusicchanges && !fromlapexec) // keep lap music intanct tho + if (ignoremusicchanges && (leveltime < (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho return; // console player only unless NOCLIMB is set From 7fa21e9aeaee811a8b6b11a0943448ef2fd3c566 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 15:41:19 +0200 Subject: [PATCH 084/166] work around custom vote theme music + rename a bunch of stuff please help me --- src/g_game.c | 2 +- src/k_kart.c | 4 ++-- src/p_setup.c | 2 +- src/p_spec.c | 6 +++--- src/s_sound.c | 60 +++++++++++++++++++++++++++++++++++++++++---------- src/s_sound.h | 7 +++--- 6 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index d4d358431..29e65a002 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4368,7 +4368,7 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool else { LUAh_MapChange(gamemap); - S_KeepMusic(); + S_CheckMap(); G_DoLoadLevel(resetplayer); } diff --git a/src/k_kart.c b/src/k_kart.c index fcb373782..1a586943f 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5360,9 +5360,9 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) // Handle invincibility sfx K_UpdateInvincibilitySounds(player); // Also thanks, VAda! - // Plays the music after the starting countdown. + // Plays the music during and after the starting countdown. if (P_IsLocalPlayer(player)) - M_Start(); + S_StartMapMusic(); } void K_KartPlayerAfterThink(player_t *player) diff --git a/src/p_setup.c b/src/p_setup.c index 17d050dc4..672b1b347 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2683,7 +2683,7 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) // As oddly named as this is, this handles music only. // We should be fine starting it here. if (!reloadinggamestate) - S_Start(); + S_InitMapMusic(); levelfadecol = (encoremode && !ranspecialwipe ? 122 : 120); diff --git a/src/p_spec.c b/src/p_spec.c index decea017d..058fe9413 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2118,12 +2118,12 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) return; if (bot) - P_Teleport(bot, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, (line->flags & ML_BLOCKMONSTERS) == 0, (line->flags & ML_EFFECT4) == ML_EFFECT4); + P_Teleport(bot, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, (line->flags & ML_BLOCKMONSTERS) == 0, (line->flags & ML_EFFECT4) == ML_EFFECT4); if (line->flags & ML_BLOCKMONSTERS) - P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, false, (line->flags & ML_EFFECT4) == ML_EFFECT4); + P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, false, (line->flags & ML_EFFECT4) == ML_EFFECT4); else { - P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, true, (line->flags & ML_EFFECT4) == ML_EFFECT4); + P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, true, (line->flags & ML_EFFECT4) == ML_EFFECT4); // Play the 'bowrwoosh!' sound S_StartSound(dest, sfx_mixup); } diff --git a/src/s_sound.c b/src/s_sound.c index 0380a2788..f8b0619eb 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -11,6 +11,7 @@ /// \file s_sound.c /// \brief System-independent sound and music routines +#include "d_netcmd.h" #include "doomdef.h" #include "doomstat.h" #include "command.h" @@ -124,6 +125,7 @@ consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo boolean ignoremusicchanges = false; boolean keepmusic = false; +static void S_CheckEventMus(const char *newmus); #ifdef HAVE_OPENMPT openmpt_module *openmpt_mhandle = NULL; @@ -1973,6 +1975,8 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 strncpy(newmusic, mmusic, 6); + S_CheckEventMus(newmusic); + if (LUAh_MusicChange(music_name, newmusic, &mflags, &looping, &position, &prefadems, &fadeinms)) return; @@ -2161,6 +2165,10 @@ boolean S_FadeOutStopMusic(UINT32 ms) return I_FadeSong(0, ms, &S_StopMusic); } +/// ------------------------ +/// Init & Others +/// ------------------------ + /*static boolean S_KeepMusic(void) { //if (!cv_keepmusic.value) @@ -2183,8 +2191,45 @@ boolean S_FadeOutStopMusic(UINT32 ms) static INT16 oldmap = 0; static boolean oldencore = 0; +static boolean skipmusic = false; -void S_KeepMusic(void) +static const char *musicexception_list[16] = { + "vote", "voteea", "voteeb", "racent", "krwin", + "krok", "krlose", "krfail", "kbwin", "kbok", + "kblose", "kstart", "estart", "wait2j", "CHRSHP", + "CHRSHF" +}; + +//checks for any kind of event music like intermission, vote etc. +//always runs when musicchange gets invoked +static void S_CheckEventMus(const char *newmus) +{ + //if (leveltime > (starttime + (TICRATE/2))) + //return; + + skipmusic = false; + + if (!cv_keepmusic.value) + { + return; + } + + //this one compares map and encoremode instead of the music itself + //makes tunes work and stuff + for (int i = 0; i < 16; i++) + if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) + { + skipmusic = true; + break; + } + + //CONS_Printf("musname = %s\n", music_name); + //CONS_Printf("newmus = %s\n", newmus); + //CONS_Printf("newmus = %d\n", skipmusic); +} + +//check if map and encoremode has changed +void S_CheckMap(void) { if (!cv_keepmusic.value) { @@ -2192,24 +2237,18 @@ void S_KeepMusic(void) return; } - //this one compares map and encoremode instead of the music itself - //makes tunes work and stuff - keepmusic = (strcmp(music_name, (encoremode ? "estart" : "kstart")) != 0 && oldmap == gamemap && oldencore == encoremode); // we on the same map and intro sound aint playin? keep it + keepmusic = (!skipmusic && oldmap == gamemap && oldencore == encoremode); oldencore = encoremode; oldmap = gamemap; } -/// ------------------------ -/// Init & Others -/// ------------------------ - // // Per level startup code. // Kills playing sounds at start of level, // determines music if any, changes music. // -void S_Start(void) +void S_InitMapMusic(void) { if (mapmusflags & MUSIC_RELOADRESET) { @@ -2239,7 +2278,7 @@ void S_Start(void) //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); } -void M_Start(void) +void S_StartMapMusic(void) { // need to be after race starts so "certain" maps don´t break Zzz... ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); @@ -2272,7 +2311,6 @@ void M_Start(void) } } - void S_RestartMusic(void) { S_StopMusic(); diff --git a/src/s_sound.h b/src/s_sound.h index 2367d7729..0c576bfc1 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -107,10 +107,11 @@ void S_InitSfxChannels(INT32 sfxVolume); // void S_StopSounds(void); void S_ClearSfx(void); -void S_Start(void); -void M_Start(void); -void S_KeepMusic(void); +void S_InitMapMusic(void); +void S_StartMapMusic(void); + +void S_CheckMap(void); // Stops music and restarts it from same position. Used for instant applying changes to amiga filters. void S_RestartMusic(void); From 2ee29630fb3b30868ee73a3e63bdf0c827e094f4 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 16:19:54 +0200 Subject: [PATCH 085/166] fix encore music again lol --- src/p_spec.c | 2 +- src/p_user.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 058fe9413..f09562f4d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2135,7 +2135,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... return; - if (ignoremusicchanges && (leveltime < (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho + if (ignoremusicchanges && (leveltime > (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho return; // console player only unless NOCLIMB is set diff --git a/src/p_user.c b/src/p_user.c index 093143e95..a6e4791e6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -650,9 +650,6 @@ boolean P_EndingMusic(player_t *player) INT32 bestlocalpos; player_t *bestlocalplayer; - if (ignoremusicchanges) - return false; - if (!P_IsLocalPlayer(player)) // Only applies to a local player return false; From 67435ebf9ee9384abacc53c5c4d7fccf6f851f0b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 16:27:56 +0200 Subject: [PATCH 086/166] work around encore music again S_InitMapMusic would play before the level actually started thus playing a smol bit of non encore music in encore --- src/s_sound.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index f8b0619eb..2970bce63 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2262,17 +2262,13 @@ void S_InitMapMusic(void) if (keepmusic) return; - if (cv_skipintromusic.value) - { - S_StopMusic(); - S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); - return; - } - // Starting ambience should always be restarted // lug: but not when we keep the map music lol S_StopMusic(); + if (cv_skipintromusic.value) + return; + if (leveltime < starttime) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); @@ -2293,6 +2289,8 @@ void S_StartMapMusic(void) if (cv_skipintromusic.value) { + if (leveltime == 0) + S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); if (leveltime == (starttime + (TICRATE/2))) S_ShowMusicCredit(); return; From d06b8ac398d7fad39f9175ece8b79ca54e1925d6 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 16:32:03 +0200 Subject: [PATCH 087/166] cleanup + comments --- src/p_spec.c | 2 +- src/s_sound.c | 23 +++++++---------------- src/s_sound.h | 2 -- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index f09562f4d..e7d937a91 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2135,7 +2135,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... return; - if (ignoremusicchanges && (leveltime > (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho + if (cv_ignoremusicchanges.value && (leveltime > (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho return; // console player only unless NOCLIMB is set diff --git a/src/s_sound.c b/src/s_sound.c index 2970bce63..4ac8a9860 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -123,7 +123,6 @@ consvar_t cv_keepmusic = {"keepmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, N consvar_t cv_skipintromusic = {"skipintromusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -boolean ignoremusicchanges = false; boolean keepmusic = false; static void S_CheckEventMus(const char *newmus); @@ -2204,9 +2203,6 @@ static const char *musicexception_list[16] = { //always runs when musicchange gets invoked static void S_CheckEventMus(const char *newmus) { - //if (leveltime > (starttime + (TICRATE/2))) - //return; - skipmusic = false; if (!cv_keepmusic.value) @@ -2214,8 +2210,7 @@ static void S_CheckEventMus(const char *newmus) return; } - //this one compares map and encoremode instead of the music itself - //makes tunes work and stuff + for (int i = 0; i < 16; i++) if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) { @@ -2228,7 +2223,8 @@ static void S_CheckEventMus(const char *newmus) //CONS_Printf("newmus = %d\n", skipmusic); } -//check if map and encoremode has changed +//this one compares map and encoremode instead of the music itself +//makes tunes work and stuff void S_CheckMap(void) { if (!cv_keepmusic.value) @@ -2276,9 +2272,6 @@ void S_InitMapMusic(void) void S_StartMapMusic(void) { - // need to be after race starts so "certain" maps don´t break Zzz... - ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); - //no need to constantly run this after race has started //but let it run atleast half a tic after map music started to let shit update lmao if (leveltime > (starttime + TICRATE)) @@ -2289,20 +2282,18 @@ void S_StartMapMusic(void) if (cv_skipintromusic.value) { - if (leveltime == 0) + if (leveltime == 0) // dumb but i dont need this to be spammed honestly S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); if (leveltime == (starttime + (TICRATE/2))) S_ShowMusicCredit(); return; } - // The GO! sound stops the level start ambience - if (leveltime == starttime) + if (leveltime == starttime) // The GO! sound stops the level start ambience S_StopMusic(); else if (leveltime < starttime) // SRB2Kart - S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); - // Plays the music after the starting countdown. - else if (leveltime == (starttime + (TICRATE/2))) + S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); // yes this will be spammed otherwise encore and some stuff WILL overwrite it + else if (leveltime == (starttime + (TICRATE/2))) // Plays the music after the starting countdown. { S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); S_ShowMusicCredit(); diff --git a/src/s_sound.h b/src/s_sound.h index 0c576bfc1..9d53cc357 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -70,8 +70,6 @@ extern consvar_t cv_birdmusic; extern consvar_t cv_keepmusic; extern consvar_t cv_skipintromusic; extern consvar_t cv_ignoremusicchanges; - -extern boolean ignoremusicchanges; extern boolean keepmusic; extern consvar_t precachesound; From 6b0d67ac36746398f4d840607598fd12429a5404 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 16:33:29 +0200 Subject: [PATCH 088/166] more --- src/s_sound.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 4ac8a9860..33767a885 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2210,9 +2210,8 @@ static void S_CheckEventMus(const char *newmus) return; } - for (int i = 0; i < 16; i++) - if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) + if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) // weird? sure! but were lucky enough newmus reflects whats being replaced { skipmusic = true; break; From 3a951576ee498641a0b46e3193e298984c88ada9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 14:42:20 +0200 Subject: [PATCH 089/166] use stricmp for this --- src/s_sound.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 33767a885..0eedb57ec 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2206,12 +2206,10 @@ static void S_CheckEventMus(const char *newmus) skipmusic = false; if (!cv_keepmusic.value) - { return; - } for (int i = 0; i < 16; i++) - if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) // weird? sure! but were lucky enough newmus reflects whats being replaced + if (stricmp(music_name, musicexception_list[i]) == 0 || stricmp(newmus, musicexception_list[i]) == 0) // weird? sure! but were lucky enough newmus reflects whats being replaced { skipmusic = true; break; From 3db6770dfdd650f796f8f46b836067512ce5fa30 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 16:24:14 +0300 Subject: [PATCH 090/166] Fix IT_CV_STRING crashing game in M_DrawGenericMenu --- src/m_menu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index cc8bf39a6..30d0ee0b2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5151,10 +5151,12 @@ static void M_DrawGenericMenu(void) break; case IT_CV_STRING: M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, menuinput.buffer); - if (skullAnimCounter < 4 && i == itemOn) - V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, - '_' | 0x80, false); + + if (itemOn == i) + M_DrawTextInput(x + 8, y + 12, &menuinput, 0); + else + V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); + y += 16; break; default: From 9abf2bca75bd5f938f7de44aaa1ee1bbd21e57b7 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 15:46:09 +0200 Subject: [PATCH 091/166] fix some stuff --- src/p_spec.c | 6 +++--- src/p_user.c | 4 +++- src/s_sound.c | 17 ++++++++--------- src/s_sound.h | 1 + 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index e7d937a91..6146f422a 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2132,10 +2132,10 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 413: // Change music - if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... + if (keepmusic && (leveltime <= MUSICSTARTTIME)) //why check for starttime? cause encore music Zzz... return; - if (cv_ignoremusicchanges.value && (leveltime > (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho + if (cv_ignoremusicchanges.value && (leveltime >= MUSICSTARTTIME) && !fromlapexec) // keep lap music intanct tho return; // console player only unless NOCLIMB is set @@ -2221,7 +2221,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 sfxnum; //dont play any funky sound intros that may interfere with the music - if (cv_skipintromusic.value && (leveltime < (starttime + (TICRATE/2)))) + if (cv_skipintromusic.value && (leveltime < MUSICSTARTTIME)) return; sfxnum = sides[line->sidenum[0]].toptexture; //P_AproxDistance(line->dx, line->dy)>>FRACBITS; diff --git a/src/p_user.c b/src/p_user.c index a6e4791e6..ac1537eb0 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -742,7 +742,9 @@ void P_RestoreMusic(player_t *player) if (P_EndingMusic(player)) return; - if (leveltime > (starttime + (TICRATE/2))) + if (leveltime < MUSICSTARTTIME) + S_StartMapMusic(); + else // see also where time overs are handled - search for "lives = 2" in this file { INT32 wantedmus = 0; // 0 is level music, 1 is invincibility, 2 is grow diff --git a/src/s_sound.c b/src/s_sound.c index 0eedb57ec..7aab19db9 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2262,7 +2262,7 @@ void S_InitMapMusic(void) if (cv_skipintromusic.value) return; - if (leveltime < starttime) // SRB2Kart + if (leveltime < MUSICSTARTTIME) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); } @@ -2270,8 +2270,7 @@ void S_InitMapMusic(void) void S_StartMapMusic(void) { //no need to constantly run this after race has started - //but let it run atleast half a tic after map music started to let shit update lmao - if (leveltime > (starttime + TICRATE)) + if (leveltime > MUSICSTARTTIME) return; if (keepmusic) @@ -2279,18 +2278,18 @@ void S_StartMapMusic(void) if (cv_skipintromusic.value) { - if (leveltime == 0) // dumb but i dont need this to be spammed honestly + if (leveltime < starttime) // dumb but i dont need this to be spammed honestly S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); - if (leveltime == (starttime + (TICRATE/2))) + if (leveltime == MUSICSTARTTIME) S_ShowMusicCredit(); return; } - if (leveltime == starttime) // The GO! sound stops the level start ambience - S_StopMusic(); - else if (leveltime < starttime) // SRB2Kart + if (leveltime < starttime) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); // yes this will be spammed otherwise encore and some stuff WILL overwrite it - else if (leveltime == (starttime + (TICRATE/2))) // Plays the music after the starting countdown. + else if (leveltime == starttime) // The GO! sound stops the level start ambience + S_StopMusic(); + else if (leveltime == MUSICSTARTTIME) // Plays the music after the starting countdown. { S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); S_ShowMusicCredit(); diff --git a/src/s_sound.h b/src/s_sound.h index 9d53cc357..39b61b49d 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -71,6 +71,7 @@ extern consvar_t cv_keepmusic; extern consvar_t cv_skipintromusic; extern consvar_t cv_ignoremusicchanges; extern boolean keepmusic; +#define MUSICSTARTTIME (starttime + (TICRATE/2)) extern consvar_t precachesound; From a90ffff320a109a9fecae6f2f31502d50d65c5c0 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 16:49:59 +0300 Subject: [PATCH 092/166] Fix (hopefully) all other menu types that use IT_CV_STRING --- src/m_menu.c | 71 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 30d0ee0b2..da58348d8 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3532,18 +3532,9 @@ static void M_ResetCvars(void) } } -static void M_NextOpt(void) +// If current menu item is IT_CV_STRING, setup menuinput +static void M_CheckStringItem(void) { - INT16 oldItemOn = itemOn; // prevent infinite loop - - do - { - if (itemOn + 1 > currentMenu->numitems - 1) - itemOn = 0; - else - itemOn++; - } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); - if (itemOn < currentMenu->numitems && (currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_STRING) { consvar_t *cv = (consvar_t *)currentMenu->menuitems[itemOn].itemaction; @@ -3558,6 +3549,21 @@ static void M_NextOpt(void) } } +static void M_NextOpt(void) +{ + INT16 oldItemOn = itemOn; // prevent infinite loop + + do + { + if (itemOn + 1 > currentMenu->numitems - 1) + itemOn = 0; + else + itemOn++; + } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); + + M_CheckStringItem(); +} + static void M_PrevOpt(void) { INT16 oldItemOn = itemOn; // prevent infinite loop @@ -3569,6 +3575,8 @@ static void M_PrevOpt(void) else itemOn--; } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); + + M_CheckStringItem(); } // lock out further input in a tic when important buttons are pressed @@ -4589,6 +4597,8 @@ void M_SetupNextMenu(menu_t *menudef) } } } + + M_CheckStringItem(); } // @@ -4930,11 +4940,16 @@ void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 fla void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) { + INT32 skullx = x; + V_DrawString(x, y, V_ALLOWLOWERCASE|flags, input->buffer); // draw text cursor for name - if (input->length && skullAnimCounter < 4) // blink cursor - V_DrawCharacter(x+V_SubStringWidth(input->buffer, input->cursor, V_ALLOWLOWERCASE), y+3, '_'|flags, false); + if (input->length) + skullx = x+V_SubStringWidth(input->buffer, input->cursor, V_ALLOWLOWERCASE); + + if (skullAnimCounter < 4) // blink cursor + V_DrawCharacter(skullx, y+3, '_'|flags, false); // draw selection if (input->select != input->cursor) @@ -5340,10 +5355,12 @@ static void M_DrawGenericScrollMenu(void) if (y + 12 > (currentMenu->y + 2*scrollareaheight)) break; M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, lowercase, cv->string); - if (skullAnimCounter < 4 && i == itemOn) - V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, - '_' | 0x80, false); + + if (itemOn == i) + M_DrawTextInput(x + 8, y + 12, &menuinput, 0); + else + V_DrawString(x + 8, y + 12, lowercase, cv->string); + break; default: V_DrawRightAlignedString(BASEVIDWIDTH - x, y, @@ -5479,10 +5496,12 @@ static void M_DrawCenteredMenu(void) break; case IT_CV_STRING: M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); - if (skullAnimCounter < 4 && i == itemOn) - V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, - '_' | 0x80, false); + + if (itemOn == i) + M_DrawTextInput(x + 8, y + 12, &menuinput, 0); + else + V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); + y += 16; break; default: @@ -12866,10 +12885,12 @@ static void M_DrawColorMenu(void) if (y + 12 > (currentMenu->y + 2*scrollareaheight)) break; M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); - if (skullAnimCounter < 4 && i == itemOn) - V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, - '_' | 0x80, false); + + if (itemOn == i) + M_DrawTextInput(x + 8, y + 12, &menuinput, 0); + else + V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); + y += 16; break; default: From fb71da3627d9a9becaf10e1bf16e57fb49d3b5c0 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 16:50:44 +0300 Subject: [PATCH 093/166] Remove debug print --- src/m_menu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index da58348d8..355be3cd2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3544,8 +3544,6 @@ static void M_CheckStringItem(void) M_TextInputInit(&menuinput, menu_text_input_buf, sizeof menu_text_input_buf); M_TextInputSetString(&menuinput, cv->string); - - CONS_Printf("Set input string to %s\n", cv->string); } } From 12d65460622c58745d5add88254d74f7705d6776 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 16:02:39 +0200 Subject: [PATCH 094/166] dumb special case for wandering balls Zzz... --- src/p_spec.c | 2 +- src/s_sound.c | 7 +++++-- src/s_sound.h | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 6146f422a..dc7743446 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2221,7 +2221,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 sfxnum; //dont play any funky sound intros that may interfere with the music - if (cv_skipintromusic.value && (leveltime < MUSICSTARTTIME)) + if (skipintromus && (leveltime < MUSICSTARTTIME)) return; sfxnum = sides[line->sidenum[0]].toptexture; //P_AproxDistance(line->dx, line->dy)>>FRACBITS; diff --git a/src/s_sound.c b/src/s_sound.c index 7aab19db9..8728db343 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2191,6 +2191,7 @@ boolean S_FadeOutStopMusic(UINT32 ms) static INT16 oldmap = 0; static boolean oldencore = 0; static boolean skipmusic = false; +boolean skipintromus = false; static const char *musicexception_list[16] = { "vote", "voteea", "voteeb", "racent", "krwin", @@ -2243,6 +2244,8 @@ void S_CheckMap(void) // void S_InitMapMusic(void) { + skipintromus = cv_skipintromusic.value && stricmp(G_BuildMapTitle(gamemap), "Wandering Falls") != 0; + if (mapmusflags & MUSIC_RELOADRESET) { strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname, 7); @@ -2259,7 +2262,7 @@ void S_InitMapMusic(void) // lug: but not when we keep the map music lol S_StopMusic(); - if (cv_skipintromusic.value) + if (skipintromus) return; if (leveltime < MUSICSTARTTIME) // SRB2Kart @@ -2276,7 +2279,7 @@ void S_StartMapMusic(void) if (keepmusic) return; - if (cv_skipintromusic.value) + if (skipintromus) { if (leveltime < starttime) // dumb but i dont need this to be spammed honestly S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); diff --git a/src/s_sound.h b/src/s_sound.h index 39b61b49d..e31040eac 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -71,6 +71,7 @@ extern consvar_t cv_keepmusic; extern consvar_t cv_skipintromusic; extern consvar_t cv_ignoremusicchanges; extern boolean keepmusic; +extern boolean skipintromus; #define MUSICSTARTTIME (starttime + (TICRATE/2)) extern consvar_t precachesound; From b985ce06a2b36bf2689cde4dae58cc14faa4f6e6 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 16:03:48 +0200 Subject: [PATCH 095/166] lol --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 8728db343..7505c622e 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2244,7 +2244,7 @@ void S_CheckMap(void) // void S_InitMapMusic(void) { - skipintromus = cv_skipintromusic.value && stricmp(G_BuildMapTitle(gamemap), "Wandering Falls") != 0; + skipintromus = cv_skipintromusic.value && stricmp(G_BuildMapTitle(gamemap), "Wandering Falls") != 0; // thanks diggle! if (mapmusflags & MUSIC_RELOADRESET) { From 31516c7987698bd7a3be7973304b0bf2d0a42bd3 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 17:56:15 +0200 Subject: [PATCH 096/166] fix G_BuildMapTitle leaks --- src/d_netcmd.c | 5 ++++- src/hu_stuff.c | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 46a2a2ba7..ceaa38e2b 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3247,7 +3247,10 @@ static void Command_ReplayMarker(void) demo.savemode = DSM_WILLAUTOSAVE; if (adjustedleveltime < 0) adjustedleveltime = 0; - snprintf(demo.titlename, 64, "%s [%i:%02d/%.5s]", G_BuildMapTitle(gamemap), G_TicsToMinutes(adjustedleveltime, false), G_TicsToSeconds(adjustedleveltime), modeattacking ? "Record Attack" : connectedservername); + char *title = G_BuildMapTitle(gamemap); + snprintf(demo.titlename, 64, "%s [%i:%02d/%.5s]", title, G_TicsToMinutes(adjustedleveltime, false), G_TicsToSeconds(adjustedleveltime), modeattacking ? "Record Attack" : connectedservername); + if (title) + Z_Free(title); CONS_Printf("Replay will be saved!\n"); } } diff --git a/src/hu_stuff.c b/src/hu_stuff.c index ba6bb72bc..35430119b 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2748,10 +2748,14 @@ static void HU_DrawRankings(void) //V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, gametype_cons_t[gametype].strvalue); // draw the current map in the lower right if theres none just say its unknown - if (!G_BuildMapTitle(gamemap)) + char *maptitle = G_BuildMapTitle(gamemap); + if (!maptitle) V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, "UNKNOWN"); else - V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, G_BuildMapTitle(gamemap)); + { + V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, maptitle); + Z_Free(maptitle); + } if (G_GametypeHasTeams()) { From bdb39fcd8d29d5e3fd8043f61952b9db05f740bb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 17:57:45 +0200 Subject: [PATCH 097/166] dont leak pls --- src/s_sound.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 7505c622e..aa266c5a1 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2244,7 +2244,10 @@ void S_CheckMap(void) // void S_InitMapMusic(void) { - skipintromus = cv_skipintromusic.value && stricmp(G_BuildMapTitle(gamemap), "Wandering Falls") != 0; // thanks diggle! + char *maptitle = G_BuildMapTitle(gamemap); + skipintromus = cv_skipintromusic.value && stricmp(maptitle, "Wandering Falls") != 0; // thanks diggle! + if (maptitle) + Z_Free(maptitle); if (mapmusflags & MUSIC_RELOADRESET) { From 2e8769496f20806949d2faa22cb4911a274339e0 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 20:39:04 +0300 Subject: [PATCH 098/166] Use textinput_t for replay save prompt too --- src/g_game.c | 36 +++++++++---------------- src/g_game.h | 2 ++ src/st_stuff.c | 73 +++++++++++++++++++++++++++++++++++++++++++------- src/v_video.c | 39 +++++++++++++++++++++++++++ src/v_video.h | 3 +++ 5 files changed, 119 insertions(+), 34 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 8311d7cbc..709a34415 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -6368,8 +6368,18 @@ void G_BeginRecording(void) // Full replay title demo_p += 64; { + char demotitlename[65]; char *title = G_BuildMapTitle(gamemap); - snprintf(demo.titlename, 64, "%s - %s", title, modeattacking ? "Time Attack" : connectedservername); + + // Print to a separate temp buffer instead of demo.titlename, so we can use it in M_TextInputSetString + snprintf(demotitlename, 64, "%s - %s", title, modeattacking ? "Time Attack" : connectedservername); + + // Init just in case it isn't initialized already + M_TextInputInit(&demo.titlenameinput, demo.titlename, sizeof(demo.titlename)); + + // This will indirectly assign to demo.titlename too + M_TextInputSetString(&demo.titlenameinput, demotitlename); + Z_Free(title); } @@ -8359,7 +8369,6 @@ void G_SaveDemo(void) boolean G_DemoTitleResponder(event_t *ev) { - size_t len; INT32 ch; if (ev->type != ev_keydown) @@ -8380,28 +8389,7 @@ boolean G_DemoTitleResponder(event_t *ev) return true; } - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) - || ch == ' ') // Allow spaces, of course - { - len = strlen(demo.titlename); - if (len < 64) - { - demo.titlename[len+1] = 0; - demo.titlename[len] = cv_keyboardlayout.value == 3 ? CON_ShitAndAltGrChar(ch) : CON_ShiftChar(ch); - } - } - else if (ch == KEY_BACKSPACE) - { - if (shiftdown) - memset(demo.titlename, 0, sizeof(demo.titlename)); - else - { - len = strlen(demo.titlename); - - if (len > 0) - demo.titlename[len-1] = 0; - } - } + M_TextInputHandle(&demo.titlenameinput, ch); return true; } diff --git a/src/g_game.h b/src/g_game.h index 14decd858..aaafa233c 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -17,6 +17,7 @@ #include "doomdef.h" #include "doomstat.h" #include "d_event.h" +#include "m_textinput.h" extern char gamedatafilename[64]; extern char timeattackfolder[64]; @@ -44,6 +45,7 @@ extern consvar_t cv_recordmultiplayerdemos, cv_netdemosyncquality, cv_maxdemosiz // Publicly-accessible demo vars struct demovars_s { char titlename[65]; + textinput_t titlenameinput; boolean recording, playback, timing; UINT16 version; // Current file format of the demo being played boolean title; // Title Screen demo can be cancelled by any key diff --git a/src/st_stuff.c b/src/st_stuff.c index aa5e07ed6..83222e64f 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -808,25 +808,78 @@ static void ST_overlayDrawer(void) } } -void ST_DrawDemoTitleEntry(void) +static void ST_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) { static UINT8 skullAnimCounter = 0; - char *nametodraw; + static const INT32 MAXINPUTWIDTH = (MAXSTRINGLENGTH-1)*8; - skullAnimCounter++; + if (renderisnewtic) + skullAnimCounter++; skullAnimCounter %= 8; - nametodraw = demo.titlename; - while (V_StringWidth(nametodraw, 0) > MAXSTRINGLENGTH*8 - 8) - nametodraw++; + char nametodraw[MAXSTRINGLENGTH*2+1] = {0}; + size_t drawstart = 0; + + INT32 skullx = x; + + while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH) + ++drawstart; + + memcpy(nametodraw, input->buffer+drawstart, V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1); + + if (input->length) + skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE); + + V_DrawString(x, y, V_ALLOWLOWERCASE|flags, nametodraw); + + // draw text cursor for name + if (skullAnimCounter < 4) // blink cursor + V_DrawCharacter(skullx, y+3, '_'|flags, false); + + // draw selection + if (input->select != input->cursor) + { + size_t start = min(input->select, input->cursor); + size_t end = max(input->select, input->cursor); + + INT32 startx = 0; + INT32 width = 0; + + // I couldn't figure out one formula so here's bunch of separate cases + if (start < drawstart && end > drawstart + MAXSTRINGLENGTH) // Selection covers whole visible portion of demo name + { + startx = 0; + width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE); + } + else if (start < drawstart) // Only left side of selection is off visible part + { + startx = 0; + size_t len = (end - start) - (drawstart - start); + width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE); + } + else if (end > drawstart + MAXSTRINGLENGTH) // Only right side of selection is off visible part + { + startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); + width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE); + } + else // All selection is on visible part + { + startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); + width = V_SubStringWidth(nametodraw+(start-drawstart), end-start, V_ALLOWLOWERCASE); + } + + V_DrawFill(x+startx, y, width, 8, 103|V_TRANSLUCENT|flags); + } +} + +void ST_DrawDemoTitleEntry(void) +{ #define x (BASEVIDWIDTH/2 - 139) #define y (BASEVIDHEIGHT/2) M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, nametodraw); - if (skullAnimCounter < 4) - V_DrawCharacter(x + 8 + V_StringWidth(nametodraw, 0), y + 12, - '_' | 0x80, false); + + ST_DrawTextInput(x + 8, y + 12, &demo.titlenameinput, 0); M_DrawTextBox(x + 30, y - 24, 26, 1); V_DrawString(x + 38, y - 16, V_ALLOWLOWERCASE, "Enter the name of the replay."); diff --git a/src/v_video.c b/src/v_video.c index 492a75004..e7bc81a27 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2981,6 +2981,45 @@ INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option) return w; } +// +// Find maximum length for substring taken from current string to fit into given width +// +INT32 V_SubStringLengthToFit(const char *string, INT32 width, INT32 option) +{ + INT32 c, w = 0; + INT32 spacewidth = 4, charwidth = 0; + INT32 i; + + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = 8; + /* FALLTHRU */ + case V_OLDSPACING: + charwidth = 8; + break; + case V_6WIDTHSPACE: + spacewidth = 6; + default: + break; + } + + for (i = 0; string[i] && w < width; i++) + { + c = string[i]; + if ((UINT8)c >= 0x80 && (UINT8)c <= 0x8F) //color parsing! -Inuyasha 2.16.09 + continue; + + c = toupper(c) - HU_FONTSTART; + if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) + w += spacewidth; + else + w += (charwidth ? charwidth : SHORT(hu_font[c]->width)); + } + + return max(i-1, 0); +} + char V_GetSkincolorChar(INT32 color) { char cstart = 0x80; diff --git a/src/v_video.h b/src/v_video.h index 0dae04aaa..bc1e8c546 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -246,6 +246,9 @@ INT32 V_SmallSubStringWidth(const char *string, INT32 length, INT32 option); INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option); #define V_ThinStringWidth(string, option) V_ThinSubStringWidth(string, -1, option) +// Find maximum length for substring taken from current string to fit into given width +INT32 V_SubStringLengthToFit(const char *string, INT32 width, INT32 option); + char V_GetSkincolorChar(INT32 color); void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); From fb0765a5f381fc8eeedc612bbc5ecc4771da06d9 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 20:55:27 +0300 Subject: [PATCH 099/166] Fix selection in replay save prompt --- src/st_stuff.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 83222e64f..dd6bd5f6b 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -820,13 +820,17 @@ static void ST_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) char nametodraw[MAXSTRINGLENGTH*2+1] = {0}; size_t drawstart = 0; + size_t drawend = 0; // Only used for selection INT32 skullx = x; while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH) ++drawstart; - memcpy(nametodraw, input->buffer+drawstart, V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1); + size_t drawlength = V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1; + drawend = drawstart + drawlength; + + memcpy(nametodraw, input->buffer+drawstart, drawlength); if (input->length) skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE); @@ -847,21 +851,21 @@ static void ST_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) INT32 width = 0; // I couldn't figure out one formula so here's bunch of separate cases - if (start < drawstart && end > drawstart + MAXSTRINGLENGTH) // Selection covers whole visible portion of demo name + if (start < drawstart && end > drawend) // Selection covers whole visible portion of demo name { - startx = 0; - width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE); + startx = -2; + width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE)+4; } else if (start < drawstart) // Only left side of selection is off visible part { - startx = 0; + startx = -2; size_t len = (end - start) - (drawstart - start); - width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE); + width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE)+2; } - else if (end > drawstart + MAXSTRINGLENGTH) // Only right side of selection is off visible part + else if (end > drawend) // Only right side of selection is off visible part { startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); - width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE); + width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE)+2; } else // All selection is on visible part { From dfb6006f9c3f23cddd133a2bc33bacaa580f4020 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 2 Oct 2024 12:14:31 +0200 Subject: [PATCH 100/166] fix up old fps counter --- src/screen.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/screen.c b/src/screen.c index 8fe00e821..b7777fc32 100644 --- a/src/screen.c +++ b/src/screen.c @@ -366,15 +366,13 @@ double averageFPS = 0.0f; #define USE_FPS_SAMPLES #ifdef USE_FPS_SAMPLES -#define MAX_FRAME_TIME 0.05 +#define MAX_FRAME_TIME (0.05) #define NUM_FPS_SAMPLES (16) // Number of samples to store -#define NUM_FPS_SAMPLES2 (32) // Number of samples to store for inaccurate counter static double total_frame_time = 0.0; static int frame_index; -static double fps_samples[NUM_FPS_SAMPLES2]; -static int fps_index; +static double fps_samples[NUM_FPS_SAMPLES]; #endif static boolean fps_init = false; @@ -383,7 +381,6 @@ static precise_t fps_enter = 0; void SCR_CalculateFPS(void) { precise_t fps_finish = 0; - int i; double frameElapsed = 0.0; @@ -398,7 +395,6 @@ void SCR_CalculateFPS(void) fps_enter = fps_finish; #ifdef USE_FPS_SAMPLES - if (cv_accuratefps.value) { total_frame_time += frameElapsed; @@ -411,13 +407,35 @@ void SCR_CalculateFPS(void) } else { - fps_samples[fps_index] = frameElapsed / NUM_FPS_SAMPLES2; - fps_index = (fps_index + 1) % NUM_FPS_SAMPLES2; + total_frame_time += frameElapsed; - averageFPS = 0.0; - for (i = 0; i < NUM_FPS_SAMPLES2; i++) - averageFPS += fps_samples[i]; - averageFPS = 1.0 / averageFPS; + if (total_frame_time >= MAX_FRAME_TIME) + { + static int sampleIndex = 0; + int i; + + fps_samples[sampleIndex] = frameElapsed; + + sampleIndex++; + if (sampleIndex >= NUM_FPS_SAMPLES) + sampleIndex = 0; + + averageFPS = 0.0; + for (i = 0; i < NUM_FPS_SAMPLES; i++) + { + averageFPS += fps_samples[i]; + } + + if (averageFPS > 0.0) + { + averageFPS = 1.0 / (averageFPS / NUM_FPS_SAMPLES); + } + } + + while (total_frame_time >= MAX_FRAME_TIME) + { + total_frame_time -= MAX_FRAME_TIME; + } } #else // Direct, unsampled counter. From 837216d78e60213cdc9a38c1aad81c30d9cc85e6 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 2 Oct 2024 14:22:39 +0200 Subject: [PATCH 101/166] we dont need any of this in ogl --- src/r_main.c | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 9b1787931..25394a2e3 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -979,6 +979,16 @@ void R_ExecuteSetViewSize(void) R_InitTextureMapping(); + // why did we calc all the software crap? +#ifdef HWRENDER + if (rendermode == render_opengl) + { + HWR_SetViewSize(); + am_recalc = true; + return; + } +#endif + // thing clipping for (i = 0; i < viewwidth; i++) screenheightarray[i] = (INT16)viewheight; @@ -987,27 +997,24 @@ void R_ExecuteSetViewSize(void) R_SetSkyScale(); // planes - if (rendermode == render_soft) + // this is only used for planes rendering in software mode + j = viewheight*16; + for (i = 0; i < j; i++) { - // this is only used for planes rendering in software mode - j = viewheight*16; - for (i = 0; i < j; i++) - { - dy = (i - viewheight*8)< Date: Wed, 2 Oct 2024 14:20:29 +0200 Subject: [PATCH 102/166] prevent this from overflowing ye well idk anymore. --- src/screen.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/screen.h b/src/screen.h index 4f3b0b1ff..be8cd9614 100644 --- a/src/screen.h +++ b/src/screen.h @@ -39,12 +39,12 @@ // we try to re-allocate a minimum of buffers for stability of the memory, // so all the small-enough tables based on screen size, are allocated once // and for all at the maximum size. -#define MAXVIDWIDTH 2560 // don't set this too high because actually -#define MAXVIDHEIGHT 1440 // lots of tables are allocated with the MAX size. +#define MAXVIDWIDTH 5120 // don't set this too high because actually +#define MAXVIDHEIGHT 2880 // lots of tables are allocated with the MAX size. #define BASEVIDWIDTH 320 // NEVER CHANGE THIS! This is the original #define BASEVIDHEIGHT 200 // resolution of the graphics. -// max res for png capture; seperated it so both MAXVID values can be lower for software performance reasons; OpenGL does not care about those anyways +// max res for png capture; just here to prevent some crashes on very high resoltions; tho you should never go this high cause ogl allocs certain things with MAXVIDWIDTH and MAXVIDHEIGHT too Zzz... #define MAXPNGWIDTH 7680 #define MAXPNGHEIGHT 4320 From a0437713bf1635d6a73ec82244c0026396d39271 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 2 Oct 2024 14:39:57 +0200 Subject: [PATCH 103/166] smol dupe --- src/screen.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/screen.c b/src/screen.c index b7777fc32..22ce5e8f1 100644 --- a/src/screen.c +++ b/src/screen.c @@ -395,9 +395,10 @@ void SCR_CalculateFPS(void) fps_enter = fps_finish; #ifdef USE_FPS_SAMPLES + total_frame_time += frameElapsed; + if (cv_accuratefps.value) { - total_frame_time += frameElapsed; if (frame_index++ >= NUM_FPS_SAMPLES || total_frame_time >= MAX_FRAME_TIME) { averageFPS = 1.0 / (total_frame_time / frame_index); @@ -407,8 +408,6 @@ void SCR_CalculateFPS(void) } else { - total_frame_time += frameElapsed; - if (total_frame_time >= MAX_FRAME_TIME) { static int sampleIndex = 0; From ec3b1cf130919b93be111c562a14ac47100c6666 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 2 Oct 2024 20:32:26 +0200 Subject: [PATCH 104/166] make this more readable --- src/p_mobj.c | 72 +++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 3e94b3ec4..fb5a0fd0a 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -592,7 +592,8 @@ fixed_t P_MobjFloorZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t { I_Assert(mobj != NULL); I_Assert(sector != NULL); - if (sector->f_slope) { + if (sector->f_slope) + { fixed_t testx, testy; pslope_t *slope = sector->f_slope; @@ -607,7 +608,8 @@ fixed_t P_MobjFloorZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t else testy = -mobj->radius; - if ((slope->zdelta > 0) ^ !!(lowest)) { + if ((slope->zdelta > 0) ^ !!(lowest)) + { testx = -testx; testy = -testy; } @@ -620,22 +622,21 @@ fixed_t P_MobjFloorZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t return P_GetZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point - if (perfect) { + if (perfect) + { size_t i; line_t *ld; fixed_t bbox[4]; fixed_t finalheight; - if (lowest) - finalheight = INT32_MAX; - else - finalheight = INT32_MIN; + finalheight = lowest ? INT32_MAX : INT32_MIN; bbox[BOXLEFT] = x-mobj->radius; bbox[BOXRIGHT] = x+mobj->radius; bbox[BOXTOP] = y+mobj->radius; bbox[BOXBOTTOM] = y-mobj->radius; - for (i = 0; i < boundsec->linecount; i++) { + for (i = 0; i < boundsec->linecount; i++) + { ld = boundsec->lines[i]; if (bbox[BOXRIGHT] <= ld->bbox[BOXLEFT] || bbox[BOXLEFT] >= ld->bbox[BOXRIGHT] @@ -668,7 +669,8 @@ fixed_t P_MobjCeilingZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed { I_Assert(mobj != NULL); I_Assert(sector != NULL); - if (sector->c_slope) { + if (sector->c_slope) + { fixed_t testx, testy; pslope_t *slope = sector->c_slope; @@ -683,7 +685,8 @@ fixed_t P_MobjCeilingZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed else testy = -mobj->radius; - if ((slope->zdelta > 0) ^ !!(lowest)) { + if ((slope->zdelta > 0) ^ !!(lowest)) + { testx = -testx; testy = -testy; } @@ -696,22 +699,21 @@ fixed_t P_MobjCeilingZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed return P_GetZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point - if (perfect) { + if (perfect) + { size_t i; line_t *ld; fixed_t bbox[4]; fixed_t finalheight; - if (lowest) - finalheight = INT32_MAX; - else - finalheight = INT32_MIN; + finalheight = lowest ? INT32_MAX : INT32_MIN; bbox[BOXLEFT] = x-mobj->radius; bbox[BOXRIGHT] = x+mobj->radius; bbox[BOXTOP] = y+mobj->radius; bbox[BOXBOTTOM] = y-mobj->radius; - for (i = 0; i < boundsec->linecount; i++) { + for (i = 0; i < boundsec->linecount; i++) + { ld = boundsec->lines[i]; if (bbox[BOXRIGHT] <= ld->bbox[BOXLEFT] || bbox[BOXLEFT] >= ld->bbox[BOXRIGHT] @@ -746,7 +748,8 @@ fixed_t P_CameraFloorZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, fix I_Assert(mobj != NULL); I_Assert(sector != NULL); - if (sector->f_slope) { + if (sector->f_slope) + { fixed_t testx, testy; pslope_t *slope = sector->f_slope; @@ -761,7 +764,8 @@ fixed_t P_CameraFloorZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, fix else testy = -mobj->radius; - if ((slope->zdelta > 0) ^ !!(lowest)) { + if ((slope->zdelta > 0) ^ !!(lowest)) + { testx = -testx; testy = -testy; } @@ -774,22 +778,21 @@ fixed_t P_CameraFloorZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, fix return P_GetZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point - if (perfect) { + if (perfect) + { size_t i; line_t *ld; fixed_t bbox[4]; fixed_t finalheight; - if (lowest) - finalheight = INT32_MAX; - else - finalheight = INT32_MIN; + finalheight = lowest ? INT32_MAX : INT32_MIN; bbox[BOXLEFT] = x-mobj->radius; bbox[BOXRIGHT] = x+mobj->radius; bbox[BOXTOP] = y+mobj->radius; bbox[BOXBOTTOM] = y-mobj->radius; - for (i = 0; i < boundsec->linecount; i++) { + for (i = 0; i < boundsec->linecount; i++) + { ld = boundsec->lines[i]; if (bbox[BOXRIGHT] <= ld->bbox[BOXLEFT] || bbox[BOXLEFT] >= ld->bbox[BOXRIGHT] @@ -823,7 +826,8 @@ fixed_t P_CameraCeilingZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, f I_Assert(mobj != NULL); I_Assert(sector != NULL); - if (sector->c_slope) { + if (sector->c_slope) + { fixed_t testx, testy; pslope_t *slope = sector->c_slope; @@ -838,7 +842,8 @@ fixed_t P_CameraCeilingZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, f else testy = -mobj->radius; - if ((slope->zdelta > 0) ^ !!(lowest)) { + if ((slope->zdelta > 0) ^ !!(lowest)) + { testx = -testx; testy = -testy; } @@ -851,22 +856,21 @@ fixed_t P_CameraCeilingZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, f return P_GetZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point - if (perfect) { + if (perfect) + { size_t i; line_t *ld; fixed_t bbox[4]; fixed_t finalheight; - if (lowest) - finalheight = INT32_MAX; - else - finalheight = INT32_MIN; + finalheight = lowest ? INT32_MAX : INT32_MIN; bbox[BOXLEFT] = x-mobj->radius; bbox[BOXRIGHT] = x+mobj->radius; bbox[BOXTOP] = y+mobj->radius; bbox[BOXBOTTOM] = y-mobj->radius; - for (i = 0; i < boundsec->linecount; i++) { + for (i = 0; i < boundsec->linecount; i++) + { ld = boundsec->lines[i]; if (bbox[BOXRIGHT] <= ld->bbox[BOXLEFT] || bbox[BOXLEFT] >= ld->bbox[BOXRIGHT] @@ -6034,7 +6038,7 @@ void P_RollPitchMobj(mobj_t* mobj) if (cv_sloperolldist.value > 0) usedist = true; - if ((cv_spriteroll.value) && (cv_sloperoll.value == 2)) + if (cv_spriteroll.value && cv_sloperoll.value == 2) { K_RollMobjBySlopes(mobj, usedist); } @@ -6260,7 +6264,7 @@ void P_MobjThinker(mobj_t *mobj) return; } - if (mobj->state == &states[S_SHADOW] && cv_sloperoll.value == 2) + if (cv_sloperoll.value == 2 && mobj->state == &states[S_SHADOW]) { mobj->slopepitch = mobj->target->slopepitch; mobj->sloperoll = mobj->target->sloperoll; From 3165004d0e2b781ab7706d02e8e15be2e3b1af24 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 3 Oct 2024 18:15:12 +0200 Subject: [PATCH 105/166] add comment to try and explain this crap --- src/d_clisrv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index cf6637edc..f9110bb2d 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5383,6 +5383,7 @@ static void HandlePacketFromPlayer(SINT8 node) } #ifdef SATURNSYNCH + // this decreases by one point at twice the cooldown time (ex cooldown of 2 seconds means, this counter decreases by one every 4 seconds), pretty much there to prevent a resynch loop if ((gamestate_resend_counter[node] != 0) && (I_GetTime() % ((max(cv_resynchcooldown.value, 1) * TICRATE) *2) == 0)) gamestate_resend_counter[node]--; From f32c34653476da6ecc2fbcf48d0c6460d98b6276 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 5 Oct 2024 06:56:21 +0200 Subject: [PATCH 106/166] this needs gamestate check sometimes the title music kept playing --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index aa266c5a1..6016b028b 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2231,7 +2231,7 @@ void S_CheckMap(void) return; } - keepmusic = (!skipmusic && oldmap == gamemap && oldencore == encoremode); + keepmusic = (!skipmusic && gamestate == GS_LEVEL && oldmap == gamemap && oldencore == encoremode); oldencore = encoremode; oldmap = gamemap; From 0b3e7240a8594c72341f8fa662fb39028cd2e3cd Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:07:17 +0200 Subject: [PATCH 107/166] use saturn packet to determine if client can receive gamestate before the server always assumed every client cant receive the gamestate using the vanilla consistency check for everyone. aswell as before the first resynch it tried to send the gamestate resend packets to everyone --- src/Makefile | 12 ++++++------ src/d_clisrv.c | 46 +++++++++++++++++++--------------------------- src/doomdef.h | 6 +++--- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/Makefile b/src/Makefile index 4668518b9..87226a60b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -213,9 +213,9 @@ DOSATURNSYNCH=1 ifndef NOSATURNJOIN DOSATURNJOIN=1 endif -#ifndef NOSATURNPAK -#DOSATURNPAK=1 -#endif +ifndef NOSATURNPAK +DOSATURNPAK=1 +endif endif endif @@ -404,9 +404,9 @@ OPTS+=-DDOSATURNSYNCH ifndef NOSATURNJOIN OPTS+=-DDOSATURNJOIN endif -#ifndef NOSATURNPAK -#OPTS+=-DDOSATURNPAK -#endif +ifndef NOSATURNPAK +OPTS+=-DDOSATURNPAK +endif endif endif diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f9110bb2d..ac0dfad34 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5394,6 +5394,7 @@ static void HandlePacketFromPlayer(SINT8 node) && !resendingsavegame[node] && savegameresendcooldown[node] <= I_GetTime() && !SV_ResendingSavegameToAnyone())) { +#ifndef SATURNPAK // we need to send this so the client can tell us if it can receive the savegame netbuffer->packettype = PT_WILLRESENDGAMESTATE; HSendPacket(node, true, 0, 0); @@ -5405,6 +5406,21 @@ static void HandlePacketFromPlayer(SINT8 node) SV_RequireResynch(node); resendingsavegame[node] = false; } +#else + if (can_receive_gamestate[node]) + { + // Tell the client we are about to resend them the gamestate + netbuffer->packettype = PT_WILLRESENDGAMESTATE; + HSendPacket(node, true, 0, 0); + + resendingsavegame[node] = true; + } + else + { + SV_RequireResynch(node); + resendingsavegame[node] = false; + } +#endif if ((!can_receive_gamestate[node] && cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250) || (can_receive_gamestate[node] && (gamestate_resend_counter[node] < cv_gamestateattempts.value))) { @@ -5584,31 +5600,6 @@ static void HandlePacketFromPlayer(SINT8 node) else buf[1] = KICK_MSG_PLAYER_QUIT; SendNetXCmd(XD_KICK, &buf, 2); - //nodetoplayer[node] = -1; - - /*if (nodetoplayer2[node] != -1 && nodetoplayer2[node] >= 0 - && playeringame[(UINT8)nodetoplayer2[node]]) - { - buf[0] = nodetoplayer2[node]; - SendNetXCmd(XD_KICK, &buf, 2); - nodetoplayer2[node] = -1; - } - - if (nodetoplayer3[node] != -1 && nodetoplayer3[node] >= 0 - && playeringame[(UINT8)nodetoplayer3[node]]) - { - buf[0] = nodetoplayer3[node]; - SendNetXCmd(XD_KICK, &buf, 2); - nodetoplayer3[node] = -1; - } - - if (nodetoplayer4[node] != -1 && nodetoplayer4[node] >= 0 - && playeringame[(UINT8)nodetoplayer4[node]]) - { - buf[0] = nodetoplayer4[node]; - SendNetXCmd(XD_KICK, &buf, 2); - nodetoplayer4[node] = -1; - }*/ } Net_CloseConnection(node); nodeingame[node] = false; @@ -5799,6 +5790,7 @@ static void HandlePacketFromPlayer(SINT8 node) case PT_ISSATURN: //CONS_Printf("hi im on saturn%d\n", node); is_client_saturn[node] = true; + can_receive_gamestate[node] = true; break; #endif default: @@ -6634,7 +6626,7 @@ void NetKeepAlive(void) #ifdef MASTERSERVER MasterClient_Ticker(); #endif - + #ifdef HOLEPUNCH if (netgame && serverrunning) { @@ -6745,7 +6737,7 @@ void NetUpdate(void) CL_SendClientCmd(); // send it GetPackets(); // get packet from client or from server - + // client send the command after a receive of the server // the server send before because in single player is beter diff --git a/src/doomdef.h b/src/doomdef.h index bdc82a0ca..361cd92d1 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -585,9 +585,9 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Server detection for if a connecting client is on Saturn. /// For stuff like extra synching, etc. -//#ifdef DOSATURNPAK -//#define SATURNPAK -//#endif +#ifdef DOSATURNPAK +#define SATURNPAK +#endif //-- <( ̄︶ ̄)> __ #endif From fc39a0dedf51ceab5e9de841d6b93f3e6b398c6f Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:12:59 +0200 Subject: [PATCH 108/166] make the debug print a little better --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ac0dfad34..8a9a5417c 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5788,7 +5788,7 @@ static void HandlePacketFromPlayer(SINT8 node) #endif #ifdef SATURNPAK case PT_ISSATURN: - //CONS_Printf("hi im on saturn%d\n", node); + //CONS_Printf("hi im on saturn [node = %d]\n", node); is_client_saturn[node] = true; can_receive_gamestate[node] = true; break; From 5cb207edfabacd34ccec7ad430e6eb3678acfc28 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:14:32 +0200 Subject: [PATCH 109/166] add debfile prints whenever gamestate counter changes --- src/d_clisrv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 8a9a5417c..97ad460d6 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5385,7 +5385,10 @@ static void HandlePacketFromPlayer(SINT8 node) #ifdef SATURNSYNCH // this decreases by one point at twice the cooldown time (ex cooldown of 2 seconds means, this counter decreases by one every 4 seconds), pretty much there to prevent a resynch loop if ((gamestate_resend_counter[node] != 0) && (I_GetTime() % ((max(cv_resynchcooldown.value, 1) * TICRATE) *2) == 0)) + { gamestate_resend_counter[node]--; + DEBFILE(va("gamestate counter %d for node %d\n", gamestate_resend_counter[node], netconsole)); + } // Check player consistancy during the level if (((!can_receive_gamestate[node]) && realstart <= gametic && realstart > gametic - TICQUEUE+1 && gamestate == GS_LEVEL @@ -5427,7 +5430,7 @@ static void HandlePacketFromPlayer(SINT8 node) if (can_receive_gamestate[node] && resendingsavegame[node]) { gamestate_resend_counter[node]++; - DEBFILE(va("gamestate counter %d for player %d\n", gamestate_resend_counter[node], netconsole)); + DEBFILE(va("gamestate counter %d for node %d\n", gamestate_resend_counter[node], netconsole)); } if (cv_blamecfail.value) @@ -5451,6 +5454,7 @@ static void HandlePacketFromPlayer(SINT8 node) netconsole, realstart, consistancy[realstart%TICQUEUE], SHORT(netbuffer->u.clientpak.consistancy))); gamestate_resend_counter[node] = 0; + DEBFILE(va("gamestate counter %d for node %d\n", gamestate_resend_counter[node], netconsole)); break; } } From 4877c81728149b75571e4fd3902b327d146ccde1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:32:57 +0200 Subject: [PATCH 110/166] comment this out for now so v7 clients dont use vanilla resynch system keep sending PT_WILLRESENDGAMESTATE packets to everyone for now saturnpak will still mark the right clients so they will use the right consistency check without having to desynch first --- src/d_clisrv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 97ad460d6..996afbf7a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5397,7 +5397,7 @@ static void HandlePacketFromPlayer(SINT8 node) && !resendingsavegame[node] && savegameresendcooldown[node] <= I_GetTime() && !SV_ResendingSavegameToAnyone())) { -#ifndef SATURNPAK +//#ifndef SATURNPAK // we need to send this so the client can tell us if it can receive the savegame netbuffer->packettype = PT_WILLRESENDGAMESTATE; HSendPacket(node, true, 0, 0); @@ -5409,7 +5409,7 @@ static void HandlePacketFromPlayer(SINT8 node) SV_RequireResynch(node); resendingsavegame[node] = false; } -#else +/*#else if (can_receive_gamestate[node]) { // Tell the client we are about to resend them the gamestate @@ -5423,7 +5423,7 @@ static void HandlePacketFromPlayer(SINT8 node) SV_RequireResynch(node); resendingsavegame[node] = false; } -#endif +#endif*/ if ((!can_receive_gamestate[node] && cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250) || (can_receive_gamestate[node] && (gamestate_resend_counter[node] < cv_gamestateattempts.value))) { From 7d65b5369ff5f3e61bbc66b5069b1ab0e946dd71 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:34:51 +0200 Subject: [PATCH 111/166] add some brackets lul --- src/d_clisrv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 996afbf7a..c58491cfa 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5397,7 +5397,7 @@ static void HandlePacketFromPlayer(SINT8 node) && !resendingsavegame[node] && savegameresendcooldown[node] <= I_GetTime() && !SV_ResendingSavegameToAnyone())) { -//#ifndef SATURNPAK +//#ifndef SATURNPAK // lug: keep this behaviour for v7.1 atleast // we need to send this so the client can tell us if it can receive the savegame netbuffer->packettype = PT_WILLRESENDGAMESTATE; HSendPacket(node, true, 0, 0); @@ -5425,7 +5425,7 @@ static void HandlePacketFromPlayer(SINT8 node) } #endif*/ - if ((!can_receive_gamestate[node] && cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250) || (can_receive_gamestate[node] && (gamestate_resend_counter[node] < cv_gamestateattempts.value))) + if ((!can_receive_gamestate[node] && (cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250)) || (can_receive_gamestate[node] && (gamestate_resend_counter[node] < cv_gamestateattempts.value))) { if (can_receive_gamestate[node] && resendingsavegame[node]) { @@ -5466,7 +5466,7 @@ static void HandlePacketFromPlayer(SINT8 node) if (realstart <= gametic && realstart > gametic - TICQUEUE+1 && gamestate == GS_LEVEL && consistancy[realstart%TICQUEUE] != SHORT(netbuffer->u.clientpak.consistancy)) { - SV_RequireResynch(node); + SV_RequireResynch(node); if (cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250) { From 6f1252e27d165485ed81d156d741f4b61b48b2b9 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 5 Oct 2024 05:41:30 +0200 Subject: [PATCH 112/166] set timeinmap for demo rewind idk maybe this helps with that feature desynching all the time lol --- src/p_tick.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_tick.c b/src/p_tick.c index 9dbdd7ed5..6ffc18a49 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -429,6 +429,8 @@ void P_Ticker(boolean run) if (demo.rewinding && leveltime > 0) { leveltime = (leveltime-1) & ~3; + if (timeinmap > 0) + timeinmap = (timeinmap-1) & ~3; G_PreviewRewind(leveltime); } else if (demo.freecam && democam.cam) // special case: allow freecam to MOVE during pause! From f54bb349b53c02211e704ea43256ec38b7f9e489 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 5 Oct 2024 06:04:12 +0200 Subject: [PATCH 113/166] add G_FixCamera --- src/g_game.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index f6b7d562c..adf86476b 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1991,6 +1991,23 @@ INT32 G_CountPlayersPotentiallyViewable(boolean active) return total; } +// +// G_FixCamera +// Reset camera position, angle and interpolation on a view +// after changing state. +// +static void G_FixCamera(UINT8 view) +{ + player_t *player = &players[displayplayers[view - 1]]; + // The order of displayplayers can change, which would + // invalidate localangle. + localangle[view - 1] = player->cmd.angleturn; + P_ResetCamera(player, &camera[view - 1]); + // Make sure the viewport doesn't interpolate at all into + // its new position -- just snap instantly into place. + R_ResetViewInterpolation(view); +} + // // G_ResetView // Correct a viewpoint to playernum or the next available, wraps forward. @@ -2003,7 +2020,6 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) UINT8 viewd; INT32 *displayplayerp; - camera_t *camerap; INT32 olddisplayplayer; INT32 playersviewable; @@ -2042,28 +2058,14 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) (*displayplayerp) = playernum; if ((*displayplayerp) != olddisplayplayer) { - camerap = &camera[viewnum-1]; - P_ResetCamera(&players[(*displayplayerp)], camerap); - - // Make sure the viewport doesn't interpolate at all into - // its new position -- just snap instantly into place. - R_ResetViewInterpolation(viewnum); + G_FixCamera(viewnum); } if (viewnum > splits) { for (viewd = splits+1; viewd < viewnum; ++viewd) { - displayplayerp = (&displayplayers[viewd-1]); - camerap = &camera[viewd]; - - (*displayplayerp) = G_FindView(0, viewd, onlyactive, false); - - P_ResetCamera(&players[(*displayplayerp)], camerap); - - // Make sure the viewport doesn't interpolate at all into - // its new position -- just snap instantly into place. - R_ResetViewInterpolation(viewd); + G_FixCamera(viewd); } } From 6574ec2fb9b187a2b0d8bd3e1810360eb2ebeb3f Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 5 Oct 2024 06:09:48 +0200 Subject: [PATCH 114/166] attempt to cleanup R_SetupFrame --- src/r_main.c | 105 ++++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 64 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 25394a2e3..c85ef09f2 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1361,51 +1361,35 @@ void R_SetupFrame(player_t *player, boolean skybox) camera_t *thiscam; boolean chasecam = false; +#define SETUPCAM(num, var, context)\ + thiscam = &camera[num];\ + chasecam = (var.value != 0);\ + R_SetViewContext(context);\ + if (thiscam->reset)\ + {\ + R_ResetViewInterpolation(num+1);\ + thiscam->reset = false;\ + } + if (splitscreen > 2 && player == &players[displayplayers[3]]) { - thiscam = &camera[3]; - chasecam = (cv_chasecam4.value != 0); - R_SetViewContext(VIEWCONTEXT_PLAYER4); - if (thiscam->reset) - { - R_ResetViewInterpolation(4); - thiscam->reset = false; - } + SETUPCAM(3, cv_chasecam4, VIEWCONTEXT_PLAYER4) } else if (splitscreen > 1 && player == &players[displayplayers[2]]) { - thiscam = &camera[2]; - chasecam = (cv_chasecam3.value != 0); - R_SetViewContext(VIEWCONTEXT_PLAYER3); - if (thiscam->reset) - { - R_ResetViewInterpolation(3); - thiscam->reset = false; - } + SETUPCAM(2, cv_chasecam3, VIEWCONTEXT_PLAYER3) } else if (splitscreen && player == &players[displayplayers[1]]) { - thiscam = &camera[1]; - chasecam = (cv_chasecam2.value != 0); - R_SetViewContext(VIEWCONTEXT_PLAYER2); - if (thiscam->reset) - { - R_ResetViewInterpolation(2); - thiscam->reset = false; - } + SETUPCAM(1, cv_chasecam2, VIEWCONTEXT_PLAYER2) } else { - thiscam = &camera[0]; - chasecam = (cv_chasecam.value != 0); - R_SetViewContext(VIEWCONTEXT_PLAYER1); - if (thiscam->reset) - { - R_ResetViewInterpolation(1); - thiscam->reset = false; - } + SETUPCAM(0, cv_chasecam, VIEWCONTEXT_PLAYER1) } +#undef SETUPCAM + if (player->spectator) // no spectator chasecam chasecam = false; // force chasecam off else if (player->playerstate == PST_DEAD || player->exiting) @@ -1425,20 +1409,40 @@ void R_SetupFrame(player_t *player, boolean skybox) // cut-away view stuff viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN I_Assert(viewmobj != NULL); + + newview->x = viewmobj->x; + newview->y = viewmobj->y; newview->z = viewmobj->z + 20*FRACUNIT; newview->aim = player->awayviewaiming; newview->angle = viewmobj->angle; + + newview->x += quake.x; + newview->y += quake.y; + + if (!P_MobjWasRemoved(viewmobj) && viewmobj->subsector && thiscam && thiscam->subsector->sector) + newview->sector = viewmobj->subsector->sector; + else + newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; } - else if (!player->spectator && (thiscam && chasecam)) - // use outside cam view + else if (!player->spectator && (thiscam && chasecam)) // use outside cam view { viewmobj = NULL; + + newview->x = thiscam->x; + newview->y = thiscam->y; newview->z = thiscam->z + (thiscam->height>>1); newview->aim = thiscam->aiming; newview->angle = thiscam->angle; + + newview->x += quake.x; + newview->y += quake.y; + + if (thiscam->subsector && thiscam->subsector->sector) + newview->sector = thiscam->subsector->sector; + else + newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; } - else - // use the player's eyes view + else // use the player's eyes view { newview->z = player->viewz; @@ -1470,39 +1474,12 @@ void R_SetupFrame(player_t *player, boolean skybox) } } } + newview->roll = R_ViewRollAngle(player); newview->z += quake.z; newview->player = player; - if ((thiscam && chasecam) && !player->awayviewtics && !player->spectator) - { - newview->x = thiscam->x; - newview->y = thiscam->y; - newview->x += quake.x; - newview->y += quake.y; - - if (thiscam->subsector && thiscam->subsector->sector) - newview->sector = thiscam->subsector->sector; - else - newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; - } - else - { - newview->x = viewmobj->x; - newview->y = viewmobj->y; - newview->x += quake.x; - newview->y += quake.y; - - if (!P_MobjWasRemoved(viewmobj) && viewmobj->subsector && thiscam && thiscam->subsector->sector) - newview->sector = viewmobj->subsector->sector; - else - newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; - } - - // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT); - // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac : FRACUNIT, false); } From 4b083ee72ee6616bda2e2f4ee917abe1c7b5d972 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 5 Oct 2024 08:26:06 +0200 Subject: [PATCH 115/166] make function for quakes, scale with mobjscale --- src/doomstat.h | 2 +- src/k_kart.c | 3 +-- src/lua_baselib.c | 8 +++----- src/p_inter.c | 3 +-- src/p_spec.c | 33 ++++++++++++++++++++++++++------- src/p_spec.h | 2 ++ 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/doomstat.h b/src/doomstat.h index 35ae67d1b..01d98fd4e 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -192,7 +192,7 @@ extern struct quake // camera offsets and duration fixed_t x,y,z; angle_t roll; - UINT16 time; + tic_t time; // location, radius, and intensity... mappoint_t *epicenter; diff --git a/src/k_kart.c b/src/k_kart.c index 44497b0f2..a96a6bbda 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -2686,8 +2686,7 @@ void K_ExplodePlayer(player_t *player, mobj_t *source, mobj_t *inflictor) // A b if (P_IsLocalPlayer(player)) { - quake.intensity = 64*FRACUNIT; - quake.time = 5; + P_StartQuake(5, 64<kartstuff[k_instashield] = 15; diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 3fbfd463d..1e60863ef 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1553,8 +1553,9 @@ static int lib_pSetSkyboxMobj(lua_State *L) // Shhh, neither does P_StartQuake. static int lib_pStartQuake(lua_State *L) { + tic_t q_time = (tic_t)luaL_checkinteger(L, 2); fixed_t q_intensity = luaL_checkinteger(L, 1); - UINT16 q_time = (UINT16)luaL_checkinteger(L, 2); + fixed_t q_radius = luaL_optinteger(L, 4, 512<sidenum[0]].textureoffset; - quake.radius = sides[line->sidenum[0]].rowoffset; - quake.time = P_AproxDistance(line->dx, line->dy)>>FRACBITS; + fixed_t intensity = sides[line->sidenum[0]].textureoffset; + fixed_t radius = sides[line->sidenum[0]].rowoffset; + tic_t time = P_AproxDistance(line->dx, line->dy)>>FRACBITS; quake.epicenter = NULL; /// \todo // reasonable defaults. - if (!quake.intensity) - quake.intensity = 8< 0) + { + quake.radius = FixedMul(radius, mapobjectscale); + } +} + static void P_SearchForDisableLinedefs(void) { size_t i; diff --git a/src/p_spec.h b/src/p_spec.h index 477dd4950..7612ac657 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -454,4 +454,6 @@ void P_CalcHeight(player_t *player); sector_t *P_ThingOnSpecial3DFloor(mobj_t *mo); +void P_StartQuake(tic_t time, fixed_t intensity, fixed_t radius); + #endif From 55c9c7297f984afb3a778b1432c66dabc3968bd8 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 5 Oct 2024 08:29:40 +0200 Subject: [PATCH 116/166] throw this into own function too --- src/p_tick.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index 6ffc18a49..5edb29f80 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -397,6 +397,36 @@ void P_RunChaseCameras(void) } } +static inline void P_RunQuakes(void) +{ + fixed_t ir; + + if (quake.time <= 0) + { + quake.x = quake.y = quake.z = quake.roll = 0; + return; + } + + ir = quake.intensity>>1; + + /// \todo Calculate distance from epicenter if set and modulate the intensity accordingly based on radius. + quake.x = M_RandomRange(-ir,ir); + quake.y = M_RandomRange(-ir,ir); + quake.z = M_RandomRange(-ir,ir); + + ir >>= 2; + ir = M_RandomRange(-ir,ir); + + if (ir < 0) + ir = ANGLE_MAX - FixedAngle(-ir); + else + ir = FixedAngle(ir); + + quake.roll = ir; + + --quake.time; +} + // // P_Ticker // @@ -589,24 +619,7 @@ void P_Ticker(boolean run) K_CalculateBattleWanted(); } - if (quake.time) - { - fixed_t ir = quake.intensity>>1; - /// \todo Calculate distance from epicenter if set and modulate the intensity accordingly based on radius. - quake.x = M_RandomRange(-ir,ir); - quake.y = M_RandomRange(-ir,ir); - quake.z = M_RandomRange(-ir,ir); - ir >>= 2; - ir = M_RandomRange(-ir,ir); - if (ir < 0) - ir = ANGLE_MAX - FixedAngle(-ir); - else - ir = FixedAngle(ir); - quake.roll = ir; - --quake.time; - } - else - quake.x = quake.y = quake.z = quake.roll = 0; + P_RunQuakes(); if (metalplayback) G_ReadMetalTic(metalplayback); From ff2006ad74052b048f7c2b3b55f1a9d3dfa8d0a1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 5 Oct 2024 08:35:35 +0200 Subject: [PATCH 117/166] smol fix --- src/g_game.c | 14 +++++++++----- src/p_tick.c | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index adf86476b..1b6beb96c 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2056,18 +2056,22 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) /* Focus our target view first so that we don't take its player. */ (*displayplayerp) = playernum; - if ((*displayplayerp) != olddisplayplayer) - { - G_FixCamera(viewnum); - } + /* If a viewpoint changes, reset the camera to clear uninitialized memory. */ if (viewnum > splits) { - for (viewd = splits+1; viewd < viewnum; ++viewd) + for (viewd = splits+1; viewd <= viewnum; ++viewd) { G_FixCamera(viewd); } } + else + { + if ((*displayplayerp) != olddisplayplayer) + { + G_FixCamera(viewnum); + } + } if (viewnum == 1 && demo.playback) consoleplayer = displayplayers[0]; diff --git a/src/p_tick.c b/src/p_tick.c index 5edb29f80..7405792d0 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -683,8 +683,10 @@ void P_Ticker(boolean run) { player_t *player = &players[displayplayers[i]]; boolean isSkyVisibleForPlayer = skyVisiblePerPlayer[i]; + if (!player->mo) continue; + if (isSkyVisibleForPlayer && skyboxmo[0] && cv_skybox.value) { R_SkyboxFrame(player); @@ -698,8 +700,6 @@ void P_Ticker(boolean run) if (demo.playback) G_StoreRewindInfo(); - -// Z_CheckMemCleanup(); } // Abbreviated ticker for pre-loading, calls thinkers and assorted things From 76198f61de21179c2bb32f97869512097d3fefca Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:56:19 +0200 Subject: [PATCH 118/166] add missing break --- src/p_telept.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/p_telept.c b/src/p_telept.c index a7cef7b1d..ceed7dc93 100644 --- a/src/p_telept.c +++ b/src/p_telept.c @@ -166,6 +166,7 @@ boolean P_Teleport(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle P_ResetCamera(thing->player, &camera[i]); R_ResetViewInterpolation(i + 1); + break; } // don't run in place after a teleport From a2799ddccad59e982ae8340c24fe187e365a5d80 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 13:12:27 +0200 Subject: [PATCH 119/166] Interpolate view, even when paused https://github.com/KartKrewDev/RingRacers/commit/3320faec8cebecb124882d38c7ec0ad37b79340a#diff-607b68058edc6124b3061267d902aabeddb6ba338c6483df0af8b1a7cf796a01R43 --- src/d_main.c | 3 +++ src/r_main.c | 5 +++-- src/r_main.h | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 9ca370c2a..28c1dd594 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -825,11 +825,14 @@ void D_SRB2Loop(void) { rendertimefrac = FRACUNIT; } + + rendertimefrac_unpaused = g_time.timefrac; } else { renderdeltatics = realtics * FRACUNIT; rendertimefrac = FRACUNIT; + rendertimefrac_unpaused = FRACUNIT; } if ((interp || doDisplay) && !frameskip) diff --git a/src/r_main.c b/src/r_main.c index c85ef09f2..e0cc44ea9 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -75,6 +75,7 @@ line_t *portalclipline; INT32 portalclipstart, portalclipend; fixed_t rendertimefrac; +fixed_t rendertimefrac_unpaused; fixed_t renderdeltatics; boolean renderisnewtic; @@ -1353,7 +1354,7 @@ void R_SkyboxFrame(player_t *player) // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT); // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac_unpaused : FRACUNIT, false); } void R_SetupFrame(player_t *player, boolean skybox) @@ -1480,7 +1481,7 @@ void R_SetupFrame(player_t *player, boolean skybox) newview->player = player; - R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac_unpaused : FRACUNIT, false); } #define ANGLED_PORTALS diff --git a/src/r_main.h b/src/r_main.h index 8766ea65c..e6ae49103 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -33,6 +33,8 @@ extern size_t validcount, linecount, loopcount, framecount; // The fraction of a tic being drawn (for interpolation between two tics) extern fixed_t rendertimefrac; +// Same as rendertimefrac but not suspended when the game is paused +extern fixed_t rendertimefrac_unpaused; // Evaluated delta tics for this frame (how many tics since the last frame) extern fixed_t renderdeltatics; // The current render is a new logical tic From e3b0204b2c6d658ed8d3c175adef01e2d7957e9b Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 13:32:46 +0200 Subject: [PATCH 120/166] fix main menu interpolation apparently in main menu, opening the menu pauses the game so rendertimefrac was FRACUNIT and didnt interpolate --- src/f_finale.c | 10 +++++----- src/r_main.c | 5 +++++ src/r_main.h | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/f_finale.c b/src/f_finale.c index 7f86303c0..18eab51eb 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -170,8 +170,8 @@ static void F_SkyScroll(INT32 scrollspeed) w = (vid.width / vid.dupx)<width)*16))<width)<width)*16))<width)*16))<width)<width)*16))<= 20) V_DrawSmallScaledPatch(84, 87, 0, ttkart); else if (finalecount >= 10) - V_DrawSciencePatch((84< Date: Sun, 6 Oct 2024 14:30:21 +0200 Subject: [PATCH 121/166] only do this in replays otherwise shit will jitter during netlag --- src/r_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index f61753a19..90b4bbd55 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1359,7 +1359,7 @@ void R_SkyboxFrame(player_t *player) // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT); // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac_unpaused : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } void R_SetupFrame(player_t *player, boolean skybox) @@ -1486,7 +1486,7 @@ void R_SetupFrame(player_t *player, boolean skybox) newview->player = player; - R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac_unpaused : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } #define ANGLED_PORTALS From 48a00ba911ba0861b65b4bd4c0872cf63549a7df Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 14:52:54 +0200 Subject: [PATCH 122/166] this needs to be set twice Zzz... --- src/g_game.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/g_game.c b/src/g_game.c index 1b6beb96c..6b61f0a43 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1999,12 +1999,18 @@ INT32 G_CountPlayersPotentiallyViewable(boolean active) static void G_FixCamera(UINT8 view) { player_t *player = &players[displayplayers[view - 1]]; + // The order of displayplayers can change, which would // invalidate localangle. localangle[view - 1] = player->cmd.angleturn; + P_ResetCamera(player, &camera[view - 1]); + // Make sure the viewport doesn't interpolate at all into // its new position -- just snap instantly into place. + + // Why does it need to be done twice? + R_ResetViewInterpolation(view); R_ResetViewInterpolation(view); } From cfdbf1f4ad60472cadb983b0e663e615f5d619a7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 14:53:10 +0200 Subject: [PATCH 123/166] hopefully fix awayview cam interp crap --- src/p_spec.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/p_spec.c b/src/p_spec.c index c0ad9ea7f..2a4e13d55 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2485,6 +2485,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 422: // Cut away to another view { mobj_t *altview; + INT32 i; if (!mo || !mo->player) // only players have views return; @@ -2499,6 +2500,18 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) P_SetTarget(&mo->player->awayviewmobj, altview); mo->player->awayviewtics = P_AproxDistance(line->dx, line->dy)>>FRACBITS; + if (gamestate == GS_LEVEL) + { + for (i = 0; i <= splitscreen; i++) + { + if (displayplayers[i] == (mo->player - players)) + { + R_ResetViewInterpolation(i + 1); + R_ResetViewInterpolation(i + 1); + } + } + } + if (line->flags & ML_NOCLIMB) // lets you specify a vertical angle { INT32 aim; From 6722b4324465fb777b1bc044312f9538272f60fb Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 18:31:09 +0200 Subject: [PATCH 124/166] rendertimefrac_unpaused should be fracunit on netlag makes this a little more sane tbh --- src/d_main.c | 4 ++-- src/r_main.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 28c1dd594..fd07648be 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -826,7 +826,7 @@ void D_SRB2Loop(void) rendertimefrac = FRACUNIT; } - rendertimefrac_unpaused = g_time.timefrac; + rendertimefrac_unpaused = (!hu_stopped) ? g_time.timefrac : FRACUNIT; } else { @@ -856,7 +856,7 @@ void D_SRB2Loop(void) LUA_Step(); #ifdef HAVE_DISCORDRPC - if (! dedicated) + if (!dedicated) { Discord_RunCallbacks(); } diff --git a/src/r_main.c b/src/r_main.c index 90b4bbd55..f61753a19 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1359,7 +1359,7 @@ void R_SkyboxFrame(player_t *player) // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT); // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac_unpaused : FRACUNIT, false); } void R_SetupFrame(player_t *player, boolean skybox) @@ -1486,7 +1486,7 @@ void R_SetupFrame(player_t *player, boolean skybox) newview->player = player; - R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac_unpaused : FRACUNIT, false); } #define ANGLED_PORTALS From d1346dee533741b8ab4081622aa38560bbe87445 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 18:31:40 +0200 Subject: [PATCH 125/166] shouldnt that be a bool? --- src/d_clisrv.c | 2 +- src/d_clisrv.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f9110bb2d..ce6871288 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -136,7 +136,7 @@ static UINT8 gamestate_resend_counter[MAXNETNODES]; #endif // kart, true when a player is connecting or disconnecting so that the gameplay has stopped in its tracks -UINT8 hu_stopped = 0; +boolean hu_stopped = false; // Client specific static ticcmd_t localcmds; diff --git a/src/d_clisrv.h b/src/d_clisrv.h index cc123b1d2..197f3b794 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -656,7 +656,7 @@ extern UINT8 hu_resynching; #ifdef SATURNSYNCH extern UINT8 hu_redownloadinggamestate; #endif -extern UINT8 hu_stopped; // kart, true when the game is stopped for players due to a disconnecting or connecting player +extern boolean hu_stopped; // kart, true when the game is stopped for players due to a disconnecting or connecting player typedef struct rewind_s { UINT8 savebuffer[(768*1024)]; From c82148fafc3e12cb4b6ba2a015413e7fc5064079 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 18:44:14 +0200 Subject: [PATCH 126/166] prevent this from become super large somehow lol just like cap it at 19 it works just fine --- src/d_main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index fd07648be..471d29fa2 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -654,7 +654,7 @@ static boolean D_Display(void) // ========================================================================= tic_t rendergametic; -static int menuInputDelayTimer = 0; +static SINT8 menuInputDelayTimer = 0; void D_SRB2Loop(void) { @@ -792,9 +792,10 @@ void D_SRB2Loop(void) event_t myev; myev.type = ev_keydown; - menuInputDelayTimer++; + if (menuInputDelayTimer < 19) + menuInputDelayTimer++; - 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 (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 (DPADUPSCROLL) DPADSCROLLINPUT(KEY_UPARROW) From 297af069cb3fd3059cc8f7160f14a1c6f5eafe23 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:41:59 +0200 Subject: [PATCH 127/166] doubt anyone wants this also psure this will cause some weird issues somewhere idk --- src/p_spec.c | 10 +++++----- src/s_sound.c | 4 ++-- src/s_sound.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 710e76fd7..67d8cb617 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -99,7 +99,7 @@ typedef struct thinker_t **thinkers; } thinkerlist_t; -static boolean fromlapexec = false; +//static boolean fromlapexec = false; static void P_SearchForDisableLinedefs(void); static void P_SpawnScrollers(void); @@ -1342,7 +1342,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller fixed_t dist = P_AproxDistance(triggerline->dx, triggerline->dy)>>FRACBITS; size_t i, linecnt, sectori; INT16 specialtype = triggerline->special; - fromlapexec = false; + //fromlapexec = false; ///////////////////////////////////////////////// // Distance-checking/sector trigger conditions // @@ -1465,7 +1465,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller return false; } - fromlapexec = true; + //fromlapexec = true; } // If we were not triggered by a sector type especially for the purpose, // a Linedef Executor linedef trigger is not handling sector triggers properly, return. @@ -2135,8 +2135,8 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (keepmusic && (leveltime <= MUSICSTARTTIME)) //why check for starttime? cause encore music Zzz... return; - if (cv_ignoremusicchanges.value && (leveltime >= MUSICSTARTTIME) && !fromlapexec) // keep lap music intanct tho - return; + //if (cv_ignoremusicchanges.value && (leveltime >= MUSICSTARTTIME) && !fromlapexec) // keep lap music intanct tho + //return; // console player only unless NOCLIMB is set if ((line->flags & ML_NOCLIMB) || (mo && mo->player && P_IsLocalPlayer(mo->player))) diff --git a/src/s_sound.c b/src/s_sound.c index 6016b028b..c68e4d8e1 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -121,7 +121,7 @@ consvar_t cv_birdmusic = {"birdmusicstuff", "No", CV_SAVE|CV_CALL, CV_YesNo, Bir consvar_t cv_keepmusic = {"keepmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skipintromusic = {"skipintromusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +//consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; boolean keepmusic = false; static void S_CheckEventMus(const char *newmus); @@ -305,7 +305,7 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_keepmusic); CV_RegisterVar(&cv_skipintromusic); - CV_RegisterVar(&cv_ignoremusicchanges); + //CV_RegisterVar(&cv_ignoremusicchanges); COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); diff --git a/src/s_sound.h b/src/s_sound.h index e31040eac..5232ef5c1 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -69,7 +69,7 @@ extern consvar_t cv_birdmusic; extern consvar_t cv_keepmusic; extern consvar_t cv_skipintromusic; -extern consvar_t cv_ignoremusicchanges; +//extern consvar_t cv_ignoremusicchanges; extern boolean keepmusic; extern boolean skipintromus; #define MUSICSTARTTIME (starttime + (TICRATE/2)) From e8351d44b6d25b019bcd4df2ce68b253dbf5101b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:45:03 +0200 Subject: [PATCH 128/166] add crap to menu --- src/m_menu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2bfb3e1f1..0f92ccedf 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1667,7 +1667,10 @@ static menuitem_t OP_SoundAdvancedMenu[] = {IT_STRING | IT_CVAR, NULL, "Grow Music", &cv_growmusic, 117}, {IT_STRING | IT_CVAR, NULL, "Invulnerability Music", &cv_supermusic, 127}, - {IT_STRING | IT_CVAR, NULL, "Audio Buffer Size", &cv_audbuffersize, 147}, + {IT_STRING | IT_CVAR, NULL, "Keep Map Music", &cv_keepmusic, 139}, + {IT_STRING | IT_CVAR, NULL, "Skip Intro Music", &cv_skipintromusic, 149}, + + {IT_STRING | IT_CVAR, NULL, "Audio Buffer Size", &cv_audbuffersize, 157}, }; static const char* OP_SoundAdvancedTooltips[] = @@ -1685,6 +1688,8 @@ static const char* OP_SoundAdvancedTooltips[] = NULL, "Should the Grow music be on or off?", "Should the Invulnerability music be on or off?", + "Should music be kept when restarting the map?", + "Should the Intro fanfare be skipped\nand map music be played on map start?", "Size of the Audio Buffer\nreducing it will result in less sound latency\nbut may cause issues such as crackling or distorted Sound.", }; From f3a18a0655179fc294b3b6f320295d0dd20839a7 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:48:29 +0200 Subject: [PATCH 129/166] false --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index c68e4d8e1..5019213fb 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2189,7 +2189,7 @@ boolean S_FadeOutStopMusic(UINT32 ms) }*/ static INT16 oldmap = 0; -static boolean oldencore = 0; +static boolean oldencore = false; static boolean skipmusic = false; boolean skipintromus = false; From 8b915f9ac1cbed7698b130a1db7e4d8e6a12b0fc Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:53:25 +0200 Subject: [PATCH 130/166] make this less ugly --- src/m_menu.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 0f92ccedf..0aa2d3e93 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1653,24 +1653,25 @@ static const char* OP_SoundTooltips[] = static menuitem_t OP_SoundAdvancedMenu[] = { #ifdef HAVE_OPENMPT - {IT_HEADER, NULL, "Tracker Module Options", NULL, 10}, + {IT_HEADER, NULL, "Tracker Module Options", NULL, 0}, - {IT_STRING | IT_CVAR, NULL, "Instrument Filter", &cv_modfilter, 22}, - {IT_STRING | IT_CVAR, NULL, "Amiga Resampler", &cv_amigafilter, 42}, + {IT_STRING | IT_CVAR, NULL, "Instrument Filter", &cv_modfilter, 20}, + {IT_STRING | IT_CVAR, NULL, "Amiga Resampler", &cv_amigafilter, 30}, #if OPENMPT_API_VERSION_MAJOR < 1 && OPENMPT_API_VERSION_MINOR > 4 - {IT_STRING | IT_CVAR, NULL, "Amiga Type", &cv_amigatype, 62}, + {IT_STRING | IT_CVAR, NULL, "Amiga Type", &cv_amigatype, 40}, #endif - {IT_STRING | IT_CVAR, NULL, "Stereo Seperation", &cv_stereosep, 82}, + {IT_STRING | IT_CVAR, NULL, "Stereo Seperation", &cv_stereosep, 50}, #endif - {IT_HEADER, NULL, "Misc", NULL, 105}, - {IT_STRING | IT_CVAR, NULL, "Grow Music", &cv_growmusic, 117}, - {IT_STRING | IT_CVAR, NULL, "Invulnerability Music", &cv_supermusic, 127}, + {IT_HEADER, NULL, "Misc", NULL, 70}, - {IT_STRING | IT_CVAR, NULL, "Keep Map Music", &cv_keepmusic, 139}, - {IT_STRING | IT_CVAR, NULL, "Skip Intro Music", &cv_skipintromusic, 149}, + {IT_STRING | IT_CVAR, NULL, "Grow Music", &cv_growmusic, 90}, + {IT_STRING | IT_CVAR, NULL, "Invulnerability Music", &cv_supermusic, 100}, - {IT_STRING | IT_CVAR, NULL, "Audio Buffer Size", &cv_audbuffersize, 157}, + {IT_STRING | IT_CVAR, NULL, "Keep Map Music", &cv_keepmusic, 120}, + {IT_STRING | IT_CVAR, NULL, "Skip Intro Music", &cv_skipintromusic, 130}, + + {IT_STRING | IT_CVAR, NULL, "Audio Buffer Size", &cv_audbuffersize, 150}, }; static const char* OP_SoundAdvancedTooltips[] = From 63c1372c34d13b34e654f340f8cd0ae0fad67ab9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:57:55 +0200 Subject: [PATCH 131/166] keep debug print for now --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index a4049db9c..09813198a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5792,7 +5792,7 @@ static void HandlePacketFromPlayer(SINT8 node) #endif #ifdef SATURNPAK case PT_ISSATURN: - //CONS_Printf("hi im on saturn [node = %d]\n", node); + CONS_Printf("hi im on saturn node = %d\n", node); is_client_saturn[node] = true; can_receive_gamestate[node] = true; break; From 3f5b96bd4532ef2d27fc8c2ab3b22e302d0d3129 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 18:33:25 +0200 Subject: [PATCH 132/166] this shouldnt be here lol --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ce6871288..345431d4e 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -6385,7 +6385,7 @@ boolean TryRunTics(tic_t realtics) if (demo.playback) { - neededtic = gametic + realtics * (gamestate == GS_LEVEL ? cv_playbackspeed.value : 1); + neededtic = gametic + realtics; // start a game after a demo maketic += realtics; firstticstosend = maketic; From e47c13b7ac5540cda013efdc0ac9534b7960af30 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 23:01:03 +0200 Subject: [PATCH 133/166] proper inline M_Memcpy --- src/doomdef.h | 7 ++++++- src/m_misc.c | 5 ----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index bdc82a0ca..92e45ac1a 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -474,7 +474,12 @@ void M_StartupLocale(void); // M_GetText function that just returns the string. #define M_GetText(x) (x) #endif -void *M_Memcpy(void* dest, const void* src, size_t n); + +FUNCINLINE static ATTRINLINE void *M_Memcpy(void *dest, const void *src, size_t n) +{ + return memcpy(dest, src, n); +} + char *va(const char *format, ...) FUNCPRINTF; char *M_GetToken(const char *inputString); char *sizeu1(size_t num); diff --git a/src/m_misc.c b/src/m_misc.c index b8c88abb5..8bb82cdd7 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1987,11 +1987,6 @@ char *sizeu5(size_t num) return sizeu5_buf; } -FUNCINLINE ATTRINLINE void *M_Memcpy(void *dest, const void *src, size_t n) -{ - return memcpy(dest, src, n); -} - /** Return the appropriate message for a file error or end of file. */ const char *M_FileError(FILE *fp) From 9d13ff3c9fa18d97f828133ee585b16c61dbd8dd Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 23:01:17 +0200 Subject: [PATCH 134/166] proper inline P_MobjWasRemoved --- src/p_local.h | 8 +++++++- src/p_mobj.c | 7 ------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/p_local.h b/src/p_local.h index ab078e8b5..0902c8b3d 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -249,7 +249,7 @@ void P_RecalcPrecipInSector(sector_t *sector); void P_PrecipitationEffects(void); void P_RemoveMobj(mobj_t *th); -boolean P_MobjWasRemoved(const mobj_t *th); + void P_RemoveSavegameMobj(mobj_t *th); boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state); boolean P_SetMobjState(mobj_t *mobj, statenum_t state); @@ -261,6 +261,12 @@ boolean P_RailThinker(mobj_t *mobj); void P_PushableThinker(mobj_t *mobj); void P_SceneryThinker(mobj_t *mobj); +// This does not need to be added to Lua. +// To test it in Lua, check mobj.valid +FUNCINLINE static ATTRINLINE boolean P_MobjWasRemoved(const mobj_t *mobj) +{ + return !(mobj && mobj->thinker.function.acp1 == (actionf_p1)P_MobjThinker); +} fixed_t P_MobjFloorZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, line_t *line, boolean lowest, boolean perfect); fixed_t P_MobjCeilingZ(mobj_t *mobj, sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, line_t *line, boolean lowest, boolean perfect); diff --git a/src/p_mobj.c b/src/p_mobj.c index fb5a0fd0a..0fc870045 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10140,13 +10140,6 @@ void P_RemoveMobj(mobj_t *mobj) } } -// This does not need to be added to Lua. -// To test it in Lua, check mobj.valid -FUNCINLINE ATTRINLINE boolean P_MobjWasRemoved(const mobj_t *mobj) -{ - return !(mobj && mobj->thinker.function.acp1 == (actionf_p1)P_MobjThinker); -} - void P_FreePrecipMobj(precipmobj_t *mobj) { // unlink from sector and block lists From aa0cbfda74b55539b8355f683104259147cd858a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 9 Oct 2024 15:32:51 +0200 Subject: [PATCH 135/166] Revert "rendertimefrac_unpaused should be fracunit on netlag" This reverts commit 6722b4324465fb777b1bc044312f9538272f60fb. --- src/d_main.c | 4 ++-- src/r_main.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 471d29fa2..996d879e3 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -827,7 +827,7 @@ void D_SRB2Loop(void) rendertimefrac = FRACUNIT; } - rendertimefrac_unpaused = (!hu_stopped) ? g_time.timefrac : FRACUNIT; + rendertimefrac_unpaused = g_time.timefrac; } else { @@ -857,7 +857,7 @@ void D_SRB2Loop(void) LUA_Step(); #ifdef HAVE_DISCORDRPC - if (!dedicated) + if (! dedicated) { Discord_RunCallbacks(); } diff --git a/src/r_main.c b/src/r_main.c index f61753a19..90b4bbd55 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1359,7 +1359,7 @@ void R_SkyboxFrame(player_t *player) // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT); // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac_unpaused : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } void R_SetupFrame(player_t *player, boolean skybox) @@ -1486,7 +1486,7 @@ void R_SetupFrame(player_t *player, boolean skybox) newview->player = player; - R_InterpolateView(R_UsingFrameInterpolation() ? rendertimefrac_unpaused : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } #define ANGLED_PORTALS From 1428c3c2bfb74f2e08eb727120945a0c32134a97 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 11 Oct 2024 21:00:05 +0200 Subject: [PATCH 136/166] fix spec cam bug + more cleanup --- src/r_main.c | 59 +++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 90b4bbd55..618899c72 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1362,6 +1362,27 @@ void R_SkyboxFrame(player_t *player) R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } +static void +R_SetupCommonFrame +( player_t * player, + subsector_t * subsector) +{ + newview->player = player; + + newview->x += quake.x; + newview->y += quake.y; + newview->z += quake.z; + + newview->roll = R_ViewRollAngle(player); + + if (subsector) + newview->sector = subsector->sector; + else + newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; + + R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); +} + void R_SetupFrame(player_t *player, boolean skybox) { camera_t *thiscam; @@ -1393,7 +1414,6 @@ void R_SetupFrame(player_t *player, boolean skybox) { SETUPCAM(0, cv_chasecam, VIEWCONTEXT_PLAYER1) } - #undef SETUPCAM if (player->spectator) // no spectator chasecam @@ -1410,25 +1430,20 @@ void R_SetupFrame(player_t *player, boolean skybox) thiscam->chase = false; newview->sky = !skybox; - if (player->awayviewtics) + + if (player->awayviewtics) // cut-away view stuff { - // cut-away view stuff viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN I_Assert(viewmobj != NULL); newview->x = viewmobj->x; newview->y = viewmobj->y; newview->z = viewmobj->z + 20*FRACUNIT; + newview->aim = player->awayviewaiming; newview->angle = viewmobj->angle; - newview->x += quake.x; - newview->y += quake.y; - - if (!P_MobjWasRemoved(viewmobj) && viewmobj->subsector && thiscam && thiscam->subsector->sector) - newview->sector = viewmobj->subsector->sector; - else - newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; + R_SetupCommonFrame(player, viewmobj->subsector); } else if (!player->spectator && (thiscam && chasecam)) // use outside cam view { @@ -1437,24 +1452,21 @@ void R_SetupFrame(player_t *player, boolean skybox) newview->x = thiscam->x; newview->y = thiscam->y; newview->z = thiscam->z + (thiscam->height>>1); + newview->aim = thiscam->aiming; newview->angle = thiscam->angle; - newview->x += quake.x; - newview->y += quake.y; - - if (thiscam->subsector && thiscam->subsector->sector) - newview->sector = thiscam->subsector->sector; - else - newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; + R_SetupCommonFrame(player, thiscam->subsector); } else // use the player's eyes view { - newview->z = player->viewz; - viewmobj = player->mo; I_Assert(viewmobj != NULL); + newview->x = viewmobj->x; + newview->y = viewmobj->y; + newview->z = player->viewz; + newview->aim = player->aiming; newview->angle = viewmobj->angle; @@ -1479,14 +1491,9 @@ void R_SetupFrame(player_t *player, boolean skybox) } } } + + R_SetupCommonFrame(player, viewmobj->subsector); } - - newview->roll = R_ViewRollAngle(player); - newview->z += quake.z; - - newview->player = player; - - R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } #define ANGLED_PORTALS From c33afa4a3bf70ff9a592d28778b163ef5e729dd0 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 11 Oct 2024 19:09:49 +0200 Subject: [PATCH 137/166] shut up mingw --- src/lzf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lzf.c b/src/lzf.c index 28ba1b6cb..d5a837888 100644 --- a/src/lzf.c +++ b/src/lzf.c @@ -166,7 +166,7 @@ typedef unsigned char u8; #ifdef LZF_HSLOT # define LZF_HSLOT_BIAS ((const u8 *)in_data) #else -# if LZF_USE_OFFSETS +# ifdef LZF_USE_OFFSETS # define LZF_HSLOT_BIAS ((const u8 *)in_data) typedef unsigned int LZF_HSLOT; # else From b6a84c1646204332adc148b3c2ca36047ace765d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 19:39:52 +0200 Subject: [PATCH 138/166] readd music_resync_powerups_only --- src/m_menu.c | 1 + src/p_spec.c | 4 +--- src/s_sound.c | 2 ++ src/s_sound.h | 1 + src/sdl/mixer_sound.c | 4 +++- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2bfb3e1f1..62a303d7e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2577,6 +2577,7 @@ static menuitem_t OP_AdvancedBirdMenu[] = {IT_STRING | IT_CVAR, NULL, "Fade Back In While Respawning", &cv_respawnfademusicback, 40}, {IT_STRING | IT_CVAR, NULL, "Resync Threshold", &cv_music_resync_threshold, 60}, + {IT_STRING | IT_CVAR, NULL, "Resync Special Music Only", &cv_music_resync_powerups_only, 70}, }; static const char* OP_AdvancedBirdTooltips[] = diff --git a/src/p_spec.c b/src/p_spec.c index 2a4e13d55..81d5ad8b4 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2179,9 +2179,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) mapmusflags |= MUSIC_FORCERESET; mapmusposition = position; - - if (cv_birdmusic.value) - mapmusresume = 0; + mapmusresume = 0; S_ChangeMusicEx(mapmusname, mapmusflags, !(line->flags & ML_EFFECT4), position, !(line->flags & ML_EFFECT2) ? prefadems : 0, diff --git a/src/s_sound.c b/src/s_sound.c index ec5ebf00d..9496ea4e9 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -107,6 +107,7 @@ static CV_PossibleValue_t music_resync_threshold_cons_t[] = { {0} }; consvar_t cv_music_resync_threshold = {"music_resync_threshold", "0", CV_SAVE|CV_CALL, music_resync_threshold_cons_t, I_UpdateSongLagThreshold, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_music_resync_powerups_only = {"music_resync_powerups_only", "No", CV_SAVE|CV_CALL, CV_YesNo, I_UpdateSongLagThreshold, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_invincmusicfade = {"invincmusicfade", "300", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_growmusicfade = {"growmusicfade", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -281,6 +282,7 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_pausemusic); CV_RegisterVar(&cv_music_resync_threshold); + CV_RegisterVar(&cv_music_resync_powerups_only); CV_RegisterVar(&cv_invincmusicfade); CV_RegisterVar(&cv_growmusicfade); diff --git a/src/s_sound.h b/src/s_sound.h index 6f4d03f09..899d0e043 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -54,6 +54,7 @@ extern consvar_t cv_amigatype; //bird music stuff extern consvar_t cv_music_resync_threshold; +extern consvar_t cv_music_resync_powerups_only; extern consvar_t cv_invincmusicfade; extern consvar_t cv_growmusicfade; diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 12abb7c65..2fb3dc621 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -93,6 +93,8 @@ static UINT16 SAMPLERATE = 44100; /// ------------------------ UINT8 sound_started = false; + +static UINT32 stutter_threshold_user; static UINT32 stutter_threshold; static Mix_Music *music; @@ -1046,7 +1048,7 @@ void I_UpdateSongLagThreshold (void) if (!cv_birdmusic.value) return; - stutter_threshold = cv_music_resync_threshold.value/1000.0*(4*44100); + stutter_threshold = cv_music_resync_powerups_only.value ? 0 : (cv_music_resync_threshold.value/1000.0*(4*44100)); } /// ------------------------ From 659243baa1302c2937c0568cf91d6de590e8638f Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 19:44:15 +0200 Subject: [PATCH 139/166] always assign stutter_threshold --- src/sdl/mixer_sound.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 2fb3dc621..3f36399b3 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -594,6 +594,9 @@ Countstutter (int len) { UINT32 bytes; + if (!cv_birdmusic.value || gamestate != GS_LEVEL) + return; + if (hu_stopped) { music_stutter_bytes += len; @@ -629,8 +632,7 @@ static void count_music_bytes(int chan, void *stream, int len, void *udata) music_bytes += len; - if (cv_birdmusic.value && gamestate == GS_LEVEL) - Countstutter(len); + Countstutter(len); } static void music_loop(void) @@ -1045,9 +1047,6 @@ UINT32 I_GetSongPosition(void) void I_UpdateSongLagThreshold (void) { - if (!cv_birdmusic.value) - return; - stutter_threshold = cv_music_resync_powerups_only.value ? 0 : (cv_music_resync_threshold.value/1000.0*(4*44100)); } From 8630d8cd4759ba63a37cda17739c5f9e3d07c2e8 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 19:54:56 +0200 Subject: [PATCH 140/166] clean bird music stuff again we dont need to return everywhere but instead stuff can be mostly just set to 0 this also somewhat ensures stuff works after toggling without having to restart the game or map --- src/p_user.c | 16 +++++----------- src/s_sound.c | 9 ++++----- src/sdl/mixer_sound.c | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index a9b1b6b72..4cdbd2ae5 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -800,19 +800,13 @@ void P_RestoreMusic(player_t *player) if (G_RaceGametype() && player->laps >= (UINT8)(cv_numlaps.value - 1)) S_SpeedMusic(1.2f); #endif - if (cv_birdmusic.value) - { - if (mapmusresume && cv_resume.value) - position = mapmusresume; - else - position = mapmusposition; - - S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, S_GetRestoreMusicFadeIn()); - S_ClearRestoreMusicFadeInCvar(); - } + if (mapmusresume && cv_resume.value) // mapmusresume will be 0 anyways when birdmusic stuff is disabled + position = mapmusresume; else - S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); + position = mapmusposition; + S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, S_GetRestoreMusicFadeIn()); + S_ClearRestoreMusicFadeInCvar(); mapmusresume = 0; } } diff --git a/src/s_sound.c b/src/s_sound.c index 9496ea4e9..2abafc7ee 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2036,8 +2036,10 @@ void S_StopMusic(void) || demo.title) // SRB2Kart: Demos don't interrupt title screen music return; - if ((cv_birdmusic.value) && (strcasecmp(music_name, mapmusname) == 0)) + if (cv_birdmusic.value && (strcasecmp(music_name, mapmusname) == 0)) mapmusresume = I_GetSongPosition(); + else + mapmusresume = 0; if (I_SongPaused()) I_ResumeSong(); @@ -2110,10 +2112,7 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) void S_SetRestoreMusicFadeInCvar (consvar_t *cv) { - if (!cv_birdmusic.value) - return; - - music_refade_cv = cv; + music_refade_cv = cv_birdmusic.value ? cv : 0; } int S_GetRestoreMusicFadeIn (void) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 3f36399b3..854b451ad 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -1045,7 +1045,7 @@ UINT32 I_GetSongPosition(void) // 8M: 1 | 8S: 2 | 16M: 2 | 16S: 4 } -void I_UpdateSongLagThreshold (void) +void I_UpdateSongLagThreshold(void) { stutter_threshold = cv_music_resync_powerups_only.value ? 0 : (cv_music_resync_threshold.value/1000.0*(4*44100)); } From c51d33fa6efb9efa5573e9a8f8b362deb3bf06e6 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 20:19:44 +0200 Subject: [PATCH 141/166] save 1 G_BuildMapTitle call kek --- src/s_sound.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 5019213fb..b36783d41 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2244,10 +2244,15 @@ void S_CheckMap(void) // void S_InitMapMusic(void) { - char *maptitle = G_BuildMapTitle(gamemap); - skipintromus = cv_skipintromusic.value && stricmp(maptitle, "Wandering Falls") != 0; // thanks diggle! - if (maptitle) - Z_Free(maptitle); + if (!cv_skipintromusic.value) + skipintromus = false; + else + { + char *maptitle = G_BuildMapTitle(gamemap); + skipintromus = cv_skipintromusic.value && stricmp(maptitle, "Wandering Falls") != 0; // thanks diggle! + if (maptitle) + Z_Free(maptitle); + } if (mapmusflags & MUSIC_RELOADRESET) { From 4927e55c7ea8baafc00d7fbaa929a5130602b086 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 21:23:58 +0200 Subject: [PATCH 142/166] fix some warnings when compiling with older sdl version --- src/sdl/i_system.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 444fbb370..0815ee968 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2668,6 +2668,7 @@ void I_GamepadRumble(INT32 device_id, UINT16 low_strength, UINT16 high_strength, (void)device_id; (void)low_strength; (void)high_strength; + (void)duration; #else I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher @@ -2685,6 +2686,9 @@ void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 b { #if !(SDL_VERSION_ATLEAST(2,0,14)) (void)device_id; + (void)red; + (void)green; + (void)blue; #else I_Assert(device_id > 0); // Gamepad devices are always ID 1 or higher From 2e7f0721b9e48a89ed94fe51c8abe5cb143d4b68 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 21:24:37 +0200 Subject: [PATCH 143/166] make s_sound a little prettier --- src/s_sound.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 2abafc7ee..f8db2b296 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -276,14 +276,14 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_gamemidimusic); #endif - //bird music stuff + // bird music stuff CV_RegisterVar(&cv_playmusicifunfocused); CV_RegisterVar(&cv_playsoundifunfocused); CV_RegisterVar(&cv_pausemusic); CV_RegisterVar(&cv_music_resync_threshold); CV_RegisterVar(&cv_music_resync_powerups_only); - + CV_RegisterVar(&cv_invincmusicfade); CV_RegisterVar(&cv_growmusicfade); @@ -295,6 +295,7 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_resume); CV_RegisterVar(&cv_fading); CV_RegisterVar(&cv_birdmusic); + // bird music stuff end COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); @@ -1244,7 +1245,7 @@ void S_InitSfxChannels(INT32 sfxVolume) if (S_PrecacheSound()) { // Initialize external data (all sounds) at start, keep static. - CONS_Printf(M_GetText("Loading sounds... ")); + CONS_Printf(M_GetText("Pre-caching sounds...")); for (i = 1; i < sfx_freeslot0; i++) if (S_sfx[i].name && !S_sfx[i].data) @@ -1254,7 +1255,7 @@ void S_InitSfxChannels(INT32 sfxVolume) if (S_sfx[i].priority && !S_sfx[i].data) S_sfx[i].data = I_GetSfx(&S_sfx[i]); - CONS_Printf(M_GetText(" pre-cached all sound data\n")); + CONS_Printf(M_GetText("...pre-cached all sound data\n")); } } @@ -1770,9 +1771,7 @@ boolean S_MusicPaused(void) boolean S_MusicNotInFocus(void) { - return ( - ( window_notinfocus && ! cv_playmusicifunfocused.value ) - ); + return (window_notinfocus && !cv_playmusicifunfocused.value); } musictype_t S_MusicType(void) @@ -1800,10 +1799,8 @@ boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi) { - return ( - (checkDigi ? W_CheckNumForName(va("O_%s", mname)) != LUMPERROR : false) - || (checkMIDI ? W_CheckNumForName(va("D_%s", mname)) != LUMPERROR : false) - ); + return (checkDigi ? W_CheckNumForName(va("O_%s", mname)) != LUMPERROR : false) + || (checkMIDI ? W_CheckNumForName(va("D_%s", mname)) != LUMPERROR : false); } /// ------------------------ @@ -2371,7 +2368,7 @@ static void GameDigiMusic_OnChange(void) digital_disabled = false; I_StartupSound(); // will return early if initialised I_InitMusic(); - + if (Playing()) P_RestoreMusic(&players[consoleplayer]); else @@ -2408,14 +2405,12 @@ static void ModFilter_OnChange(void) { if (openmpt_mhandle) openmpt_module_set_render_param(openmpt_mhandle, OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, cv_modfilter.value); - } static void StereoSep_OnChange(void) { if (openmpt_mhandle) openmpt_module_set_render_param(openmpt_mhandle, OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT, cv_stereosep.value); - } static void AmigaFilter_OnChange(void) From 23b36b50749008fd2be4ecb44eb6de8b28576e80 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 21:29:39 +0200 Subject: [PATCH 144/166] oops --- src/sdl/mixer_sound.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 854b451ad..20cd3107c 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -94,7 +94,6 @@ static UINT16 SAMPLERATE = 44100; UINT8 sound_started = false; -static UINT32 stutter_threshold_user; static UINT32 stutter_threshold; static Mix_Music *music; From 55248e7fcf5e79fca5d8b7d3aef2de6c42c9bb1d Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 19 May 2024 13:45:34 +0300 Subject: [PATCH 145/166] Attempt to fix a lua panic when unarchiveing extvars (print error to console instead. Not sure if it would be safe for game to read from save afterwards though) --- src/lua_script.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index 9d5bef4a7..c6df314d4 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1460,7 +1460,13 @@ static void UnArchiveExtVars(void *pointer) for (i = 0; i < field_count; i++) { READSTRING(save_p, field); - UnArchiveValue(TABLESINDEX); + + if (UnArchiveValue(TABLESINDEX) == 1) + { + CONS_Alert(CONS_ERROR, "Unexpected end marker when reading ExtVars (field '%s')\n", field); + break; + } + lua_setfield(gL, -2, field); } From 210d6ac8ac38b2c0c300b87f8e5f764355b08646 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 4 May 2024 17:25:37 +0300 Subject: [PATCH 146/166] Add few checks to prevent game crashing if netgame archive becomes corrupted --- src/lua_script.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index c6df314d4..8015e75f3 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1333,6 +1333,9 @@ static UINT8 UnArchiveValue(int TABLESINDEX) break; case ARCH_TEND: return 1; + default: + CONS_Alert(CONS_ERROR, "Unknown value type unarchived, save is corrupted!\n"); + return 1; } return 0; } @@ -1530,12 +1533,29 @@ static void UnArchiveTables(void) for (i = 1; i <= n; i++) { lua_rawgeti(gL, TABLESINDEX, i); + + if (!lua_istable(gL, -1)) + { + CONS_Alert(CONS_ERROR, "Value in tables list #%d is not a table! (corrupted save?)\n", i); + continue; + } + while (true) { if (UnArchiveValue(TABLESINDEX) == 1) // read key break; - if (UnArchiveValue(TABLESINDEX) == 2) // read value + + UINT8 ret = UnArchiveValue(TABLESINDEX); + + if (ret == 1) + { + CONS_Alert(CONS_ERROR, "Unexpected end of save reached (Corrupted save?)\n"); + lua_pop(gL, 1); // Pop key + break; + } + 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); From d00014ea599c542d3ba94137ee94826da62936b6 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 4 May 2024 18:14:34 +0300 Subject: [PATCH 147/166] If corrupted save received, leave netgame --- src/lua_script.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lua_script.c b/src/lua_script.c index 8015e75f3..f65f49f92 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -22,6 +22,8 @@ #include "p_saveg.h" #include "p_local.h" #include "p_slopes.h" // for P_SlopeById +#include "s_sound.h" +#include "m_menu.h" #ifdef LUA_ALLOW_BYTECODE #include "d_netfil.h" // for LUA_DumpFile #endif @@ -1335,6 +1337,9 @@ static UINT8 UnArchiveValue(int TABLESINDEX) return 1; default: CONS_Alert(CONS_ERROR, "Unknown value type unarchived, save is corrupted!\n"); + G_SetExitGameFlag(); + S_StartSound(NULL, sfx_syfail); // he he he + M_StartMessage(M_GetText("Corrupted save received\nPress ESC\n"), NULL, MM_NOTHING); return 1; } return 0; From 02bbb38606983badaa6cc046f6ce2b5fd5b6fed0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 23:10:01 +0200 Subject: [PATCH 148/166] Fix insane TTY input latency https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2360 --- src/sdl/i_system.c | 79 ++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 0815ee968..66e0819dc 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -111,6 +111,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #endif #if defined (__unix__) || (defined (UNIXCOMMON) && !defined (__APPLE__)) +#include #include #include #define NEWSIGNALHANDLER @@ -698,50 +699,60 @@ void I_GetConsoleEvents(void) // we use this when sending back commands event_t ev = {0,0,0,0}; char key = 0; - ssize_t d; + struct pollfd pfd = + { + .fd = STDIN_FILENO, + .events = POLLIN, + .revents = 0, + }; if (!consolevent) return; - ev.type = ev_console; - ev.data1 = 0; - if (read(STDIN_FILENO, &key, 1) == -1 || !key) - return; + for (;;) + { + if (poll(&pfd, 1, 0) < 1 || !(pfd.revents & POLLIN)) + return; - // we have something - // backspace? - // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere - if ((key == tty_erase) || (key == 127) || (key == 8)) - { - if (tty_con.cursor > 0) + ev.type = ev_console; + ev.data1 = 0; + if (read(STDIN_FILENO, &key, 1) == -1 || !key) + return; + + // we have something + // backspace? + // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere + if ((key == tty_erase) || (key == 127) || (key == 8)) { - tty_con.cursor--; - tty_con.buffer[tty_con.cursor] = '\0'; - tty_Back(); + if (tty_con.cursor > 0) + { + tty_con.cursor--; + tty_con.buffer[tty_con.cursor] = '\0'; + tty_Back(); + } + ev.data1 = KEY_BACKSPACE; } - ev.data1 = KEY_BACKSPACE; - } - else if (key < ' ') // check if this is a control char - { - if (key == '\n') + else if (key < ' ') // check if this is a control char { - tty_Clear(); - tty_con.cursor = 0; - ev.data1 = KEY_ENTER; + if (key == '\n') + { + tty_Clear(); + tty_con.cursor = 0; + ev.data1 = KEY_ENTER; + } + else continue; } - else return; + else if (tty_con.cursor < sizeof(tty_con.buffer)) + { + // push regular character + ev.data1 = tty_con.buffer[tty_con.cursor] = key; + tty_con.cursor++; + // print the current line (this is differential) + write(STDOUT_FILENO, &key, 1); + } + if (ev.data1) D_PostEvent(&ev); + //tty_FlushIn(); } - else if (tty_con.cursor < sizeof (tty_con.buffer)) - { - // push regular character - ev.data1 = tty_con.buffer[tty_con.cursor] = key; - tty_con.cursor++; - // print the current line (this is differential) - d = write(STDOUT_FILENO, &key, 1); - } - if (ev.data1) D_PostEvent(&ev); - //tty_FlushIn(); - (void)d; } #elif defined (_WIN32) From 081dcc021b2029ff825ac1995b9f5c198146f74f Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 23:21:05 +0200 Subject: [PATCH 149/166] fix tty converting everything to lowercase --- src/console.c | 1 - src/m_textinput.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/console.c b/src/console.c index dbeb2b42b..9781078fa 100644 --- a/src/console.c +++ b/src/console.c @@ -898,7 +898,6 @@ boolean CON_Responder(event_t *ev) // show all cvars/commands that match what we have inputted if (key == KEY_TAB) { - if (!completion[0]) { if (!input.length || input.length >= 40 || strchr(input.buffer, ' ')) diff --git a/src/m_textinput.c b/src/m_textinput.c index 8b608cc9a..a73511f77 100644 --- a/src/m_textinput.c +++ b/src/m_textinput.c @@ -295,10 +295,6 @@ boolean M_TextInputHandle(textinput_t *input, INT32 key) if (key < 32 || key > 127) return false; - // add key to cmd line here - if (key >= 'A' && key <= 'Z' && !(shiftdown ^ capslock)) //this is only really necessary for dedicated servers - key = key + 'a' - 'A'; - if (input->select != input->cursor) M_TextInputDelSelection(input); M_TextInputAddChar(input, key); From d7ed91af1d2dbd5f84ea4ed2ebec57f7066dec0d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 23:26:07 +0200 Subject: [PATCH 150/166] Refactor TTY input handling https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2451#b2f76b3273f1780347c35ec752bcde560c5f73a5 --- src/sdl/i_system.c | 98 +++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 54 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 66e0819dc..f999d8684 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -545,10 +545,9 @@ typedef struct feild_t tty_con; -// when printing general stuff to stdout stderr (Sys_Printf) -// we need to disable the tty console stuff -// this increments so we can recursively disable -static INT32 ttycon_hide = 0; +// lock to prevent clearing partial lines, since not everything +// printed ends on a newline. +static boolean ttycon_ateol = true; // some key codes that the terminal may be using // TTimo NOTE: I'm not sure how relevant this is static INT32 tty_erase; @@ -576,63 +575,31 @@ static inline void tty_FlushIn(void) // TTimo NOTE: it seems on some terminals just sending '\b' is not enough // so for now, in any case we send "\b \b" .. yeah well .. // (there may be a way to find out if '\b' alone would work though) +// Hanicef NOTE: using \b this way is unreliable because of terminal state, +// it's better to use \r to reset the cursor to the beginning of the +// line and clear from there. static void tty_Back(void) { - char key; - ssize_t d; - key = '\b'; - d = write(STDOUT_FILENO, &key, 1); - key = ' '; - d = write(STDOUT_FILENO, &key, 1); - key = '\b'; - d = write(STDOUT_FILENO, &key, 1); - (void)d; + write(STDOUT_FILENO, "\r", 1); + if (tty_con.cursor>0) + { + write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor); + } + write(STDOUT_FILENO, " \b", 2); } static void tty_Clear(void) { size_t i; + write(STDOUT_FILENO, "\r", 1); if (tty_con.cursor>0) { for (i=0; i0); - ttycon_hide--; - if (ttycon_hide == 0 && tty_con.cursor) - { - for (i=0; i 0) { LPVOID blank = malloc(oldLength); - if (!blank) return; + if (!blank) + { + free(txt); + return; + } memset(blank, ' ', oldLength); // Blank out. oldLines = malloc(oldLength*sizeof(TCHAR)); if (!oldLines) { + free(txt); free(blank); return; } @@ -1039,18 +1026,20 @@ void I_OutputMsg(const char *fmt, ...) } #else #ifdef HAVE_TERMIOS - if (consolevent) + if (consolevent && ttycon_ateol) { - tty_Hide(); + tty_Clear(); + ttycon_ateol = false; } #endif if (!framebuffer) fprintf(stderr, "%s", txt); #ifdef HAVE_TERMIOS - if (consolevent) + if (consolevent && txt[len-1] == '\n') { - tty_Show(); + write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor); + ttycon_ateol = true; } #endif @@ -1059,6 +1048,7 @@ void I_OutputMsg(const char *fmt, ...) fflush(stderr); #endif + free(txt); } // From f01d2a0ba6aebf8a21caa1aaef85bf116d950289 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 23:29:11 +0200 Subject: [PATCH 151/166] print saturnpak print into debfile instead of console --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 89aa24b13..f230ab190 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5792,7 +5792,7 @@ static void HandlePacketFromPlayer(SINT8 node) #endif #ifdef SATURNPAK case PT_ISSATURN: - CONS_Printf("hi im on saturn node = %d\n", node); + DEBFILE(va("hi im on saturn! node = %d\n", node)); is_client_saturn[node] = true; can_receive_gamestate[node] = true; break; From b58fcf331c4350aa1c7b8fe905622b45dbc6fee1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 00:40:37 +0200 Subject: [PATCH 152/166] ignore keepmusic when called from P_RestoreMusic most of the sound handling just calls this and this may just stop the music entirely on some occasions so just ignore keepmusic for that --- src/k_kart.c | 2 +- src/p_user.c | 2 +- src/s_sound.c | 6 +++--- src/s_sound.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 8c6356fdf..f71ceb049 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5361,7 +5361,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) // Plays the music during and after the starting countdown. if (P_IsLocalPlayer(player)) - S_StartMapMusic(); + S_StartMapMusic(false); } void K_KartPlayerAfterThink(player_t *player) diff --git a/src/p_user.c b/src/p_user.c index 643e03e9b..7612b17e6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -743,7 +743,7 @@ void P_RestoreMusic(player_t *player) return; if (leveltime < MUSICSTARTTIME) - S_StartMapMusic(); + S_StartMapMusic(true); else // see also where time overs are handled - search for "lives = 2" in this file { INT32 wantedmus = 0; // 0 is level music, 1 is invincibility, 2 is grow diff --git a/src/s_sound.c b/src/s_sound.c index 5e171b6d4..868bccc77 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2276,18 +2276,18 @@ void S_InitMapMusic(void) //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); } -void S_StartMapMusic(void) +void S_StartMapMusic(boolean restore) { //no need to constantly run this after race has started if (leveltime > MUSICSTARTTIME) return; - if (keepmusic) + if (keepmusic && !restore) // make sure this doesent kill the music when its called from P_RestoreMusic in some cases return; if (skipintromus) { - if (leveltime < starttime) // dumb but i dont need this to be spammed honestly + if (leveltime < starttime) S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); if (leveltime == MUSICSTARTTIME) S_ShowMusicCredit(); diff --git a/src/s_sound.h b/src/s_sound.h index a22763449..887cdd878 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -110,7 +110,7 @@ void S_StopSounds(void); void S_ClearSfx(void); void S_InitMapMusic(void); -void S_StartMapMusic(void); +void S_StartMapMusic(boolean restore); void S_CheckMap(void); From 3f12ebb2bd461303297ae72dfd6543becdee7b07 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 01:11:48 +0200 Subject: [PATCH 153/166] only interp cam during pause for replay freecam to not jitter during pause --- src/r_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 618899c72..ef1560470 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1359,7 +1359,7 @@ void R_SkyboxFrame(player_t *player) // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT); // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } static void @@ -1380,7 +1380,7 @@ R_SetupCommonFrame else newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; - R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } void R_SetupFrame(player_t *player, boolean skybox) From 262a84aac6478f81cbee5720bfef7dd00cd5f151 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 02:28:07 +0200 Subject: [PATCH 154/166] fix ogl shearing no clue wtf kart was doing here lmao --- src/hardware/hw_defs.h | 2 +- src/hardware/hw_main.c | 42 ++++++++++++++++++-------------- src/hardware/r_opengl/r_opengl.c | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 7d2d17532..dc8d44ca8 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -156,7 +156,7 @@ typedef struct boolean mirrorflip; // Encore Mode with Flipcam #endif boolean shearing; // 14042019 - angle_t viewaiming; // 17052019 + float viewaiming; // 17052019 } FTransform; // Transformed vector, as passed to HWR API diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index db9846c07..5d243d4c3 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -309,9 +309,10 @@ FTransform atransform; // Float variants of viewx, viewy, viewz, etc. static float gr_viewx, gr_viewy, gr_viewz; float gr_viewsin, gr_viewcos; +static float gr_viewludsin, gr_viewludcos; static angle_t gr_aimingangle; -static float gr_viewludsin, gr_viewludcos; +static void HWR_SetTransformAiming(FTransform *trans); // ========================================================================== // Visual portals (attr. Hannu Hanhi) @@ -5130,15 +5131,12 @@ void HWR_DrawSkyBackground(float fpov) //04/01/2000: Hurdler: added for T&L // It should replace all other gr_viewxxx when finished - if (!atransform.shearing) - dometransform.anglex = (float)(aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); + HWR_SetTransformAiming(&dometransform); dometransform.angley = (float)((viewangle-ANGLE_270)>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); dometransform.flip = atransform.flip; dometransform.mirror = atransform.mirror; dometransform.mirrorflip = atransform.mirrorflip; - dometransform.shearing = atransform.shearing; - dometransform.viewaiming = atransform.viewaiming; dometransform.scalex = 1; dometransform.scaley = (float)vid.width/vid.height; @@ -5199,6 +5197,25 @@ void HWR_SetViewSize(void) HWD.pfnFlushScreenTextures(); } +// Set view aiming, for the sky dome, the skybox, +// and the normal view, all with a single function. +static void HWR_SetTransformAiming(FTransform *trans) +{ + if (cv_grshearing.value) + { + fixed_t fixedaiming = AIMINGTODY(aimingangle); + trans->viewaiming = FIXED_TO_FLOAT(fixedaiming); + trans->shearing = true; + gr_aimingangle = 0; + } + else + { + trans->shearing = false; + gr_aimingangle = aimingangle; + } + trans->anglex = (float)(gr_aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); +} + void HWR_SetTransform(float fpov, player_t *player) { postimg_t *postprocessor = &postimgtype[0]; @@ -5221,23 +5238,12 @@ void HWR_SetTransform(float fpov, player_t *player) atransform.scaley = (float)vid.width/vid.height; atransform.scalez = 1; - // 14042019 - gr_aimingangle = aimingangle; - atransform.shearing = false; - atransform.viewaiming = aimingangle; - - if (cv_grshearing.value) - { - gr_aimingangle = 0; - atransform.shearing = true; - } + HWR_SetTransformAiming(&atransform); + atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); gr_viewludsin = FIXED_TO_FLOAT(FINECOSINE(gr_aimingangle>>ANGLETOFINESHIFT)); gr_viewludcos = FIXED_TO_FLOAT(-FINESINE(gr_aimingangle>>ANGLETOFINESHIFT)); - atransform.anglex = (float)(gr_aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); - atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); - atransform.fovxangle = fpov; // Tails atransform.fovyangle = fpov; // Tails HWR_RollTransform(&atransform, viewroll); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index abfbfdd25..4be4d4c27 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2984,7 +2984,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) // https://zdoom.org/wiki/Y-shearing if (shearing) { - float dy = FIXED_TO_FLOAT(AIMINGTODY((stransform->viewaiming)) * 2)* ((float)vid.width / vid.height) / ((float)BASEVIDWIDTH / BASEVIDHEIGHT); //screen_width/BASEVIDWIDTH; + float dy = stransform->viewaiming * 2; if (stransform->flip || stransform->mirrorflip) dy *= -1.0f; pglTranslatef(0.0f, -dy/BASEVIDHEIGHT, 0.0f); From 7f6ce1f299c25070d09e6434203b9ec8cc7c327d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 02:46:04 +0200 Subject: [PATCH 155/166] this uhhh actually makes things crash lol --- src/r_things.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 31c3dcbe4..56dfb8d76 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -609,6 +609,7 @@ void R_DrawMaskedColumn(column_t *column) dc_yh = mfloorclip[dc_x]-1; if (dc_yl <= mceilingclip[dc_x]) dc_yl = mceilingclip[dc_x]+1; + if (dc_yl < 0) dc_yl = 0; if (dc_yh >= vid.height) @@ -625,6 +626,10 @@ void R_DrawMaskedColumn(column_t *column) // quick fix... something more proper should be done!!! if (ylookup[dc_yl]) colfunc(); +#ifdef PARANOIA + else + I_Error("R_DrawMaskedColumn: Invalid ylookup for dc_yl %d", dc->yl); +#endif } column = (column_t *)((UINT8 *)column + column->length + 4); } @@ -837,14 +842,6 @@ static void R_DrawVisSprite(vissprite_t *vis) if (vis->x2 >= vid.width) vis->x2 = vid.width-1; - // Something is occasionally setting 1px-wide sprites whose frac is exactly the width of the sprite, causing crashes due to - // accessing invalid column info. Until the cause is found, let's try to correct those manually... - { - fixed_t temp = ((frac + vis->xiscale*(vis->x2-vis->x1))>>FRACBITS) - SHORT(patch->width); - if (temp > 0) - vis->x2 -= temp; - } - localcolfunc = (vis->vflip) ? R_DrawFlippedMaskedColumn : R_DrawMaskedColumn; lengthcol = patch->height; From d37505ff06f37716f879f047e4488b9a8f1eccf0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 02:58:46 +0200 Subject: [PATCH 156/166] this should be SHORT --- src/r_things.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/r_things.c b/src/r_things.c index 56dfb8d76..3f96ed419 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -843,13 +843,14 @@ static void R_DrawVisSprite(vissprite_t *vis) vis->x2 = vid.width-1; localcolfunc = (vis->vflip) ? R_DrawFlippedMaskedColumn : R_DrawMaskedColumn; - lengthcol = patch->height; + lengthcol = SHORT(patch->height); // Split drawing loops for paper and non-paper to reduce conditional checks per sprite if (vis->scalestep) { fixed_t horzscale = FixedMul(vis->spritexscale, this_scale); fixed_t scalestep = FixedMul(vis->scalestep, vis->spriteyscale); + pwidth = SHORT(patch->width); // Papersprite drawing loop From a19c4dc5e5cf6e62de8a566ccd944c38cca12b67 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 13 Oct 2024 15:09:10 +0300 Subject: [PATCH 157/166] Fix game crashing when using P_DoPlayerExit on player without mobj --- src/p_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_user.c b/src/p_user.c index 7612b17e6..7c57fb107 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1249,7 +1249,7 @@ void P_DoPlayerExit(player_t *player) player->exiting = raceexittime+2; K_KartUpdatePosition(player); - if (cv_kartvoices.value) + if (!P_MobjWasRemoved(player->mo) && cv_kartvoices.value) { if (P_IsLocalPlayer(player)) { From 4cf4d49f482c03e7826c23ab94253fd89a2453e3 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 13 Oct 2024 15:37:29 +0300 Subject: [PATCH 158/166] Fix error handler staying on lua stack after lua commands being called --- src/lua_consolelib.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 3e70ce008..f2fb03dc6 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -81,6 +81,9 @@ void Got_Luacmd(UINT8 **cp, INT32 playernum) lua_pushstring(gL, buf); } LUA_Call(gL, (int)argc, 0, 1); // argc is 1-based, so this will cover the player we passed too. + + lua_pop(gL, 1); // Pop LUA_GetErrorMessage (lua_pcall doesn't pop it) + return; deny: @@ -143,7 +146,7 @@ void COM_Lua_f(void) if (netgame && !( flags & COM_LOCAL ))/* don't send local commands */ { // Send the command through the network UINT8 argc; - lua_pop(gL, 1); // pop command info table + lua_pop(gL, 2); // pop command info table and LUA_GetErrorMessage if (flags & COM_ADMIN && !server && !IsPlayerAdmin(playernum)) // flag 1: only server/admin can use this command. { @@ -182,6 +185,8 @@ void COM_Lua_f(void) for (i = 1; i < COM_Argc(); i++) lua_pushstring(gL, COM_Argv(i)); LUA_Call(gL, (int)COM_Argc(), 0, 1); // COM_Argc is 1-based, so this will cover the player we passed too. + + lua_pop(gL, 1); // Pop LUA_GetErrorMessage (lua_pcall doesn't pop it) } // Wrapper for COM_AddCommand From 38f3e48aed20ca2168143e72b995430582644ba6 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 23:07:32 +0200 Subject: [PATCH 159/166] only do this in software renderer doesent work even with pal rendering in ogl --- src/d_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index 996d879e3..1dfe3eafa 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -568,7 +568,7 @@ static boolean D_Display(void) V_DrawScaledPatch(viewwindowx + (BASEVIDWIDTH - SHORT(patch->width))/2, py, V_SNAPTOTOP, patch); } - if (demo.rewinding) + if (rendermode == render_soft && demo.rewinding) V_DrawFadeScreen(TC_RAINBOW, (leveltime & 0x20) ? SKINCOLOR_PASTEL : SKINCOLOR_MOONSLAM); // vid size change is now finished if it was on... From 1daac9a124b6fea2ed9592c45879d8748878a509 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 14 Oct 2024 22:15:27 +0200 Subject: [PATCH 160/166] revert all the cam things for now here Dont wanna deal with this shit for 7.1 anymore --- src/r_main.c | 122 +++++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 57 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index ef1560470..75ff41126 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1356,30 +1356,6 @@ void R_SkyboxFrame(player_t *player) else newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; - // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT); - // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - - R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); -} - -static void -R_SetupCommonFrame -( player_t * player, - subsector_t * subsector) -{ - newview->player = player; - - newview->x += quake.x; - newview->y += quake.y; - newview->z += quake.z; - - newview->roll = R_ViewRollAngle(player); - - if (subsector) - newview->sector = subsector->sector; - else - newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; - R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } @@ -1388,33 +1364,50 @@ void R_SetupFrame(player_t *player, boolean skybox) camera_t *thiscam; boolean chasecam = false; -#define SETUPCAM(num, var, context)\ - thiscam = &camera[num];\ - chasecam = (var.value != 0);\ - R_SetViewContext(context);\ - if (thiscam->reset)\ - {\ - R_ResetViewInterpolation(num+1);\ - thiscam->reset = false;\ - } - if (splitscreen > 2 && player == &players[displayplayers[3]]) { - SETUPCAM(3, cv_chasecam4, VIEWCONTEXT_PLAYER4) + thiscam = &camera[3]; + chasecam = (cv_chasecam4.value != 0); + R_SetViewContext(VIEWCONTEXT_PLAYER4); + if (thiscam->reset) + { + R_ResetViewInterpolation(4); + thiscam->reset = false; + } } else if (splitscreen > 1 && player == &players[displayplayers[2]]) { - SETUPCAM(2, cv_chasecam3, VIEWCONTEXT_PLAYER3) + thiscam = &camera[2]; + chasecam = (cv_chasecam3.value != 0); + R_SetViewContext(VIEWCONTEXT_PLAYER3); + if (thiscam->reset) + { + R_ResetViewInterpolation(3); + thiscam->reset = false; + } } else if (splitscreen && player == &players[displayplayers[1]]) { - SETUPCAM(1, cv_chasecam2, VIEWCONTEXT_PLAYER2) + thiscam = &camera[1]; + chasecam = (cv_chasecam2.value != 0); + R_SetViewContext(VIEWCONTEXT_PLAYER2); + if (thiscam->reset) + { + R_ResetViewInterpolation(2); + thiscam->reset = false; + } } else { - SETUPCAM(0, cv_chasecam, VIEWCONTEXT_PLAYER1) + thiscam = &camera[0]; + chasecam = (cv_chasecam.value != 0); + R_SetViewContext(VIEWCONTEXT_PLAYER1); + if (thiscam->reset) + { + R_ResetViewInterpolation(1); + thiscam->reset = false; + } } -#undef SETUPCAM if (player->spectator) // no spectator chasecam chasecam = false; // force chasecam off @@ -1435,38 +1428,24 @@ void R_SetupFrame(player_t *player, boolean skybox) { viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN I_Assert(viewmobj != NULL); - - newview->x = viewmobj->x; - newview->y = viewmobj->y; newview->z = viewmobj->z + 20*FRACUNIT; - newview->aim = player->awayviewaiming; newview->angle = viewmobj->angle; - - R_SetupCommonFrame(player, viewmobj->subsector); } else if (!player->spectator && (thiscam && chasecam)) // use outside cam view { viewmobj = NULL; - - newview->x = thiscam->x; - newview->y = thiscam->y; newview->z = thiscam->z + (thiscam->height>>1); - newview->aim = thiscam->aiming; newview->angle = thiscam->angle; - - R_SetupCommonFrame(player, thiscam->subsector); } else // use the player's eyes view { + newview->z = player->viewz; + viewmobj = player->mo; I_Assert(viewmobj != NULL); - newview->x = viewmobj->x; - newview->y = viewmobj->y; - newview->z = player->viewz; - newview->aim = player->aiming; newview->angle = viewmobj->angle; @@ -1491,9 +1470,38 @@ void R_SetupFrame(player_t *player, boolean skybox) } } } - - R_SetupCommonFrame(player, viewmobj->subsector); } + newview->roll = R_ViewRollAngle(player); + newview->z += quake.z; + + newview->player = player; + + if ((thiscam && chasecam) && !player->awayviewtics && !player->spectator) + { + newview->x = thiscam->x; + newview->y = thiscam->y; + newview->x += quake.x; + newview->y += quake.y; + + if (thiscam->subsector && thiscam->subsector->sector) + newview->sector = thiscam->subsector->sector; + else + newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; + } + else + { + newview->x = viewmobj->x; + newview->y = viewmobj->y; + newview->x += quake.x; + newview->y += quake.y; + + if (!P_MobjWasRemoved(viewmobj) && viewmobj->subsector && thiscam && thiscam->subsector->sector) + newview->sector = viewmobj->subsector->sector; + else + newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; + } + + R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } #define ANGLED_PORTALS From d3e2875c94ac4cec114f2f98e07383d1842b12c7 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Oct 2024 12:57:27 +0200 Subject: [PATCH 161/166] =?UTF-8?q?those=20can=20be=20registered=20in=20l?= =?UTF-8?q?=C3=B6=C3=B6p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/d_netcmd.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index ceaa38e2b..e54251125 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -978,7 +978,6 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_audbuffersize); // m_menu.c - //CV_RegisterVar(&cv_compactscoreboard); CV_RegisterVar(&cv_chatheight); CV_RegisterVar(&cv_chatwidth); CV_RegisterVar(&cv_chattime); @@ -1090,20 +1089,12 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_controlperkey); CV_RegisterVar(&cv_turnsmooth); - CV_RegisterVar(&cv_rumble[0]); - CV_RegisterVar(&cv_rumble[1]); - CV_RegisterVar(&cv_rumble[2]); - CV_RegisterVar(&cv_rumble[3]); - - CV_RegisterVar(&cv_gamepadled[0]); - CV_RegisterVar(&cv_gamepadled[1]); - CV_RegisterVar(&cv_gamepadled[2]); - CV_RegisterVar(&cv_gamepadled[3]); - - CV_RegisterVar(&cv_ledpowerup[0]); - CV_RegisterVar(&cv_ledpowerup[1]); - CV_RegisterVar(&cv_ledpowerup[2]); - CV_RegisterVar(&cv_ledpowerup[3]); + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + CV_RegisterVar(&cv_rumble[i]); + CV_RegisterVar(&cv_gamepadled[i]); + CV_RegisterVar(&cv_ledpowerup[i]); + } CV_RegisterVar(&cv_usemouse); CV_RegisterVar(&cv_usemouse2); @@ -1207,26 +1198,16 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_speed); CV_RegisterVar(&cv_opflags); CV_RegisterVar(&cv_mapthingnum); - //CV_RegisterVar(&cv_grid); - //CV_RegisterVar(&cv_snapto); // add cheat commands COM_AddCommand("noclip", Command_CheatNoClip_f); COM_AddCommand("god", Command_CheatGod_f); COM_AddCommand("notarget", Command_CheatNoTarget_f); - /*COM_AddCommand("getallemeralds", Command_Getallemeralds_f); - COM_AddCommand("resetemeralds", Command_Resetemeralds_f); - COM_AddCommand("setrings", Command_Setrings_f); - COM_AddCommand("setlives", Command_Setlives_f); - COM_AddCommand("setcontinues", Command_Setcontinues_f);*/ COM_AddCommand("devmode", Command_Devmode_f); COM_AddCommand("savecheckpoint", Command_Savecheckpoint_f); COM_AddCommand("scale", Command_Scale_f); COM_AddCommand("gravflip", Command_Gravflip_f); COM_AddCommand("hurtme", Command_Hurtme_f); - /*COM_AddCommand("jumptoaxis", Command_JumpToAxis_f); - COM_AddCommand("charability", Command_Charability_f); - COM_AddCommand("charspeed", Command_Charspeed_f);*/ COM_AddCommand("teleport", Command_Teleport_f); COM_AddCommand("rteleport", Command_RTeleport_f); COM_AddCommand("skynum", Command_Skynum_f); From afca521fe5b40f1628ebe15900a295c502aba219 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 17 Oct 2024 22:54:44 +0200 Subject: [PATCH 162/166] dont run director if theres only one player ingame idk if this is good lol --- src/g_game.h | 12 ++---------- src/k_director.c | 17 ++++++++++++++++- src/st_stuff.c | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/g_game.h b/src/g_game.h index aaafa233c..b00bf1343 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -419,19 +419,9 @@ void G_SetGamestate(gamestate_t newstate); // Gamedata record shit void G_AllocMainRecordData(INT16 i); -//void G_AllocNightsRecordData(INT16 i); void G_ClearRecords(void); -//UINT32 G_GetBestScore(INT16 map); tic_t G_GetBestTime(INT16 map); -//tic_t G_GetBestLap(INT16 map); -//UINT16 G_GetBestRings(INT16 map); -//UINT32 G_GetBestNightsScore(INT16 map, UINT8 mare); -//tic_t G_GetBestNightsTime(INT16 map, UINT8 mare); -//UINT8 G_GetBestNightsGrade(INT16 map, UINT8 mare); - -//void G_AddTempNightsRecords(UINT32 pscore, tic_t ptime, UINT8 mare); -//void G_SetNightsRecords(void); FUNCMATH INT32 G_TicsToHours(tic_t tics); FUNCMATH INT32 G_TicsToMinutes(tic_t tics, boolean full); @@ -439,6 +429,8 @@ FUNCMATH INT32 G_TicsToSeconds(tic_t tics); FUNCMATH INT32 G_TicsToCentiseconds(tic_t tics); FUNCMATH INT32 G_TicsToMilliseconds(tic_t tics); +boolean K_DirectorIsPlayerAlone(void); // idk where else to put this lol + // Don't split up TOL handling INT16 G_TOLFlag(INT32 pgametype); diff --git a/src/k_director.c b/src/k_director.c index 3c5938713..1bbe438b9 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -38,6 +38,21 @@ struct directorinfo INT32 boredom[MAXPLAYERS]; // how long has a given position had no credible attackers? } directorinfo; +boolean K_DirectorIsPlayerAlone(void) +{ + UINT8 pingame = 0; + + // Gotta check how many players are active at this moment. + for (UINT8 i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + continue; + pingame++; + } + + return (pingame <= 1); +} + static inline boolean race_rules(void) { return gametype == GT_RACE; @@ -50,7 +65,7 @@ static fixed_t ScaleFromMap(fixed_t n, fixed_t scale) static boolean K_DirectorIsEnabled(void) { - return cv_director.value && !splitscreen && (gamestate == GS_LEVEL && (((stplyr && !stplyr->spectator) && (!playeringame[consoleplayer] || players[consoleplayer].spectator)) || (demo.playback && !demo.freecam && (!demo.title || !modeattacking)))); + return cv_director.value && !splitscreen && (gamestate == GS_LEVEL && (((stplyr && !stplyr->spectator) && (!playeringame[consoleplayer] || players[consoleplayer].spectator)) || (demo.playback && !demo.freecam && (!demo.title || !modeattacking))) && !K_DirectorIsPlayerAlone()); } void K_InitDirector(void) diff --git a/src/st_stuff.c b/src/st_stuff.c index dd6bd5f6b..8b15e711a 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -664,7 +664,7 @@ static void ST_overlayDrawer(void) if (!hu_showscores) // hide the following if TAB is held { - if (cv_showdirectorhud.value && ((demo.playback && !demo.freecam && (!demo.title || !modeattacking)) || !P_IsLocalPlayer(stplyr)) && !splitscreen) + if (cv_showdirectorhud.value && !splitscreen && ((demo.playback && !demo.freecam && (!demo.title || !modeattacking)) || !P_IsLocalPlayer(stplyr)) && !K_DirectorIsPlayerAlone()) { char directortext[20] = {0}; From 7a6f43bece9dfbc22022f6605bc5c09fc252f6f5 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 18 Oct 2024 20:34:00 +0200 Subject: [PATCH 163/166] dont show encore toggle text in record attack menu dont think you can even record attack in encore hmm --- src/m_menu.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 101afbd8d..94b5f8f3b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9991,16 +9991,19 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) patch_t *PictureOfLevel; INT32 x, y, w, i, oldval, trans, dupadjust = ((vid.width/vid.dupx) - BASEVIDWIDTH)>>1; - char encoretoggle[32] = {0}; - const char *item1 = gamecontrol[gc_fire][0] != 0 ? G_KeynumToString(gamecontrol[gc_fire][0]) : NULL; - const char *item2 = gamecontrol[gc_fire][1] != 0 ? G_KeynumToString(gamecontrol[gc_fire][1]) : NULL; + if (levellistmode != LLM_RECORDATTACK) // so it doesent show in record attack menu + { + char encoretoggle[32] = {0}; + const char *item1 = gamecontrol[gc_fire][0] != 0 ? G_KeynumToString(gamecontrol[gc_fire][0]) : NULL; + const char *item2 = gamecontrol[gc_fire][1] != 0 ? G_KeynumToString(gamecontrol[gc_fire][1]) : NULL; - if (item1 != NULL && item2 != NULL) - snprintf(encoretoggle, 32, "%s/%s: Toggle Encore", item1, item2); - else - snprintf(encoretoggle, 32, "%s: Toggle Encore", item1 != NULL ? item1 : item2 != NULL ? item2 : "Item"); + if (item1 != NULL && item2 != NULL) + snprintf(encoretoggle, 32, "%s/%s: Toggle Encore", item1, item2); + else + snprintf(encoretoggle, 32, "%s: Toggle Encore", item1 != NULL ? item1 : item2 != NULL ? item2 : "Item"); - V_DrawThinString(1, BASEVIDHEIGHT-8-1, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_TRANSLUCENT|V_ALLOWLOWERCASE, encoretoggle); + V_DrawThinString(1, BASEVIDHEIGHT-8-1, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_TRANSLUCENT|V_ALLOWLOWERCASE, encoretoggle); + } // A 160x100 image of the level as entry MAPxxP if (cv_nextmap.value) From fbe97556de4a2b8366af60a1a44b63cc1f934e62 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 18 Oct 2024 20:36:16 +0200 Subject: [PATCH 164/166] change versionstring also remove the fbo one, its honestly not necessary anymore --- src/doomdef.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index ff53c8c8e..046cd6897 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -127,13 +127,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#ifndef USE_FBO_OGL -#define VERSIONSTRING "Saturn v7" -#define VERSIONSTRINGW L"Saturn v7" -#else -#define VERSIONSTRING "Saturn v7 - FBO " -#define VERSIONSTRINGW L"Saturn v7 - FBO" -#endif +#define VERSIONSTRING "Saturn v7.1" +#define VERSIONSTRINGW L"Saturn v7.1" // Hey! If you change this, add 1 to the MODVERSION below! Otherwise we can't force updates! // And change CMakeLists.txt (not src/, but in root), for CMake users! // AND appveyor.yml, for the build bots! From 0af52ba3ae2a7f42d194fa71a2616dd714d16107 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 19 Oct 2024 21:14:45 +0200 Subject: [PATCH 165/166] dont need to always check this 16 times if we already know theres more than one player ingame --- src/k_director.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/k_director.c b/src/k_director.c index 1bbe438b9..fc6e211f6 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -47,7 +47,11 @@ boolean K_DirectorIsPlayerAlone(void) { if (!playeringame[i] || players[i].spectator) continue; + pingame++; + + if (pingame >= 2) // we dont need to check further + break; } return (pingame <= 1); From d30c96e8cbcc56c55e96d161731642b3c15a3127 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 00:21:48 +0200 Subject: [PATCH 166/166] fix a maybe-uninitialized warning --- src/r_things.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 3f96ed419..7c1b7d9b5 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2448,8 +2448,8 @@ static boolean R_CheckSpriteVisible(vissprite_t *spr, INT32 x1, INT32 x2) INT16 sz = spr->sz; INT16 szt = spr->szt; - fixed_t texturemid, yscale, scalestep = spr->scalestep; - INT32 height; + fixed_t texturemid = 0, yscale = 0, scalestep = spr->scalestep; // "= 0" pleases the compiler + INT32 height = 0; if (scalestep) {