shithub: nanobsp

Download patch

ref: 27942f730b8e78af93097fb3e5b3fec3c35f2ce6
parent: 9cbf12c8123634202a7c3162c4b3c0ed5007f7a6
author: Andrew Apted <ajapted@gmail.com>
date: Sat Dec 9 09:26:59 EST 2023

updated code in "p_sight.c" for the subsector_t/node_t changes.

--- a/p_sight.c
+++ b/p_sight.c
@@ -122,165 +122,148 @@
 
 //
 // P_CrossSubsector
-// Returns true
-//  if strace crosses the given subsector successfully.
+// Returns true if strace crosses the given subsector successfully.
 //
-boolean P_CrossSubsector (int num)
+boolean P_CrossSubsector (subsector_t * sub)
 {
-    seg_t*		seg;
-    line_t*		line;
-    int			s1;
-    int			s2;
-    int			count;
-    subsector_t*	sub;
-    sector_t*		front;
-    sector_t*		back;
-    fixed_t		opentop;
-    fixed_t		openbottom;
-    divline_t		divl;
-    vertex_t*		v1;
-    vertex_t*		v2;
-    fixed_t		frac;
-    fixed_t		slope;
-	
-    sub = &subsectors[num];
-    
     // check lines
-    count = sub->numlines;
-    seg = &segs[sub->firstline];
-
-    for ( ; count ; seg++, count--)
+    seg_t * seg;
+    for (seg = sub->segs ; seg != NULL ; seg = seg->next)
     {
-	line = seg->linedef;
+        line_t * line = seg->linedef;
 
-	// allready checked other side?
-	if (line->validcount == validcount)
-	    continue;
-	
-	line->validcount = validcount;
+        // allready checked other side?
+        if (line->validcount == validcount)
+            continue;
 
-	v1 = line->v1;
-	v2 = line->v2;
-	s1 = P_DivlineSide (v1->x,v1->y, &strace);
-	s2 = P_DivlineSide (v2->x, v2->y, &strace);
+        line->validcount = validcount;
 
-	// line isn't crossed?
-	if (s1 == s2)
-	    continue;
-	
-	divl.x = v1->x;
-	divl.y = v1->y;
-	divl.dx = v2->x - v1->x;
-	divl.dy = v2->y - v1->y;
-	s1 = P_DivlineSide (strace.x, strace.y, &divl);
-	s2 = P_DivlineSide (t2x, t2y, &divl);
+        vertex_t * v1 = line->v1;
+        vertex_t * v2 = line->v2;
 
-	// line isn't crossed?
-	if (s1 == s2)
-	    continue;	
+        int s1 = P_DivlineSide (v1->x, v1->y, &strace);
+        int s2 = P_DivlineSide (v2->x, v2->y, &strace);
 
+        // line isn't crossed?
+        if (s1 == s2)
+            continue;
+
+        divline_t  divl;
+
+        divl.x  = v1->x;
+        divl.y  = v1->y;
+        divl.dx = v2->x - v1->x;
+        divl.dy = v2->y - v1->y;
+
+        s1 = P_DivlineSide (strace.x, strace.y, &divl);
+        s2 = P_DivlineSide (t2x, t2y, &divl);
+
+        // line isn't crossed?
+        if (s1 == s2)
+            continue;
+
         // Backsector may be NULL if this is an "impassible
         // glass" hack line.
 
         if (line->backsector == NULL)
-        {
             return false;
-        }
 
-	// stop because it is not two sided anyway
-	// might do this after updating validcount?
-	if ( !(line->flags & ML_TWOSIDED) )
-	    return false;
-	
-	// crosses a two sided line
-	front = seg->frontsector;
-	back = seg->backsector;
+        // stop because it is not two sided anyway
+        // might do this after updating validcount?
+        if ( !(line->flags & ML_TWOSIDED) )
+            return false;
 
-	// no wall to block sight with?
-	if (front->floorheight == back->floorheight
-	    && front->ceilingheight == back->ceilingheight)
-	    continue;	
+        // crosses a two sided line
+        sector_t * front = seg->frontsector;
+        sector_t * back = seg->backsector;
 
-	// possible occluder
-	// because of ceiling height differences
-	if (front->ceilingheight < back->ceilingheight)
-	    opentop = front->ceilingheight;
-	else
-	    opentop = back->ceilingheight;
+        // no wall to block sight with?
+        if (front->floorheight == back->floorheight
+            && front->ceilingheight == back->ceilingheight)
+            continue;
 
-	// because of ceiling height differences
-	if (front->floorheight > back->floorheight)
-	    openbottom = front->floorheight;
-	else
-	    openbottom = back->floorheight;
-		
-	// quick test for totally closed doors
-	if (openbottom >= opentop)	
-	    return false;		// stop
-	
-	frac = P_InterceptVector2 (&strace, &divl);
-		
-	if (front->floorheight != back->floorheight)
-	{
-	    slope = FixedDiv (openbottom - sightzstart , frac);
-	    if (slope > bottomslope)
-		bottomslope = slope;
-	}
-		
-	if (front->ceilingheight != back->ceilingheight)
-	{
-	    slope = FixedDiv (opentop - sightzstart , frac);
-	    if (slope < topslope)
-		topslope = slope;
-	}
-		
-	if (topslope <= bottomslope)
-	    return false;		// stop				
+        fixed_t  opentop;
+        fixed_t  openbottom;
+
+        // possible occluder
+        // because of ceiling height differences
+        if (front->ceilingheight < back->ceilingheight)
+            opentop = front->ceilingheight;
+        else
+            opentop = back->ceilingheight;
+
+        // because of ceiling height differences
+        if (front->floorheight > back->floorheight)
+            openbottom = front->floorheight;
+        else
+            openbottom = back->floorheight;
+
+        // quick test for totally closed doors
+        if (openbottom >= opentop)
+            return false;        // stop
+
+        fixed_t frac = P_InterceptVector2 (&strace, &divl);
+        fixed_t slope;
+
+        if (front->floorheight != back->floorheight)
+        {
+            slope = FixedDiv (openbottom - sightzstart , frac);
+            if (slope > bottomslope)
+            bottomslope = slope;
+        }
+
+        if (front->ceilingheight != back->ceilingheight)
+        {
+            slope = FixedDiv (opentop - sightzstart , frac);
+            if (slope < topslope)
+                topslope = slope;
+        }
+
+        if (topslope <= bottomslope)
+            return false;        // stop
     }
+
     // passed the subsector ok
-    return true;		
+    return true;
 }
 
 
