From 0e25de897d02ba496df0f663b854f3b373d81695 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 29 Nov 2021 05:27:44 -0500 Subject: [PATCH] Instead of gentlemens dropping packets, it simply delays what it sends --- src/d_clisrv.c | 70 +++++++++++++++++++++++++++----------------------- src/d_clisrv.h | 9 +++++++ 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5b4141328..f33649cc7 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -141,7 +141,7 @@ UINT8 adminpassmd5[16]; boolean adminpasswordset = false; // Client specific -static ticcmd_t localcmds[MAXSPLITSCREENPLAYERS]; +static ticcmd_t localcmds[MAXSPLITSCREENPLAYERS][MAXGENTLEMENDELAY]; static boolean cl_packetmissed; // here it is for the secondary local player (splitscreen) static UINT8 mynode; // my address pointofview server @@ -440,10 +440,15 @@ static void D_Clearticcmd(tic_t tic) void D_ResetTiccmds(void) { - INT32 i; + INT32 i, j; for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - memset(&localcmds[i], 0, sizeof(ticcmd_t)); + { + for (j = 0; j < MAXGENTLEMENDELAY; j++) + { + memset(&localcmds[i][j], 0, sizeof(ticcmd_t)); + } + } // Reset the net command list for (i = 0; i < TEXTCMD_HASH_SIZE; i++) @@ -4934,12 +4939,6 @@ static void CL_SendClientCmd(void) size_t packetsize = 0; boolean mis = false; - if (lowest_lag && ( gametic % lowest_lag )) - { - cl_packetmissed = true; - return; - } - netbuffer->packettype = PT_CLIENTCMD; if (cl_packetmissed) @@ -4960,27 +4959,35 @@ static void CL_SendClientCmd(void) } else if (gamestate != GS_NULL && (addedtogame || dedicated)) { + UINT8 lagDelay = 0; + + if (lowest_lag > 0) + { + // Gentlemens' ping. + lagDelay = min(lowest_lag, MAXGENTLEMENDELAY); + } + packetsize = sizeof (clientcmd_pak); - G_MoveTiccmd(&netbuffer->u.clientpak.cmd, &localcmds[0], 1); - netbuffer->u.clientpak.consistancy = SHORT(consistancy[gametic%TICQUEUE]); + G_MoveTiccmd(&netbuffer->u.clientpak.cmd, &localcmds[0][lagDelay], 1); + netbuffer->u.clientpak.consistancy = SHORT(consistancy[gametic % TICQUEUE]); if (splitscreen) // Send a special packet with 2 cmd for splitscreen { netbuffer->packettype = (mis ? PT_CLIENT2MIS : PT_CLIENT2CMD); packetsize = sizeof (client2cmd_pak); - G_MoveTiccmd(&netbuffer->u.client2pak.cmd2, &localcmds[1], 1); + G_MoveTiccmd(&netbuffer->u.client2pak.cmd2, &localcmds[1][lagDelay], 1); if (splitscreen > 1) { netbuffer->packettype = (mis ? PT_CLIENT3MIS : PT_CLIENT3CMD); packetsize = sizeof (client3cmd_pak); - G_MoveTiccmd(&netbuffer->u.client3pak.cmd3, &localcmds[2], 1); + G_MoveTiccmd(&netbuffer->u.client3pak.cmd3, &localcmds[2][lagDelay], 1); if (splitscreen > 2) { netbuffer->packettype = (mis ? PT_CLIENT4MIS : PT_CLIENT4CMD); packetsize = sizeof (client4cmd_pak); - G_MoveTiccmd(&netbuffer->u.client4pak.cmd4, &localcmds[3], 1); + G_MoveTiccmd(&netbuffer->u.client4pak.cmd4, &localcmds[3][lagDelay], 1); } } } @@ -5143,8 +5150,23 @@ static void SV_SendTics(void) // // TryRunTics // +static void CreateNewLocalCMD(UINT8 p, INT32 realtics) +{ + INT32 i; + + for (i = MAXGENTLEMENDELAY-1; i > 0; i--) + { + G_MoveTiccmd(&localcmds[p][i], &localcmds[p][i-1], 1); + } + + G_BuildTiccmd(&localcmds[p][0], realtics, p+1); + localcmds[p][0].flags |= TICCMD_RECEIVED; +} + static void Local_Maketic(INT32 realtics) { + INT32 i; + I_OsPolling(); // I_Getevent D_ProcessEvents(); // menu responder, cons responder, // game responder calls HU_Responder, AM_Responder, @@ -5153,25 +5175,9 @@ static void Local_Maketic(INT32 realtics) if (!dedicated) rendergametic = gametic; // translate inputs (keyboard/mouse/joystick) into game controls - G_BuildTiccmd(&localcmds[0], realtics, 1); - localcmds[0].flags |= TICCMD_RECEIVED; - - if (splitscreen) + for (i = 0; i <= splitscreen; i++) { - G_BuildTiccmd(&localcmds[1], realtics, 2); - localcmds[1].flags |= TICCMD_RECEIVED; - - if (splitscreen > 1) - { - G_BuildTiccmd(&localcmds[2], realtics, 3); - localcmds[2].flags |= TICCMD_RECEIVED; - - if (splitscreen > 2) - { - G_BuildTiccmd(&localcmds[3], realtics, 4); - localcmds[3].flags |= TICCMD_RECEIVED; - } - } + CreateNewLocalCMD(i, realtics); } } diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 93593d736..88712f01c 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -39,6 +39,15 @@ applications may follow different packet versions. // Networking and tick handling related. #define TICQUEUE 512 // more than enough for most timeouts.... #define MAXTEXTCMD 256 + +// No. of tics your controls can be delayed by. + +// TODO: Instead of storing a ton of extra cmds for gentlemens' delay, +// keep them in a linked-list, with timestamps to discard everything that's older than already sent. +// That will support any amount of lag, and be less wasteful for clients who don't use it. +// This just works as a quick implementation. +#define MAXGENTLEMENDELAY TICRATE + // // Packet structure //