shithub: nanobsp

Download patch

ref: 652d061c1c31c7f9b020039344175b37fc9aef63
parent: 9b93fd311e645f37e6291d416016c8134388fa17
author: Andrew Apted <ajapted@gmail.com>
date: Fri Dec 15 09:57:19 EST 2023

implemented counting the number of nodes (etc), allocating arrays.

--- a/nano_bsp.c
+++ b/nano_bsp.c
@@ -65,6 +65,9 @@
 	sector_t * sector;
 	seg_t    * segs;
 
+	// final index number of this node / leaf
+	int  index;
+
 	// partition line (start coord, delta to end)
 	fixed_t  x, y, dx, dy;
 
@@ -99,8 +102,7 @@
 	return node;
 }
 
-
-// DEBUG:
+/* DEBUG:
 void DumpNode (nanode_t * N, int lev)
 {
 	char spaces[256];
@@ -149,7 +151,7 @@
 		}
 	}
 }
-//
+*/
 
 //----------------------------------------------------------------------------
 
@@ -526,7 +528,6 @@
 	return seg->v1->y + FixedMul (seg->v2->y - seg->v1->y, along);
 }
 
-
 fixed_t BSP_HorizIntersection (fixed_t part_y, seg_t * seg)
 {
 	// vertical seg?
@@ -541,7 +542,6 @@
 	return seg->v1->x + FixedMul (seg->v2->x - seg->v1->x, along);
 }
 
-
 void BSP_ComputeIntersection (seg_t * part, seg_t * seg, fixed_t * x, fixed_t * y)
 {
 	// vertical partition?
@@ -600,7 +600,6 @@
 		*y = seg->v1->y + FixedMul (seg->v2->y - seg->v1->y, along);
 }
 
-
 //
 // For segs not intersecting the partition, just move them into the
 // correct output list (`lefts` or `rights`).  otherwise split the seg
@@ -720,6 +719,60 @@
 
 //----------------------------------------------------------------------------
 
+static int nano_seg_index;
+
+void BSP_CountStuff (nanode_t * N)
+{
+	if (N->sector == NULL)
+	{
+		// must recurse first, to ensure root node gets highest index
+		BSP_CountStuff (N->left);
+		BSP_CountStuff (N->right);
+
+		N->index = numnodes;
+		numnodes += 1;
+	}
+	else
+	{
+		N->index = numsubsectors;
+		numsubsectors += 1;
+
+		seg_t * seg;
+		for (seg = N->segs ; seg != NULL; seg = seg->next)
+		{
+			numsegs += 1;
+		}
+	}
+}
+
+
+#if 0
+void BSP_TransferSubsector (nanode_t * N)
+{
+}
+
+void BSP_TransferNode (nanode_t * N)
+{
+	if (N->sector != NULL)
+	{
+		BSP_TransferSubsector (N);
+		return;
+	}
+
+	{
+		numnodes += 1;
+
+		BSP_CountStuff (N->right);
+		BSP_CountStuff (N->left);
+
+		node_t * out = &nodes[numnodes - 1];
+
+		out->
+
+	}
+}
+#endif
+
 void BSP_BuildNodes (void)
 {
 	seg_t * list = BSP_CreateSegs ();
@@ -729,4 +782,18 @@
 /* DEBUG:
 	DumpNode (root, 0);
 */
+	// determine total number of nodes, subsectors and segs
+	numnodes = 0;
+	numsubsectors = 0;
+	numsegs = 0;
+
+	BSP_CountStuff (root);
+
+	nodes      = Z_Malloc (numnodes*sizeof(node_t), PU_LEVEL, NULL);
+	subsectors = Z_Malloc (numsubsectors*sizeof(subsector_t), PU_LEVEL, NULL);
+	segs       = Z_Malloc (numsegs*sizeof(seg_t), PU_LEVEL, NULL);
+
+	nano_seg_index = 0;
+
+	// BSP_Transfer ...
 }
--