Fix many instances of splitscreen view number if there are duplicate displayplayers

- Avoid iterating displayplayers to find view number and
  prefer R_GetViewNumber.
- Iterate over all matching displayplayers if necessary,
  instead of stopping at the first match.
This commit is contained in:
James R. 2023-10-01 03:22:30 -07:00 committed by James R
parent d5bac57409
commit 7b3010c93d
17 changed files with 133 additions and 218 deletions

View file

@ -206,7 +206,15 @@ class TiccmdBuilder
else
#endif
{
localangle[viewnum] += angleChange;
int p = g_localplayers[forplayer()];
for (int i = 0; i <= r_splitscreen; ++i)
{
if (displayplayers[i] == p)
{
localangle[i] += angleChange;
}
}
}
}

View file

@ -5398,17 +5398,7 @@ static void HWR_DrawSkyBackground(player_t *player)
{
FTransform dometransform;
const float fpov = FIXED_TO_FLOAT(cv_fov[viewssnum].value+player->fovadd);
postimg_t *type = &postimgtype[0];
SINT8 i;
for (i = r_splitscreen; i >= 0; i--)
{
if (player == &players[displayplayers[i]])
{
type = &postimgtype[i];
break;
}
}
postimg_t *type = &postimgtype[R_GetViewNumber()];
memset(&dometransform, 0x00, sizeof(FTransform));
@ -6104,20 +6094,10 @@ INT32 HWR_GetTextureUsed(void)
void HWR_DoPostProcessor(player_t *player)
{
postimg_t *type = &postimgtype[0];
SINT8 i;
postimg_t *type = &postimgtype[R_GetViewNumber()];
HWD.pfnUnSetShader();
for (i = r_splitscreen; i >= 0; i--)
{
if (player == &players[displayplayers[i]])
{
type = &postimgtype[i];
break;
}
}
// Armageddon Blast Flash!
// Could this even be considered postprocessor?
if (player->flashcount)

View file

@ -4,6 +4,7 @@
#include "../g_game.h"
#include "../k_hud.h"
#include "../p_local.h"
#include "../r_fps.h"
#include "../v_draw.hpp"
using srb2::Draw;
@ -24,7 +25,7 @@ void K_drawKart2PTimestamp(void)
{
auto get_row = []
{
if (stplyr == &players[displayplayers[0]])
if (R_GetViewNumber() == 0)
{
return Draw(286, 31).flags(V_SNAPTOTOP);
}

View file

@ -1481,7 +1481,7 @@ static void K_drawKartItem(void)
// pain and suffering defined below
if (offset)
{
if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3...
if (!(R_GetViewNumber() & 1)) // If we are P1 or P3...
{
fx = ITEM_X;
fy = ITEM_Y;
@ -1622,7 +1622,7 @@ static void K_drawKartItem(void)
{
xo++;
if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // Flip for P1 and P3 (yes, that's correct)
if (!(R_GetViewNumber() & 1)) // Flip for P1 and P3 (yes, that's correct)
{
xo -= 62;
flip = V_FLIP;
@ -1730,7 +1730,7 @@ static void K_drawKartSlotMachine(void)
if (offset)
{
boxoffx -= 4;
if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3...
if (!(R_GetViewNumber() & 1)) // If we are P1 or P3...
{
fx = ITEM_X + 10;
fy = ITEM_Y + 10;
@ -2052,7 +2052,7 @@ static void K_DrawKartPositionNum(UINT8 num)
{
fx = BASEVIDWIDTH << FRACBITS;
if (stplyr == &players[displayplayers[0]])
if (R_GetViewNumber() == 0)
{
// for player 1: display this at the top right, above the minimap.
fy = 0;
@ -2071,8 +2071,7 @@ static void K_DrawKartPositionNum(UINT8 num)
{
fy = BASEVIDHEIGHT << FRACBITS;
if (stplyr == &players[displayplayers[0]]
|| stplyr == &players[displayplayers[2]])
if (!(R_GetViewNumber() & 1)) // If we are P1 or P3...
{
// If we are P1 or P3...
fx = 0;
@ -2512,7 +2511,7 @@ static void K_drawKartEmeralds(void)
if (r_splitscreen < 2)
{
startx -= 8;
if (r_splitscreen == 1 && stplyr == &players[displayplayers[0]])
if (r_splitscreen == 1 && R_GetViewNumber() == 0)
{
starty = 1;
}
@ -2522,7 +2521,7 @@ static void K_drawKartEmeralds(void)
{
xindex = 2;
starty -= 15;
if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3...
if (!(R_GetViewNumber() & 1)) // If we are P1 or P3...
{
startx = LAPS_X;
splitflags = V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_SPLITSCREEN;
@ -2586,7 +2585,7 @@ static void K_drawKartLaps(void)
}
else
{
if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3...
if (!(R_GetViewNumber() & 1)) // If we are P1 or P3...
{
fx = LAPS_X;
fy = LAPS_Y;
@ -2693,7 +2692,7 @@ static void K_drawRingCounter(boolean gametypeinfoshown)
}
else
{
if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3...
if (!(R_GetViewNumber() & 1)) // If we are P1 or P3...
{
fx = LAPS_X;
fy = LAPS_Y;
@ -2833,7 +2832,7 @@ static void K_drawKartAccessibilityIcons(boolean gametypeinfoshown, INT32 fx)
{
fx = LAPS_X+44;
fy = LAPS_Y;
if (!(stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]])) // If we are not P1 or P3...
if (R_GetViewNumber() & 1) // If we are not P1 or P3...
{
splitflags ^= (V_SNAPTOLEFT|V_SNAPTORIGHT);
fx = (BASEVIDWIDTH/2) - fx;
@ -2992,7 +2991,7 @@ static void K_drawBlueSphereMeter(boolean gametypeinfoshown)
else
{
xstep = 8;
if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3...
if (!(R_GetViewNumber() & 1)) // If we are P1 or P3...
{
fx = LAPS_X-2;
fy = LAPS_Y;
@ -3077,7 +3076,7 @@ static void K_drawKartBumpersOrKarma(void)
}
else
{
if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3...
if (!(R_GetViewNumber() & 1)) // If we are P1 or P3...
{
fx = LAPS_X;
fy = LAPS_Y;
@ -3704,20 +3703,10 @@ static void K_drawKartNameTags(void)
if (result.onScreen == true)
{
if (!(demo.playback == true && demo.freecam == true))
if (!(demo.playback == true && demo.freecam == true) && P_IsDisplayPlayer(ntplayer) &&
ntplayer != &players[displayplayers[cnum]])
{
for (j = 0; j <= (unsigned)r_splitscreen; j++)
{
if (ntplayer == &players[displayplayers[j]])
{
break;
}
}
if (j <= (unsigned)r_splitscreen && j != cnum)
{
localindicator = j;
}
localindicator = G_PartyPosition(ntplayer - players);
}
if (localindicator >= 0)
@ -3896,7 +3885,7 @@ static void K_drawKartMinimap(void)
// Only draw for the first player
// Maybe move this somewhere else where this won't be a concern?
if (stplyr != &players[displayplayers[0]])
if (R_GetViewNumber() != 0)
return;
if (specialstageinfo.valid == true)
@ -4431,7 +4420,7 @@ static void K_drawKartFinish(boolean finish)
interpx = R_InterpolateFixed(ox, x);
if (r_splitscreen && stplyr == &players[displayplayers[1]])
if (r_splitscreen && R_GetViewNumber() == 1)
interpx = -interpx;
V_DrawFixedPatch(interpx + (STCD_X<<FRACBITS) - (pwidth / 2),
@ -4669,14 +4658,12 @@ static void K_drawKartFirstPerson(void)
if (stplyr->spectator || !stplyr->mo || (stplyr->mo->renderflags & RF_DONTDRAW))
return;
if (stplyr == &players[displayplayers[1]] && r_splitscreen)
{ pn = pnum[1]; tn = turn[1]; dr = drift[1]; }
else if (stplyr == &players[displayplayers[2]] && r_splitscreen > 1)
{ pn = pnum[2]; tn = turn[2]; dr = drift[2]; }
else if (stplyr == &players[displayplayers[3]] && r_splitscreen > 2)
{ pn = pnum[3]; tn = turn[3]; dr = drift[3]; }
else
{ pn = pnum[0]; tn = turn[0]; dr = drift[0]; }
{
UINT8 view = R_GetViewNumber();
pn = pnum[view];
tn = turn[view];
dr = drift[view];
}
if (r_splitscreen)
{
@ -4805,14 +4792,12 @@ static void K_drawKartFirstPerson(void)
V_DrawFixedPatch(x, y, scale, splitflags, kp_fpview[target], colmap);
if (stplyr == &players[displayplayers[1]] && r_splitscreen)
{ pnum[1] = pn; turn[1] = tn; drift[1] = dr; }
else if (stplyr == &players[displayplayers[2]] && r_splitscreen > 1)
{ pnum[2] = pn; turn[2] = tn; drift[2] = dr; }
else if (stplyr == &players[displayplayers[3]] && r_splitscreen > 2)
{ pnum[3] = pn; turn[3] = tn; drift[3] = dr; }
else
{ pnum[0] = pn; turn[0] = tn; drift[0] = dr; }
{
UINT8 view = R_GetViewNumber();
pnum[view] = pn;
turn[view] = tn;
drift[view] = dr;
}
}
// doesn't need to ever support 4p
@ -5093,26 +5078,19 @@ static void
K_drawMiniPing (void)
{
UINT32 f = V_SNAPTORIGHT;
UINT8 i;
UINT8 i = R_GetViewNumber();
if (!cv_showping.value)
{
return;
}
for (i = 0; i <= r_splitscreen; i++)
{
if (stplyr == &players[displayplayers[i]])
{
if (r_splitscreen > 1 && !(i & 1))
{
f = V_SNAPTOLEFT;
}
Draw_party_ping(i, f);
break;
}
}
}
void K_drawButton(fixed_t x, fixed_t y, INT32 flags, patch_t *button[2], boolean pressed)
@ -5210,7 +5188,7 @@ static void K_drawDistributionDebugger(void)
fixed_t y = -pad;
size_t i;
if (stplyr != &players[displayplayers[0]]) // only for p1
if (R_GetViewNumber() != 0) // only for p1
{
return;
}
@ -5268,7 +5246,7 @@ static void K_DrawWaypointDebugger(void)
if (cv_kartdebugwaypoints.value == 0)
return;
if (stplyr != &players[displayplayers[0]]) // only for p1
if (R_GetViewNumber() != 0) // only for p1
return;
if (netgame)
@ -5298,7 +5276,7 @@ static void K_DrawBotDebugger(void)
return;
}
if (stplyr != &players[displayplayers[0]]) // only for p1
if (R_GetViewNumber() != 0) // only for p1
{
return;
}
@ -5368,7 +5346,7 @@ static void K_DrawGPRankDebugger(void)
return;
}
if (stplyr != &players[displayplayers[0]]) // only for p1
if (R_GetViewNumber() != 0) // only for p1
{
return;
}
@ -5425,7 +5403,7 @@ void K_drawKartHUD(void)
K_drawKartFirstPerson();
// Draw full screen stuff that turns off the rest of the HUD
if (mapreset && stplyr == &players[displayplayers[0]])
if (mapreset && R_GetViewNumber() == 0)
{
K_drawChallengerScreen();
return;

View file

@ -264,13 +264,13 @@ UINT32 K_GetPlayerDontDrawFlag(player_t *player)
return flag;
if (player == &players[displayplayers[0]])
flag = RF_DONTDRAWP1;
else if (r_splitscreen >= 1 && player == &players[displayplayers[1]])
flag = RF_DONTDRAWP2;
else if (r_splitscreen >= 2 && player == &players[displayplayers[2]])
flag = RF_DONTDRAWP3;
else if (r_splitscreen >= 3 && player == &players[displayplayers[3]])
flag = RF_DONTDRAWP4;
flag |= RF_DONTDRAWP1;
if (r_splitscreen >= 1 && player == &players[displayplayers[1]])
flag |= RF_DONTDRAWP2;
if (r_splitscreen >= 2 && player == &players[displayplayers[2]])
flag |= RF_DONTDRAWP3;
if (r_splitscreen >= 3 && player == &players[displayplayers[3]])
flag |= RF_DONTDRAWP4;
return flag;
}

View file

@ -33,6 +33,7 @@
#include "m_easing.h"
#include "s_sound.h"
#include "st_stuff.h"
#include "r_fps.h"
boolean level_tally_t::UseBonuses(void)
{
@ -883,14 +884,14 @@ void level_tally_t::Draw(void)
SINT8 h_transition_sign = 1;
if (r_splitscreen > 1)
{
if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]])
if (!(R_GetViewNumber() & 1))
{
h_transition_sign = -h_transition_sign;
}
}
else if (r_splitscreen > 0)
{
if (stplyr == &players[displayplayers[1]])
if (R_GetViewNumber() == 1)
{
h_transition_sign = -h_transition_sign;
}

View file

@ -662,7 +662,7 @@ static int libd_drawOnMinimap(lua_State *L)
if (gamestate != GS_LEVEL)
return 0;
if (stplyr != &players[displayplayers[0]])
if (R_GetViewNumber() != 0)
return 0;
AutomapPic = mapheaderinfo[gamemap-1]->minimapPic;

View file

@ -599,7 +599,6 @@ static int player_set(lua_State *L)
if (plr == &players[displayplayers[i]])
{
localaiming[i] = plr->aiming;
break;
}
}
}

View file

@ -1439,7 +1439,6 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget
if (target->player == &players[displayplayers[i]])
{
localaiming[i] = 0;
break;
}
}

View file

@ -167,7 +167,6 @@ boolean P_IsMachineLocalPlayer(player_t *player);
boolean P_IsDisplayPlayer(player_t *player);
void P_SetPlayerAngle(player_t *player, angle_t angle);
angle_t P_GetLocalAngle(player_t *player);
void P_ForceLocalAngle(player_t *player, angle_t angle);
boolean P_PlayerFullbright(player_t *player);

View file

@ -2867,7 +2867,6 @@ boolean P_ProcessSpecial(activator_t *activator, INT16 special, INT32 *args, cha
camera[i].z += z;
camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y);
R_RelativeTeleportViewInterpolation(i, x, y, z, 0);
break;
}
}
}

View file

@ -79,7 +79,6 @@ void P_MixUp(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle,
if (camera[i].chase)
P_ResetCamera(thing->player, &camera[i]);
R_ResetViewInterpolation(i + 1);
break;
}
// don't run in place after a teleport
@ -170,8 +169,6 @@ boolean P_Teleport(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle
}
R_ResetViewInterpolation(1 + i);
break;
}
}

View file

@ -3544,19 +3544,10 @@ boolean P_SpectatorJoinGame(player_t *player)
player->enteredGame = true;
// Reset away view (some code referenced from Got_Teamchange)
{
UINT8 i = 0;
const UINT8 *localplayertable = G_PartyArray(consoleplayer);
for (i = 0; i <= r_splitscreen; i++)
{
if (localplayertable[i] == (player-players))
if (G_IsPartyLocal(player - players))
{
LUA_HookViewpointSwitch(player, player, true);
displayplayers[i] = (player-players);
break;
}
}
displayplayers[G_PartyPosition(player - players)] = (player-players);
}
// a surprise tool that will help us later...
@ -3572,11 +3563,11 @@ boolean P_SpectatorJoinGame(player_t *player)
}
// the below is first person only, if you're curious. check out P_CalcChasePostImg in p_mobj.c for chasecam
static void P_CalcPostImg(player_t *player)
static void P_CalcPostImg(player_t *player, size_t viewnum)
{
sector_t *sector = player->mo->subsector->sector;
postimg_t *type = NULL;
INT32 *param;
postimg_t *type = &postimgtype[viewnum];
INT32 *param = &postimgparam[viewnum];
fixed_t pviewheight;
size_t i;
@ -3591,16 +3582,6 @@ static void P_CalcPostImg(player_t *player)
pviewheight = player->awayview.mobj->z;
}
for (i = 0; i <= (unsigned)r_splitscreen; i++)
{
if (player == &players[displayplayers[i]])
{
type = &postimgtype[i];
param = &postimgparam[i];
break;
}
}
// see if we are in heat (no, not THAT kind of heat...)
for (i = 0; i < sector->tags.count; i++)
{
@ -4400,7 +4381,6 @@ void P_PlayerThink(player_t *player)
//
void P_PlayerAfterThink(player_t *player)
{
camera_t *thiscam = NULL; // if not one of the displayed players, just don't bother
UINT8 i;
#ifdef PARANOIA
@ -4425,15 +4405,6 @@ void P_PlayerAfterThink(player_t *player)
P_PlayerInSpecialSector(player);
#endif
for (i = 0; i <= r_splitscreen; i++)
{
if (player == &players[displayplayers[i]])
{
thiscam = &camera[i];
break;
}
}
if (player->playerstate == PST_DEAD)
{
// Followers need handled while dead.
@ -4448,12 +4419,20 @@ void P_PlayerAfterThink(player_t *player)
return;
}
if (thiscam)
{
if (!thiscam->chase) // bob view only if looking through the player's eyes
boolean chase = true;
for (i = 0; i <= r_splitscreen; i++)
{
if (player == &players[displayplayers[i]] && !camera[i].chase)
{
chase = false;
}
}
if (!chase) // bob view only if looking through the player's eyes
{
P_CalcHeight(player);
P_CalcPostImg(player);
}
else
{
@ -4466,6 +4445,14 @@ void P_PlayerAfterThink(player_t *player)
else
player->viewz = player->mo->z + player->viewheight;
}
for (i = 0; i <= r_splitscreen; i++)
{
if (player == &players[displayplayers[i]] && !camera[i].chase)
{
P_CalcPostImg(player, i);
}
}
}
// spectator invisibility and nogravity.
@ -4530,10 +4517,15 @@ void P_PlayerAfterThink(player_t *player)
K_UpdateBotGameplayVars(player);
}
if (thiscam)
for (i = 0; i <= r_splitscreen; i++)
{
if (player != &players[displayplayers[i]])
{
continue;
}
// Store before it gets 0'd out
thiscam->pmomz = player->mo->pmomz;
camera[i].pmomz = player->mo->pmomz;
}
if (P_IsObjectOnGround(player->mo))
@ -4632,21 +4624,6 @@ void P_SetPlayerAngle(player_t *player, angle_t angle)
player->angleturn = angle;
}
angle_t P_GetLocalAngle(player_t *player)
{
// this function is from vanilla srb2. can you tell?
// (hint: they have separate variables for all of this shit instead of arrays)
UINT8 i;
for (i = 0; i <= r_splitscreen; i++)
{
if (player == &players[displayplayers[i]])
return localangle[i];
}
return 0;
}
void P_ForceLocalAngle(player_t *player, angle_t angle)
{
UINT8 i;
@ -4658,8 +4635,6 @@ void P_ForceLocalAngle(player_t *player, angle_t angle)
if (player == &players[displayplayers[i]])
{
localangle[i] = angle;
break;
}
}

View file

@ -20,6 +20,7 @@
#include "r_local.h"
#include "r_state.h"
#include "r_portal.h" // Add seg portals
#include "r_fps.h"
#include "r_splats.h"
#include "p_local.h" // camera
@ -276,18 +277,11 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
mobj_t *viewmobj = viewplayer->mo;
INT32 heightsec;
boolean underwater;
UINT8 i;
UINT8 i = R_GetViewNumber();
for (i = 0; i <= r_splitscreen; i++)
{
if (viewplayer == &players[displayplayers[i]] && camera[i].chase)
{
if (camera[i].chase)
heightsec = R_PointInSubsector(camera[i].x, camera[i].y)->sector->heightsec;
break;
}
}
if (i > r_splitscreen && viewmobj)
else if (i > r_splitscreen && viewmobj)
heightsec = R_PointInSubsector(viewmobj->x, viewmobj->y)->sector->heightsec;
else
return sec;

View file

@ -20,6 +20,7 @@
#include "g_game.h"
#include "p_setup.h" // levelflats
#include "p_slopes.h"
#include "r_fps.h"
#include "r_data.h"
#include "r_textures.h"
#include "r_local.h"
@ -963,8 +964,6 @@ void R_DrawSinglePlane(visplane_t *pl)
planeripple.active = true;
if (spanfunctype == SPANDRAWFUNC_TRANS)
{
UINT8 i;
spanfunctype = SPANDRAWFUNC_WATER;
// Copy the current scene, ugh
@ -977,10 +976,7 @@ void R_DrawSinglePlane(visplane_t *pl)
bottom = viewheight;
// Only copy the part of the screen we need
for (i = 0; i <= r_splitscreen; i++)
{
if (viewplayer == &players[displayplayers[i]])
{
UINT8 i = R_GetViewNumber();
INT32 scrx = 0;
INT32 scry = top;
INT32 offset;
@ -1014,8 +1010,6 @@ void R_DrawSinglePlane(visplane_t *pl)
vid.width, vid.width);
}
}
}
}
#endif
}

View file

@ -1203,7 +1203,7 @@ static void ST_overlayDrawer(void)
{
char name[MAXPLAYERNAME+12];
INT32 y = (stplyr == &players[displayplayers[0]]) ? 4 : BASEVIDHEIGHT/2-12;
INT32 y = (viewnum == 0) ? 4 : BASEVIDHEIGHT/2-12;
sprintf(name, "VIEWPOINT: %s", player_names[stplyr-players]);
V_DrawRightAlignedThinString(BASEVIDWIDTH-40, y, V_HUDTRANSHALF|V_SNAPTOTOP|V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_SPLITSCREEN, name);
}

View file

@ -27,6 +27,7 @@
#include "f_finale.h"
#include "r_draw.h"
#include "console.h"
#include "r_fps.h"
#include "i_video.h" // rendermode
#include "z_zone.h"
@ -513,8 +514,7 @@ void V_AdjustXYWithSnap(INT32 *x, INT32 *y, UINT32 options, INT32 dupx, INT32 du
INT32 screenheight = vid.height;
INT32 basewidth = BASEVIDWIDTH * dupx;
INT32 baseheight = BASEVIDHEIGHT * dupy;
SINT8 player = -1;
UINT8 i;
SINT8 player = R_GetViewNumber();
if (options & V_SPLITSCREEN)
{
@ -531,15 +531,6 @@ void V_AdjustXYWithSnap(INT32 *x, INT32 *y, UINT32 options, INT32 dupx, INT32 du
}
}
for (i = 0; i <= r_splitscreen; i++)
{
if (stplyr == &players[displayplayers[i]])
{
player = i;
break;
}
}
if (vid.width != (BASEVIDWIDTH * dupx))
{
if (options & V_SNAPTORIGHT)
@ -586,7 +577,7 @@ void V_AdjustXYWithSnap(INT32 *x, INT32 *y, UINT32 options, INT32 dupx, INT32 du
if (r_splitscreen > 1)
{
if (stplyr == &players[displayplayers[1]] || stplyr == &players[displayplayers[3]])
if (player & 1)
slidefromright = true;
}