shithub: nanobsp

Download patch

ref: 60643a184fafa1d2e092b1cd141a60b90de920a2
parent: 35fc4078cabb6cb183b38e693a560b67681c061d
author: Andrew Apted <ajapted@gmail.com>
date: Fri Dec 8 19:03:06 EST 2023

define two structs `nsubsec_t` and `nnode_t`, funcs to alloc them.

--- a/nano_bsp.c
+++ b/nano_bsp.c
@@ -44,6 +44,27 @@
 // #define DIST_EPSILON  (1.0 / 256.0)
 
 
+// TODO: probably make these global
+typedef struct nsubsec_s
+{
+	sector_t * sector;
+	seg_t    * segs;
+} nsubsec_t;
+
+typedef struct nnode_s
+{
+	// when non-NULL, this is actually a leaf of the BSP tree
+	nsubsec_t * sub;
+
+	// partition line (start coord, delta to end)
+	fixed_t  x, y, dx, dy;
+
+	// right and left children
+	struct nnode_s * right;
+	struct nnode_s * left;
+} nnode_t;
+
+
 vertex_t * BSP_NewVertex (void)
 {
 	vertex_t * vert = Z_Malloc(sizeof(vertex_t), PU_LEVEL, NULL);
@@ -50,7 +71,6 @@
 	return vert;
 }
 
-
 seg_t * BSP_NewSeg (void)
 {
 	seg_t * seg = Z_Malloc (sizeof(seg_t), PU_LEVEL, NULL);
@@ -58,6 +78,18 @@
 	return seg;
 }
 
+nsubsec_t * BSP_NewSubsector (void)
+{
+	nsubsec_t * sub = Z_Malloc (sizeof(nsubsec_t), PU_LEVEL, NULL);
+	return sub;
+}
+
+nnode_t * BSP_NewNode (void)
+{
+	nnode_t * node = Z_Malloc (sizeof(nnode_t), PU_LEVEL, NULL);
+	memset (node, 0, sizeof(*node));
+	return node;
+}
 
 //----------------------------------------------------------------------------
 
--