Merge branch 'autocope' into 'master'

Offline input delay cvar

See merge request KartKrew/Kart!687
This commit is contained in:
Oni 2022-09-21 10:56:22 +00:00
commit 1b373cf0e8
9 changed files with 79 additions and 14 deletions

View file

@ -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", "2", CV_SAVE, mindelay_cons_t, NULL);
SINT8 nodetoplayer[MAXNETNODES];
SINT8 nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if any (splitscreen)
@ -5648,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;
@ -5662,7 +5664,7 @@ static void UpdatePingTable(void)
if (server)
{
if (netgame && !(gametime % 35)) // update once per second.
if (Playing() && !(gametime % 35)) // update once per second.
PingUpdate();
fastest = 0;
@ -5688,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)
@ -5719,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)

View file

@ -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;

View file

@ -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);

View file

@ -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");
@ -2334,37 +2338,65 @@ 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;
}
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);
if (!server && lag <= (tic_t)cv_mindelay.value)
{
lag = cv_mindelay.value;
drawlocal = true;
}
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 +2421,16 @@ HU_drawMiniPing (INT32 x, INT32 y, UINT32 lag, INT32 flags)
w /= 2;
}
patch = mping[Ping_gfx_num(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)];
if (( flags & V_SNAPTORIGHT ))
x += ( w - SHORT (patch->width) );

View file

@ -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[]);

View file

@ -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 && Playing())
{
K_drawMiniPing();
}

View file

@ -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, "Minimum Input Delay", "Practice for online play! Higher = more delay.",
NULL, {.cvar = &cv_mindelay}, 0, 0},
{IT_SPACE | IT_NOTHING, NULL, NULL,
NULL, {NULL}, 0, 0},

View file

@ -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);
}
}

View file

@ -1219,6 +1219,8 @@ void I_FinishUpdate(void)
}
}
}
if (cv_mindelay.value && consoleplayer == serverplayer && Playing())
SCR_DisplayLocalPing();
}
if (marathonmode)