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 ------------------------------------------------------------------------------- */
49 ProcessAdvertisements()
50 copies advertisement info into the BSP structures
53 static void ProcessAdvertisements( void ) {
55 const char* className;
59 bspDrawSurface_t* adSurface;
61 Sys_FPrintf( SYS_VRB, "--- ProcessAdvertisements ---\n" );
63 for( i = 0; i < numEntities; i++ ) {
65 /* is an advertisement? */
66 className = ValueForKey( &entities[ i ], "classname" );
68 if( !Q_stricmp( "advertisement", className ) ) {
70 modelKey = ValueForKey( &entities[ i ], "model" );
72 if( strlen( modelKey ) > MAX_QPATH - 1 ) {
73 Error( "Model Key for entity exceeds ad struct string length." );
75 if( numBSPAds < MAX_MAP_ADVERTISEMENTS ) {
76 bspAds[numBSPAds].cellId = IntForKey( &entities[ i ], "cellId" );
77 strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) );
80 modelNum = atoi( modelKey );
81 adModel = &bspModels[modelNum];
83 if( adModel->numBSPSurfaces != 1 ) {
84 Error( "Ad cell id %d has more than one surface.", bspAds[numBSPAds].cellId );
87 adSurface = &bspDrawSurfaces[adModel->firstBSPSurface];
89 // store the normal for use at run time.. all ad verts are assumed to
90 // have identical normals (because they should be a simple rectangle)
91 // so just use the first vert's normal
92 VectorCopy( bspDrawVerts[adSurface->firstVert].normal, bspAds[numBSPAds].normal );
94 // store the ad quad for quick use at run time
95 if( adSurface->surfaceType == MST_PATCH ) {
96 int v0 = adSurface->firstVert + adSurface->patchHeight - 1;
97 int v1 = adSurface->firstVert + adSurface->numVerts - 1;
98 int v2 = adSurface->firstVert + adSurface->numVerts - adSurface->patchWidth;
99 int v3 = adSurface->firstVert;
100 VectorCopy( bspDrawVerts[v0].xyz, bspAds[numBSPAds].rect[0] );
101 VectorCopy( bspDrawVerts[v1].xyz, bspAds[numBSPAds].rect[1] );
102 VectorCopy( bspDrawVerts[v2].xyz, bspAds[numBSPAds].rect[2] );
103 VectorCopy( bspDrawVerts[v3].xyz, bspAds[numBSPAds].rect[3] );
105 Error( "Ad cell %d has an unsupported Ad Surface type.", bspAds[numBSPAds].cellId );
110 Error( "Maximum number of map advertisements exceeded." );
116 Sys_FPrintf( SYS_VRB, "%9d in-game advertisements\n", numBSPAds );
120 SetCloneModelNumbers() - ydnar
121 sets the model numbers for brush entities
124 static void SetCloneModelNumbers( void )
128 char modelValue[ 10 ];
129 const char *value, *value2, *value3;
132 /* start with 1 (worldspawn is model 0) */
134 for( i = 1; i < numEntities; i++ )
136 /* only entities with brushes or patches get a model number */
137 if( entities[ i ].brushes == NULL && entities[ i ].patches == NULL )
140 /* is this a clone? */
141 value = ValueForKey( &entities[ i ], "_clone" );
142 if( value[ 0 ] != '\0' )
145 /* add the model key */
146 sprintf( modelValue, "*%d", models );
147 SetKeyValue( &entities[ i ], "model", modelValue );
149 /* increment model count */
154 for( i = 1; i < numEntities; i++ )
156 /* only entities with brushes or patches get a model number */
157 if( entities[ i ].brushes == NULL && entities[ i ].patches == NULL )
160 /* is this a clone? */
161 value = ValueForKey( &entities[ i ], "_ins" );
162 if( value[ 0 ] == '\0' )
163 value = ValueForKey( &entities[ i ], "_instance" );
164 if( value[ 0 ] == '\0' )
165 value = ValueForKey( &entities[ i ], "_clone" );
166 if( value[ 0 ] == '\0' )
169 /* find an entity with matching clone name */
170 for( j = 0; j < numEntities; j++ )
172 /* is this a clone parent? */
173 value2 = ValueForKey( &entities[ j ], "_clonename" );
174 if( value2[ 0 ] == '\0' )
178 if( strcmp( value, value2 ) == 0 )
180 /* get the model num */
181 value3 = ValueForKey( &entities[ j ], "model" );
182 if( value3[ 0 ] == '\0' )
184 Sys_Printf( "WARNING: Cloned entity %s referenced entity without model\n", value2 );
187 models = atoi( &value2[ 1 ] );
189 /* add the model key */
190 sprintf( modelValue, "*%d", models );
191 SetKeyValue( &entities[ i ], "model", modelValue );
193 /* nuke the brushes/patches for this entity (fixme: leak!) */
194 entities[ i ].brushes = NULL;
195 entities[ i ].patches = NULL;
204 FixBrushSides() - ydnar
205 matches brushsides back to their appropriate drawsurface and shader
208 static void FixBrushSides( entity_t *e )
211 mapDrawSurface_t *ds;
213 bspBrushSide_t *side;
217 Sys_FPrintf( SYS_VRB, "--- FixBrushSides ---\n" );
219 /* walk list of drawsurfaces */
220 for( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
222 /* get surface and try to early out */
223 ds = &mapDrawSurfs[ i ];
224 if( ds->outputNum < 0 )
227 /* walk sideref list */
228 for( sideRef = ds->sideRef; sideRef != NULL; sideRef = sideRef->next )
230 /* get bsp brush side */
231 if( sideRef->side == NULL || sideRef->side->outputNum < 0 )
233 side = &bspBrushSides[ sideRef->side->outputNum ];
235 /* set drawsurface */
236 side->surfaceNum = ds->outputNum;
237 //% Sys_FPrintf( SYS_VRB, "DS: %7d Side: %7d ", ds->outputNum, sideRef->side->outputNum );
240 if( strcmp( bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader ) )
242 //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader );
243 side->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
253 creates a full bsp + surfaces for the worldspawn entity
256 void ProcessWorldModel( void )
262 qboolean ignoreLeaks, leaked;
263 xmlNodePtr polyline, leaknode;
264 char level[ 2 ], shader[ 1024 ];
267 /* sets integer blockSize from worldspawn "_blocksize" key if it exists */
268 value = ValueForKey( &entities[ 0 ], "_blocksize" );
269 if( value[ 0 ] == '\0' )
270 value = ValueForKey( &entities[ 0 ], "blocksize" );
271 if( value[ 0 ] == '\0' )
272 value = ValueForKey( &entities[ 0 ], "chopsize" ); /* sof2 */
273 if( value[ 0 ] != '\0' )
276 s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] );
278 /* handle legacy case */
281 blockSize[ 1 ] = blockSize[ 0 ];
282 blockSize[ 2 ] = blockSize[ 0 ];
285 Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] );
287 /* sof2: ignore leaks? */
288 value = ValueForKey( &entities[ 0 ], "_ignoreleaks" ); /* ydnar */
289 if( value[ 0 ] == '\0' )
290 value = ValueForKey( &entities[ 0 ], "ignoreleaks" );
291 if( value[ 0 ] == '1' )
294 ignoreLeaks = qfalse;
296 /* begin worldspawn model */
299 e->firstDrawSurf = 0;
302 ClearMetaTriangles();
304 /* check for patches with adjacent edges that need to lod together */
305 PatchMapDrawSurfs( e );
307 /* build an initial bsp tree using all of the sides of all of the structural brushes */
308 faces = MakeStructuralBSPFaceList( entities[ 0 ].brushes );
309 tree = FaceBSP( faces );
310 MakeTreePortals( tree );
311 FilterStructuralBrushesIntoTree( e, tree );
313 /* see if the bsp is completely enclosed */
314 if( FloodEntities( tree ) || ignoreLeaks )
316 /* rebuild a better bsp tree using only the sides that are visible from the inside */
317 FillOutside( tree->headnode );
319 /* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
320 ClipSidesIntoTree( e, tree );
322 /* build a visible face tree */
323 faces = MakeVisibleBSPFaceList( entities[ 0 ].brushes );
325 tree = FaceBSP( faces );
326 MakeTreePortals( tree );
327 FilterStructuralBrushesIntoTree( e, tree );
330 /* ydnar: flood again for skybox */
332 FloodEntities( tree );
336 Sys_FPrintf( SYS_NOXML, "**********************\n" );
337 Sys_FPrintf( SYS_NOXML, "******* leaked *******\n" );
338 Sys_FPrintf( SYS_NOXML, "**********************\n" );
339 polyline = LeakFile( tree );
340 leaknode = xmlNewNode( NULL, "message" );
341 xmlNodeSetContent( leaknode, "MAP LEAKED\n" );
342 xmlAddChild( leaknode, polyline );
343 level[0] = (int) '0' + SYS_ERR;
345 xmlSetProp( leaknode, "level", (char*) &level );
346 xml_SendNode( leaknode );
349 Sys_Printf ("--- MAP LEAKED, ABORTING LEAKTEST ---\n");
354 /* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
355 ClipSidesIntoTree( e, tree );
358 /* save out information for visibility processing */
359 NumberClusters( tree );
361 WritePortalFile( tree );
363 /* flood from entities */
366 /* create drawsurfs for triangle models */
367 AddTriangleModels( e );
369 /* create drawsurfs for surface models */
370 AddEntitySurfaceModels( e );
372 /* generate bsp brushes from map brushes */
373 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
375 /* add references to the detail brushes */
376 FilterDetailBrushesIntoTree( e, tree );
378 /* drawsurfs that cross fog boundaries will need to be split along the fog boundary */
380 FogDrawSurfaces( e );
382 /* subdivide each drawsurf as required by shader tesselation */
384 SubdivideFaceSurfaces( e, tree );
386 /* add in any vertexes required to fix t-junctions */
390 /* ydnar: classify the surfaces */
391 ClassifyEntitySurfaces( e );
393 /* ydnar: project decals */
394 MakeEntityDecals( e );
396 /* ydnar: meta surfaces */
397 MakeEntityMetaTriangles( e );
398 SmoothMetaTriangles();
400 MergeMetaTriangles();
402 /* ydnar: debug portals */
404 MakeDebugPortalSurfs( tree );
406 /* ydnar: fog hull */
407 value = ValueForKey( &entities[ 0 ], "_foghull" );
408 if( value[ 0 ] != '\0' )
410 sprintf( shader, "textures/%s", value );
411 MakeFogHullSurfs( e, tree, shader );
414 /* ydnar: bug 645: do flares for lights */
415 for( i = 0; i < numEntities && emitFlares; i++ )
417 entity_t *light, *target;
418 const char *value, *flareShader;
419 vec3_t origin, targetOrigin, normal, color;
424 light = &entities[ i ];
425 value = ValueForKey( light, "classname" );
426 if( !strcmp( value, "light" ) )
428 /* get flare shader */
429 flareShader = ValueForKey( light, "_flareshader" );
430 value = ValueForKey( light, "_flare" );
431 if( flareShader[ 0 ] != '\0' || value[ 0 ] != '\0' )
434 GetVectorForKey( light, "origin", origin );
435 GetVectorForKey( light, "_color", color );
436 lightStyle = IntForKey( light, "_style" );
437 if( lightStyle == 0 )
438 lightStyle = IntForKey( light, "style" );
440 /* handle directional spotlights */
441 value = ValueForKey( light, "target" );
442 if( value[ 0 ] != '\0' )
444 /* get target light */
445 target = FindTargetEntity( value );
448 GetVectorForKey( target, "origin", targetOrigin );
449 VectorSubtract( targetOrigin, origin, normal );
450 VectorNormalize( normal, normal );
454 //% VectorClear( normal );
455 VectorSet( normal, 0, 0, -1 );
457 /* create the flare surface (note shader defaults automatically) */
458 DrawSurfaceForFlare( mapEntityNum, origin, normal, color, (char*) flareShader, lightStyle );
463 /* add references to the final drawsurfs in the apropriate clusters */
464 FilterDrawsurfsIntoTree( e, tree );
466 /* match drawsurfaces back to original brushsides (sof2) */
470 EndModel( e, tree->headnode );
478 creates bsp + surfaces for other brush models
481 void ProcessSubModel( void )
489 /* start a brush model */
491 e = &entities[ mapEntityNum ];
492 e->firstDrawSurf = numMapDrawSurfs;
495 ClearMetaTriangles();
497 /* check for patches with adjacent edges that need to lod together */
498 PatchMapDrawSurfs( e );
500 /* allocate a tree */
502 node->planenum = PLANENUM_LEAF;
504 tree->headnode = node;
506 /* add the sides to the tree */
507 ClipSidesIntoTree( e, tree );
509 /* ydnar: create drawsurfs for triangle models */
510 AddTriangleModels( e );
512 /* create drawsurfs for surface models */
513 AddEntitySurfaceModels( e );
515 /* generate bsp brushes from map brushes */
516 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
518 /* just put all the brushes in headnode */
519 for( b = e->brushes; b; b = b->next )
522 bc->next = node->brushlist;
523 node->brushlist = bc;
526 /* subdivide each drawsurf as required by shader tesselation */
528 SubdivideFaceSurfaces( e, tree );
530 /* add in any vertexes required to fix t-junctions */
534 /* ydnar: classify the surfaces and project lightmaps */
535 ClassifyEntitySurfaces( e );
537 /* ydnar: project decals */
538 MakeEntityDecals( e );
540 /* ydnar: meta surfaces */
541 MakeEntityMetaTriangles( e );
542 SmoothMetaTriangles();
544 MergeMetaTriangles();
546 /* add references to the final drawsurfs in the apropriate clusters */
547 FilterDrawsurfsIntoTree( e, tree );
549 /* match drawsurfaces back to original brushsides (sof2) */
561 process world + other models into the bsp
564 void ProcessModels( void )
570 /* preserve -v setting */
571 oldVerbose = verbose;
573 /* start a new bsp */
576 /* create map fogs */
579 /* walk entity list */
580 for( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
583 entity = &entities[ mapEntityNum ];
584 if( entity->brushes == NULL && entity->patches == NULL )
587 /* process the model */
588 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
589 if( mapEntityNum == 0 )
594 /* potentially turn off the deluge of text */
595 verbose = verboseEntities;
598 /* restore -v setting */
599 verbose = oldVerbose;
604 /* vortex: emit meta stats */
612 this is probably broken unless teamed with a radiant version that preserves entity order
615 void OnlyEnts( void )
619 char save_cmdline[1024], save_version[1024];
623 Sys_Printf( "--- OnlyEnts ---\n" );
625 sprintf( out, "%s.bsp", source );
629 p = ValueForKey(&entities[0], "_q3map2_cmdline");
630 strncpy(save_cmdline, p, sizeof(save_cmdline));
631 save_cmdline[sizeof(save_cmdline)-1] = 0;
632 p = ValueForKey(&entities[0], "_q3map2_version");
633 strncpy(save_version, p, sizeof(save_version));
634 save_version[sizeof(save_version)-1] = 0;
639 LoadMapFile( name, qfalse );
644 SetKeyValue(&entities[0], "_q3map2_cmdline", save_cmdline);
646 SetKeyValue(&entities[0], "_q3map2_version", save_version);
648 numBSPEntities = numEntities;
658 handles creation of a bsp from a map file
661 int BSPMain( int argc, char **argv )
664 char path[ 1024 ], tempSource[ 1024 ];
665 qboolean onlyents = qfalse;
669 Sys_Printf( "--- BSP ---\n" );
671 SetDrawSurfacesBuffer();
672 mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
673 memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
676 tempSource[ 0 ] = '\0';
677 globalCelShader[0] = 0;
679 /* set standard game flags */
680 maxSurfaceVerts = game->maxSurfaceVerts;
681 maxSurfaceIndexes = game->maxSurfaceIndexes;
682 emitFlares = game->emitFlares;
684 /* process arguments */
685 for( i = 1; i < (argc - 1); i++ )
687 if( !strcmp( argv[ i ], "-onlyents" ) )
689 Sys_Printf( "Running entity-only compile\n" );
692 else if( !strcmp( argv[ i ], "-tempname" ) )
693 strcpy( tempSource, argv[ ++i ] );
694 else if( !strcmp( argv[ i ], "-tmpout" ) )
695 strcpy( outbase, "/tmp" );
696 else if( !strcmp( argv[ i ], "-nowater" ) )
698 Sys_Printf( "Disabling water\n" );
701 else if( !strcmp( argv[ i ], "-nodetail" ) )
703 Sys_Printf( "Ignoring detail brushes\n") ;
706 else if( !strcmp( argv[ i ], "-fulldetail" ) )
708 Sys_Printf( "Turning detail brushes into structural brushes\n" );
711 else if( !strcmp( argv[ i ], "-nofog" ) )
713 Sys_Printf( "Fog volumes disabled\n" );
716 else if( !strcmp( argv[ i ], "-nosubdivide" ) )
718 Sys_Printf( "Disabling brush face subdivision\n" );
721 else if( !strcmp( argv[ i ], "-leaktest" ) )
723 Sys_Printf( "Leaktest enabled\n" );
726 else if( !strcmp( argv[ i ], "-verboseentities" ) )
728 Sys_Printf( "Verbose entities enabled\n" );
729 verboseEntities = qtrue;
731 else if( !strcmp( argv[ i ], "-nocurves" ) )
733 Sys_Printf( "Ignoring curved surfaces (patches)\n" );
734 noCurveBrushes = qtrue;
736 else if( !strcmp( argv[ i ], "-notjunc" ) )
738 Sys_Printf( "T-junction fixing disabled\n" );
741 else if( !strcmp( argv[ i ], "-fakemap" ) )
743 Sys_Printf( "Generating fakemap.map\n" );
746 else if( !strcmp( argv[ i ], "-samplesize" ) )
748 sampleSize = atoi( argv[ i + 1 ] );
752 Sys_Printf( "Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
754 else if( !strcmp( argv[ i ], "-minsamplesize" ) )
756 minSampleSize = atoi( argv[ i + 1 ] );
757 if( minSampleSize < 1 )
760 Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
762 else if( !strcmp( argv[ i ], "-custinfoparms") )
764 Sys_Printf( "Custom info parms enabled\n" );
765 useCustomInfoParms = qtrue;
769 else if( !strcmp( argv[ i ], "-rename" ) )
771 Sys_Printf( "Appending _bsp suffix to misc_model shaders (SOF2)\n" );
772 renameModelShaders = qtrue;
776 else if( !strcmp( argv[ i ], "-ne" ) )
778 normalEpsilon = atof( argv[ i + 1 ] );
780 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
782 else if( !strcmp( argv[ i ], "-de" ) )
784 distanceEpsilon = atof( argv[ i + 1 ] );
786 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
788 else if( !strcmp( argv[ i ], "-mv" ) )
790 maxLMSurfaceVerts = atoi( argv[ i + 1 ] );
791 if( maxLMSurfaceVerts < 3 )
792 maxLMSurfaceVerts = 3;
793 if( maxLMSurfaceVerts > maxSurfaceVerts )
794 maxSurfaceVerts = maxLMSurfaceVerts;
796 Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
798 else if( !strcmp( argv[ i ], "-mi" ) )
800 maxSurfaceIndexes = atoi( argv[ i + 1 ] );
801 if( maxSurfaceIndexes < 3 )
802 maxSurfaceIndexes = 3;
804 Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
806 else if( !strcmp( argv[ i ], "-np" ) )
808 npDegrees = atof( argv[ i + 1 ] );
809 if( npDegrees < 0.0f )
810 shadeAngleDegrees = 0.0f;
811 else if( npDegrees > 0.0f )
812 Sys_Printf( "Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees );
815 else if( !strcmp( argv[ i ], "-snap" ) )
817 bevelSnap = atoi( argv[ i + 1 ]);
822 Sys_Printf( "Snapping brush bevel planes to %d units\n", bevelSnap );
824 else if( !strcmp( argv[ i ], "-texrange" ) )
826 texRange = atoi( argv[ i + 1 ]);
830 Sys_Printf( "Limiting per-surface texture range to %d texels\n", texRange );
832 else if( !strcmp( argv[ i ], "-nohint" ) )
834 Sys_Printf( "Hint brushes disabled\n" );
837 else if( !strcmp( argv[ i ], "-flat" ) )
839 Sys_Printf( "Flatshading enabled\n" );
842 else if( !strcmp( argv[ i ], "-celshader" ) )
846 sprintf( globalCelShader, "textures/%s", argv[ i ] );
848 *globalCelShader = 0;
849 Sys_Printf( "Global cel shader set to \"%s\"\n", globalCelShader );
851 else if( !strcmp( argv[ i ], "-meta" ) )
853 Sys_Printf( "Creating meta surfaces from brush faces\n" );
856 else if( !strcmp( argv[ i ], "-patchmeta" ) )
858 Sys_Printf( "Creating meta surfaces from patches\n" );
861 else if( !strcmp( argv[ i ], "-flares" ) )
863 Sys_Printf( "Flare surfaces enabled\n" );
866 else if( !strcmp( argv[ i ], "-noflares" ) )
868 Sys_Printf( "Flare surfaces disabled\n" );
871 else if( !strcmp( argv[ i ], "-skyfix" ) )
873 Sys_Printf( "GL_CLAMP sky fix/hack/workaround enabled\n" );
876 else if( !strcmp( argv[ i ], "-debugsurfaces" ) )
878 Sys_Printf( "emitting debug surfaces\n" );
879 debugSurfaces = qtrue;
881 else if( !strcmp( argv[ i ], "-debuginset" ) )
883 Sys_Printf( "Debug surface triangle insetting enabled\n" );
886 else if( !strcmp( argv[ i ], "-debugportals" ) )
888 Sys_Printf( "Debug portal surfaces enabled\n" );
889 debugPortals = qtrue;
891 else if( !strcmp( argv[ i ], "-altsplit" ) )
893 Sys_Printf( "Alternate BSP splitting (by 27) enabled\n" );
894 bspAlternateSplitWeights = qtrue;
896 else if( !strcmp( argv[ i ], "-deep" ) )
898 Sys_Printf( "Deep BSP tree generation enabled\n" );
901 else if( !strcmp( argv[ i ], "-bsp" ) )
902 Sys_Printf( "-bsp argument unnecessary\n" );
905 Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] );
909 /* fixme: print more useful usage here */
910 if( i != (argc - 1) )
911 Error( "usage: q3map [options] mapfile" );
913 /* copy source name */
914 strcpy( source, ExpandArg( argv[ i ] ) );
915 StripExtension( source );
917 /* ydnar: set default sample size */
918 SetDefaultSampleSize( sampleSize );
920 /* delete portal, line and surface files */
921 sprintf( path, "%s.prt", source );
923 sprintf( path, "%s.lin", source );
925 //% sprintf( path, "%s.srf", source ); /* ydnar */
929 strcpy( name, ExpandArg( argv[ i ] ) );
930 if( strcmp( name + strlen( name ) - 4, ".reg" ) )
932 /* if we are doing a full map, delete the last saved region map */
933 sprintf( path, "%s.reg", source );
935 DefaultExtension( name, ".map" ); /* might be .reg */
938 /* if onlyents, just grab the entites and resave */
948 /* load original file from temp spot in case it was renamed by the editor on the way in */
949 if( strlen( tempSource ) > 0 )
950 LoadMapFile( tempSource, qfalse );
952 LoadMapFile( name, qfalse );
954 /* div0: inject command line parameters */
955 InjectCommandLine(argv, 1, argc - 1);
957 /* ydnar: decal setup */
960 /* ydnar: cloned brush model entities */
961 SetCloneModelNumbers();
963 /* process world and submodels */
966 /* set light styles from targetted light entities */
969 /* process in game advertisements */
970 ProcessAdvertisements();
972 /* finish and write bsp */
975 /* remove temp map source file if appropriate */
976 if( strlen( tempSource ) > 0)
977 remove( tempSource );
979 /* return to sender */