mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-01 14:10:54 +00:00
Split SV_SendTics into functions
This commit is contained in:
parent
530a03cc7d
commit
9291416a90
3 changed files with 66 additions and 51 deletions
|
@ -304,6 +304,27 @@ void PT_TextCmd(SINT8 node, INT32 netconsole)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SV_WriteNetCommandsForTic(tic_t tic, UINT8 **buf)
|
||||||
|
{
|
||||||
|
UINT8 *numcmds;
|
||||||
|
|
||||||
|
numcmds = (*buf)++;
|
||||||
|
*numcmds = 0;
|
||||||
|
for (INT32 i = 0; i < MAXPLAYERS; i++)
|
||||||
|
{
|
||||||
|
UINT8 *cmd = D_GetExistingTextcmd(tic, i);
|
||||||
|
INT32 size = cmd ? cmd[0] : 0;
|
||||||
|
|
||||||
|
if ((!i || playeringame[i]) && size)
|
||||||
|
{
|
||||||
|
(*numcmds)++;
|
||||||
|
WRITEUINT8(*buf, i);
|
||||||
|
M_Memcpy(*buf, cmd, size + 1);
|
||||||
|
*buf += size + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CL_CopyNetCommandsFromServerPacket(tic_t tic)
|
void CL_CopyNetCommandsFromServerPacket(tic_t tic)
|
||||||
{
|
{
|
||||||
servertics_pak *packet = &netbuffer->u.serverpak;
|
servertics_pak *packet = &netbuffer->u.serverpak;
|
||||||
|
|
|
@ -57,6 +57,7 @@ void ExtraDataTicker(void);
|
||||||
size_t TotalTextCmdPerTic(tic_t tic);
|
size_t TotalTextCmdPerTic(tic_t tic);
|
||||||
|
|
||||||
void PT_TextCmd(SINT8 node, INT32 netconsole);
|
void PT_TextCmd(SINT8 node, INT32 netconsole);
|
||||||
|
void SV_WriteNetCommandsForTic(tic_t tic, UINT8 **buf);
|
||||||
void CL_CopyNetCommandsFromServerPacket(tic_t tic);
|
void CL_CopyNetCommandsFromServerPacket(tic_t tic);
|
||||||
void CL_SendNetCommands(void);
|
void CL_SendNetCommands(void);
|
||||||
void SendKick(UINT8 playernum, UINT8 msg);
|
void SendKick(UINT8 playernum, UINT8 msg);
|
||||||
|
|
|
@ -298,16 +298,56 @@ void CL_SendClientCmd(void)
|
||||||
CL_SendNetCommands();
|
CL_SendNetCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PT_SERVERTICS packets can grow too large for a single UDP packet,
|
||||||
|
// So this checks how many tics worth of data can be sent in one packet.
|
||||||
|
// The rest can be sent later, usually the next tic.
|
||||||
|
static tic_t SV_CalculateNumTicsForPacket(SINT8 nodenum, tic_t firsttic, tic_t lasttic)
|
||||||
|
{
|
||||||
|
size_t size = BASESERVERTICSSIZE;
|
||||||
|
tic_t tic;
|
||||||
|
|
||||||
|
for (tic = firsttic; tic < lasttic; tic++)
|
||||||
|
{
|
||||||
|
size += sizeof (ticcmd_t) * doomcom->numslots;
|
||||||
|
size += TotalTextCmdPerTic(tic);
|
||||||
|
|
||||||
|
if (size > software_MAXPACKETLENGTH)
|
||||||
|
{
|
||||||
|
DEBFILE(va("packet too large (%s) at tic %d (should be from %d to %d)\n",
|
||||||
|
sizeu1(size), tic, firsttic, lasttic));
|
||||||
|
lasttic = tic;
|
||||||
|
|
||||||
|
// too bad: too much player have send extradata and there is too
|
||||||
|
// much data in one tic.
|
||||||
|
// To avoid it put the data on the next tic. (see getpacket
|
||||||
|
// textcmd case) but when numplayer changes the computation can be different
|
||||||
|
if (lasttic == firsttic)
|
||||||
|
{
|
||||||
|
if (size > MAXPACKETLENGTH)
|
||||||
|
I_Error("Too many players: can't send %s data for %d players to node %d\n"
|
||||||
|
"Well sorry nobody is perfect....\n",
|
||||||
|
sizeu1(size), doomcom->numslots, nodenum);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lasttic++; // send it anyway!
|
||||||
|
DEBFILE("sending it anyway\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lasttic - firsttic;
|
||||||
|
}
|
||||||
|
|
||||||
// send the server packet
|
// send the server packet
|
||||||
// send tic from firstticstosend to maketic-1
|
// send tic from firstticstosend to maketic-1
|
||||||
void SV_SendTics(void)
|
void SV_SendTics(void)
|
||||||
{
|
{
|
||||||
tic_t realfirsttic, lasttictosend, i;
|
tic_t realfirsttic, lasttictosend, i;
|
||||||
UINT32 n;
|
UINT32 n;
|
||||||
INT32 j;
|
|
||||||
size_t packsize;
|
size_t packsize;
|
||||||
UINT8 *bufpos;
|
UINT8 *bufpos;
|
||||||
UINT8 *ntextcmd;
|
|
||||||
|
|
||||||
// send to all client but not to me
|
// send to all client but not to me
|
||||||
// for each node create a packet with x tics and send it
|
// for each node create a packet with x tics and send it
|
||||||
|
@ -336,38 +376,7 @@ void SV_SendTics(void)
|
||||||
if (realfirsttic < firstticstosend)
|
if (realfirsttic < firstticstosend)
|
||||||
realfirsttic = firstticstosend;
|
realfirsttic = firstticstosend;
|
||||||
|
|
||||||
// compute the length of the packet and cut it if too large
|
lasttictosend = realfirsttic + SV_CalculateNumTicsForPacket(n, realfirsttic, lasttictosend);
|
||||||
packsize = BASESERVERTICSSIZE;
|
|
||||||
for (i = realfirsttic; i < lasttictosend; i++)
|
|
||||||
{
|
|
||||||
packsize += sizeof (ticcmd_t) * doomcom->numslots;
|
|
||||||
packsize += TotalTextCmdPerTic(i);
|
|
||||||
|
|
||||||
if (packsize > software_MAXPACKETLENGTH)
|
|
||||||
{
|
|
||||||
DEBFILE(va("packet too large (%s) at tic %d (should be from %d to %d)\n",
|
|
||||||
sizeu1(packsize), i, realfirsttic, lasttictosend));
|
|
||||||
lasttictosend = i;
|
|
||||||
|
|
||||||
// too bad: too much player have send extradata and there is too
|
|
||||||
// much data in one tic.
|
|
||||||
// To avoid it put the data on the next tic. (see getpacket
|
|
||||||
// textcmd case) but when numplayer changes the computation can be different
|
|
||||||
if (lasttictosend == realfirsttic)
|
|
||||||
{
|
|
||||||
if (packsize > MAXPACKETLENGTH)
|
|
||||||
I_Error("Too many players: can't send %s data for %d players to node %d\n"
|
|
||||||
"Well sorry nobody is perfect....\n",
|
|
||||||
sizeu1(packsize), doomcom->numslots, n);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lasttictosend++; // send it anyway!
|
|
||||||
DEBFILE("sending it anyway\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the tics
|
// Send the tics
|
||||||
netbuffer->packettype = PT_SERVERTICS;
|
netbuffer->packettype = PT_SERVERTICS;
|
||||||
|
@ -383,23 +392,7 @@ void SV_SendTics(void)
|
||||||
|
|
||||||
// add textcmds
|
// add textcmds
|
||||||
for (i = realfirsttic; i < lasttictosend; i++)
|
for (i = realfirsttic; i < lasttictosend; i++)
|
||||||
{
|
SV_WriteNetCommandsForTic();
|
||||||
ntextcmd = bufpos++;
|
|
||||||
*ntextcmd = 0;
|
|
||||||
for (j = 0; j < MAXPLAYERS; j++)
|
|
||||||
{
|
|
||||||
UINT8 *textcmd = D_GetExistingTextcmd(i, j);
|
|
||||||
INT32 size = textcmd ? textcmd[0] : 0;
|
|
||||||
|
|
||||||
if ((!j || playeringame[j]) && size)
|
|
||||||
{
|
|
||||||
(*ntextcmd)++;
|
|
||||||
WRITEUINT8(bufpos, j);
|
|
||||||
M_Memcpy(bufpos, textcmd, size + 1);
|
|
||||||
bufpos += size + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
packsize = bufpos - (UINT8 *)&(netbuffer->u);
|
packsize = bufpos - (UINT8 *)&(netbuffer->u);
|
||||||
|
|
||||||
HSendPacket(n, false, 0, packsize);
|
HSendPacket(n, false, 0, packsize);
|
||||||
|
|
Loading…
Reference in a new issue