Merge branch 'hold-my-input' into 'master'

Improve netplay instability and network timing drift (resolves #573)

Closes #573

See merge request KartKrew/Kart!1326
This commit is contained in:
Oni 2023-07-10 21:51:34 +00:00
commit 6c9ed3a388
2 changed files with 28 additions and 10 deletions

View file

@ -5170,8 +5170,14 @@ static void HandlePacketFromPlayer(SINT8 node)
|| netbuffer->packettype == PT_NODEKEEPALIVEMIS)
break;
// If we already received a ticcmd for this tic, just submit it for the next one.
tic_t faketic = maketic;
if (!!(netcmds[maketic % BACKUPTICS][netconsole].flags & TICCMD_RECEIVED))
faketic++;
// Copy ticcmd
G_MoveTiccmd(&netcmds[maketic%BACKUPTICS][netconsole], &netbuffer->u.clientpak.cmd, 1);
G_MoveTiccmd(&netcmds[faketic%BACKUPTICS][netconsole], &netbuffer->u.clientpak.cmd, 1);
// Check ticcmd for "speed hacks"
if (CheckForSpeedHacks((UINT8)netconsole))
@ -5183,7 +5189,7 @@ static void HandlePacketFromPlayer(SINT8 node)
|| (netbuffer->packettype == PT_CLIENT4CMD || netbuffer->packettype == PT_CLIENT4MIS))
&& (nodetoplayer2[node] >= 0))
{
G_MoveTiccmd(&netcmds[maketic%BACKUPTICS][(UINT8)nodetoplayer2[node]],
G_MoveTiccmd(&netcmds[faketic%BACKUPTICS][(UINT8)nodetoplayer2[node]],
&netbuffer->u.client2pak.cmd2, 1);
if (CheckForSpeedHacks((UINT8)nodetoplayer2[node]))
@ -5194,7 +5200,7 @@ static void HandlePacketFromPlayer(SINT8 node)
|| (netbuffer->packettype == PT_CLIENT4CMD || netbuffer->packettype == PT_CLIENT4MIS))
&& (nodetoplayer3[node] >= 0))
{
G_MoveTiccmd(&netcmds[maketic%BACKUPTICS][(UINT8)nodetoplayer3[node]],
G_MoveTiccmd(&netcmds[faketic%BACKUPTICS][(UINT8)nodetoplayer3[node]],
&netbuffer->u.client3pak.cmd3, 1);
if (CheckForSpeedHacks((UINT8)nodetoplayer3[node]))
@ -5204,7 +5210,7 @@ static void HandlePacketFromPlayer(SINT8 node)
if ((netbuffer->packettype == PT_CLIENT4CMD || netbuffer->packettype == PT_CLIENT4MIS)
&& (nodetoplayer4[node] >= 0))
{
G_MoveTiccmd(&netcmds[maketic%BACKUPTICS][(UINT8)nodetoplayer4[node]],
G_MoveTiccmd(&netcmds[faketic%BACKUPTICS][(UINT8)nodetoplayer4[node]],
&netbuffer->u.client4pak.cmd4, 1);
if (CheckForSpeedHacks((UINT8)nodetoplayer4[node]))

View file

@ -2380,7 +2380,24 @@ static void P_UpdatePlayerAngle(player_t *player)
INT16 targetsteering = K_UpdateSteeringValue(player->steering, player->cmd.turning);
angleChange = K_GetKartTurnValue(player, targetsteering) << TICCMD_REDUCE;
if (!K_PlayerUsesBotMovement(player))
if (K_PlayerUsesBotMovement(player))
{
// You're a bot. Go where you're supposed to go
player->steering = targetsteering;
}
else if ((!(player->cmd.flags & TICCMD_RECEIVED)) && (!!(player->oldcmd.flags && TICCMD_RECEIVED)))
{
// Missed a single tic. This ticcmd is copied from their previous one
// (less the TICCMD_RECEIVED flag), so it will include an old angle, and
// steering towards that will turn unambitiously. A better guess is to
// assume their inputs are the same, and turn based on those for 1 tic.
player->steering = targetsteering;
// "Why not use this for multiple consecutive dropped tics?" Oversimplification:
// Clients have default netticbuffer 1, so missing more than 1 tic will freeze
// your client, and with it, your local camera. Our goal then becomes not to
// steer PAST the angle you can see, so the default turn solver behavior is best.
}
else
{
// With a full slam on the analog stick, how far could we steer in either direction?
INT16 steeringRight = K_UpdateSteeringValue(player->steering, KART_FULLTURN);
@ -2431,11 +2448,6 @@ static void P_UpdatePlayerAngle(player_t *player)
angleChange = targetDelta;
}
}
else
{
// You're a bot. Go where you're supposed to go
player->steering = targetsteering;
}
if (p == UINT8_MAX)
{