/** * @brief The incoming list will be freed before exiting */ tree_t *BuildTree (bspbrush_t *brushlist, const vec3_t mins, const vec3_t maxs) { node_t *node; tree_t *tree; vec3_t blmins, blmaxs; Verb_Printf(VERB_EXTRA, "--- BrushBSP ---\n"); tree = AllocTree(); ClearBounds(blmins, blmaxs); BrushlistCalcStats(brushlist, blmins, blmaxs); tree->aabb.add(blmins); tree->aabb.add(blmaxs); c_nodes = 0; c_nonvis = 0; node = AllocNode(); node->volume = BrushFromBounds(mins, maxs); tree->headnode = node; node = BuildTree_r(node, brushlist); Verb_Printf(VERB_EXTRA, "%5i visible nodes\n", c_nodes / 2 - c_nonvis); Verb_Printf(VERB_EXTRA, "%5i nonvis nodes\n", c_nonvis); Verb_Printf(VERB_EXTRA, "%5i leafs\n", (c_nodes + 1) / 2); return tree; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== bspbrush_t *Q1_CreateBrushesFromBSP(int modelnum) { bspbrush_t *brushlist; bspbrush_t *brush; q1_dnode_t *headnode; vec3_t mins, maxs; int i; // headnode = &q1_dnodes[q1_dmodels[modelnum].headnode[0]]; //get the mins and maxs of the world VectorCopy(headnode->mins, mins); VectorCopy(headnode->maxs, maxs); //enlarge these mins and maxs for (i = 0; i < 3; i++) { mins[i] -= 8; maxs[i] += 8; } //end for //NOTE: have to add the BSP tree mins and maxs to the MAP mins and maxs AddPointToBounds(mins, map_mins, map_maxs); AddPointToBounds(maxs, map_mins, map_maxs); // if (!modelnum) { Log_Print("brush size: %5.0f,%5.0f,%5.0f to %5.0f,%5.0f,%5.0f\n", map_mins[0], map_mins[1], map_mins[2], map_maxs[0], map_maxs[1], map_maxs[2]); } //end if //create one huge brush containing the whole world brush = BrushFromBounds(mins, maxs); VectorCopy(mins, brush->mins); VectorCopy(maxs, brush->maxs); // #ifdef Q1_PRINT qprintf("creating Quake brushes\n"); qprintf("%5d brushes", q1_numbrushes = 0); #endif //Q1_PRINT //create the brushes brushlist = Q1_CreateBrushes_r(brush, q1_dmodels[modelnum].headnode[0]); // #ifdef Q1_PRINT qprintf("\n"); #endif //Q1_PRINT //now we've got a list with brushes! return brushlist; } //end of the function Q1_CreateBrushesFromBSP
/* ================= BrushBSP The incoming list will be freed before exiting ================= */ tree_t *BrushBSP (bspbrush_t *brushlist, Vector& mins, Vector& maxs) { node_t *node; bspbrush_t *b; int c_faces, c_nonvisfaces; int c_brushes; tree_t *tree; int i; vec_t volume; qprintf ("--- BrushBSP ---\n"); tree = AllocTree (); c_faces = 0; c_nonvisfaces = 0; c_brushes = 0; for (b=brushlist ; b ; b=b->next) { c_brushes++; volume = BrushVolume (b); if (volume < microvolume) { Warning("Brush %i: WARNING, microbrush\n", b->original->id); } for (i=0 ; i<b->numsides ; i++) { if (b->sides[i].bevel) continue; if (!b->sides[i].winding) continue; if (b->sides[i].texinfo == TEXINFO_NODE) continue; if (b->sides[i].visible) c_faces++; else c_nonvisfaces++; } AddPointToBounds (b->mins, tree->mins, tree->maxs); AddPointToBounds (b->maxs, tree->mins, tree->maxs); } qprintf ("%5i brushes\n", c_brushes); qprintf ("%5i visible faces\n", c_faces); qprintf ("%5i nonvisible faces\n", c_nonvisfaces); c_nodes = 0; c_nonvis = 0; node = AllocNode (); node->volume = BrushFromBounds (mins, maxs); tree->headnode = node; node = BuildTree_r (node, brushlist); qprintf ("%5i visible nodes\n", c_nodes/2 - c_nonvis); qprintf ("%5i nonvis nodes\n", c_nonvis); qprintf ("%5i leafs\n", (c_nodes+1)/2); #if 0 { // debug code static node_t *tnode; Vector p; p[0] = -1469; p[1] = -118; p[2] = 119; tnode = PointInLeaf (tree->headnode, p); Msg("contents: %i\n", tnode->contents); p[0] = 0; } #endif return tree; }
/* * ================= * BrushBSP * * The incoming list will be freed before exiting * ================= */ tree_t *BrushBSP(brush_t *brushlist, vec3_t mins, vec3_t maxs) { node_t *node; brush_t *b; int32_t c_faces, c_nonvisfaces; int32_t c_brushes; tree_t *tree; int32_t i; vec_t volume; Com_Debug(DEBUG_ALL, "--- BrushBSP ---\n"); tree = AllocTree(); c_faces = 0; c_nonvisfaces = 0; c_brushes = 0; for (b = brushlist; b; b = b->next) { c_brushes++; volume = BrushVolume(b); if (volume < microvolume) { Mon_SendSelect(ERROR_WARN, b->original->entity_num, b->original->brush_num, "Microbrush"); } for (i = 0; i < b->num_sides; i++) { if (b->sides[i].bevel) { continue; } if (!b->sides[i].winding) { continue; } if (b->sides[i].texinfo == TEXINFO_NODE) { continue; } if (b->sides[i].visible) { c_faces++; } else { c_nonvisfaces++; } } AddPointToBounds(b->mins, tree->mins, tree->maxs); AddPointToBounds(b->maxs, tree->mins, tree->maxs); } Com_Debug(DEBUG_ALL, "%5i brushes\n", c_brushes); Com_Debug(DEBUG_ALL, "%5i visible faces\n", c_faces); Com_Debug(DEBUG_ALL, "%5i nonvisible faces\n", c_nonvisfaces); SDL_DestroySemaphore(semaphores.vis_nodes); semaphores.vis_nodes = SDL_CreateSemaphore(0); SDL_DestroySemaphore(semaphores.nonvis_nodes); semaphores.nonvis_nodes = SDL_CreateSemaphore(0); node = AllocNode(); node->volume = BrushFromBounds(mins, maxs); tree->head_node = node; node = BuildTree_r(node, brushlist); const uint32_t vis_nodes = SDL_SemValue(semaphores.vis_nodes); const uint32_t nonvis_nodes = SDL_SemValue(semaphores.nonvis_nodes); Com_Debug(DEBUG_ALL, "%5i visible nodes\n", vis_nodes / 2 - nonvis_nodes); Com_Debug(DEBUG_ALL, "%5i nonvis nodes\n", nonvis_nodes); Com_Debug(DEBUG_ALL, "%5i leafs\n", (vis_nodes + 1) / 2); return tree; }
//=========================================================================== // The incoming brush list will be freed before exiting // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== tree_t *BrushBSP( bspbrush_t *brushlist, vec3_t mins, vec3_t maxs ) { int i, c_faces, c_nonvisfaces, c_brushes; bspbrush_t *b; node_t *node; tree_t *tree; vec_t volume; // vec3_t point; Log_Print( "-------- Brush BSP ---------\n" ); tree = Tree_Alloc(); c_faces = 0; c_nonvisfaces = 0; c_brushes = 0; c_totalsides = 0; for ( b = brushlist; b; b = b->next ) { c_brushes++; volume = BrushVolume( b ); if ( volume < microvolume ) { Log_Print( "WARNING: entity %i, brush %i: microbrush\n", b->original->entitynum, b->original->brushnum ); } //end if for ( i = 0 ; i < b->numsides ; i++ ) { if ( b->sides[i].flags & SFL_BEVEL ) { continue; } if ( !b->sides[i].winding ) { continue; } if ( b->sides[i].texinfo == TEXINFO_NODE ) { continue; } if ( b->sides[i].flags & SFL_VISIBLE ) { c_faces++; } //end if else { c_nonvisfaces++; //if (create_aas) b->sides[i].texinfo = TEXINFO_NODE; } //end if } //end for c_totalsides += b->numsides; AddPointToBounds( b->mins, tree->mins, tree->maxs ); AddPointToBounds( b->maxs, tree->mins, tree->maxs ); } //end for Log_Print( "%6i brushes\n", c_brushes ); Log_Print( "%6i visible faces\n", c_faces ); Log_Print( "%6i nonvisible faces\n", c_nonvisfaces ); Log_Print( "%6i total sides\n", c_totalsides ); c_active_brushes = c_brushes; c_nodememory = 0; c_brushmemory = 0; c_peak_brushmemory = 0; c_nodes = 0; c_nonvis = 0; node = AllocNode(); //volume of first node (head node) node->volume = BrushFromBounds( mins, maxs ); // tree->headnode = node; //just get some statistics and the mins/maxs of the node numrecurse = 0; // qprintf("%6d splits", numrecurse); tree->headnode->brushlist = brushlist; BuildTree( tree ); //build the bsp tree with the start node from the brushlist // node = BuildTree_r(node, brushlist); //if the conversion is cancelled if ( cancelconversion ) { return tree; } qprintf( "\n" ); Log_Write( "%6d splits\r\n", numrecurse ); // Log_Print("%6i visible nodes\n", c_nodes/2 - c_nonvis); // Log_Print("%6i nonvis nodes\n", c_nonvis); // Log_Print("%6i leaves\n", (c_nodes+1)/2); // Log_Print("%6i solid leaf nodes\n", c_solidleafnodes); // Log_Print("%6i active brushes\n", c_active_brushes); if ( numthreads == 1 ) { // Log_Print("%6i KB of node memory\n", c_nodememory >> 10); // Log_Print("%6i KB of brush memory\n", c_brushmemory >> 10); // Log_Print("%6i KB of peak brush memory\n", c_peak_brushmemory >> 10); // Log_Print("%6i KB of winding memory\n", WindingMemory() >> 10); // Log_Print("%6i KB of peak winding memory\n", WindingPeakMemory() >> 10); Log_Print( "%6i KB of peak total bsp memory\n", c_peak_totalbspmemory >> 10 ); } //end if