-
 //
 // P_CrossBSPNode
 // Returns true
 //  if strace crosses the given node successfully.
 //
-boolean P_CrossBSPNode (int bspnum)
+boolean P_CrossBSPNode (node_t * bsp)
 {
-    node_t*	bsp;
-    int		side;
+loop:
+    if (bsp->sub != NULL)
+        return P_CrossSubsector (bsp->sub);
 
-    if (bspnum & NF_SUBSECTOR)
-    {
-	if (bspnum == -1)
-	    return P_CrossSubsector (0);
-	else
-	    return P_CrossSubsector (bspnum&(~NF_SUBSECTOR));
-    }
-		
-    bsp = &nodes[bspnum];
-    
     // decide which side the start point is on
-    side = P_DivlineSide (strace.x, strace.y, (divline_t *)bsp);
+    divline_t div;
+    div.x  = bsp->x;
+    div.y  = bsp->y;
+    div.dx = bsp->dx;
+    div.dy = bsp->dy;
+
+    int side = P_DivlineSide (strace.x, strace.y, &div);
     if (side == 2)
-	side = 0;	// an "on" should cross both sides
+        side = 0;    // an "on" should cross both sides
 
     // cross the starting side
-    if (!P_CrossBSPNode (bsp->children[side]) )
-	return false;
-	
+    if (! P_CrossBSPNode (side ? bsp->left : bsp->right))
+        return false;
+
     // the partition plane is crossed here
-    if (side == P_DivlineSide (t2x, t2y,(divline_t *)bsp))
+    if (side == P_DivlineSide (t2x, t2y, &div))
     {
-	// the line doesn't touch the other side
-	return true;
+        // the line doesn't touch the other side
+        return true;
     }
-    
-    // cross the ending side		
-    return P_CrossBSPNode (bsp->children[side^1]);
+
+    // cross the ending side
+    bsp = side ? bsp->right : bsp->left;
+    goto loop;
 }
 
 
@@ -337,7 +320,7 @@
     strace.dy = t2->y - t1->y;
 
     // the head node is the last node output
-    return P_CrossBSPNode (numnodes-1);	
+    return P_CrossBSPNode (root_node);
 }
 
 
--