Refactor global variables out of doomcom

This commit is contained in:
Gustaf Alhäll 2024-12-15 12:32:02 +01:00
parent e570328ce6
commit ca2edd4d51
8 changed files with 54 additions and 47 deletions

View file

@ -1217,7 +1217,7 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic
void CL_ConnectToServer(void)
{
INT32 pnumnodes, nodewaited = doomcom->numnodes, i;
INT32 pnumnodes, nodewaited = numnetnodes, i;
tic_t oldtic;
tic_t asksent;
char tmpsave[256];
@ -1243,7 +1243,7 @@ void CL_ConnectToServer(void)
if (gamestate == GS_INTERMISSION)
Y_EndIntermission(); // clean up intermission graphics etc
DEBFILE(va("waiting %d nodes\n", doomcom->numnodes));
DEBFILE(va("waiting %d nodes\n", numnetnodes));
G_SetGamestate(GS_WAITINGPLAYERS);
wipegamestate = GS_WAITINGPLAYERS;
@ -1404,7 +1404,7 @@ void PT_ServerCFG(SINT8 node)
netnodes[(UINT8)servernode].ingame = true;
serverplayer = netbuffer->u.servercfg.serverplayer;
doomcom->numslots = SHORT(netbuffer->u.servercfg.totalslotnum);
numslots = SHORT(netbuffer->u.servercfg.totalslotnum);
mynode = netbuffer->u.servercfg.clientnode;
if (serverplayer >= 0)
playernode[(UINT8)serverplayer] = servernode;

View file

@ -147,8 +147,8 @@ void CL_Reset(void)
multiplayer = false;
servernode = 0;
server = true;
doomcom->numnodes = 1;
doomcom->numslots = 1;
numnetnodes = 1;
numslots = 1;
SV_StopServer();
SV_ResetServer();
@ -213,8 +213,8 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
CL_ClearPlayer(newplayernum);
playeringame[newplayernum] = true;
G_AddPlayer(newplayernum);
if (newplayernum+1 > doomcom->numslots)
doomcom->numslots = (INT16)(newplayernum+1);
if (newplayernum+1 > numslots)
numslots = (INT16)(newplayernum+1);
if (server && I_GetNodeAddress)
{
@ -610,8 +610,8 @@ void CL_RemovePlayer(INT32 playernum, kickreason_t reason)
// remove avatar of player
playeringame[playernum] = false;
while (!playeringame[doomcom->numslots-1] && doomcom->numslots > 1)
doomcom->numslots--;
while (!playeringame[numslots-1] && numslots > 1)
numslots--;
// Reset the name
sprintf(player_names[playernum], "Player %d", playernum+1);
@ -751,7 +751,7 @@ void SV_ResetServer(void)
if (server)
servernode = 0;
doomcom->numslots = 0;
numslots = 0;
// clear server_context
memset(server_context, '-', 8);
@ -803,7 +803,7 @@ void SV_SpawnServer(void)
// non dedicated server just connect to itself
if (!dedicated)
CL_ConnectToServer();
else doomcom->numslots = 1;
else numslots = 1;
}
}

View file

@ -48,6 +48,10 @@
#define FORCECLOSE 0x8000
tic_t connectiontimeout = (10*TICRATE);
INT16 numnetnodes;
INT16 numslots;
INT16 extratics;
/// \brief network packet
doomcom_t *doomcom = NULL;
/// \brief network packet data, points inside doomcom
@ -1176,8 +1180,8 @@ void D_SetDoomcom(void)
{
if (doomcom) return;
doomcom = Z_Calloc(sizeof (doomcom_t), PU_STATIC, NULL);
doomcom->numslots = doomcom->numnodes = 1;
doomcom->extratics = 0;
numslots = numnetnodes = 1;
extratics = 0;
}
//
@ -1223,10 +1227,10 @@ boolean D_CheckNetGame(void)
if (M_CheckParm("-extratic"))
{
if (M_IsNextParm())
doomcom->extratics = (INT16)atoi(M_GetNextParm());
extratics = (INT16)atoi(M_GetNextParm());
else
doomcom->extratics = 1;
CONS_Printf(M_GetText("Set extratics to %d\n"), doomcom->extratics);
extratics = 1;
CONS_Printf(M_GetText("Set extratics to %d\n"), extratics);
}
software_MAXPACKETLENGTH = hardware_MAXPACKETLENGTH;
@ -1248,8 +1252,8 @@ boolean D_CheckNetGame(void)
if (netgame)
multiplayer = true;
if (doomcom->numnodes > MAXNETNODES)
I_Error("Too many nodes (%d), max:%d", doomcom->numnodes, MAXNETNODES);
if (numnetnodes > MAXNETNODES)
I_Error("Too many nodes (%d), max:%d", numnetnodes, MAXNETNODES);
netbuffer = (doomdata_t *)(void *)&doomcom->data;

View file

