Replays: keep party in sync with current viewpoints

- More and more parts of the game rely on parties
- Parties are assumed to match the displayplayers
- This fixes A/B/C/D nametags
This commit is contained in:
James R 2024-03-01 06:05:52 -08:00
parent 3179183df7
commit adebfb000c
5 changed files with 52 additions and 7 deletions

View file

@ -1838,8 +1838,15 @@ static void Command_SetViews_f(void)
// Even if the splits go beyond the real number of
// splitscreen players, displayplayers was filled
// with duplicates of P1 (see Got_AddPlayer).
r_splitscreen = newsplits-1;
R_ExecuteSetViewSize();
if (demo.playback)
{
G_SyncDemoParty(consoleplayer, newsplits-1);
}
else
{
r_splitscreen = newsplits-1;
R_ExecuteSetViewSize();
}
// If promoting (outside of replays), make sure the
// camera is in the correct position.

View file

@ -47,6 +47,7 @@
#include "lua_hook.h"
#include "md5.h" // demo checksums
#include "p_saveg.h" // savebuffer_t
#include "g_party.h"
// SRB2Kart
#include "d_netfil.h" // nameonly
@ -4096,3 +4097,33 @@ boolean G_CheckDemoTitleEntry(void)
return true;
}
void G_SyncDemoParty(INT32 rem, INT32 newsplitscreen)
{
int r_splitscreen_copy = r_splitscreen;
INT32 displayplayers_copy[MAXSPLITSCREENPLAYERS];
memcpy(displayplayers_copy, displayplayers, sizeof displayplayers);
// If we switch away from someone's view, that player
// should be removed from the party.
// However, it is valid to have the player on multiple
// viewports.
// Remove this player
G_LeaveParty(rem);
// And reset the rest of the party
for (int i = 0; i <= r_splitscreen_copy; ++i)
G_LeaveParty(displayplayers_copy[i]);
// Restore the party, without the removed player, and
// with the order matching displayplayers
for (int i = 0; i <= newsplitscreen; ++i)
G_JoinParty(consoleplayer, displayplayers_copy[i]);
// memcpy displayplayers back to preserve duplicates
// (G_JoinParty will not create duplicates itself)
r_splitscreen = newsplitscreen;
memcpy(displayplayers, displayplayers_copy, sizeof displayplayers);
R_ExecuteSetViewSize();
}

View file

@ -243,6 +243,8 @@ typedef enum
DEMO_ATTRACT_CREDITS
} demoAttractMode_t;
void G_SyncDemoParty(INT32 rem, INT32 newsplitscreen);
#ifdef __cplusplus
} // extern "C"
#endif

View file

@ -1685,8 +1685,13 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive)
}
}
if (viewnum == 1 && demo.playback)
consoleplayer = displayplayers[0];
if (demo.playback)
{
if (viewnum == 1)
consoleplayer = displayplayers[0];
G_SyncDemoParty(olddisplayplayer, r_splitscreen);
}
// change statusbar also if playing back demo
if (demo.quitafterplaying)

View file

@ -9,6 +9,7 @@
#include "../../p_local.h" // P_InitCameraCmd
#include "../../d_main.h" // D_StartTitle
#include "../../k_credits.h"
#include "../../g_demo.h"
static void M_PlaybackTick(void);
@ -220,13 +221,12 @@ void M_PlaybackSetViews(INT32 choice)
{
if (choice == 0)
{
r_splitscreen--;
G_SyncDemoParty(displayplayers[r_splitscreen], r_splitscreen - 1);
}
else
{
r_splitscreen = 0;
G_SyncDemoParty(consoleplayer, 0);
}
R_ExecuteSetViewSize();
}
}