Move net command copying to a new function

This commit is contained in:
LJ Sonic 2023-01-14 14:52:13 +01:00
parent 715893ad25
commit 2639dc176d
3 changed files with 24 additions and 18 deletions

View file

@ -304,6 +304,26 @@ void PT_TextCmd(SINT8 node, INT32 netconsole)
}
}
void SV_CopyNetCommandsToServerPacket(tic_t tic)
{
servertics_pak *packet = &netbuffer->u.serverpak;
UINT8 *cmds = (UINT8*)&packet->cmds[packet->numslots * packet->numtics];
UINT8 numcmds;
numcmds = *cmds++;
for (UINT32 i = 0; i < numcmds; i++)
{
INT32 playernum = *cmds++; // playernum
size_t size = cmds[0]+1;
if (tic >= gametic) // Don't copy old net commands
M_Memcpy(D_GetTextcmd(tic, playernum), cmds, size);
cmds += size;
}
}
void CL_SendNetCommands(void)
void SendKick(UINT8 playernum, UINT8 msg)
{
UINT8 buf[2];

View file

@ -57,6 +57,7 @@ void ExtraDataTicker(void);
size_t TotalTextCmdPerTic(tic_t tic);
void PT_TextCmd(SINT8 node, INT32 netconsole);
void SV_CopyNetCommandsToServerPacket(tic_t tic);
void SendKick(UINT8 playernum, UINT8 msg);
void SendKicksForNode(SINT8 node, UINT8 msg);

View file

@ -204,7 +204,6 @@ void PT_ClientCmd(SINT8 node, INT32 netconsole)
void PT_ServerTics(SINT8 node, INT32 netconsole)
{
UINT8 *pak, *txtpak, numtxtpak;
tic_t realend, realstart;
if (!netnodes[node].ingame)
@ -230,19 +229,15 @@ void PT_ServerTics(SINT8 node, INT32 netconsole)
realstart = netbuffer->u.serverpak.starttic;
realend = realstart + netbuffer->u.serverpak.numtics;
txtpak = (UINT8 *)&netbuffer->u.serverpak.cmds[netbuffer->u.serverpak.numslots
* netbuffer->u.serverpak.numtics];
if (realend > gametic + CLIENTBACKUPTICS)
realend = gametic + CLIENTBACKUPTICS;
cl_packetmissed = realstart > neededtic;
if (realstart <= neededtic && realend > neededtic)
{
tic_t i, j;
pak = (UINT8 *)&netbuffer->u.serverpak.cmds;
UINT8 *pak = (UINT8 *)&netbuffer->u.serverpak.cmds;
for (i = realstart; i < realend; i++)
for (tic_t i = realstart; i < realend; i++)
{
// clear first
D_Clearticcmd(i);
@ -251,17 +246,7 @@ void PT_ServerTics(SINT8 node, INT32 netconsole)
pak = G_ScpyTiccmd(netcmds[i%BACKUPTICS], pak,
netbuffer->u.serverpak.numslots*sizeof (ticcmd_t));
// copy the textcmds
numtxtpak = *txtpak++;
for (j = 0; j < numtxtpak; j++)
{
INT32 k = *txtpak++; // playernum
const size_t txtsize = txtpak[0]+1;
if (i >= gametic) // Don't copy old net commands
M_Memcpy(D_GetTextcmd(i, k), txtpak, txtsize);
txtpak += txtsize;
}
SV_CopyNetCommandsToServerPacket(i);
}
neededtic = realend;