Move party construction to G_AddPlayer

- Fixes crash when a player leaves when viewing a replay
- Slightly refactors player joining code (including bots)
This commit is contained in:
James R 2024-01-28 23:01:54 -08:00
parent bf1e4cb5bc
commit 6c2736bd1d
5 changed files with 10 additions and 12 deletions

View file

@ -3542,7 +3542,6 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
CONS_Debug(DBG_NETPLAY, "addplayer: %d %d\n", node, newplayernum);
G_AddPlayer(newplayernum);
//G_SpectatePlayerOnJoin(newplayernum); -- caused desyncs in this spot :(
if (newplayernum+1 > doomcom->numslots)
@ -3557,6 +3556,8 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
console = READUINT8(*p);
splitscreenplayer = READUINT8(*p);
G_AddPlayer(newplayernum, console);
for (i = 0; i < MAXAVAILABILITY; i++)
{
newplayer->availabilities[i] = READUINT8(*p);
@ -3593,9 +3594,6 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
players[newplayernum].splitscreenindex = splitscreenplayer;
players[newplayernum].bot = false;
playerconsole[newplayernum] = console;
G_BuildLocalSplitscreenParty(newplayernum);
if (node == mynode && splitscreenplayer == 0)
S_AttemptToRestoreMusic(); // Earliest viable point

View file

@ -235,7 +235,7 @@ void G_ReadDemoExtraData(void)
{
if (!playeringame[p])
{
G_AddPlayer(p);
G_AddPlayer(p, p);
}
for (i = 0; i < MAXAVAILABILITY; i++)
@ -3511,7 +3511,7 @@ void G_DoPlayDemo(const char *defdemoname)
if (!playeringame[displayplayers[0]] || players[displayplayers[0]].spectator)
displayplayers[0] = consoleplayer = serverplayer = p;
G_AddPlayer(p);
G_AddPlayer(p, p);
players[p].spectator = spectator;
if (flags & DEMO_KICKSTART)

View file

@ -2919,13 +2919,16 @@ void G_DoReborn(INT32 playernum)
// These are the barest esentials.
// This func probably doesn't even need to know if the player is a bot.
void G_AddPlayer(INT32 playernum)
void G_AddPlayer(INT32 playernum, INT32 console)
{
CL_ClearPlayer(playernum);
G_DestroyParty(playernum);
playeringame[playernum] = true;
playerconsole[playernum] = console;
G_BuildLocalSplitscreenParty(playernum);
player_t *newplayer = &players[playernum];
newplayer->playerstate = PST_REBORN;

View file

@ -239,7 +239,7 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive);
void G_AdjustView(UINT8 viewnum, INT32 offset, boolean onlyactive);
void G_FixCamera(UINT8 viewnum);
void G_AddPlayer(INT32 playernum);
void G_AddPlayer(INT32 playernum, INT32 console);
void G_SpectatePlayerOnJoin(INT32 playernum);
void G_SetExitGameFlag(void);

View file

@ -55,7 +55,7 @@ void K_SetBot(UINT8 newplayernum, UINT8 skinnum, UINT8 difficulty, botStyle_e st
{
CONS_Debug(DBG_NETPLAY, "addbot: %d\n", newplayernum);
G_AddPlayer(newplayernum);
G_AddPlayer(newplayernum, newplayernum);
if (newplayernum+1 > doomcom->numslots)
doomcom->numslots = (INT16)(newplayernum+1);
@ -121,9 +121,6 @@ void K_SetBot(UINT8 newplayernum, UINT8 skinnum, UINT8 difficulty, botStyle_e st
SetPlayerSkinByNum(newplayernum, skinnum);
playerconsole[newplayernum] = newplayernum;
G_BuildLocalSplitscreenParty(newplayernum);
if (netgame)
{
HU_AddChatText(va("\x82*Bot %d has been added to the game", newplayernum+1), false);