Instead of gentlemens dropping packets, it simply delays what it sends

This commit is contained in:
Sally Coolatta 2021-11-29 05:27:44 -05:00
parent 0fad5f5a23
commit 0e25de897d
2 changed files with 47 additions and 32 deletions

View file

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

View file

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