ref: 8fa8d85c98de9a6a2a675cfd863fcbeabcd80b86
parent: 652d061c1c31c7f9b020039344175b37fc9aef63
author: Andrew Apted <ajapted@gmail.com>
date: Fri Dec 15 10:20:26 EST 2023
implemented BSP_WriteNode() -- write the info for a node (and children).
--- a/nano_bsp.c
+++ b/nano_bsp.c
@@ -61,7 +61,8 @@
struct Nanode
{- // when non-NULL, this is actually a leaf of the BSP tree
+ // when non-NULL, this is actually a leaf of the BSP tree.
+ // TODO : probably remove sector
sector_t * sector;
seg_t * segs;
@@ -745,33 +746,46 @@
}
}
+void BSP_WriteSeg (seg_t * in, seg_t * out)
+{+ memcpy (out, in, sizeof(seg_t));
-#if 0
-void BSP_TransferSubsector (nanode_t * N)
+ out->next = NULL;
+}
+
+unsigned int BSP_WriteSubsector (nanode_t * N)
{+ // TODO
+
+ return (unsigned int) N->index | NF_SUBSECTOR;
}
-void BSP_TransferNode (nanode_t * N)
+unsigned int BSP_WriteNode (nanode_t * N)
{if (N->sector != NULL)
- {- BSP_TransferSubsector (N);
- return;
- }
+ return BSP_WriteSubsector (N);
- {- numnodes += 1;
+ node_t * out = &nodes[N->index];
- BSP_CountStuff (N->right);
- BSP_CountStuff (N->left);
+ out->x = N->x;
+ out->y = N->y;
+ out->dx = N->dx;
+ out->dy = N->dy;
- node_t * out = &nodes[numnodes - 1];
+ int c;
+ for (c = 0 ; c < 2 ; c++)
+ {+ nanode_t * child = (c == 0) ? N->right : N->left;
- out->
+ out->children[c] = BSP_WriteNode (child);
+ int k;
+ for (k = 0 ; k < 4 ; k++)
+ out->bbox[c][k] = child->bbox[k];
}
+
+ return (unsigned int) N->index;
}
-#endif
void BSP_BuildNodes (void)
{@@ -789,6 +803,7 @@
BSP_CountStuff (root);
+ // allocate the global arrays
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);
@@ -795,5 +810,5 @@
nano_seg_index = 0;
- // BSP_Transfer ...
+ BSP_WriteNode (root);
}
--
⑨