1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ----------------------------------------------------------------------------------
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
27 ------------------------------------------------------------------------------- */
41 /* -------------------------------------------------------------------------------
45 ------------------------------------------------------------------------------- */
48 ProcessAdvertisements()
49 copies advertisement info into the BSP structures
52 static void ProcessAdvertisements( void ) {
54 const char* className;
58 bspDrawSurface_t* adSurface;
60 Sys_FPrintf( SYS_VRB, "--- ProcessAdvertisements ---\n" );
62 for( i = 0; i < numEntities; i++ ) {
64 /* is an advertisement? */
65 className = ValueForKey( &entities[ i ], "classname" );
67 if( !Q_stricmp( "advertisement", className ) ) {
69 modelKey = ValueForKey( &entities[ i ], "model" );
71 if( strlen( modelKey ) > MAX_QPATH - 1 ) {
72 Error( "Model Key for entity exceeds ad struct string length." );
74 if( numBSPAds < MAX_MAP_ADVERTISEMENTS ) {
75 bspAds[numBSPAds].cellId = IntForKey( &entities[ i ], "cellId" );
76 strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) );
79 modelNum = atoi( modelKey );
80 adModel = &bspModels[modelNum];
82 if( adModel->numBSPSurfaces != 1 ) {
83 Error( "Ad cell id %d has more than one surface.", bspAds[numBSPAds].cellId );
86 adSurface = &bspDrawSurfaces[adModel->firstBSPSurface];
88 // store the normal for use at run time.. all ad verts are assumed to
89 // have identical normals (because they should be a simple rectangle)
90 // so just use the first vert's normal
91 VectorCopy( bspDrawVerts[adSurface->firstVert].normal, bspAds[numBSPAds].normal );
93 // store the ad quad for quick use at run time
94 if( adSurface->surfaceType == MST_PATCH ) {
95 int v0 = adSurface->firstVert + adSurface->patchHeight - 1;
96 int v1 = adSurface->firstVert + adSurface->numVerts - 1;
97 int v2 = adSurface->firstVert + adSurface->numVerts - adSurface->patchWidth;
98 int v3 = adSurface->firstVert;
99 VectorCopy( bspDrawVerts[v0].xyz, bspAds[numBSPAds].rect[0] );
100 VectorCopy( bspDrawVerts[v1].xyz, bspAds[numBSPAds].rect[1] );
101 VectorCopy( bspDrawVerts[v2].xyz, bspAds[numBSPAds].rect[2] );
102 VectorCopy( bspDrawVerts[v3].xyz, bspAds[numBSPAds].rect[3] );
104 Error( "Ad cell %d has an unsupported Ad Surface type.", bspAds[numBSPAds].cellId );
109 Error( "Maximum number of map advertisements exceeded." );
115 Sys_FPrintf( SYS_VRB, "%9d in-game advertisements\n", numBSPAds );
119 SetCloneModelNumbers() - ydnar
120 sets the model numbers for brush entities
123 static void SetCloneModelNumbers( void )
127 char modelValue[ 10 ];
128 const char *value, *value2, *value3;
131 /* start with 1 (worldspawn is model 0) */
133 for( i = 1; i < numEntities; i++ )
135 /* only entities with brushes or patches get a model number */
136 if( entities[ i ].brushes == NULL && entities[ i ].patches == NULL )
139 /* is this a clone? */
140 value = ValueForKey( &entities[ i ], "_clone" );
141 if( value[ 0 ] != '\0' )
144 /* add the model key */
145 sprintf( modelValue, "*%d", models );
146 SetKeyValue( &entities[ i ], "model", modelValue );
148 /* increment model count */
153 for( i = 1; i < numEntities; i++ )
155 /* only entities with brushes or patches get a model number */
156 if( entities[ i ].brushes == NULL && entities[ i ].patches == NULL )
159 /* is this a clone? */
160 value = ValueForKey( &entities[ i ], "_ins" );
161 if( value[ 0 ] == '\0' )
162 value = ValueForKey( &entities[ i ], "_instance" );
163 if( value[ 0 ] == '\0' )
164 value = ValueForKey( &entities[ i ], "_clone" );
165 if( value[ 0 ] == '\0' )
168 /* find an entity with matching clone name */
169 for( j = 0; j < numEntities; j++ )
171 /* is this a clone parent? */
172 value2 = ValueForKey( &entities[ j ], "_clonename" );
173 if( value2[ 0 ] == '\0' )
177 if( strcmp( value, value2 ) == 0 )
179 /* get the model num */
180 value3 = ValueForKey( &entities[ j ], "model" );
181 if( value3[ 0 ] == '\0' )
183 Sys_Printf( "WARNING: Cloned entity %s referenced entity without model\n", value2 );
186 models = atoi( &value2[ 1 ] );
188 /* add the model key */
189 sprintf( modelValue, "*%d", models );
190 SetKeyValue( &entities[ i ], "model", modelValue );
192 /* nuke the brushes/patches for this entity (fixme: leak!) */
193 entities[ i ].brushes = NULL;
194 entities[ i ].patches = NULL;
203 FixBrushSides() - ydnar
204 matches brushsides back to their appropriate drawsurface and shader
207 static void FixBrushSides( entity_t *e )
210 mapDrawSurface_t *ds;
212 bspBrushSide_t *side;
216 Sys_FPrintf( SYS_VRB, "--- FixBrushSides ---\n" );
218 /* walk list of drawsurfaces */
219 for( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
221 /* get surface and try to early out */
222 ds = &mapDrawSurfs[ i ];
223 if( ds->outputNum < 0 )
226 /* walk sideref list */
227 for( sideRef = ds->sideRef; sideRef != NULL; sideRef = sideRef->next )
229 /* get bsp brush side */
230 if( sideRef->side == NULL || sideRef->side->outputNum < 0 )
232 side = &bspBrushSides[ sideRef->side->outputNum ];
234 /* set drawsurface */
235 side->surfaceNum = ds->outputNum;
236 //% Sys_FPrintf( SYS_VRB, "DS: %7d Side: %7d ", ds->outputNum, sideRef->side->outputNum );
239 if( strcmp( bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader ) )
241 //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader );
242 side->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
252 creates a full bsp + surfaces for the worldspawn entity
255 void ProcessWorldModel( void )
261 qboolean ignoreLeaks, leaked;
262 xmlNodePtr polyline, leaknode;
263 char level[ 2 ], shader[ 1024 ];
266 /* sets integer blockSize from worldspawn "_blocksize" key if it exists */
267 value = ValueForKey( &entities[ 0 ], "_blocksize" );
268 if( value[ 0 ] == '\0' )
269 value = ValueForKey( &entities[ 0 ], "blocksize" );
270 if( value[ 0 ] == '\0' )
271 value = ValueForKey( &entities[ 0 ], "chopsize" ); /* sof2 */
272 if( value[ 0 ] != '\0' )
275 s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] );
277 /* handle legacy case */
280 blockSize[ 1 ] = blockSize[ 0 ];
281 blockSize[ 2 ] = blockSize[ 0 ];
284 Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] );
286 /* sof2: ignore leaks? */
287 value = ValueForKey( &entities[ 0 ], "_ignoreleaks" ); /* ydnar */
288 if( value[ 0 ] == '\0' )
289 value = ValueForKey( &entities[ 0 ], "ignoreleaks" );
290 if( value[ 0 ] == '1' )
293 ignoreLeaks = qfalse;
295 /* begin worldspawn model */
298 e->firstDrawSurf = 0;
301 ClearMetaTriangles();
303 /* check for patches with adjacent edges that need to lod together */
304 PatchMapDrawSurfs( e );
306 /* build an initial bsp tree using all of the sides of all of the structural brushes */
307 faces = MakeStructuralBSPFaceList( entities[ 0 ].brushes );
308 tree = FaceBSP( faces );
309 MakeTreePortals( tree );
310 FilterStructuralBrushesIntoTree( e, tree );
312 /* see if the bsp is completely enclosed */
313 if( FloodEntities( tree ) || ignoreLeaks )
315 /* rebuild a better bsp tree using only the sides that are visible from the inside */
316 FillOutside( tree->headnode );
318 /* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
319 ClipSidesIntoTree( e, tree );
321 /* build a visible face tree */
322 faces = MakeVisibleBSPFaceList( entities[ 0 ].brushes );
324 tree = FaceBSP( faces );
325 MakeTreePortals( tree );
326 FilterStructuralBrushesIntoTree( e, tree );
329 /* ydnar: flood again for skybox */
331 FloodEntities( tree );
335 Sys_FPrintf( SYS_NOXML, "**********************\n" );
336 Sys_FPrintf( SYS_NOXML, "******* leaked *******\n" );
337 Sys_FPrintf( SYS_NOXML, "**********************\n" );
338 polyline = LeakFile( tree );
339 leaknode = xmlNewNode( NULL, "message" );
340 xmlNodeSetContent( leaknode, "MAP LEAKED\n" );
341 xmlAddChild( leaknode, polyline );
342 level[0] = (int) '0' + SYS_ERR;
344 xmlSetProp( leaknode, "level", (char*) &level );
345 xml_SendNode( leaknode );
348 Sys_Printf ("--- MAP LEAKED, ABORTING LEAKTEST ---\n");
353 /* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
354 ClipSidesIntoTree( e, tree );
357 /* save out information for visibility processing */
358 NumberClusters( tree );
360 WritePortalFile( tree );
362 /* flood from entities */
365 /* create drawsurfs for triangle models */
366 AddTriangleModels( e );
368 /* create drawsurfs for surface models */
369 AddEntitySurfaceModels( e );
371 /* generate bsp brushes from map brushes */
372 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
374 /* add references to the detail brushes */
375 FilterDetailBrushesIntoTree( e, tree );
377 /* drawsurfs that cross fog boundaries will need to be split along the fog boundary */
379 FogDrawSurfaces( e );
381 /* subdivide each drawsurf as required by shader tesselation */
383 SubdivideFaceSurfaces( e, tree );
385 /* add in any vertexes required to fix t-junctions */
389 /* ydnar: classify the surfaces */
390 ClassifyEntitySurfaces( e );
392 /* ydnar: project decals */
393 MakeEntityDecals( e );
395 /* ydnar: meta surfaces */
396 MakeEntityMetaTriangles( e );
397 SmoothMetaTriangles();
399 MergeMetaTriangles();
401 /* ydnar: debug portals */
403 MakeDebugPortalSurfs( tree );
405 /* ydnar: fog hull */
406 value = ValueForKey( &entities[ 0 ], "_foghull" );
407 if( value[ 0 ] != '\0' )
409 sprintf( shader, "textures/%s", value );
410 MakeFogHullSurfs( e, tree, shader );
413 /* ydnar: bug 645: do flares for lights */
414 for( i = 0; i < numEntities && emitFlares; i++ )
416 entity_t *light, *target;
417 const char *value, *flareShader;
418 vec3_t origin, targetOrigin, normal, color;
423 light = &entities[ i ];
424 value = ValueForKey( light, "classname" );
425 if( !strcmp( value, "light" ) )
427 /* get flare shader */
428 flareShader = ValueForKey( light, "_flareshader" );
429 value = ValueForKey( light, "_flare" );
430 if( flareShader[ 0 ] != '\0' || value[ 0 ] != '\0' )
433 GetVectorForKey( light, "origin", origin );
434 GetVectorForKey( light, "_color", color );
435 lightStyle = IntForKey( light, "_style" );
436 if( lightStyle == 0 )
437 lightStyle = IntForKey( light, "style" );
439 /* handle directional spotlights */
440 value = ValueForKey( light, "target" );
441 if( value[ 0 ] != '\0' )
443 /* get target light */
444 target = FindTargetEntity( value );
447 GetVectorForKey( target, "origin", targetOrigin );
448 VectorSubtract( targetOrigin, origin, normal );
449 VectorNormalize( normal, normal );
453 //% VectorClear( normal );
454 VectorSet( normal, 0, 0, -1 );
456 /* create the flare surface (note shader defaults automatically) */
457 DrawSurfaceForFlare( mapEntityNum, origin, normal, color, (char*) flareShader, lightStyle );
462 /* add references to the final drawsurfs in the apropriate clusters */
463 FilterDrawsurfsIntoTree( e, tree );
465 /* match drawsurfaces back to original brushsides (sof2) */
469 EndModel( e, tree->headnode );
477 creates bsp + surfaces for other brush models
480 void ProcessSubModel( void )
488 /* start a brush model */
490 e = &entities[ mapEntityNum ];
491 e->firstDrawSurf = numMapDrawSurfs;
494 ClearMetaTriangles();
496 /* check for patches with adjacent edges that need to lod together */
497 PatchMapDrawSurfs( e );
499 /* allocate a tree */
501 node->planenum = PLANENUM_LEAF;
503 tree->headnode = node;
505 /* add the sides to the tree */
506 ClipSidesIntoTree( e, tree );
508 /* ydnar: create drawsurfs for triangle models */
509 AddTriangleModels( e );
511 /* create drawsurfs for surface models */
512 AddEntitySurfaceModels( e );
514 /* generate bsp brushes from map brushes */
515 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
517 /* just put all the brushes in headnode */
518 for( b = e->brushes; b; b = b->next )
521 bc->next = node->brushlist;
522 node->brushlist = bc;
525 /* subdivide each drawsurf as required by shader tesselation */
527 SubdivideFaceSurfaces( e, tree );
529 /* add in any vertexes required to fix t-junctions */
533 /* ydnar: classify the surfaces and project lightmaps */
534 ClassifyEntitySurfaces( e );
536 /* ydnar: project decals */
537 MakeEntityDecals( e );
539 /* ydnar: meta surfaces */
540 MakeEntityMetaTriangles( e );
541 SmoothMetaTriangles();
543 MergeMetaTriangles();
545 /* add references to the final drawsurfs in the apropriate clusters */
546 FilterDrawsurfsIntoTree( e, tree );
548 /* match drawsurfaces back to original brushsides (sof2) */
560 process world + other models into the bsp
563 void ProcessModels( void )
569 /* preserve -v setting */
570 oldVerbose = verbose;
572 /* start a new bsp */
575 /* create map fogs */
578 /* walk entity list */
579 for( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
582 entity = &entities[ mapEntityNum ];
583 if( entity->brushes == NULL && entity->patches == NULL )
586 /* process the model */
587 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
588 if( mapEntityNum == 0 )
593 /* potentially turn off the deluge of text */
594 verbose = verboseEntities;
597 /* restore -v setting */
598 verbose = oldVerbose;
603 /* vortex: emit meta stats */
611 this is probably broken unless teamed with a radiant version that preserves entity order
614 void OnlyEnts( void )
618 char save_cmdline[1024], save_version[1024];
622 Sys_Printf( "--- OnlyEnts ---\n" );
624 sprintf( out, "%s.bsp", source );
628 p = ValueForKey(&entities[0], "_q3map2_cmdline");
629 strncpy(save_cmdline, p, sizeof(save_cmdline));
630 save_cmdline[sizeof(save_cmdline)-1] = 0;
631 p = ValueForKey(&entities[0], "_q3map2_version");
632 strncpy(save_version, p, sizeof(save_version));
633 save_version[sizeof(save_version)-1] = 0;
638 LoadMapFile( name, qfalse );
643 SetKeyValue(&entities[0], "_q3map2_cmdline", save_cmdline);
645 SetKeyValue(&entities[0], "_q3map2_version", save_version);
647 numBSPEntities = numEntities;
657 handles creation of a bsp from a map file
660 int BSPMain( int argc, char **argv )
663 char path[ 1024 ], tempSource[ 1024 ];
664 qboolean onlyents = qfalse;
668 Sys_Printf( "--- BSP ---\n" );
670 SetDrawSurfacesBuffer();
671 mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
672 memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
675 tempSource[ 0 ] = '\0';
676 globalCelShader[0] = 0;
678 /* set standard game flags */
679 maxSurfaceVerts = game->maxSurfaceVerts;
680 maxSurfaceIndexes = game->maxSurfaceIndexes;
681 emitFlares = game->emitFlares;
683 /* process arguments */
684 for( i = 1; i < (argc - 1); i++ )
686 if( !strcmp( argv[ i ], "-onlyents" ) )
688 Sys_Printf( "Running entity-only compile\n" );
691 else if( !strcmp( argv[ i ], "-tempname" ) )
692 strcpy( tempSource, argv[ ++i ] );
693 else if( !strcmp( argv[ i ], "-tmpout" ) )
694 strcpy( outbase, "/tmp" );
695 else if( !strcmp( argv[ i ], "-nowater" ) )
697 Sys_Printf( "Disabling water\n" );
700 else if( !strcmp( argv[ i ], "-nodetail" ) )
702 Sys_Printf( "Ignoring detail brushes\n") ;
705 else if( !strcmp( argv[ i ], "-fulldetail" ) )
707 Sys_Printf( "Turning detail brushes into structural brushes\n" );
710 else if( !strcmp( argv[ i ], "-nofog" ) )
712 Sys_Printf( "Fog volumes disabled\n" );
715 else if( !strcmp( argv[ i ], "-nosubdivide" ) )
717 Sys_Printf( "Disabling brush face subdivision\n" );
720 else if( !strcmp( argv[ i ], "-leaktest" ) )
722 Sys_Printf( "Leaktest enabled\n" );
725 else if( !strcmp( argv[ i ], "-verboseentities" ) )
727 Sys_Printf( "Verbose entities enabled\n" );
728 verboseEntities = qtrue;
730 else if( !strcmp( argv[ i ], "-nocurves" ) )
732 Sys_Printf( "Ignoring curved surfaces (patches)\n" );
733 noCurveBrushes = qtrue;
735 else if( !strcmp( argv[ i ], "-notjunc" ) )
737 Sys_Printf( "T-junction fixing disabled\n" );
740 else if( !strcmp( argv[ i ], "-fakemap" ) )
742 Sys_Printf( "Generating fakemap.map\n" );
745 else if( !strcmp( argv[ i ], "-samplesize" ) )
747 sampleSize = atoi( argv[ i + 1 ] );
751 Sys_Printf( "Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
753 else if( !strcmp( argv[ i ], "-minsamplesize" ) )
755 minSampleSize = atoi( argv[ i + 1 ] );
756 if( minSampleSize < 1 )
759 Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
761 else if( !strcmp( argv[ i ], "-custinfoparms") )
763 Sys_Printf( "Custom info parms enabled\n" );
764 useCustomInfoParms = qtrue;
768 else if( !strcmp( argv[ i ], "-rename" ) )
770 Sys_Printf( "Appending _bsp suffix to misc_model shaders (SOF2)\n" );
771 renameModelShaders = qtrue;
775 else if( !strcmp( argv[ i ], "-ne" ) )
777 normalEpsilon = atof( argv[ i + 1 ] );
779 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
781 else if( !strcmp( argv[ i ], "-de" ) )
783 distanceEpsilon = atof( argv[ i + 1 ] );
785 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
787 else if( !strcmp( argv[ i ], "-mv" ) )
789 maxLMSurfaceVerts = atoi( argv[ i + 1 ] );
790 if( maxLMSurfaceVerts < 3 )
791 maxLMSurfaceVerts = 3;
792 if( maxLMSurfaceVerts > maxSurfaceVerts )
793 maxSurfaceVerts = maxLMSurfaceVerts;
795 Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
797 else if( !strcmp( argv[ i ], "-mi" ) )
799 maxSurfaceIndexes = atoi( argv[ i + 1 ] );
800 if( maxSurfaceIndexes < 3 )
801 maxSurfaceIndexes = 3;
803 Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
805 else if( !strcmp( argv[ i ], "-np" ) )
807 npDegrees = atof( argv[ i + 1 ] );
808 if( npDegrees < 0.0f )
809 shadeAngleDegrees = 0.0f;
810 else if( npDegrees > 0.0f )
811 Sys_Printf( "Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees );
814 else if( !strcmp( argv[ i ], "-snap" ) )
816 bevelSnap = atoi( argv[ i + 1 ]);
821 Sys_Printf( "Snapping brush bevel planes to %d units\n", bevelSnap );
823 else if( !strcmp( argv[ i ], "-texrange" ) )
825 texRange = atoi( argv[ i + 1 ]);
829 Sys_Printf( "Limiting per-surface texture range to %d texels\n", texRange );
831 else if( !strcmp( argv[ i ], "-nohint" ) )
833 Sys_Printf( "Hint brushes disabled\n" );
836 else if( !strcmp( argv[ i ], "-flat" ) )
838 Sys_Printf( "Flatshading enabled\n" );
841 else if( !strcmp( argv[ i ], "-celshader" ) )
845 sprintf( globalCelShader, "textures/%s", argv[ i ] );
847 *globalCelShader = 0;
848 Sys_Printf( "Global cel shader set to \"%s\"\n", globalCelShader );
850 else if( !strcmp( argv[ i ], "-meta" ) )
852 Sys_Printf( "Creating meta surfaces from brush faces\n" );
855 else if( !strcmp( argv[ i ], "-patchmeta" ) )
857 Sys_Printf( "Creating meta surfaces from patches\n" );
860 else if( !strcmp( argv[ i ], "-flares" ) )
862 Sys_Printf( "Flare surfaces enabled\n" );
865 else if( !strcmp( argv[ i ], "-noflares" ) )
867 Sys_Printf( "Flare surfaces disabled\n" );
870 else if( !strcmp( argv[ i ], "-skyfix" ) )
872 Sys_Printf( "GL_CLAMP sky fix/hack/workaround enabled\n" );
875 else if( !strcmp( argv[ i ], "-debugsurfaces" ) )
877 Sys_Printf( "emitting debug surfaces\n" );
878 debugSurfaces = qtrue;
880 else if( !strcmp( argv[ i ], "-debuginset" ) )
882 Sys_Printf( "Debug surface triangle insetting enabled\n" );
885 else if( !strcmp( argv[ i ], "-debugportals" ) )
887 Sys_Printf( "Debug portal surfaces enabled\n" );
888 debugPortals = qtrue;
890 else if( !strcmp( argv[ i ], "-altsplit" ) )
892 Sys_Printf( "Alternate BSP splitting (by 27) enabled\n" );
893 bspAlternateSplitWeights = qtrue;
895 else if( !strcmp( argv[ i ], "-deep" ) )
897 Sys_Printf( "Deep BSP tree generation enabled\n" );
900 else if( !strcmp( argv[ i ], "-bsp" ) )
901 Sys_Printf( "-bsp argument unnecessary\n" );
904 Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] );
908 /* fixme: print more useful usage here */
909 if( i != (argc - 1) )
910 Error( "usage: q3map [options] mapfile" );
912 /* copy source name */
913 strcpy( source, ExpandArg( argv[ i ] ) );
914 StripExtension( source );
916 /* ydnar: set default sample size */
917 SetDefaultSampleSize( sampleSize );
919 /* delete portal, line and surface files */
920 sprintf( path, "%s.prt", source );
922 sprintf( path, "%s.lin", source );
924 //% sprintf( path, "%s.srf", source ); /* ydnar */
928 strcpy( name, ExpandArg( argv[ i ] ) );
929 if( strcmp( name + strlen( name ) - 4, ".reg" ) )
931 /* if we are doing a full map, delete the last saved region map */
932 sprintf( path, "%s.reg", source );
934 DefaultExtension( name, ".map" ); /* might be .reg */
937 /* if onlyents, just grab the entites and resave */
947 /* load original file from temp spot in case it was renamed by the editor on the way in */
948 if( strlen( tempSource ) > 0 )
949 LoadMapFile( tempSource, qfalse );
951 LoadMapFile( name, qfalse );
953 /* div0: inject command line parameters */
954 InjectCommandLine(argv, 1, argc - 1);
956 /* ydnar: decal setup */
959 /* ydnar: cloned brush model entities */
960 SetCloneModelNumbers();
962 /* process world and submodels */
965 /* set light styles from targetted light entities */
968 /* process in game advertisements */
969 ProcessAdvertisements();
971 /* finish and write bsp */
974 /* remove temp map source file if appropriate */
975 if( strlen( tempSource ) > 0)
976 remove( tempSource );
978 /* return to sender */