From 1ad7d23e6bc7727f1085a7e04febc7e73948dc62 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Thu, 9 Oct 2025 03:07:39 -0400 Subject: [PATCH] Port old ping display from Saturn --- src/d_netcmd.c | 6 +++++ src/d_netcmd.h | 2 ++ src/hu_stuff.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/hu_stuff.h | 1 + src/screen.c | 8 ++++-- 5 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 955c27ad3..c0736c7ab 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -686,6 +686,10 @@ consvar_t cv_showping = CVAR_INIT ("showping", "Always", CV_SAVE, showping_cons_ static CV_PossibleValue_t pingmeasurement_cons_t[] = {{0, "Frames"}, {1, "Milliseconds"}, {0, NULL}}; consvar_t cv_pingmeasurement = CVAR_INIT ("pingmeasurement", "Frames", CV_SAVE, pingmeasurement_cons_t, NULL); +consvar_t cv_pingicon = CVAR_INIT ("pingicon", "On", CV_SAVE, CV_OnOff, NULL); + +static CV_PossibleValue_t cv_pingstyle_cons_t[] = {{0, "New"}, {1, "Old"}, {0, NULL}}; +consvar_t cv_pingstyle = CVAR_INIT ("pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, NULL); static CV_PossibleValue_t showlapemblem_cons_t[] = {{0, "Off"}, {1, "Emblem Only"}, {2, "Splits Only"}, {3, "All"}, {0, NULL}}; consvar_t cv_showlapemblem = CVAR_INIT ("showlapemblem", "All", CV_SAVE, showlapemblem_cons_t, NULL); @@ -1016,6 +1020,8 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_pingtimeout); CV_RegisterVar(&cv_showping); CV_RegisterVar(&cv_pingmeasurement); + CV_RegisterVar(&cv_pingicon); + CV_RegisterVar(&cv_pingstyle); CV_RegisterVar(&cv_showminimapnames); CV_RegisterVar(&cv_showminimapangle); CV_RegisterVar(&cv_minihead); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index af46ba17e..527838570 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -237,6 +237,8 @@ extern consvar_t cv_lagless; extern consvar_t cv_pingtimeout; extern consvar_t cv_showping; extern consvar_t cv_pingmeasurement; +extern consvar_t cv_pingicon; +extern consvar_t cv_pingstyle; extern consvar_t cv_showminimapnames; extern consvar_t cv_showminimapangle; diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 0c4e4d88b..ff8101538 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2373,6 +2373,75 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 ping, UINT32 mindelay, UINT32 pl, INT3 V_DrawMappedPatch(x+1 - pingmeasure[measureid]->width, y+11, flags, pingmeasure[measureid], colormap); } +// +// HU_drawOldPing +// +void HU_drawOldPing(INT32 x, INT32 y, UINT32 ping, UINT32 mindelay, UINT32 pl, INT32 flags) +{ + INT32 measureid = cv_pingmeasurement.value ? 1 : 0; + UINT32 lag = max(ping, mindelay); + + //SRB2/Kart v1.0 style + UINT8 numbars = 0; // how many ping bars do we draw? + UINT8 barcolor = 31; // color we use for the bars (green, yellow, red or black) + SINT8 i = 0; + SINT8 yoffset = 6; + + if (vid.width >= 640) // how sad, we're using a shit resolution. + { + if (measureid == 1) + { + V_DrawRightAlignedSmallString(x+12, y+13, V_ALLOWLOWERCASE|flags, va("%dms", Ping_conversion(lag))); + } + else if (measureid == 0) + { + V_DrawRightAlignedSmallString(x+12, y+13, flags, va("d%d", Ping_conversion(lag))); + } + } + + if (cv_pingicon.value) + { + switch (lag) + { + case 0 ... 1: + numbars = 3; + barcolor = 215; // Blue + break; + case 2 ... 3: + numbars = 3; + barcolor = 184; // Green + break; + case 4 ... 6: + numbars = 2; // Apparently ternaries w/ multiple statements don't look good in C so I decided against it. + barcolor = 103; // Yellow + break; + case 7 ... 9: + numbars = 1; + barcolor = 155; // Red + break; + default: // Brazil + numbars = 0; + barcolor = 31; // black + break; + } + + if (pl) + { + barcolor = 194; // make it purplish + // bars get indirectly set earlier + } + + for (i = 0; (i < 3); i++) // Draw the ping bar + { + V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-4, 2, 8-yoffset, 31|flags); + if (i < numbars) + V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-3, 1, 8-yoffset-1, barcolor|flags); + + yoffset -= 2; + } + } +} + void HU_drawMiniPing (INT32 x, INT32 y, UINT32 ping, UINT32 lag, INT32 flags) { diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 0ccb9f60c..fd95c5a76 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -134,6 +134,7 @@ char HU_dequeueChatChar(void); void HU_Erase(void); void HU_clearChatChars(void); void HU_drawPing(INT32 x, INT32 y, UINT32 ping, UINT32 mindelay, UINT32 pl, INT32 flags, boolean icon); +void HU_drawOldPing(INT32 x, INT32 y, UINT32 ping, UINT32 mindelay, UINT32 pl, INT32 flags); void HU_drawMiniPing (INT32 x, INT32 y, UINT32 ping, UINT32 lag, INT32 flags); INT32 HU_CreateTeamScoresTbl(playersort_t *tab, UINT32 dmtotals[]); diff --git a/src/screen.c b/src/screen.c index c4bc47775..ffd52bbbc 100644 --- a/src/screen.c +++ b/src/screen.c @@ -675,8 +675,12 @@ void SCR_DisplayLocalPing(void) UINT32 pl = playerpacketlosstable[consoleplayer]; if (( cv_showping.value == 1 || (cv_showping.value == 2 && ping > servermaxping) )) // only show 2 (warning) if our ping is at a bad level { - INT32 dispy = cv_ticrate.value ? 160 : 181; - HU_drawPing(307, dispy, ping, mindelay, pl, V_SNAPTORIGHT | V_SNAPTOBOTTOM, true); + INT32 dispy = (cv_ticrate.value == 1) ? 165 : ((cv_ticrate.value == 2 || cv_ticrate.value == 4) ? 172 : ((cv_ticrate.value == 3) ? 163 : 181)); // absolute buttpain + + if (cv_pingstyle.value) + HU_drawOldPing(308, dispy, ping, mindelay, pl, V_SNAPTORIGHT | V_SNAPTOBOTTOM); + else + HU_drawPing(307, dispy, ping, mindelay, pl, V_SNAPTORIGHT | V_SNAPTOBOTTOM, cv_pingicon.value); } }