]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Slightly improve branching performance for BIH collision
authoruis <uis9936@gmail.com>
Sat, 11 May 2024 02:16:42 +0000 (05:16 +0300)
committerbones_was_here <bones_was_here@xonotic.au>
Sat, 20 Jul 2024 10:43:43 +0000 (20:43 +1000)
model_brush.c

index 397208bafc028f44ba92bed0a5e1c26722dd6799..b911682791493e5233866a2c5d1518e6b0c81dda 100644 (file)
@@ -6815,19 +6815,23 @@ void Mod_CollisionBIH_TracePoint(model_t *model, const frameblend_t *frameblend,
        {
                nodenum = nodestack[--nodestackpos];
                node = bih->nodes + nodenum;
+               assert(node->type <= BIH_UNORDERED);
 #if 1
                if (!BoxesOverlap(start, start, node->mins, node->maxs))
                        continue;
 #endif
-               if (node->type <= BIH_SPLITZ && nodestackpos+2 <= 1024)
+               if (node->type != BIH_UNORDERED)
                {
+                       if(nodestackpos > 1024 - 2)
+                               //Out of stack
+                               continue;
                        axis = node->type - BIH_SPLITX;
                        if (start[axis] >= node->frontmin)
                                nodestack[nodestackpos++] = node->front;
                        if (start[axis] <= node->backmax)
                                nodestack[nodestackpos++] = node->back;
                }
-               else if (node->type == BIH_UNORDERED)
+               else
                {
                        for (axis = 0;axis < BIH_MAXUNORDEREDCHILDREN && node->children[axis] >= 0;axis++)
                        {
@@ -6904,8 +6908,12 @@ static void Mod_CollisionBIH_TraceLineShared(model_t *model, const frameblend_t
                sweepnodemaxs[2] = max(nodestart[2], nodeend[2]) + 1;
                if (!BoxesOverlap(sweepnodemins, sweepnodemaxs, node->mins, node->maxs) && !collision_bih_fullrecursion.integer)
                        continue;
-               if (node->type <= BIH_SPLITZ && nodestackpos+2 <= 1024)
+               assert(node->type <= BIH_UNORDERED);
+               if (node->type != BIH_UNORDERED)
                {
+                       if(nodestackpos > 1024 - 2)
+                               //Out of stack
+                               continue;
                        // recurse children of the split
                        axis = node->type - BIH_SPLITX;
                        d1 = node->backmax - nodestart[axis];
@@ -7023,7 +7031,7 @@ static void Mod_CollisionBIH_TraceLineShared(model_t *model, const frameblend_t
                                break;
                        }
                }
-               else if (node->type == BIH_UNORDERED)
+               else
                {
                        // calculate sweep bounds for this node
                        // copy node bounds into local variables
@@ -7151,8 +7159,12 @@ void Mod_CollisionBIH_TraceBrush(model_t *model, const frameblend_t *frameblend,
                sweepnodemaxs[2] = max(nodestart[2], nodeend[2]) + maxs[2] + 1;
                if (!BoxesOverlap(sweepnodemins, sweepnodemaxs, node->mins, node->maxs))
                        continue;
-               if (node->type <= BIH_SPLITZ && nodestackpos+2 <= 1024)
+               assert(node->type <= BIH_UNORDERED);
+               if (node->type != BIH_UNORDERED)
                {
+                       if(nodestackpos > 1024 - 2)
+                               //Out of stack
+                               continue;
                        // recurse children of the split
                        axis = node->type - BIH_SPLITX;
                        d1 = node->backmax - nodestart[axis] - mins[axis];
@@ -7268,7 +7280,7 @@ void Mod_CollisionBIH_TraceBrush(model_t *model, const frameblend_t *frameblend,
                                break;
                        }
                }
-               else if (node->type == BIH_UNORDERED)
+               else
                {
                        // calculate sweep bounds for this node
                        // copy node bounds into local variables and expand to get Minkowski Sum of the two shapes