@ -44,15 +44,6 @@ typedef struct
/// Number of bytes in doomdata to be sent
INT16 datalength;
/// Info common to all nodes.
/// Console is always node 0.
INT16 numnodes;
/// Flag: 1 = send a backup tic in every packet.
INT16 extratics;
/// Number of "slots": the highest player number in use plus one.
INT16 numslots;
/// The packet data to be sent.
char data[MAXPACKETLENGTH];
} ATTRPACK doomcom_t;
@ -61,6 +52,18 @@ typedef struct
#pragma pack()
#endif
/** \brief Number of connected nodes.
*/
extern INT16 numnetnodes;
/** \brief Number of "slots": the highest player number in use plus one.
*/
extern INT16 numslots;
/** \brief Flag: 1 = send a backup tic in every packet.
*/
extern INT16 extratics;
extern doomcom_t *doomcom;
/** \brief return packet in doomcom struct

View file

@ -1016,7 +1016,7 @@ static boolean UDP_Socket(void)
broadcastaddresses = s;
doomcom->extratics = 1; // internet is very high ping
extratics = 1; // internet is very high ping
return true;
}
@ -1304,18 +1304,18 @@ boolean I_InitTcpNetwork(void)
// in-game.
// Since Boris has implemented join in-game, there is no actual need for specifying a
// particular number here.
// FIXME: for dedicated server, numnodes needs to be set to 0 upon start
// FIXME: for dedicated server, numnetnodes needs to be set to 0 upon start
if (dedicated)
doomcom->numnodes = 0;
numnetnodes = 0;
/* else if (M_IsNextParm())
doomcom->numnodes = (INT16)atoi(M_GetNextParm());*/
numnetnodes = (INT16)atoi(M_GetNextParm());*/
else
doomcom->numnodes = 1;
numnetnodes = 1;
if (doomcom->numnodes < 0)
doomcom->numnodes = 0;
if (doomcom->numnodes > MAXNETNODES)
doomcom->numnodes = MAXNETNODES;
if (numnetnodes < 0)
numnetnodes = 0;
if (numnetnodes > MAXNETNODES)
numnetnodes = MAXNETNODES;
// server
servernode = 0;

View file

@ -269,10 +269,10 @@ void PT_TextCmd(SINT8 node, INT32 netconsole)
}
// check if tic that we are making isn't too large else we cannot send it :(
// doomcom->numslots+1 "+1" since doomcom->numslots can change within this time and sent time
// numslots+1 "+1" since numslots can change within this time and sent time
j = software_MAXPACKETLENGTH
- (netbuffer->u.textcmd[0]+2+BASESERVERTICSSIZE
+ (doomcom->numslots+1)*sizeof(ticcmd_t));
+ (numslots+1)*sizeof(ticcmd_t));
// search a tic that have enougth space in the ticcmd
while ((textcmd = D_GetExistingTextcmd(tic, netconsole)),

View file

@ -245,7 +245,7 @@ static boolean SV_SendServerConfig(INT32 node)
netbuffer->packettype = PT_SERVERCFG;
netbuffer->u.servercfg.serverplayer = (UINT8)serverplayer;
netbuffer->u.servercfg.totalslotnum = (UINT8)(doomcom->numslots);
netbuffer->u.servercfg.totalslotnum = (UINT8)numslots;
netbuffer->u.servercfg.gametic = (tic_t)LONG(gametic);
netbuffer->u.servercfg.clientnode = (UINT8)node;
netbuffer->u.servercfg.gamestate = (UINT8)gamestate;

View file

@ -244,7 +244,7 @@ void PT_ServerTics(SINT8 node, INT32 netconsole)
if (realstart <= neededtic && realend > neededtic)
{
UINT8 *pak = (UINT8 *)&packet->cmds;
UINT8 *txtpak = (UINT8 *)&packet->cmds[packet->numslots * packet->numtics];
UINT8 *txtpak = (UINT8 *)&packet->cmds[numslots * packet->numtics];
for (tic_t i = realstart; i < realend; i++)
{
@ -253,7 +253,7 @@ void PT_ServerTics(SINT8 node, INT32 netconsole)
// copy the tics
pak = G_ScpyTiccmd(netcmds[i%BACKUPTICS], pak,
packet->numslots*sizeof (ticcmd_t));
numslots*sizeof (ticcmd_t));
CL_CopyNetCommandsFromServerPacket(i, &txtpak);
}
@ -320,7 +320,7 @@ static tic_t SV_CalculateNumTicsForPacket(SINT8 nodenum, tic_t firsttic, tic_t l
for (tic_t tic = firsttic; tic < lasttic; tic++)
{
size += sizeof (ticcmd_t) * doomcom->numslots;
size += sizeof (ticcmd_t) * numslots;
size += TotalTextCmdPerTic(tic);
if (size > software_MAXPACKETLENGTH)
@ -337,7 +337,7 @@ static tic_t SV_CalculateNumTicsForPacket(SINT8 nodenum, tic_t firsttic, tic_t l
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);
sizeu1(size), numslots, nodenum);
else
{
lasttic++; // send it anyway!
@ -394,20 +394,20 @@ void SV_SendTics(void)
netbuffer->packettype = PT_SERVERTICS;
netbuffer->u.serverpak.starttic = realfirsttic;
netbuffer->u.serverpak.numtics = (UINT8)(lasttictosend - realfirsttic);
netbuffer->u.serverpak.numslots = (UINT8)SHORT(doomcom->numslots);
netbuffer->u.serverpak.numslots = (UINT8)SHORT(numslots);
// Fill and send the packet
UINT8 *bufpos = (UINT8 *)&netbuffer->u.serverpak.cmds;
for (tic_t i = realfirsttic; i < lasttictosend; i++)
bufpos = G_DcpyTiccmd(bufpos, netcmds[i%BACKUPTICS], doomcom->numslots * sizeof (ticcmd_t));
bufpos = G_DcpyTiccmd(bufpos, netcmds[i%BACKUPTICS], numslots * sizeof (ticcmd_t));
for (tic_t i = realfirsttic; i < lasttictosend; i++)
SV_WriteNetCommandsForTic(i, &bufpos);
size_t packsize = bufpos - (UINT8 *)&(netbuffer->u);
HSendPacket(n, false, 0, packsize);
// When tics are too large, only one tic is sent so don't go backwards!
if (lasttictosend-doomcom->extratics > realfirsttic)
node->supposedtic = lasttictosend-doomcom->extratics;
if (lasttictosend-extratics > realfirsttic)
node->supposedtic = lasttictosend-extratics;
else
node->supposedtic = lasttictosend;
node->supposedtic = max(node->supposedtic, node->tic);