From 5d6463fafc1fb16930f23f8bd314a41d690bc565 Mon Sep 17 00:00:00 2001
From: toasterbabe <rollerorbital@gmail.com>
Date: Sat, 13 Aug 2016 13:39:24 +0100
Subject: [PATCH] Fixed Knuckles being able to climb in space in OpenGL.

To understand: look at AjustSegs(void) in hw_bsp.c. It reallocates the vetex_t pointers for lines as POLYVERTEX_T pointers, and of COURSE things are gonna get wacky when you're casting pointers.

I dunno how resilient the FLOAT_TO_FIXED solution is or whether it'll be netgame compatible (yayyy float precision loss) but it's not like our builds are netgame compatible with themselves
---
 src/r_main.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/r_main.c b/src/r_main.c
index 1ad125cd0f..4c81b9d8c1 100644
--- a/src/r_main.c
+++ b/src/r_main.c
@@ -33,6 +33,7 @@
 
 #ifdef HWRENDER
 #include "hardware/hw_main.h"
+#include "hardware/hw_glob.h" // polyvertex_t
 #endif
 
 //profile stuff ---------------------------------------------------------
@@ -268,10 +269,28 @@ INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node)
 // killough 5/2/98: reformatted
 INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line)
 {
-	fixed_t lx = line->v1->x;
-	fixed_t ly = line->v1->y;
-	fixed_t ldx = line->v2->x - lx;
-	fixed_t ldy = line->v2->y - ly;
+	fixed_t lx, ly, ldx, ldy;
+
+#ifdef HWRENDER // how did nobody notice this for years
+	// used for the hardware render
+	if (rendermode != render_soft && rendermode != render_none)
+	{
+		lx = FLOAT_TO_FIXED(((polyvertex_t *)line->v1)->x);
+		ly = FLOAT_TO_FIXED(((polyvertex_t *)line->v1)->y);
+		ldx = FLOAT_TO_FIXED(((polyvertex_t *)line->v2)->x);
+		ldy = FLOAT_TO_FIXED(((polyvertex_t *)line->v2)->y);
+	}
+	else
+#endif
+	{
+		lx = line->v1->x;
+		ly = line->v1->y;
+		ldx = line->v2->x;
+		ldy = line->v2->y;
+	}
+
+	ldx -= lx;
+	ldy -= ly;
 
 	if (!ldx)
 		return x <= lx ? ldy > 0 : ldy < 0;
-- 
GitLab