shithub: qk1

Download patch

ref: 0ebadacc8c2a6d5a2b7e3d6160172338f62618a3
parent: 916d1c746cd6dfac5faeb0865345a0bc07be472e
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Nov 1 18:51:25 EDT 2023

R_RecursiveWorldNode: recurse less

--- a/bspfile.h
+++ b/bspfile.h
@@ -92,16 +92,17 @@
 	float	point[3];
 } dvertex_t;
 
-// 0-2 are axial planes
-#define	PLANE_X			0
-#define	PLANE_Y			1
-#define	PLANE_Z			2
+enum {
+	// 0-2 are axial planes
+	PLANE_X,
+	PLANE_Y,
+	PLANE_Z,
+	// 3-5 are non-axial planes snapped to the nearest
+	PLANE_ANYX,
+	PLANE_ANYY,
+	PLANE_ANYZ,
+};
 
-// 3-5 are non-axial planes snapped to the nearest
-#define	PLANE_ANYX		3
-#define	PLANE_ANYY		4
-#define	PLANE_ANYZ		5
-
 typedef struct
 {
 	float	normal[3];
@@ -108,8 +109,6 @@
 	float	dist;
 	int		type;		// PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
 } dplane_t;
-
-
 
 #define	CONTENTS_EMPTY		-1
 #define	CONTENTS_SOLID		-2
--- a/r_bsp.c
+++ b/r_bsp.c
@@ -426,6 +426,7 @@
 	mleaf_t		*pleaf;
 	double		d, dot;
 
+again:
 	if (node->contents == CONTENTS_SOLID)
 		return;		// solid
 
@@ -502,23 +503,8 @@
 
 	// find which side of the node we are on
 		plane = node->plane;
-
-		switch (plane->type)
-		{
-		case PLANE_X:
-			dot = modelorg[0] - plane->dist;
-			break;
-		case PLANE_Y:
-			dot = modelorg[1] - plane->dist;
-			break;
-		case PLANE_Z:
-			dot = modelorg[2] - plane->dist;
-			break;
-		default:
-			dot = DotProduct (modelorg, plane->normal) - plane->dist;
-			break;
-		}
-	
+		dot = plane->type <= PLANE_Z ? modelorg[plane->type] : DotProduct(modelorg, plane->normal);
+		dot -= plane->dist;
 		side = dot < 0;
 
 	// recurse down the children, front side first
@@ -549,7 +535,8 @@
 		}
 
 	// recurse down the back side
-		R_RecursiveWorldNode (node->children[!side], clipflags);
+		node = node->children[!side];
+		goto again;
 	}
 }