]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/facebsp.c
fix an obvious q3map2 bug that causes BSP leafs to be too big sometimes. Maybe improv...
[xonotic/netradiant.git] / tools / quake3 / q3map2 / facebsp.c
index 65532a17acea0976a5a7e6ab91d6942b01ae5e05..16997842811a0ca0d591f85ac728174bfe598b44 100644 (file)
@@ -122,14 +122,15 @@ static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum,
        bestSplit = list;
        
 
-       for( split = list; split; split = split->next )
-               split->checked = qfalse;
+       // div0: this check causes detail/structural mixes
+       //for( split = list; split; split = split->next )
+       //      split->checked = qfalse;
        
        for( split = list; split; split = split->next )
        {
-               if ( split->checked )
-                       continue;
-               
+               //if ( split->checked )
+               //      continue;
+
                plane = &mapplanes[ split->planenum ];
                splits = 0;
                facing = 0;
@@ -138,7 +139,7 @@ static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum,
                for ( check = list ; check ; check = check->next ) {
                        if ( check->planenum == split->planenum ) {
                                facing++;
-                               check->checked = qtrue; // won't need to test this plane again
+                               //check->checked = qtrue;       // won't need to test this plane again
                                continue;
                        }
                        side = WindingOnPlaneSide( check->w, plane->normal, plane->dist );
@@ -173,7 +174,7 @@ static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum,
                        }
                }
 
-         value += split->priority;             // prioritize hints higher
+               value += split->priority;               // prioritize hints higher
 
                if ( value > bestValue ) {
                        bestValue = value;
@@ -195,6 +196,15 @@ static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum,
        *splitPlaneNum = bestSplit->planenum;
        *compileFlags = bestSplit->compileFlags;
 
+#if 0
+       if(bestSplit->compileFlags & C_DETAIL)
+               for( split = list; split; split = split->next )
+                       if(!(split->compileFlags & C_DETAIL))
+                               Sys_FPrintf(SYS_ERR, "DON'T DO SUCH SPLITS (1)\n");
+       if((node->compileFlags & C_DETAIL) && !(bestSplit->compileFlags & C_DETAIL))
+               Sys_FPrintf(SYS_ERR, "DON'T DO SUCH SPLITS (2)\n");
+#endif
+
    if (*splitPlaneNum>-1) mapplanes[ *splitPlaneNum ].counter++;
 }
 
@@ -234,6 +244,9 @@ void BuildFaceTree_r( node_t *node, face_t *list )
        winding_t       *frontWinding, *backWinding;
        int                     i;
        int                     splitPlaneNum, compileFlags;
+#if 0
+       qboolean isstruct = qfalse;
+#endif
        
        
        /* count faces left */
@@ -246,6 +259,7 @@ void BuildFaceTree_r( node_t *node, face_t *list )
        if ( splitPlaneNum == -1 )
        {
                node->planenum = PLANENUM_LEAF;
+               node->has_structural_children = qfalse;
                c_faceLeafs++;
                return;
        }
@@ -253,9 +267,11 @@ void BuildFaceTree_r( node_t *node, face_t *list )
        /* partition the list */
        node->planenum = splitPlaneNum;
        node->compileFlags = compileFlags;
+       node->has_structural_children = !(compileFlags & C_DETAIL) && !node->opaque;
        plane = &mapplanes[ splitPlaneNum ];
        childLists[0] = NULL;
        childLists[1] = NULL;
+
        for( split = list; split; split = next )
        {
                /* set next */
@@ -267,6 +283,11 @@ void BuildFaceTree_r( node_t *node, face_t *list )
                        FreeBspFace( split );
                        continue;
                }
+
+#if 0
+               if(!(split->compileFlags & C_DETAIL))
+                       isstruct = 1;
+#endif
                
                /* determine which side the face falls on */
                side = WindingOnPlaneSide( split->w, plane->normal, plane->dist );
@@ -319,11 +340,29 @@ void BuildFaceTree_r( node_t *node, face_t *list )
                        node->children[1]->maxs[i] = plane->dist;
                        break;
                }
+               if ( plane->normal[i] == -1 ) {
+                       node->children[0]->maxs[i] = -plane->dist;
+                       node->children[1]->mins[i] = -plane->dist;
+                       break;
+               }
        }
 
+#if 0
+       if((node->compileFlags & C_DETAIL) && isstruct)
+               Sys_FPrintf(SYS_ERR, "I am detail, my child is structural, this is a wtf1\n", node->has_structural_children);
+#endif
+
        for ( i = 0 ; i < 2 ; i++ ) {
                BuildFaceTree_r ( node->children[i], childLists[i]);
+               node->has_structural_children |= node->children[i]->has_structural_children;
        }
+
+#if 0
+       if((node->compileFlags & C_DETAIL) && !(node->children[0]->compileFlags & C_DETAIL) && node->children[0]->planenum != PLANENUM_LEAF)
+               Sys_FPrintf(SYS_ERR, "I am detail, my child is structural\n", node->has_structural_children);
+       if((node->compileFlags & C_DETAIL) && isstruct)
+               Sys_FPrintf(SYS_ERR, "I am detail, my child is structural, this is a wtf2\n", node->has_structural_children);
+#endif
 }
 
 
@@ -391,7 +430,7 @@ face_t *MakeStructuralBSPFaceList( brush_t *list )
        flist = NULL;
        for( b = list; b != NULL; b = b->next )
        {
-               if( b->detail )
+               if( !deepBSP && b->detail )
                        continue;
                
                for( i = 0; i < b->numsides; i++ )
@@ -411,6 +450,8 @@ face_t *MakeStructuralBSPFaceList( brush_t *list )
                        f->w = CopyWinding( w );
                        f->planenum = s->planenum & ~1;
                        f->compileFlags = s->compileFlags;      /* ydnar */
+                       if(b->detail)
+                               f->compileFlags |= C_DETAIL;
                        
                        /* ydnar: set priority */
                        f->priority = 0;
@@ -420,6 +461,8 @@ face_t *MakeStructuralBSPFaceList( brush_t *list )
                                f->priority += ANTIPORTAL_PRIORITY;
                        if( f->compileFlags & C_AREAPORTAL )
                                f->priority += AREAPORTAL_PRIORITY;
+                       if( f->compileFlags & C_DETAIL )
+                               f->priority += DETAIL_PRIORITY;
                        
                        /* get next face */
                        f->next = flist;
@@ -449,7 +492,7 @@ face_t *MakeVisibleBSPFaceList( brush_t *list )
        flist = NULL;
        for( b = list; b != NULL; b = b->next )
        {
-               if( b->detail )
+               if( !deepBSP && b->detail )
                        continue;
                
                for( i = 0; i < b->numsides; i++ )
@@ -469,6 +512,8 @@ face_t *MakeVisibleBSPFaceList( brush_t *list )
                        f->w = CopyWinding( w );
                        f->planenum = s->planenum & ~1;
                        f->compileFlags = s->compileFlags;      /* ydnar */
+                       if(b->detail)
+                               f->compileFlags |= C_DETAIL;
                        
                        /* ydnar: set priority */
                        f->priority = 0;
@@ -478,6 +523,8 @@ face_t *MakeVisibleBSPFaceList( brush_t *list )
                                f->priority += ANTIPORTAL_PRIORITY;
                        if( f->compileFlags & C_AREAPORTAL )
                                f->priority += AREAPORTAL_PRIORITY;
+                       if( f->compileFlags & C_DETAIL )
+                               f->priority += DETAIL_PRIORITY;
                        
                        /* get next face */
                        f->next = flist;