ref: faf2526174629c68285610615b66fad7d1120510
parent: 630c118915d8fc8ca8a776254f363ed9334b6b24
author: Andrew Apted <ajapted@gmail.com>
date: Sat Dec 9 08:43:06 EST 2023
removed local `nsubsec_t` and `nnode_t` types, updated global ones in r_defs.h The rest of the engine is quite broken now....
--- a/nano_bsp.c
+++ b/nano_bsp.c
@@ -44,27 +44,6 @@
#define DIST_EPSILON (FRACUNIT / 64)
-// 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 (fixed_t x, fixed_t y)
{vertex_t * vert = Z_Malloc(sizeof(vertex_t), PU_LEVEL, NULL);
@@ -80,16 +59,16 @@
return seg;
}
-nsubsec_t * BSP_NewSubsector (void)
+subsector_t * BSP_NewSubsector (void)
{- nsubsec_t * sub = Z_Malloc (sizeof(nsubsec_t), PU_LEVEL, NULL);
+ subsector_t * sub = Z_Malloc (sizeof(subsector_t), PU_LEVEL, NULL);
memset (sub, 0, sizeof(*sub));
return sub;
}
-nnode_t * BSP_NewNode (void)
+node_t * BSP_NewNode (void)
{- nnode_t * node = Z_Malloc (sizeof(nnode_t), PU_LEVEL, NULL);
+ node_t * node = Z_Malloc (sizeof(node_t), PU_LEVEL, NULL);
memset (node, 0, sizeof(*node));
return node;
}
@@ -137,18 +116,18 @@
return list;
}
-nnode_t * BSP_CreateLeaf (seg_t * soup)
+node_t * BSP_CreateLeaf (seg_t * soup)
{- nsubsec_t * sub = BSP_NewSubsector ();
- nnode_t * N = BSP_NewNode ();
+ subsector_t * sub = BSP_NewSubsector ();
+ node_t * node = BSP_NewNode ();
sub->segs = soup;
- // TODO: better algo, try to avoid self-ref lines
+ // TODO: better method, try to avoid self-ref lines
sub->sector = soup->frontsector;
- N->sub = sub;
- return N;
+ node->sub = sub;
+ return node;
}
//----------------------------------------------------------------------------
@@ -553,7 +532,7 @@
}
}
-nnode_t * BSP_SubdivideSegs (seg_t * soup)
+node_t * BSP_SubdivideSegs (seg_t * soup)
{seg_t * part = BSP_PickNode_Fast (soup);
@@ -563,7 +542,7 @@
if (part == NULL)
return BSP_CreateLeaf (soup);
- nnode_t * N = BSP_NewNode ();
+ node_t * N = BSP_NewNode ();
N->x = part->v1->x;
N->y = part->v1->y;
@@ -588,7 +567,5 @@
{seg_t * list = BSP_CreateSegs ();
- nnode_t * node = BSP_SubdivideSegs (list);
-
- // TODO
+ root_node = BSP_SubdivideSegs (list);
}
--- a/r_defs.h
+++ b/r_defs.h
@@ -210,23 +210,6 @@
//
-// A SubSector.
-// References a Sector.
-// Basically, this is a list of LineSegs,
-// indicating the visible walls that define
-// (all or some) sides of a convex BSP leaf.
-//
-typedef struct subsector_s
-{- sector_t* sector;
- short numlines;
- short firstline;
-
-} subsector_t;
-
-
-
-//
// The LineSeg.
//
typedef struct seg_s
@@ -233,7 +216,7 @@
{vertex_t* v1;
vertex_t* v2;
-
+
fixed_t offset;
angle_t angle;
@@ -254,24 +237,35 @@
//
+// A SubSector.
+// References a Sector.
+// Basically, this is a list of LineSegs,
+// indicating the visible walls that define
+// (all or some) sides of a convex BSP leaf.
+//
+typedef struct subsector_s
+{+ sector_t * sector;
+ seg_t * segs;
+} subsector_t;
+
+
+
+//
// BSP node.
//
-typedef struct
+typedef struct node_s
{- // Partition line.
- fixed_t x;
- fixed_t y;
- fixed_t dx;
- fixed_t dy;
+ // when non-NULL, this is actually a leaf of the BSP tree
+ subsector_t * sub;
- // Bounding box for each child.
- fixed_t bbox[2][4];
+ // partition line (start coord, delta to end)
+ fixed_t x, y, dx, dy;
- // If NF_SUBSECTOR its a subsector.
- unsigned short children[2];
-
+ // right and left children
+ struct node_s * right;
+ struct node_s * left;
} node_t;
-
--
⑨