From fb47b046dad8382683fd4a9995bf85ba468b61e5 Mon Sep 17 00:00:00 2001
From: MonsterIestyn <iestynjealous@ntlworld.com>
Date: Sun, 15 Feb 2015 17:15:55 +0000
Subject: [PATCH] Base draw distances on viewx/viewy coordinates, NOT the
 player object's coordinates (this can cause problems with things like
 skyboxes for instance). Splitscreen's player 2 should not affect what sprites
 player 1 can see, and vice versa! Especially not for precipitation, that just
 looks ridiculous.

git-svn-id: https://code.orospakr.ca/svn/srb2/trunk@9041 6de4a73c-47e2-0310-b8c1-93d6ecd3f8cd
---
 src/hardware/hw_main.c | 32 +++++---------------------------
 src/r_things.c         | 26 ++------------------------
 2 files changed, 7 insertions(+), 51 deletions(-)

diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c
index 3e3ad6513b..a61cc85e2d 100644
--- a/src/hardware/hw_main.c
+++ b/src/hardware/hw_main.c
@@ -4457,23 +4457,12 @@ static void HWR_AddSprites(sector_t *sec)
 	// If a limit exists, handle things a tiny bit different.
 	if ((limit_dist = (fixed_t)((maptol & TOL_NIGHTS) ? cv_drawdist_nights.value : cv_drawdist.value) << FRACBITS))
 	{
-		if (!players[displayplayer].mo)
-			return; // Draw nothing if no player.
-			// todo: is this really the best option for this situation?
-
 		for (thing = sec->thinglist; thing; thing = thing->snext)
 		{
 			if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW)
 				continue;
 
-			approx_dist = P_AproxDistance(
-				players[displayplayer].mo->x - thing->x,
-				players[displayplayer].mo->y - thing->y);
-
-			if (splitscreen && approx_dist > limit_dist && players[secondarydisplayplayer].mo)
-				approx_dist = P_AproxDistance(
-					players[secondarydisplayplayer].mo->x - thing->x,
-					players[secondarydisplayplayer].mo->y - thing->y);
+			approx_dist = P_AproxDistance(viewx-thing->x, viewy-thing->y);
 
 			if (approx_dist <= limit_dist)
 				HWR_ProjectSprite(thing);
@@ -4491,23 +4480,12 @@ static void HWR_AddSprites(sector_t *sec)
 	// Someone seriously wants infinite draw distance for precipitation?
 	if ((limit_dist = (fixed_t)cv_drawdist_precip.value << FRACBITS))
 	{
-		if (!players[displayplayer].mo)
-			return; // Draw nothing if no player.
-			// todo: is this really the best option for this situation?
-
 		for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext)
 		{
-			if (precipthing->invisible)
+			if (precipthing->precipflags & PCF_INVISIBLE)
 				continue;
 
-			approx_dist = P_AproxDistance(
-				players[displayplayer].mo->x - precipthing->x,
-				players[displayplayer].mo->y - precipthing->y);
-
-			if (splitscreen && approx_dist > limit_dist && players[secondarydisplayplayer].mo)
-				approx_dist = P_AproxDistance(
-					players[secondarydisplayplayer].mo->x - precipthing->x,
-					players[secondarydisplayplayer].mo->y - precipthing->y);
+			approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y);
 
 			if (approx_dist <= limit_dist)
 				HWR_ProjectPrecipitationSprite(precipthing);
@@ -4517,7 +4495,7 @@ static void HWR_AddSprites(sector_t *sec)
 	{
 		// Draw everything in sector, no checks
 		for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext)
-			if (!precipthing->invisible)
+			if (!(precipthing->precipflags & PCF_INVISIBLE))
 				HWR_ProjectPrecipitationSprite(precipthing);
 	}
 #endif
@@ -4578,7 +4556,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
 
 	if (rot >= sprdef->numframes)
 	{
-		CONS_Alert(CONS_ERROR, M_GetText("R_ProjectSprite: invalid sprite frame %s/%s for %s\n"),
+		CONS_Alert(CONS_ERROR, M_GetText("HWR_ProjectSprite: invalid sprite frame %s/%s for %s\n"),
 			sizeu1(rot), sizeu2(sprdef->numframes), sprnames[thing->sprite]);
 		thing->sprite = states[S_UNKNOWN].sprite;
 		thing->frame = states[S_UNKNOWN].frame;
diff --git a/src/r_things.c b/src/r_things.c
index 400fd75667..f5231854dc 100644
--- a/src/r_things.c
+++ b/src/r_things.c
@@ -1555,23 +1555,12 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel)
 	// If a limit exists, handle things a tiny bit different.
 	if ((limit_dist = (fixed_t)((maptol & TOL_NIGHTS) ? cv_drawdist_nights.value : cv_drawdist.value) << FRACBITS))
 	{
-		if (!players[displayplayer].mo)
-			return; // Draw nothing if no player.
-			// todo: is this really the best option for this situation?
-
 		for (thing = sec->thinglist; thing; thing = thing->snext)
 		{
 			if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW)
 				continue;
 
-			approx_dist = P_AproxDistance(
-				players[displayplayer].mo->x - thing->x,
-				players[displayplayer].mo->y - thing->y);
-
-			if (splitscreen && approx_dist > limit_dist && players[secondarydisplayplayer].mo)
-				approx_dist = P_AproxDistance(
-					players[secondarydisplayplayer].mo->x - thing->x,
-					players[secondarydisplayplayer].mo->y - thing->y);
+			approx_dist = P_AproxDistance(viewx-thing->x, viewy-thing->y);
 
 			if (approx_dist <= limit_dist)
 				R_ProjectSprite(thing);
@@ -1588,23 +1577,12 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel)
 	// Someone seriously wants infinite draw distance for precipitation?
 	if ((limit_dist = (fixed_t)cv_drawdist_precip.value << FRACBITS))
 	{
-		if (!players[displayplayer].mo)
-			return; // Draw nothing if no player.
-			// todo: is this really the best option for this situation?
-
 		for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext)
 		{
 			if (precipthing->precipflags & PCF_INVISIBLE)
 				continue;
 
-			approx_dist = P_AproxDistance(
-				players[displayplayer].mo->x - precipthing->x,
-				players[displayplayer].mo->y - precipthing->y);
-
-			if (splitscreen && approx_dist > limit_dist && players[secondarydisplayplayer].mo)
-				approx_dist = P_AproxDistance(
-					players[secondarydisplayplayer].mo->x - precipthing->x,
-					players[secondarydisplayplayer].mo->y - precipthing->y);
+			approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y);
 
 			if (approx_dist <= limit_dist)
 				R_ProjectPrecipitationSprite(precipthing);
-- 
GitLab