face_t *AllocBspFace( void ) {
face_t *f;
- f = safe_malloc( sizeof( *f ) );
- memset( f, 0, sizeof( *f ) );
+ f = safe_malloc0( sizeof( *f ) );
return 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 */
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;
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 );
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 ) {
/* set best split data */
*splitPlaneNum = bestSplit->planenum;
*compileFlags = bestSplit->compileFlags;
+
+ if ( *splitPlaneNum > -1 ) {
+ mapplanes[ *splitPlaneNum ].counter++;
+ }
}
/* 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;
}
/* 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 */
/* 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();
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;
}
}
}
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 );
flist = NULL;
for ( b = list; b != NULL; b = b->next )
{
- if ( b->detail ) {
+ if ( !deepBSP && b->detail ) {
continue;
}
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;
if ( f->compileFlags & C_AREAPORTAL ) {
f->priority += AREAPORTAL_PRIORITY;
}
+ if ( f->compileFlags & C_DETAIL ) {
+ f->priority += DETAIL_PRIORITY;
+ }
/* get next face */
f->next = flist;
flist = NULL;
for ( b = list; b != NULL; b = b->next )
{
- if ( b->detail ) {
+ if ( !deepBSP && b->detail ) {
continue;
}
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;
if ( f->compileFlags & C_AREAPORTAL ) {
f->priority += AREAPORTAL_PRIORITY;
}
+ if ( f->compileFlags & C_DETAIL ) {
+ f->priority += DETAIL_PRIORITY;
+ }
/* get next face */
f->next = flist;