reduce more diff noise
[xonotic/netradiant.git] / tools / quake3 / q3map2 / facebsp.c
index 66a009c..e5390ed 100644 (file)
@@ -77,18 +77,18 @@ void    FreeBspFace( face_t *f ) {
  */
 
 static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum, int *compileFlags ){
-       face_t      *split;
-       face_t      *check;
-       face_t      *bestSplit;
+       face_t *split;
+       face_t *check;
+       face_t *bestSplit;
        int splits, facing, front, back;
        int side;
-       plane_t     *plane;
+       plane_t *plane;
        int value, bestValue;
        int i;
        vec3_t normal;
        float dist;
        int planenum;
-
+       float sizeBias;
 
        /* ydnar: set some defaults */
        *splitPlaneNum = -1; /* leaf */
@@ -117,14 +117,15 @@ static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum,
        bestValue = -99999;
        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;
@@ -134,7 +135,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 );
@@ -148,10 +149,28 @@ static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum,
                                back++;
                        }
                }
-               value =  5 * facing - 5 * splits; // - abs(front-back);
-               if ( plane->type < 3 ) {
-                       value += 5;       // axial is better
+
+               if ( bspAlternateSplitWeights ) {
+                       // from 27
+
+                       //Bigger is better
+                       sizeBias = WindingArea( split->w );
+
+                       //Base score = 20000 perfectly balanced
+                       value = 20000 - ( abs( front - back ) );
+                       value -= plane->counter; // If we've already used this plane sometime in the past try not to use it again
+                       value -= facing ;       // if we're going to have alot of other surfs use this plane, we want to get it in quickly.
+                       value -= splits * 5;        //more splits = bad
+                       value +=  sizeBias * 10; //We want a huge score bias based on plane size
+               }
+               else
+               {
+                       value =  5 * facing - 5 * splits; // - abs(front-back);
+                       if ( plane->type < 3 ) {
+                               value += 5;       // axial is better
+                       }
                }
+
                value += split->priority;       // prioritize hints higher
 
                if ( value > bestValue ) {
@@ -168,6 +187,10 @@ static void SelectSplitPlaneNum( node_t *node, face_t *list, int *splitPlaneNum,
        /* set best split data */
        *splitPlaneNum = bestSplit->planenum;
        *compileFlags = bestSplit->compileFlags;
+
+       if ( *splitPlaneNum > -1 ) {
+               mapplanes[ *splitPlaneNum ].counter++;
+       }
 }
 
 
@@ -215,6 +238,7 @@ void BuildFaceTree_r( node_t *node, face_t *list ){
        /* if we don't have any more faces, this is a node */
        if ( splitPlaneNum == -1 ) {
                node->planenum = PLANENUM_LEAF;
+               node->has_structural_children = qfalse;
                c_faceLeafs++;
                return;
        }
@@ -222,9 +246,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 */
@@ -241,7 +267,8 @@ void BuildFaceTree_r( node_t *node, face_t *list ){
 
                /* switch on side */
                if ( side == SIDE_CROSS ) {
-                       ClipWindingEpsilon( split->w, plane->normal, plane->dist, CLIP_EPSILON * 2,
+                       /* strict; if no winding is left, we have a "virtually identical" plane and don't want to split by it */
+                       ClipWindingEpsilonStrict( split->w, plane->normal, plane->dist, CLIP_EPSILON * 2,
                                                                &frontWinding, &backWinding );
                        if ( frontWinding ) {
                                newFace = AllocBspFace();
@@ -288,10 +315,16 @@ 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;
+               }
        }
 
        for ( i = 0 ; i < 2 ; i++ ) {
                BuildFaceTree_r( node->children[i], childLists[i] );
+               node->has_structural_children |= node->children[i]->has_structural_children;
        }
 }
 
@@ -324,6 +357,11 @@ tree_t *FaceBSP( face_t *list ) {
        }
        Sys_FPrintf( SYS_VRB, "%9d faces\n", count );
 
+       for ( i = 0; i < nummapplanes; i++ )
+       {
+               mapplanes[ i ].counter = 0;
+       }
+
        tree->headnode = AllocNode();
        VectorCopy( tree->mins, tree->headnode->mins );
        VectorCopy( tree->maxs, tree->headnode->maxs );
@@ -354,7 +392,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;
                }
 
@@ -377,6 +415,9 @@ 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;
@@ -389,6 +430,9 @@ face_t *MakeStructuralBSPFaceList( brush_t *list ){
                        if ( f->compileFlags & C_AREAPORTAL ) {
                                f->priority += AREAPORTAL_PRIORITY;
                        }
+                       if ( f->compileFlags & C_DETAIL ) {
+                               f->priority += DETAIL_PRIORITY;
+                       }
 
                        /* get next face */
                        f->next = flist;
@@ -417,7 +461,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;
                }
 
@@ -440,6 +484,9 @@ 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;
@@ -452,6 +499,9 @@ face_t *MakeVisibleBSPFaceList( brush_t *list ){
                        if ( f->compileFlags & C_AREAPORTAL ) {
                                f->priority += AREAPORTAL_PRIORITY;
                        }
+                       if ( f->compileFlags & C_DETAIL ) {
+                               f->priority += DETAIL_PRIORITY;
+                       }
 
                        /* get next face */
                        f->next = flist;