2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 extern float subdivide_size;
30 vec_t microvolume = 1.0;
46 qboolean verboseentities;
50 int block_xl = -8, block_xh = 7, block_yl = -8, block_yh = 7;
55 node_t *block_nodes[10][10];
64 node_t *BlockTree( int xl, int yl, int xh, int yh ){
70 if ( xl == xh && yl == yh ) {
71 node = block_nodes[xl + 5][yl + 5];
72 if ( !node ) { // return an empty leaf
74 node->planenum = PLANENUM_LEAF;
75 node->contents = 0; //CONTENTS_SOLID;
81 // create a seperator along the largest axis
84 if ( xh - xl > yh - yl ) { // split x axis
85 mid = xl + ( xh - xl ) / 2 + 1;
90 node->planenum = FindFloatPlane( normal, dist );
91 node->children[0] = BlockTree( mid, yl, xh, yh );
92 node->children[1] = BlockTree( xl, yl, mid - 1, yh );
96 mid = yl + ( yh - yl ) / 2 + 1;
101 node->planenum = FindFloatPlane( normal, dist );
102 node->children[0] = BlockTree( xl, mid, xh, yh );
103 node->children[1] = BlockTree( xl, yl, xh, mid - 1 );
115 int brush_start, brush_end;
116 void ProcessBlock_Thread( int blocknum ){
123 yblock = block_yl + blocknum / ( block_xh - block_xl + 1 );
124 xblock = block_xl + blocknum % ( block_xh - block_xl + 1 );
126 Sys_FPrintf( SYS_VRB, "############### block %2i,%2i ###############\n", xblock, yblock );
128 mins[0] = xblock * 1024;
129 mins[1] = yblock * 1024;
131 maxs[0] = ( xblock + 1 ) * 1024;
132 maxs[1] = ( yblock + 1 ) * 1024;
135 // the makelist and chopbrushes could be cached between the passes...
136 brushes = MakeBspBrushList( brush_start, brush_end, mins, maxs );
139 node->planenum = PLANENUM_LEAF;
140 node->contents = CONTENTS_SOLID;
141 block_nodes[xblock + 5][yblock + 5] = node;
146 brushes = ChopBrushes( brushes );
149 tree = BrushBSP( brushes, mins, maxs );
151 block_nodes[xblock + 5][yblock + 5] = tree->headnode;
160 void ProcessWorldModel( void ){
165 xmlNodePtr polyline, leaknode;
168 e = &entities[entity_num];
170 brush_start = e->firstbrush;
171 brush_end = brush_start + e->numbrushes;
175 // perform per-block operations
177 if ( block_xh * 1024 > map_maxs[0] ) {
178 block_xh = floor( map_maxs[0] / 1024.0 );
180 if ( ( block_xl + 1 ) * 1024 < map_mins[0] ) {
181 block_xl = floor( map_mins[0] / 1024.0 );
183 if ( block_yh * 1024 > map_maxs[1] ) {
184 block_yh = floor( map_maxs[1] / 1024.0 );
186 if ( ( block_yl + 1 ) * 1024 < map_mins[1] ) {
187 block_yl = floor( map_mins[1] / 1024.0 );
190 if ( block_xl < -4 ) {
193 if ( block_yl < -4 ) {
196 if ( block_xh > 3 ) {
199 if ( block_yh > 3 ) {
203 for ( optimize = false ; optimize <= true ; optimize++ )
205 Sys_FPrintf( SYS_VRB, "--------------------------------------------\n" );
207 RunThreadsOnIndividual( ( block_xh - block_xl + 1 ) * ( block_yh - block_yl + 1 ),
208 !verbose, ProcessBlock_Thread );
211 // build the division tree
212 // oversizing the blocks guarantees that all the boundaries
213 // will also get nodes.
216 Sys_FPrintf( SYS_VRB, "--------------------------------------------\n" );
219 tree->headnode = BlockTree( block_xl - 1, block_yl - 1, block_xh + 1, block_yh + 1 );
221 tree->mins[0] = ( block_xl ) * 1024;
222 tree->mins[1] = ( block_yl ) * 1024;
223 tree->mins[2] = map_mins[2] - 8;
225 tree->maxs[0] = ( block_xh + 1 ) * 1024;
226 tree->maxs[1] = ( block_yh + 1 ) * 1024;
227 tree->maxs[2] = map_maxs[2] + 8;
230 // perform the global operations
232 MakeTreePortals( tree );
234 if ( FloodEntities( tree ) ) {
235 FillOutside( tree->headnode );
240 Sys_FPrintf( SYS_NOXML, "**********************\n" );
241 Sys_FPrintf( SYS_NOXML, "******* leaked *******\n" );
242 Sys_FPrintf( SYS_NOXML, "**********************\n" );
243 polyline = LeakFile( tree );
244 leaknode = xmlNewNode( NULL, "message" );
245 xmlNodeAddContent( leaknode, "MAP LEAKED\n" );
246 xmlAddChild( leaknode, polyline );
247 level[0] = (int) '0' + SYS_ERR;
249 xmlSetProp( leaknode, "level", (char*) &level );
250 xml_SendNode( leaknode );
252 Sys_Printf( "--- MAP LEAKED, ABORTING LEAKTEST ---\n" );
257 Sys_Printf ("**** leaked ****\n");
262 Sys_Printf ("--- MAP LEAKED ---\n");
267 MarkVisibleSides( tree, brush_start, brush_end );
268 if ( noopt || leaked ) {
278 WriteGLView( tree, source );
280 MakeFaces( tree->headnode );
281 FixTjuncs( tree->headnode );
284 PruneNodes( tree->headnode );
287 WriteBSP( tree->headnode );
290 WritePortalFile( tree );
302 void ProcessSubModel( void ){
309 e = &entities[entity_num];
311 start = e->firstbrush;
312 end = start + e->numbrushes;
314 mins[0] = mins[1] = mins[2] = -4096;
315 maxs[0] = maxs[1] = maxs[2] = 4096;
316 list = MakeBspBrushList( start, end, mins, maxs );
318 list = ChopBrushes( list );
320 tree = BrushBSP( list, mins, maxs );
321 MakeTreePortals( tree );
322 MarkVisibleSides( tree, start, end );
323 MakeFaces( tree->headnode );
324 FixTjuncs( tree->headnode );
325 WriteBSP( tree->headnode );
334 void ProcessModels( void ){
337 for ( entity_num = 0 ; entity_num < num_entities ; entity_num++ )
339 if ( !entities[entity_num].numbrushes ) {
343 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", nummodels );
345 if ( entity_num == 0 ) {
353 //if (!verboseentities)
354 // verbose = false; // don't bother printing submodels
371 Sys_Printf( "\n----- BSP ----\n\n" );
374 start = I_FloatTime();
377 SetQdirFromPath( mapname );
379 strcpy( source, ExpandArg( mapname ) );
380 StripExtension( source );
382 // delete portal and line files
383 sprintf( path, "%s.prt", source );
385 sprintf( path, "%s.lin", source );
388 strcpy( name, ExpandArg( mapname ) );
389 DefaultExtension( name, ".map" ); // might be .reg
392 // if onlyents, just grab the entites and resave
397 sprintf( out, "%s.bsp", source );
412 // start from scratch
422 total_bsp_time = (int) ( end - start );
423 Sys_Printf( "\nBSP Time: " );
424 if ( total_bsp_time > 59 ) {
425 Sys_Printf( "%d Minutes ", total_bsp_time / 60 );
427 Sys_Printf( "%d Seconds\n", total_bsp_time % 60 );