Ping measured in frame delay instead of milliseconds

The part of HOSTMOD ministats that I wanted. Can go back to ms using the pingmeasurement cvar.

If Tyron wants to bring ministats fully in I think it'd be better to bring its ideas to replace the current HUD instead, ideally using the existing ping gfx, so they should bring it up with Oni
This commit is contained in:
Sally Coolatta 2022-06-05 09:35:31 -04:00 committed by toaster
parent 113dd6a600
commit 70c48fc0e9
7 changed files with 75 additions and 41 deletions

View file

@ -122,7 +122,7 @@ SINT8 nodetoplayer4[MAXNETNODES]; // say the numplayer for this node if any (spl
UINT8 playerpernode[MAXNETNODES]; // used specialy for splitscreen
boolean nodeingame[MAXNETNODES]; // set false as nodes leave game
tic_t servermaxping = 800; // server's max ping. Defaults to 800
tic_t servermaxping = 20; // server's max delay, in frames. Defaults to 20
static tic_t nettics[MAXNETNODES]; // what tic the client have received
static tic_t supposedtics[MAXNETNODES]; // nettics prevision for smaller packet
static UINT8 nodewaiting[MAXNETNODES];
@ -2777,7 +2777,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
kickreason = KR_KICK;
break;
case KICK_MSG_PING_HIGH:
HU_AddChatText(va("\x82*%s left the game (Broke ping limit)", player_names[pnum]), false);
HU_AddChatText(va("\x82*%s left the game (Broke delay limit)", player_names[pnum]), false);
kickreason = KR_PINGLIMIT;
break;
case KICK_MSG_CON_FAIL:
@ -2869,7 +2869,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
if (msg == KICK_MSG_CON_FAIL)
M_StartMessage(M_GetText("Server closed connection\n(Synch failure)\nPress ESC\n"), NULL, MM_NOTHING);
else if (msg == KICK_MSG_PING_HIGH)
M_StartMessage(M_GetText("Server closed connection\n(Broke ping limit)\nPress ESC\n"), NULL, MM_NOTHING);
M_StartMessage(M_GetText("Server closed connection\n(Broke delay limit)\nPress ESC\n"), NULL, MM_NOTHING);
else if (msg == KICK_MSG_BANNED)
M_StartMessage(M_GetText("You have been banned by the server\n\nPress ESC\n"), NULL, MM_NOTHING);
else if (msg == KICK_MSG_CUSTOM_KICK)
@ -5337,7 +5337,7 @@ static void UpdatePingTable(void)
if (! server_lagless && playernode[i] > 0 && !players[i].spectator)
{
lag = GetLag(playernode[i]);
realpingtable[i] += (INT32)(lag * (1000.00f/TICRATE));
realpingtable[i] += lag;
if (! fastest || lag < fastest)
fastest = lag;
@ -5345,7 +5345,7 @@ static void UpdatePingTable(void)
else
{
// TicsToMilliseconds can't handle pings over 1000ms lol
realpingtable[i] += (INT32)(GetLag(playernode[i]) * (1000.00f/TICRATE));
realpingtable[i] += GetLag(playernode[i]);
}
}
}
@ -5363,7 +5363,7 @@ static void UpdatePingTable(void)
else
lag = GetLag(0);
lag = ( realpingtable[0] + G_TicsToMilliseconds(lag) );
lag = ( realpingtable[0] + lag );
switch (playerpernode[0])
{

View file

@ -1389,6 +1389,7 @@ struct pingcell
{
INT32 num;
INT32 ms;
INT32 f;
};
static int pingcellcmp(const void *va, const void *vb)
@ -1412,6 +1413,7 @@ void Command_Ping_f(void)
INT32 pingc;
int name_width = 0;
int f_width = 0;
int ms_width = 0;
int n;
@ -1419,21 +1421,35 @@ void Command_Ping_f(void)
pingc = 0;
for (i = 1; i < MAXPLAYERS; ++i)
if (playeringame[i])
{
n = strlen(player_names[i]);
if (n > name_width)
name_width = n;
if (playeringame[i])
{
INT32 ms;
n = playerpingtable[i];
if (n > ms_width)
ms_width = n;
n = strlen(player_names[i]);
if (n > name_width)
name_width = n;
pingv[pingc].num = i;
pingv[pingc].ms = playerpingtable[i];
pingc++;
n = playerpingtable[i];
if (n > f_width)
f_width = n;
ms = (INT32)(playerpingtable[i] * (1000.00f / TICRATE));
n = ms;
if (n > ms_width)
ms_width = n;
pingv[pingc].num = i;
pingv[pingc].f = playerpingtable[i];
pingv[pingc].ms = ms;
pingc++;
}
}
if (f_width < 10) f_width = 1;
else if (f_width < 100) f_width = 2;
else f_width = 3;
if (ms_width < 10) ms_width = 1;
else if (ms_width < 100) ms_width = 2;
else ms_width = 3;
@ -1442,15 +1458,16 @@ void Command_Ping_f(void)
for (i = 0; i < pingc; ++i)
{
CONS_Printf("%02d : %-*s %*d ms\n",
CONS_Printf("%02d : %-*s %*d frames (%*d ms)\n",
pingv[i].num,
name_width, player_names[pingv[i].num],
f_width, pingv[i].f,
ms_width, pingv[i].ms);
}
if (!server && playeringame[consoleplayer])
{
CONS_Printf("\nYour ping is %d ms\n", playerpingtable[consoleplayer]);
CONS_Printf("\nYour ping is %d frames (%d ms)\n", playerpingtable[consoleplayer], (INT32)(playerpingtable[i] * (1000.00f / TICRATE)));
}
}

View file

@ -485,17 +485,20 @@ static CV_PossibleValue_t nettimeout_cons_t[] = {{TICRATE/7, "MIN"}, {60*TICRATE
consvar_t cv_nettimeout = CVAR_INIT ("nettimeout", "105", CV_CALL|CV_SAVE, nettimeout_cons_t, NetTimeout_OnChange);
//static CV_PossibleValue_t jointimeout_cons_t[] = {{5*TICRATE, "MIN"}, {60*TICRATE, "MAX"}, {0, NULL}};
consvar_t cv_jointimeout = CVAR_INIT ("jointimeout", "105", CV_CALL|CV_SAVE, nettimeout_cons_t, JoinTimeout_OnChange);
consvar_t cv_maxping = CVAR_INIT ("maxping", "800", CV_SAVE, CV_Unsigned, NULL);
consvar_t cv_maxping = CVAR_INIT ("maxdelay", "20", CV_SAVE, CV_Unsigned, NULL);
consvar_t cv_lagless = CVAR_INIT ("lagless", "Off", CV_SAVE|CV_NETVAR|CV_CALL, CV_OnOff, Lagless_OnChange);
static CV_PossibleValue_t pingtimeout_cons_t[] = {{8, "MIN"}, {120, "MAX"}, {0, NULL}};
consvar_t cv_pingtimeout = CVAR_INIT ("pingtimeout", "10", CV_SAVE|CV_NETVAR, pingtimeout_cons_t, NULL);
consvar_t cv_pingtimeout = CVAR_INIT ("maxdelaytimeout", "10", CV_SAVE|CV_NETVAR, pingtimeout_cons_t, NULL);
// show your ping on the HUD next to framerate. Defaults to warning only (shows up if your ping is > maxping)
static CV_PossibleValue_t showping_cons_t[] = {{0, "Off"}, {1, "Always"}, {2, "Warning"}, {0, NULL}};
consvar_t cv_showping = CVAR_INIT ("showping", "Always", CV_SAVE, showping_cons_t, NULL);
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_showviewpointtext = CVAR_INIT ("showviewpointtext", "On", CV_SAVE, CV_OnOff, NULL);
// Intermission time Tails 04-19-2002
@ -748,6 +751,7 @@ void D_RegisterServerCommands(void)
CV_RegisterVar(&cv_lagless);
CV_RegisterVar(&cv_pingtimeout);
CV_RegisterVar(&cv_showping);
CV_RegisterVar(&cv_pingmeasurement);
CV_RegisterVar(&cv_showviewpointtext);
CV_RegisterVar(&cv_director);

View file

@ -104,6 +104,7 @@ extern consvar_t cv_maxping;
extern consvar_t cv_lagless;
extern consvar_t cv_pingtimeout;
extern consvar_t cv_showping;
extern consvar_t cv_pingmeasurement;
extern consvar_t cv_showviewpointtext;
extern consvar_t cv_skipmapcheck;

View file

@ -797,7 +797,6 @@ extern consvar_t cv_forceskin; // force clients to use the server's skin
extern consvar_t cv_downloading; // allow clients to downloading WADs.
extern consvar_t cv_nettimeout; // SRB2Kart: Advanced server options menu
extern consvar_t cv_jointimeout;
extern consvar_t cv_maxping;
extern ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS];
extern INT32 serverplayer;
extern INT32 adminplayers[MAXPLAYERS];

View file

@ -75,6 +75,7 @@
// Note: I'd like to adress that at this point we might *REALLY* want to work towards a common drawString function that can take any font we want because this is really turning into a MESS. :V -Lat'
patch_t *pinggfx[5]; // small ping graphic
patch_t *mping[5]; // smaller ping graphic
patch_t *pingmeasure[2]; // ping measurement graphic
patch_t *framecounter;
patch_t *frameslash; // framerate stuff. Used in screen.c
@ -189,6 +190,9 @@ void HU_LoadGraphics(void)
HU_UpdatePatch(&mping[i], "MPING%d", i+1);
}
HU_UpdatePatch(&pingmeasure[0], "PINGF");
HU_UpdatePatch(&pingmeasure[1], "PINGMS");
// fps stuff
HU_UpdatePatch(&framecounter, "FRAMER");
HU_UpdatePatch(&frameslash, "FRAMESL");
@ -2246,15 +2250,15 @@ void HU_Erase(void)
//======================================================================
static int
Ping_gfx_num (int ping)
Ping_gfx_num (int lag)
{
if (ping < 76)
if (lag < 2)
return 0;
else if (ping < 137)
else if (lag < 4)
return 1;
else if (ping < 256)
else if (lag < 7)
return 2;
else if (ping < 500)
else if (lag < 10)
return 3;
else
return 4;
@ -2263,22 +2267,33 @@ Ping_gfx_num (int ping)
//
// HU_drawPing
//
void HU_drawPing(INT32 x, INT32 y, UINT32 ping, INT32 flags)
void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags)
{
INT32 gfxnum; // gfx to draw
UINT8 const *colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE);
UINT8 *colormap = NULL;
INT32 measureid = cv_pingmeasurement.value ? 1 : 0;
INT32 gfxnum; // gfx to draw
gfxnum = Ping_gfx_num(ping);
gfxnum = Ping_gfx_num(lag);
V_DrawScaledPatch(x, y, flags, pinggfx[gfxnum]);
if (servermaxping && ping > servermaxping && hu_tick < 4) // flash ping red if too high
V_DrawPingNum(x, y+9, flags, ping, colormap);
else
V_DrawPingNum(x, y+9, flags, ping, NULL);
V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]);
V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]);
if (servermaxping && lag > servermaxping && hu_tick < 4)
{
// flash ping red if too high
colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE);
}
if (cv_pingmeasurement.value)
{
lag = (INT32)(lag * (1000.00f / TICRATE));
}
V_DrawPingNum(x+11 - pingmeasure[measureid]->width, y+9, flags, lag, colormap);
}
void
HU_drawMiniPing (INT32 x, INT32 y, UINT32 ping, INT32 flags)
HU_drawMiniPing (INT32 x, INT32 y, UINT32 lag, INT32 flags)
{
patch_t *patch;
INT32 w = BASEVIDWIDTH;
@ -2288,7 +2303,7 @@ HU_drawMiniPing (INT32 x, INT32 y, UINT32 ping, INT32 flags)
w /= 2;
}
patch = mping[Ping_gfx_num(ping)];
patch = mping[Ping_gfx_num(lag)];
if (( flags & V_SNAPTORIGHT ))
x += ( w - SHORT (patch->width) );

