From 8847cf77b4461d6ea330ee65ee08744048dfb1f7 Mon Sep 17 00:00:00 2001
From: Lactozilla <jp6781615@gmail.com>
Date: Mon, 29 Jan 2024 23:55:12 -0300
Subject: [PATCH] Minor changes

---
 src/lua_maplib.c |  8 +++++---
 src/m_vector.c   |  2 +-
 src/m_vector.h   |  2 +-
 src/p_slopes.c   | 16 ++++++++--------
 src/p_slopes.h   |  2 +-
 src/r_plane.c    |  9 +++++----
 6 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/lua_maplib.c b/src/lua_maplib.c
index 83f4964bf..f8e2808a2 100644
--- a/src/lua_maplib.c
+++ b/src/lua_maplib.c
@@ -2609,9 +2609,11 @@ static int slope_set(lua_State *L)
 			slope->o.z = luaL_checkfixed(L, -1);
 		else
 			slope->o.z = 0;
-		slope->dorigin.x = FixedToDouble(slope->o.x);
-		slope->dorigin.y = FixedToDouble(slope->o.y);
-		slope->dorigin.z = FixedToDouble(slope->o.z);
+		DVector3_Load(&slope->dorigin,
+			FixedToDouble(slope->o.x),
+			FixedToDouble(slope->o.y),
+			FixedToDouble(slope->o.z)
+		);
 		lua_pop(L, 1);
 		break;
 	}
diff --git a/src/m_vector.c b/src/m_vector.c
index 546826c76..3132a869d 100644
--- a/src/m_vector.c
+++ b/src/m_vector.c
@@ -1,6 +1,6 @@
 // SONIC ROBO BLAST 2
 //-----------------------------------------------------------------------------
-// Copyright (C) 1999-2024 by Sonic Team Junior.
+// Copyright (C) 2024 by Sonic Team Junior.
 // Copyright (C) 2009 by Stephen McGranahan.
 //
 // This program is free software distributed under the
diff --git a/src/m_vector.h b/src/m_vector.h
index abd23f1cf..55669be03 100644
--- a/src/m_vector.h
+++ b/src/m_vector.h
@@ -1,6 +1,6 @@
 // SONIC ROBO BLAST 2
 //-----------------------------------------------------------------------------
-// Copyright (C) 1999-2024 by Sonic Team Junior.
+// Copyright (C) 2024 by Sonic Team Junior.
 // Copyright (C) 2009 by Stephen McGranahan.
 //
 // This program is free software distributed under the
diff --git a/src/p_slopes.c b/src/p_slopes.c
index a41a3343a..bcee03181 100644
--- a/src/p_slopes.c
+++ b/src/p_slopes.c
@@ -1,6 +1,6 @@
 // SONIC ROBO BLAST 2
 //-----------------------------------------------------------------------------
-// Copyright (C) 2004      by Stephen McGranahan
+// Copyright (C) 2009      by Stephen McGranahan.
 // Copyright (C) 2015-2023 by Sonic Team Junior.
 //
 // This program is free software distributed under the
@@ -38,17 +38,17 @@ void P_CalculateSlopeNormal(pslope_t *slope) {
 static void CalculateVectors(pslope_t *slope, dvector3_t *dnormal)
 {
 	double hyp = hypot(dnormal->x, dnormal->y);
-	if (fpclassify(hyp) == FP_ZERO)
+
+	if (fpclassify(hyp) == FP_NORMAL)
 	{
-		slope->dnormdir.x = slope->dnormdir.y = 0.0;
-		slope->dzdelta = 0.0;
+		slope->dnormdir.x = -dnormal->x / hyp;
+		slope->dnormdir.y = -dnormal->y / hyp;
+		slope->dzdelta = hyp / dnormal->z;
 	}
 	else
 	{
-		slope->dnormdir.x = -(dnormal->x / hyp);
-		slope->dnormdir.y = -(dnormal->y / hyp);
-
-		slope->dzdelta = hyp / dnormal->z;
+		slope->dnormdir.x = slope->dnormdir.y = 0.0;
+		slope->dzdelta = 0.0;
 	}
 }
 
diff --git a/src/p_slopes.h b/src/p_slopes.h
index 78731c2a9..1a7e604b2 100644
--- a/src/p_slopes.h
+++ b/src/p_slopes.h
@@ -1,6 +1,6 @@
 // SONIC ROBO BLAST 2
 //-----------------------------------------------------------------------------
-// Copyright (C) 2004      by Stephen McGranahan
+// Copyright (C) 2009      by Stephen McGranahan.
 // Copyright (C) 2015-2023 by Sonic Team Junior.
 //
 // This program is free software distributed under the
diff --git a/src/r_plane.c b/src/r_plane.c
index f3536dbb2..1295b63ba 100644
--- a/src/r_plane.c
+++ b/src/r_plane.c
@@ -663,6 +663,7 @@ static void R_DrawSkyPlane(visplane_t *pl)
 // Returns the height of the sloped plane at (x, y) as a double
 static double R_GetSlopeZAt(const pslope_t *slope, fixed_t x, fixed_t y)
 {
+	// If you want to reimplement this using just the equation constants, use this instead:
 	// (d + a*x + b*y) * -(1.0 / c)
 
 	double px = FixedToDouble(x) - slope->dorigin.x;
@@ -712,11 +713,11 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos,
 		return;
 	}
 
-	// slope_v is the v direction vector in view space
+	// the v direction vector in view space
 	slope_v.x = cos(ang);
 	slope_v.z = sin(ang);
 
-	// slope_u is the u direction vector in view space
+	// the u direction vector in view space
 	slope_u.x = sin(ang);
 	slope_u.z = -cos(ang);
 
@@ -754,11 +755,11 @@ void R_SetScaledSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t
 	float xscale = FixedToFloat(xs);
 	float yscale = FixedToFloat(ys);
 
-	// m is the v direction vector in view space
+	// the v direction vector in view space
 	slope_v.x = yscale * cos(ang);
 	slope_v.z = yscale * sin(ang);
 
-	// n is the u direction vector in view space
+	// the u direction vector in view space
 	slope_u.x = xscale * sin(ang);
 	slope_u.z = -xscale * cos(ang);
 
-- 
GitLab