shithub: nanobsp

Download patch

ref: 3a12c859b22fe4d70c1bf3eb7697f286dad55191
parent: 47c5c8b5dfd6b287fe1e670aeaada92bcd8bf643
author: Andrew Apted <ajapted@gmail.com>
date: Sat Dec 9 08:10:07 EST 2023

implemented splitting a seg into two pieces.

--- a/nano_bsp.c
+++ b/nano_bsp.c
@@ -65,9 +65,11 @@
 } nnode_t;
 
 
-vertex_t * BSP_NewVertex (void)
+vertex_t * BSP_NewVertex (fixed_t x, fixed_t y)
 {
 	vertex_t * vert = Z_Malloc(sizeof(vertex_t), PU_LEVEL, NULL);
+	vert->x = x;
+	vert->y = y;
 	return vert;
 }
 
@@ -509,7 +511,43 @@
 
 		BSP_ComputeIntersection (part, S, &ix, &iy);
 
-		// TODO
+		vertex_t * iv = BSP_NewVertex (ix, iy);
+
+		seg_t * T = BSP_NewSeg ();
+
+		T->v2 = S->v2;
+		T->v1 = iv;
+		S->v2 = iv;
+
+		T->angle   = S->angle;
+		T->sidedef = S->sidedef;
+		T->linedef = S->linedef;
+
+		T->frontsector = S->frontsector;
+		T->backsector  = S->backsector;
+
+		// compute offset for new seg
+		viewx = T->v1->x;
+		viewy = T->v1->y;
+
+		T->offset = R_PointToDist (ix, iy);
+
+		if (BSP_PointOnSide (part, S->v1->x, S->v1->y) < 0)
+		{
+			S->next  = (*lefts);
+			(*lefts) = S;
+
+			T->next   = (*rights);
+			(*rights) = T;
+		}
+		else
+		{
+			S->next   = (*rights);
+			(*rights) = S;
+
+			T->next  = (*lefts);
+			(*lefts) = T;
+		}
 	}
 }
 
--