View file

@ -1521,8 +1521,8 @@ static menuitem_t OP_AdvServerOptionsMenu[] =
NULL, "Server Browser Address", {.cvar = &cv_masterserver}, 10},
{IT_STRING | IT_CVAR, NULL, "Attempts to resynchronise", {.cvar = &cv_resynchattempts}, 40},
{IT_STRING | IT_CVAR, NULL, "Ping limit (ms)", {.cvar = &cv_maxping}, 50},
{IT_STRING | IT_CVAR, NULL, "Ping timeout (s)", {.cvar = &cv_pingtimeout}, 60},
{IT_STRING | IT_CVAR, NULL, "Delay limit (frames)", {.cvar = &cv_maxping}, 50},
{IT_STRING | IT_CVAR, NULL, "Delay timeout (s)", {.cvar = &cv_pingtimeout}, 60},
{IT_STRING | IT_CVAR, NULL, "Connection timeout (tics)", {.cvar = &cv_nettimeout}, 70},
{IT_STRING | IT_CVAR, NULL, "Join timeout (tics)", {.cvar = &cv_jointimeout}, 80},
@ -2423,8 +2423,6 @@ static void M_ChangeCvar(INT32 choice)
choice *= (TICRATE/7);
else if (cv == &cv_maxsend)
choice *= 512;
else if (cv == &cv_maxping)
choice *= 50;
#endif
CV_AddValue(cv,choice);
}