ref: dcd0398ab4aad2103d4ab3eca677850087bc28c0
parent: bfede6737f89a5e13ada8eea22c62c631a8251c6
author: Andrew Apted <ajapted@gmail.com>
date: Sat Dec 9 10:03:14 EST 2023
use slow method of picking a partition when # of segs < 64. Also factored out some code --> BSP_BoundingBox() func.
--- a/nano_bsp.c
+++ b/nano_bsp.c
@@ -35,6 +35,11 @@
#include "nano_bsp.h"
+#define DIST_EPSILON (FRACUNIT / 64)
+
+#define FAST_THRESHOLD 64
+
+
#undef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -41,9 +46,7 @@
#undef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define DIST_EPSILON (FRACUNIT / 64)
-
vertex_t * BSP_NewVertex (fixed_t x, fixed_t y)
{vertex_t * vert = Z_Malloc(sizeof(vertex_t), PU_LEVEL, NULL);
@@ -228,6 +231,21 @@
return (side1 >= 0 && side2 >= 0) ? +1 : -1;
}
+void BSP_BoundingBox (seg_t * soup, fixed_t * bbox)
+{+ bbox[BOXLEFT] = INT_MAX;
+ bbox[BOXBOTTOM] = INT_MAX;
+ bbox[BOXRIGHT] = INT_MIN;
+ bbox[BOXTOP] = INT_MIN;
+
+ seg_t * S;
+ for (S = soup ; S != NULL ; S = S->next)
+ {+ M_AddToBox (bbox, S->v1->x, S->v1->y);
+ M_AddToBox (bbox, S->v2->x, S->v2->y);
+ }
+}
+
//
// Evaluate a seg as a partition candidate, storing the results in `eval`.
// returns true if the partition is viable, false otherwise.
@@ -267,20 +285,20 @@
//
seg_t * BSP_PickNode_Fast (seg_t * soup)
{- // determine bounds of segs
- fixed_t bbox[4];
+ // use slower method when number of segs is below a threshold
+ int count = 0;
- bbox[BOXLEFT] = INT_MAX;
- bbox[BOXBOTTOM] = INT_MAX;
- bbox[BOXRIGHT] = INT_MIN;
- bbox[BOXTOP] = INT_MIN;
-
seg_t * S;
for (S = soup ; S != NULL ; S = S->next)
- {- M_AddToBox (bbox, S->v1->x, S->v1->y);
- M_AddToBox (bbox, S->v2->x, S->v2->y);
- }
+ count += 1;
+
+ if (count < FAST_THRESHOLD)
+ return NULL;
+
+ // determine bounding box of segs
+ fixed_t bbox[4];
+
+ BSP_BoundingBox (soup, bbox);
fixed_t mid_x = bbox[BOXLEFT] / 2 + bbox[BOXRIGHT] / 2;
fixed_t mid_y = bbox[BOXBOTTOM] / 2 + bbox[BOXTOP] / 2;
--
⑨