shithub: nanobsp

Download patch

ref: 5f62d4213cb279eb4ecb20b2f7a4120d02746c76
parent: 69b170ae025fb1c3702e41af7d03cb89df72ae0e
author: Andrew Apted <ajapted@gmail.com>
date: Sat Dec 9 09:07:25 EST 2023

updated code in "r_bsp.c" for subsector_t/node_t changes.

--- a/p_sight.c
+++ b/p_sight.c
@@ -143,13 +143,6 @@
     fixed_t		frac;
     fixed_t		slope;
 	
-//#ifdef RANGECHECK
-    if (num>=numsubsectors)
-	I_Error ("P_CrossSubsector: ss %i with numss = %i",
-		 num,
-		 numsubsectors);
-//#endif
-
     sub = &subsectors[num];
     
     // check lines
--- a/r_bsp.c
+++ b/r_bsp.c
@@ -492,50 +492,36 @@
 // Add sprites of things in sector.
 // Draw one or more line segments.
 //
-void R_Subsector (int num)
+void R_Subsector (subsector_t * sub)
 {
-    int			count;
-    seg_t*		line;
-    subsector_t*	sub;
-	
-//#ifdef RANGECHECK
-    if (num>=numsubsectors)
-	I_Error ("R_Subsector: ss %i with numss = %i",
-		 num,
-		 numsubsectors);
-//#endif
-
     sscount++;
-    sub = &subsectors[num];
     frontsector = sub->sector;
-    count = sub->numlines;
-    line = &segs[sub->firstline];
 
     if (frontsector->floorheight < viewz)
     {
-	floorplane = R_FindPlane (frontsector->floorheight,
-				  frontsector->floorpic,
-				  frontsector->lightlevel);
+        floorplane = R_FindPlane (frontsector->floorheight,
+                      frontsector->floorpic,
+                      frontsector->lightlevel);
     }
     else
-	floorplane = NULL;
-    
-    if (frontsector->ceilingheight > viewz 
-	|| frontsector->ceilingpic == skyflatnum)
+        floorplane = NULL;
+
+    if (frontsector->ceilingheight > viewz
+        || frontsector->ceilingpic == skyflatnum)
     {
-	ceilingplane = R_FindPlane (frontsector->ceilingheight,
-				    frontsector->ceilingpic,
-				    frontsector->lightlevel);
+        ceilingplane = R_FindPlane (frontsector->ceilingheight,
+                        frontsector->ceilingpic,
+                        frontsector->lightlevel);
     }
     else
-	ceilingplane = NULL;
-		
-    R_AddSprites (frontsector);	
+        ceilingplane = NULL;
 
-    while (count--)
+    R_AddSprites (frontsector);
+
+    seg_t * line;
+    for (line = sub->segs ; line != NULL ; line = line->next)
     {
-	R_AddLine (line);
-	line++;
+        R_AddLine (line);
     }
 }
 
@@ -545,32 +531,25 @@
 // Renders all subsectors below a given node,
 //  traversing subtree recursively.
 // Just call with BSP root.
-void R_RenderBSPNode (int bspnum)
+void R_RenderBSPNode (node_t * bsp)
 {
-    node_t*	bsp;
-    int		side;
-
+loop:
     // Found a subsector?
-    if (bspnum & NF_SUBSECTOR)
+    if (bsp->sub != NULL)
     {
-	if (bspnum == -1)			
-	    R_Subsector (0);
-	else
-	    R_Subsector (bspnum&(~NF_SUBSECTOR));
-	return;
+        R_Subsector (bsp->sub);
+        return;
     }
-		
-    bsp = &nodes[bspnum];
-    
+
     // Decide which side the view point is on.
-    side = R_PointOnSide (viewx, viewy, bsp);
+    int side = R_PointOnSide (viewx, viewy, bsp);
 
     // Recursively divide front space.
-    R_RenderBSPNode (bsp->children[side]); 
+    R_RenderBSPNode (side ? bsp->left : bsp->right);
 
     // Possibly divide back space.
-    if (R_CheckBBox (bsp->bbox[side^1]))	
-	R_RenderBSPNode (bsp->children[side^1]);
+    bsp = side ? bsp->right : bsp->left;
+    if (true) //FIXME  R_CheckBBox (bsp->bbox))
+        goto loop;
 }
-
 
--- a/r_bsp.h
+++ b/r_bsp.h
@@ -55,7 +55,7 @@
 void R_ClearDrawSegs (void);
 
 
-void R_RenderBSPNode (int bspnum);
+void R_RenderBSPNode (node_t * bsp);
 
 
 #endif
--- a/r_main.c
+++ b/r_main.c
@@ -786,7 +786,7 @@
     NetUpdate ();
 
     // The head node is the last node output.
-    R_RenderBSPNode (numnodes-1);
+    R_RenderBSPNode (root_node);
     
     // Check for new console commands.
     NetUpdate ();
--