From b4cf7fbc971db693a29d4cd4eb767dc6a678c7a7 Mon Sep 17 00:00:00 2001
From: Monster Iestyn <iestynjealous@ntlworld.com>
Date: Wed, 18 May 2016 18:20:56 +0100
Subject: [PATCH] Fix player 1 and player 2 affecting whether the other can see
 skyboxes or not

---
 src/p_setup.c |  2 +-
 src/r_main.c  | 14 ++++++++++++++
 src/r_state.h |  1 +
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/p_setup.c b/src/p_setup.c
index 37e784078..7265f508f 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -2838,7 +2838,7 @@ boolean P_SetupLevel(boolean skipprecip)
 		savedata.lives = 0;
 	}
 
-	skyVisible = true; // assume the skybox is visible on level load.
+	skyVisible = skyVisible1 = skyVisible2 = true; // assume the skybox is visible on level load.
 	if (loadprecip) // uglier hack
 	{ // to make a newly loaded level start on the second frame.
 		INT32 buf = gametic % BACKUPTICS;
diff --git a/src/r_main.c b/src/r_main.c
index 41bdb6ef2..e7c37cce9 100644
--- a/src/r_main.c
+++ b/src/r_main.c
@@ -67,6 +67,7 @@ fixed_t viewx, viewy, viewz;
 angle_t viewangle, aimingangle;
 fixed_t viewcos, viewsin;
 boolean viewsky, skyVisible;
+boolean skyVisible1, skyVisible2; // saved values of skyVisible for P1 and P2, for splitscreen
 sector_t *viewsector;
 player_t *viewplayer;
 
@@ -1301,6 +1302,12 @@ void R_RenderPlayerView(player_t *player)
 			V_DrawFill(0, 0, vid.width, vid.height, 128+(timeinmap&15));
 	}
 
+	// load previous saved value of skyVisible for the player
+	if (splitscreen && player == &players[secondarydisplayplayer])
+		skyVisible = skyVisible2;
+	else
+		skyVisible = skyVisible1;
+
 	portalrender = 0;
 	portal_base = portal_cap = NULL;
 
@@ -1398,6 +1405,13 @@ void R_RenderPlayerView(player_t *player)
 
 	// Check for new console commands.
 	NetUpdate();
+
+	// save value to skyVisible1 or skyVisible2
+	// this is so that P1 can't affect whether P2 can see a skybox or not, or vice versa
+	if (splitscreen && player == &players[secondarydisplayplayer])
+		skyVisible2 = skyVisible;
+	else
+		skyVisible1 = skyVisible;
 }
 
 // =========================================================================
diff --git a/src/r_state.h b/src/r_state.h
index ed04b771f..49d0457b2 100644
--- a/src/r_state.h
+++ b/src/r_state.h
@@ -85,6 +85,7 @@ extern side_t *sides;
 extern fixed_t viewx, viewy, viewz;
 extern angle_t viewangle, aimingangle;
 extern boolean viewsky, skyVisible;
+extern boolean skyVisible1, skyVisible2; // saved values of skyVisible for P1 and P2, for splitscreen
 extern sector_t *viewsector;
 extern player_t *viewplayer;
 extern UINT8 portalrender;
-- 
GitLab