From db25599647496d6e79c4b761719ffc6c7f3ec70e Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Tue, 20 Sep 2022 02:34:53 -0700 Subject: [PATCH 1/9] Offline input delay cvar --- src/d_clisrv.c | 4 +++- src/d_clisrv.h | 1 + src/d_netcmd.c | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ebd58844e..aa4199fce 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -114,6 +114,8 @@ UINT32 playerpingtable[MAXPLAYERS]; //table of player latency values. static tic_t lowest_lag; boolean server_lagless; +static CV_PossibleValue_t mindelay_cons_t[] = {{0, "MIN"}, {30, "MAX"}, {0, NULL}}; +consvar_t cv_mindelay = CVAR_INIT ("mindelay", "0", 0, mindelay_cons_t, NULL); SINT8 nodetoplayer[MAXNETNODES]; SINT8 nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if any (splitscreen) @@ -5665,7 +5667,7 @@ static void UpdatePingTable(void) if (netgame && !(gametime % 35)) // update once per second. PingUpdate(); - fastest = 0; + fastest = cv_mindelay.value; // update node latency values so we can take an average later. for (i = 0; i < MAXPLAYERS; i++) diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 72ce18a5c..ca36ba26c 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -445,6 +445,7 @@ extern UINT32 playerpingtable[MAXPLAYERS]; extern tic_t servermaxping; extern boolean server_lagless; +extern consvar_t cv_mindelay; extern consvar_t cv_netticbuffer, cv_allownewplayer, cv_maxconnections, cv_joindelay; extern consvar_t cv_resynchattempts, cv_blamecfail; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9dcc990a9..c0057896a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -972,6 +972,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_rollingdemos); CV_RegisterVar(&cv_netstat); CV_RegisterVar(&cv_netticbuffer); + CV_RegisterVar(&cv_mindelay); #ifdef NETGAME_DEVMODE CV_RegisterVar(&cv_fishcake); From e242207d10c5edf7d12e7364eab0b2998861ebdd Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Tue, 20 Sep 2022 19:01:54 -0700 Subject: [PATCH 2/9] Mindelay: Oni suggestions rollup --- src/d_clisrv.c | 10 +++++++--- src/hu_stuff.c | 37 +++++++++++++++++++++++++++++++++---- src/hu_stuff.h | 2 +- src/k_hud.c | 4 ++-- src/k_menudef.c | 6 ++++++ src/screen.c | 5 ++++- src/sdl/i_video.c | 2 ++ 7 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index aa4199fce..2f38f0aef 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -115,7 +115,7 @@ UINT32 playerpingtable[MAXPLAYERS]; //table of player latency values. static tic_t lowest_lag; boolean server_lagless; static CV_PossibleValue_t mindelay_cons_t[] = {{0, "MIN"}, {30, "MAX"}, {0, NULL}}; -consvar_t cv_mindelay = CVAR_INIT ("mindelay", "0", 0, mindelay_cons_t, NULL); +consvar_t cv_mindelay = CVAR_INIT ("mindelay", "0", CV_SAVE, mindelay_cons_t, NULL); SINT8 nodetoplayer[MAXNETNODES]; SINT8 nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if any (splitscreen) @@ -5650,7 +5650,7 @@ static inline void PingUpdate(void) if (nodeingame[i]) HSendPacket(i, true, 0, sizeof(INT32) * (MAXPLAYERS+1)); - pingmeasurecount = 1; //Reset count + pingmeasurecount = 0; //Reset count } static tic_t gametime = 0; @@ -5667,7 +5667,7 @@ static void UpdatePingTable(void) if (netgame && !(gametime % 35)) // update once per second. PingUpdate(); - fastest = cv_mindelay.value; + fastest = 0; // update node latency values so we can take an average later. for (i = 0; i < MAXPLAYERS; i++) @@ -5690,6 +5690,10 @@ static void UpdatePingTable(void) } } + // Don't gentleman below your mindelay + if (fastest < (tic_t)cv_mindelay.value) + fastest = (tic_t)cv_mindelay.value; + pingmeasurecount++; if (server_lagless) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index fd57f4a36..2ffc80bc7 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -79,6 +79,7 @@ typedef enum patch_t *pinggfx[5]; // small ping graphic patch_t *mping[5]; // smaller ping graphic patch_t *pingmeasure[2]; // ping measurement graphic +patch_t *pinglocal[2]; // mindelay indecator patch_t *framecounter; patch_t *frameslash; // framerate stuff. Used in screen.c @@ -197,6 +198,9 @@ void HU_LoadGraphics(void) HU_UpdatePatch(&pingmeasure[0], "PINGD"); HU_UpdatePatch(&pingmeasure[1], "PINGMS"); + HU_UpdatePatch(&pinglocal[0], "PINGGFXL"); + HU_UpdatePatch(&pinglocal[1], "MPINGL"); + // fps stuff HU_UpdatePatch(&framecounter, "FRAMER"); HU_UpdatePatch(&frameslash, "FRAMESL"); @@ -2346,25 +2350,47 @@ Ping_gfx_num (int lag) return 4; } +static int +Ping_gfx_color (int lag) +{ + if (lag < 2) + return SKINCOLOR_JAWZ; + else if (lag < 4) + return SKINCOLOR_MINT; + else if (lag < 7) + return SKINCOLOR_GOLD; + else if (lag < 10) + return SKINCOLOR_RASPBERRY; + else + return SKINCOLOR_MAGENTA; +} + // // HU_drawPing // -void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags) +void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags, boolean offline) { UINT8 *colormap = NULL; INT32 measureid = cv_pingmeasurement.value ? 1 : 0; INT32 gfxnum; // gfx to draw + boolean drawlocal = (offline && cv_mindelay.value && lag <= (tic_t)cv_mindelay.value); gfxnum = Ping_gfx_num(lag); if (measureid == 1) V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); - V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); + + if (drawlocal) + V_DrawScaledPatch(x+2, y, flags, pinglocal[0]); + else + V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); + + colormap = R_GetTranslationColormap(TC_RAINBOW, Ping_gfx_color(lag), GTC_CACHE); if (servermaxping && lag > servermaxping && hu_tick < 4) { // flash ping red if too high - colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); + colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_WHITE, GTC_CACHE); } if (cv_pingmeasurement.value) @@ -2389,7 +2415,10 @@ HU_drawMiniPing (INT32 x, INT32 y, UINT32 lag, INT32 flags) w /= 2; } - patch = mping[Ping_gfx_num(lag)]; + if (cv_mindelay.value && (tic_t)cv_mindelay.value <= lag) + patch = pinglocal[1]; + else + patch = mping[Ping_gfx_num(lag)]; if (( flags & V_SNAPTORIGHT )) x += ( w - SHORT (patch->width) ); diff --git a/src/hu_stuff.h b/src/hu_stuff.h index cc9959467..9bcf45e09 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -138,7 +138,7 @@ void HU_Drawer(void); char HU_dequeueChatChar(void); void HU_Erase(void); void HU_clearChatChars(void); -void HU_drawPing(INT32 x, INT32 y, UINT32 ping, INT32 flags); // Lat': Ping drawer for scoreboard. +void HU_drawPing(INT32 x, INT32 y, UINT32 ping, INT32 flags, boolean offline); // Lat': Ping drawer for scoreboard. void HU_drawMiniPing(INT32 x, INT32 y, UINT32 ping, INT32 flags); INT32 HU_CreateTeamScoresTbl(playersort_t *tab, UINT32 dmtotals[]); diff --git a/src/k_hud.c b/src/k_hud.c index 96635584e..2496e5393 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -2177,7 +2177,7 @@ void K_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, IN } else if (tab[i].num != serverplayer || !server_lagless) { - HU_drawPing(x + ((i < 8) ? -17 : rightoffset + 11), y-4, playerpingtable[tab[i].num], 0); + HU_drawPing(x + ((i < 8) ? -17 : rightoffset + 11), y-4, playerpingtable[tab[i].num], 0, false); } } @@ -4878,7 +4878,7 @@ void K_drawKartHUD(void) V_DrawCenteredString(BASEVIDWIDTH>>1, 176, V_REDMAP|V_SNAPTOBOTTOM, "WRONG WAY"); } - if (netgame && r_splitscreen) + if ((netgame || cv_mindelay.value) && r_splitscreen) { K_drawMiniPing(); } diff --git a/src/k_menudef.c b/src/k_menudef.c index d97083509..fe243c38c 100644 --- a/src/k_menudef.c +++ b/src/k_menudef.c @@ -1035,6 +1035,12 @@ menuitem_t OPTIONS_Gameplay[] = {IT_STRING | IT_CVAR, "Karma Comeback", "Enable Karma Comeback in Battle mode.", NULL, {.cvar = &cv_kartcomeback}, 0, 0}, + {IT_SPACE | IT_NOTHING, NULL, NULL, + NULL, {NULL}, 0, 0}, + + {IT_STRING | IT_CVAR, "Offline Input Delay", "Practice for online play in offline modes. Higher = more delay.", + NULL, {.cvar = &cv_mindelay}, 0, 0}, + {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, diff --git a/src/screen.c b/src/screen.c index 5d6b59ee8..f1b53a7f2 100644 --- a/src/screen.c +++ b/src/screen.c @@ -628,11 +628,14 @@ void SCR_DisplayTicRate(void) void SCR_DisplayLocalPing(void) { + boolean offline; + UINT32 ping = playerpingtable[consoleplayer]; // consoleplayer's ping is everyone's ping in a splitnetgame :P if (! r_splitscreen && ( cv_showping.value == 1 || (cv_showping.value == 2 && ping > servermaxping) )) // only show 2 (warning) if our ping is at a bad level { INT32 dispy = cv_ticrate.value ? 160 : 181; - HU_drawPing(307, dispy, ping, V_SNAPTORIGHT | V_SNAPTOBOTTOM | V_HUDTRANS); + offline = (consoleplayer == serverplayer); + HU_drawPing(307, dispy, ping, V_SNAPTORIGHT | V_SNAPTOBOTTOM | V_HUDTRANS, offline); } } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 2361a5349..09b2f6bbf 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1219,6 +1219,8 @@ void I_FinishUpdate(void) } } } + if (cv_mindelay.value && consoleplayer == serverplayer) + SCR_DisplayLocalPing(); } if (marathonmode) From 87b92a7127137bc78739c492543f4646d305900f Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Tue, 20 Sep 2022 20:05:00 -0700 Subject: [PATCH 3/9] Bump ping tiers by 1 tic --- src/hu_stuff.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 2ffc80bc7..2fe1fb883 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2338,13 +2338,13 @@ void HU_Erase(void) static int Ping_gfx_num (int lag) { - if (lag < 2) + if (lag <= 2) return 0; - else if (lag < 4) + else if (lag <= 4) return 1; - else if (lag < 7) + else if (lag <= 7) return 2; - else if (lag < 10) + else if (lag <= 10) return 3; else return 4; @@ -2353,13 +2353,13 @@ Ping_gfx_num (int lag) static int Ping_gfx_color (int lag) { - if (lag < 2) + if (lag <= 2) return SKINCOLOR_JAWZ; - else if (lag < 4) + else if (lag <= 4) return SKINCOLOR_MINT; - else if (lag < 7) + else if (lag <= 7) return SKINCOLOR_GOLD; - else if (lag < 10) + else if (lag <= 10) return SKINCOLOR_RASPBERRY; else return SKINCOLOR_MAGENTA; From e1f72898f5543d2f0e66ff72baebafeddb8773d1 Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Tue, 20 Sep 2022 20:15:02 -0700 Subject: [PATCH 4/9] Mindelay: Update ping display even in local play --- 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 2f38f0aef..69eebe595 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5664,7 +5664,7 @@ static void UpdatePingTable(void) if (server) { - if (netgame && !(gametime % 35)) // update once per second. + if (!(gametime % 35)) // update once per second. PingUpdate(); fastest = 0; From ada40b421c1757025ff1a9369932813245a52b4c Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Tue, 20 Sep 2022 20:29:34 -0700 Subject: [PATCH 5/9] Mindelay: Never draw ping outside of games --- src/k_hud.c | 2 +- src/sdl/i_video.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/k_hud.c b/src/k_hud.c index 2496e5393..fd4493a93 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -4878,7 +4878,7 @@ void K_drawKartHUD(void) V_DrawCenteredString(BASEVIDWIDTH>>1, 176, V_REDMAP|V_SNAPTOBOTTOM, "WRONG WAY"); } - if ((netgame || cv_mindelay.value) && r_splitscreen) + if ((netgame || cv_mindelay.value) && r_splitscreen && Playing()) { K_drawMiniPing(); } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 09b2f6bbf..a1948f2f1 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1219,7 +1219,7 @@ void I_FinishUpdate(void) } } } - if (cv_mindelay.value && consoleplayer == serverplayer) + if (cv_mindelay.value && consoleplayer == serverplayer && Playing()) SCR_DisplayLocalPing(); } From bd83a9f3b198082b1aecfb2d02c41cbafb6ef447 Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Tue, 20 Sep 2022 20:33:30 -0700 Subject: [PATCH 6/9] Mindelay: Probably don't calculate ping outside of games period --- 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 69eebe595..1c3708b12 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5664,7 +5664,7 @@ static void UpdatePingTable(void) if (server) { - if (!(gametime % 35)) // update once per second. + if (Playing() && !(gametime % 35)) // update once per second. PingUpdate(); fastest = 0; From 8525dfb50273e4265bd470948f8298e25b9da630 Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Tue, 20 Sep 2022 21:21:51 -0700 Subject: [PATCH 7/9] Allow netgame clients to display and be affected by mindelay --- src/d_clisrv.c | 5 +++++ src/hu_stuff.c | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1c3708b12..f11215b60 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5725,6 +5725,11 @@ static void UpdatePingTable(void) } } } + else // We're a client, handle mindelay on the way out. + { + if ((neededtic - gametic) < (tic_t)cv_mindelay.value) + lowest_lag = cv_mindelay.value - (neededtic - gametic); + } } static void RenewHolePunch(void) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 2fe1fb883..bdcc158d4 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2375,6 +2375,12 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags, boolean offline) INT32 gfxnum; // gfx to draw boolean drawlocal = (offline && cv_mindelay.value && lag <= (tic_t)cv_mindelay.value); + if (!server && lag <= (tic_t)cv_mindelay.value) + { + lag = cv_mindelay.value; + drawlocal = true; + } + gfxnum = Ping_gfx_num(lag); if (measureid == 1) @@ -2415,7 +2421,15 @@ HU_drawMiniPing (INT32 x, INT32 y, UINT32 lag, INT32 flags) w /= 2; } - if (cv_mindelay.value && (tic_t)cv_mindelay.value <= lag) + CONS_Printf("mindelay %d / lag %d\n", cv_mindelay.value, lag); + + // This looks kinda dumb, but basically: + // Servers with mindelay set modify the ping table. + // Clients with mindelay unset don't, because they can't. + // Both are affected by mindelay, but a client's lag value is pre-adjustment. + if (server && cv_mindelay.value && (tic_t)cv_mindelay.value <= lag) + patch = pinglocal[1]; + else if (!server && cv_mindelay.value && (tic_t)cv_mindelay.value >= lag) patch = pinglocal[1]; else patch = mping[Ping_gfx_num(lag)]; From aaf18fb1cf7f000526fa22f51999edecd370c30d Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Tue, 20 Sep 2022 21:29:17 -0700 Subject: [PATCH 8/9] Offline Input Delay -> Minimum Input Delay, default 0 -> 2 --- src/d_clisrv.c | 2 +- src/k_menudef.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f11215b60..1e5787583 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -115,7 +115,7 @@ UINT32 playerpingtable[MAXPLAYERS]; //table of player latency values. static tic_t lowest_lag; boolean server_lagless; static CV_PossibleValue_t mindelay_cons_t[] = {{0, "MIN"}, {30, "MAX"}, {0, NULL}}; -consvar_t cv_mindelay = CVAR_INIT ("mindelay", "0", CV_SAVE, mindelay_cons_t, NULL); +consvar_t cv_mindelay = CVAR_INIT ("mindelay", "2", CV_SAVE, mindelay_cons_t, NULL); SINT8 nodetoplayer[MAXNETNODES]; SINT8 nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if any (splitscreen) diff --git a/src/k_menudef.c b/src/k_menudef.c index fe243c38c..97f77abd2 100644 --- a/src/k_menudef.c +++ b/src/k_menudef.c @@ -1038,7 +1038,7 @@ menuitem_t OPTIONS_Gameplay[] = {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, - {IT_STRING | IT_CVAR, "Offline Input Delay", "Practice for online play in offline modes. Higher = more delay.", + {IT_STRING | IT_CVAR, "Minimum Input Delay", "Practice for online play! Higher = more delay.", NULL, {.cvar = &cv_mindelay}, 0, 0}, {IT_SPACE | IT_NOTHING, NULL, NULL, From 51d46a2a8abd88a5a46ab6e6e5491abc5d90190f Mon Sep 17 00:00:00 2001 From: AJ Martinez Date: Tue, 20 Sep 2022 21:32:45 -0700 Subject: [PATCH 9/9] Remove debug print --- src/hu_stuff.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index bdcc158d4..1d7f23ac9 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2421,8 +2421,6 @@ HU_drawMiniPing (INT32 x, INT32 y, UINT32 lag, INT32 flags) w /= 2; } - CONS_Printf("mindelay %d / lag %d\n", cv_mindelay.value, lag); - // This looks kinda dumb, but basically: // Servers with mindelay set modify the ping table. // Clients with mindelay unset don't, because they can't.