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 ], "_ins" );
141 if( value[ 0 ] == '\0' )
142 value = ValueForKey( &entities[ i ], "_instance" );
143 if( value[ 0 ] == '\0' )
144 value = ValueForKey( &entities[ i ], "_clone" );
145 if( value[ 0 ] != '\0' )
148 /* add the model key */
149 sprintf( modelValue, "*%d", models );
150 SetKeyValue( &entities[ i ], "model", modelValue );
152 /* increment model count */
157 for( i = 1; i < numEntities; i++ )
159 /* only entities with brushes or patches get a model number */
160 if( entities[ i ].brushes == NULL && entities[ i ].patches == NULL )
163 /* is this a clone? */
164 value = ValueForKey( &entities[ i ], "_ins" );
165 if( value[ 0 ] == '\0' )
166 value = ValueForKey( &entities[ i ], "_instance" );
167 if( value[ 0 ] == '\0' )
168 value = ValueForKey( &entities[ i ], "_clone" );
169 if( value[ 0 ] == '\0' )
172 /* find an entity with matching clone name */
173 for( j = 0; j < numEntities; j++ )
175 /* is this a clone parent? */
176 value2 = ValueForKey( &entities[ j ], "_clonename" );
177 if( value2[ 0 ] == '\0' )
181 if( strcmp( value, value2 ) == 0 )
183 /* get the model num */
184 value3 = ValueForKey( &entities[ j ], "model" );
185 if( value3[ 0 ] == '\0' )
187 Sys_Printf( "WARNING: Cloned entity %s referenced entity without model\n", value2 );
190 models = atoi( &value2[ 1 ] );
192 /* add the model key */
193 sprintf( modelValue, "*%d", models );
194 SetKeyValue( &entities[ i ], "model", modelValue );
196 /* nuke the brushes/patches for this entity (fixme: leak!) */
197 entities[ i ].brushes = NULL;
198 entities[ i ].patches = NULL;
207 FixBrushSides() - ydnar
208 matches brushsides back to their appropriate drawsurface and shader
211 static void FixBrushSides( entity_t *e )
214 mapDrawSurface_t *ds;
216 bspBrushSide_t *side;
220 Sys_FPrintf( SYS_VRB, "--- FixBrushSides ---\n" );
222 /* walk list of drawsurfaces */
223 for( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
225 /* get surface and try to early out */
226 ds = &mapDrawSurfs[ i ];
227 if( ds->outputNum < 0 )
230 /* walk sideref list */
231 for( sideRef = ds->sideRef; sideRef != NULL; sideRef = sideRef->next )
233 /* get bsp brush side */
234 if( sideRef->side == NULL || sideRef->side->outputNum < 0 )
236 side = &bspBrushSides[ sideRef->side->outputNum ];
238 /* set drawsurface */
239 side->surfaceNum = ds->outputNum;
240 //% Sys_FPrintf( SYS_VRB, "DS: %7d Side: %7d ", ds->outputNum, sideRef->side->outputNum );
243 if( strcmp( bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader ) )
245 //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader );
246 side->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
256 creates a full bsp + surfaces for the worldspawn entity
259 void ProcessWorldModel( void )
265 qboolean ignoreLeaks, leaked;
266 xmlNodePtr polyline, leaknode;
267 char level[ 2 ], shader[ 1024 ];
270 /* sets integer blockSize from worldspawn "_blocksize" key if it exists */
271 value = ValueForKey( &entities[ 0 ], "_blocksize" );
272 if( value[ 0 ] == '\0' )
273 value = ValueForKey( &entities[ 0 ], "blocksize" );
274 if( value[ 0 ] == '\0' )
275 value = ValueForKey( &entities[ 0 ], "chopsize" ); /* sof2 */
276 if( value[ 0 ] != '\0' )
279 s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] );
281 /* handle legacy case */
284 blockSize[ 1 ] = blockSize[ 0 ];
285 blockSize[ 2 ] = blockSize[ 0 ];
288 Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] );
290 /* sof2: ignore leaks? */
291 value = ValueForKey( &entities[ 0 ], "_ignoreleaks" ); /* ydnar */
292 if( value[ 0 ] == '\0' )
293 value = ValueForKey( &entities[ 0 ], "ignoreleaks" );
294 if( value[ 0 ] == '1' )
297 ignoreLeaks = qfalse;
299 /* begin worldspawn model */
302 e->firstDrawSurf = 0;
305 ClearMetaTriangles();
307 /* check for patches with adjacent edges that need to lod together */
308 PatchMapDrawSurfs( e );
310 /* build an initial bsp tree using all of the sides of all of the structural brushes */
311 faces = MakeStructuralBSPFaceList( entities[ 0 ].brushes );
312 tree = FaceBSP( faces );
313 MakeTreePortals( tree );
314 FilterStructuralBrushesIntoTree( e, tree );
316 /* see if the bsp is completely enclosed */
317 if( FloodEntities( tree ) || ignoreLeaks )
319 /* rebuild a better bsp tree using only the sides that are visible from the inside */
320 FillOutside( tree->headnode );
322 /* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
323 ClipSidesIntoTree( e, tree );
325 /* build a visible face tree */
326 faces = MakeVisibleBSPFaceList( entities[ 0 ].brushes );
328 tree = FaceBSP( faces );
329 MakeTreePortals( tree );
330 FilterStructuralBrushesIntoTree( e, tree );
333 /* ydnar: flood again for skybox */
335 FloodEntities( tree );
339 Sys_FPrintf( SYS_NOXML, "**********************\n" );
340 Sys_FPrintf( SYS_NOXML, "******* leaked *******\n" );
341 Sys_FPrintf( SYS_NOXML, "**********************\n" );
342 polyline = LeakFile( tree );
343 leaknode = xmlNewNode( NULL, (xmlChar*)"message" );
344 xmlNodeSetContent( leaknode, (xmlChar*)"MAP LEAKED\n" );
345 xmlAddChild( leaknode, polyline );
346 level[0] = (int) '0' + SYS_ERR;
348 xmlSetProp( leaknode, (xmlChar*)"level", (xmlChar*) &level );
349 xml_SendNode( leaknode );
352 Sys_Printf ("--- MAP LEAKED, ABORTING LEAKTEST ---\n");
357 /* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
358 ClipSidesIntoTree( e, tree );
361 /* save out information for visibility processing */
362 NumberClusters( tree );
364 WritePortalFile( tree );
366 /* flood from entities */
369 /* create drawsurfs for triangle models */
370 AddTriangleModels( e );
372 /* create drawsurfs for surface models */
373 AddEntitySurfaceModels( e );
375 /* generate bsp brushes from map brushes */
376 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
378 /* add references to the detail brushes */
379 FilterDetailBrushesIntoTree( e, tree );
381 /* drawsurfs that cross fog boundaries will need to be split along the fog boundary */
383 FogDrawSurfaces( e );
385 /* subdivide each drawsurf as required by shader tesselation */
387 SubdivideFaceSurfaces( e, tree );
389 /* add in any vertexes required to fix t-junctions */
393 /* ydnar: classify the surfaces */
394 ClassifyEntitySurfaces( e );
396 /* ydnar: project decals */
397 MakeEntityDecals( e );
399 /* ydnar: meta surfaces */
400 MakeEntityMetaTriangles( e );
401 SmoothMetaTriangles();
403 MergeMetaTriangles();
405 /* ydnar: debug portals */
407 MakeDebugPortalSurfs( tree );
409 /* ydnar: fog hull */
410 value = ValueForKey( &entities[ 0 ], "_foghull" );
411 if( value[ 0 ] != '\0' )
413 sprintf( shader, "textures/%s", value );
414 MakeFogHullSurfs( e, tree, shader );
417 /* ydnar: bug 645: do flares for lights */
418 for( i = 0; i < numEntities && emitFlares; i++ )
420 entity_t *light, *target;
421 const char *value, *flareShader;
422 vec3_t origin, targetOrigin, normal, color;
427 light = &entities[ i ];
428 value = ValueForKey( light, "classname" );
429 if( !strcmp( value, "light" ) )
431 /* get flare shader */
432 flareShader = ValueForKey( light, "_flareshader" );
433 value = ValueForKey( light, "_flare" );
434 if( flareShader[ 0 ] != '\0' || value[ 0 ] != '\0' )
437 GetVectorForKey( light, "origin", origin );
438 GetVectorForKey( light, "_color", color );
439 lightStyle = IntForKey( light, "_style" );
440 if( lightStyle == 0 )
441 lightStyle = IntForKey( light, "style" );
443 /* handle directional spotlights */
444 value = ValueForKey( light, "target" );
445 if( value[ 0 ] != '\0' )
447 /* get target light */
448 target = FindTargetEntity( value );
451 GetVectorForKey( target, "origin", targetOrigin );
452 VectorSubtract( targetOrigin, origin, normal );
453 VectorNormalize( normal, normal );
457 //% VectorClear( normal );
458 VectorSet( normal, 0, 0, -1 );
460 /* create the flare surface (note shader defaults automatically) */
461 DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle );
466 /* add references to the final drawsurfs in the apropriate clusters */
467 FilterDrawsurfsIntoTree( e, tree );
469 /* match drawsurfaces back to original brushsides (sof2) */
473 EndModel( e, tree->headnode );
481 creates bsp + surfaces for other brush models
484 void ProcessSubModel( void )
492 /* start a brush model */
494 e = &entities[ mapEntityNum ];
495 e->firstDrawSurf = numMapDrawSurfs;
498 ClearMetaTriangles();
500 /* check for patches with adjacent edges that need to lod together */
501 PatchMapDrawSurfs( e );
503 /* allocate a tree */
505 node->planenum = PLANENUM_LEAF;
507 tree->headnode = node;
509 /* add the sides to the tree */
510 ClipSidesIntoTree( e, tree );
512 /* ydnar: create drawsurfs for triangle models */
513 AddTriangleModels( e );
515 /* create drawsurfs for surface models */
516 AddEntitySurfaceModels( e );
518 /* generate bsp brushes from map brushes */
519 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
521 /* just put all the brushes in headnode */
522 for( b = e->brushes; b; b = b->next )
525 bc->next = node->brushlist;
526 node->brushlist = bc;
529 /* subdivide each drawsurf as required by shader tesselation */
531 SubdivideFaceSurfaces( e, tree );
533 /* add in any vertexes required to fix t-junctions */
537 /* ydnar: classify the surfaces and project lightmaps */
538 ClassifyEntitySurfaces( e );
540 /* ydnar: project decals */
541 MakeEntityDecals( e );
543 /* ydnar: meta surfaces */
544 MakeEntityMetaTriangles( e );
545 SmoothMetaTriangles();
547 MergeMetaTriangles();
549 /* add references to the final drawsurfs in the apropriate clusters */
550 FilterDrawsurfsIntoTree( e, tree );
552 /* match drawsurfaces back to original brushsides (sof2) */
564 process world + other models into the bsp
567 void ProcessModels( void )
573 /* preserve -v setting */
574 oldVerbose = verbose;
576 /* start a new bsp */
579 /* create map fogs */
582 /* walk entity list */
583 for( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
586 entity = &entities[ mapEntityNum ];
587 if( entity->brushes == NULL && entity->patches == NULL )
590 /* process the model */
591 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
592 if( mapEntityNum == 0 )
597 /* potentially turn off the deluge of text */
598 verbose = verboseEntities;
601 /* restore -v setting */
602 verbose = oldVerbose;
607 /* vortex: emit meta stats */
615 this is probably broken unless teamed with a radiant version that preserves entity order
618 void OnlyEnts( void )
622 char save_cmdline[1024], save_version[1024];
626 Sys_Printf( "--- OnlyEnts ---\n" );
628 sprintf( out, "%s.bsp", source );
632 p = ValueForKey(&entities[0], "_q3map2_cmdline");
633 strncpy(save_cmdline, p, sizeof(save_cmdline));
634 save_cmdline[sizeof(save_cmdline)-1] = 0;
635 p = ValueForKey(&entities[0], "_q3map2_version");
636 strncpy(save_version, p, sizeof(save_version));
637 save_version[sizeof(save_version)-1] = 0;
642 LoadMapFile( name, qfalse, qfalse );
647 SetKeyValue(&entities[0], "_q3map2_cmdline", save_cmdline);
649 SetKeyValue(&entities[0], "_q3map2_version", save_version);
651 numBSPEntities = numEntities;
661 handles creation of a bsp from a map file
664 int BSPMain( int argc, char **argv )
667 char path[ 1024 ], tempSource[ 1024 ];
668 qboolean onlyents = qfalse;
672 Sys_Printf( "--- BSP ---\n" );
674 SetDrawSurfacesBuffer();
675 mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
676 memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
679 tempSource[ 0 ] = '\0';
680 globalCelShader[0] = 0;
682 /* set standard game flags */
683 maxSurfaceVerts = game->maxSurfaceVerts;
684 maxSurfaceIndexes = game->maxSurfaceIndexes;
685 emitFlares = game->emitFlares;
686 texturesRGB = game->texturesRGB;
687 colorsRGB = game->colorsRGB;
689 /* process arguments */
690 for( i = 1; i < (argc - 1); i++ )
692 if( !strcmp( argv[ i ], "-onlyents" ) )
694 Sys_Printf( "Running entity-only compile\n" );
697 else if( !strcmp( argv[ i ], "-tempname" ) )
698 strcpy( tempSource, argv[ ++i ] );
699 else if( !strcmp( argv[ i ], "-tmpout" ) )
700 strcpy( outbase, "/tmp" );
701 else if( !strcmp( argv[ i ], "-nowater" ) )
703 Sys_Printf( "Disabling water\n" );
706 else if( !strcmp( argv[ i ], "-keeplights" ))
709 Sys_Printf( "Leaving light entities on map after compile\n" );
711 else if( !strcmp( argv[ i ], "-nodetail" ) )
713 Sys_Printf( "Ignoring detail brushes\n") ;
716 else if( !strcmp( argv[ i ], "-fulldetail" ) )
718 Sys_Printf( "Turning detail brushes into structural brushes\n" );
721 else if( !strcmp( argv[ i ], "-nofog" ) )
723 Sys_Printf( "Fog volumes disabled\n" );
726 else if( !strcmp( argv[ i ], "-nosubdivide" ) )
728 Sys_Printf( "Disabling brush face subdivision\n" );
731 else if( !strcmp( argv[ i ], "-leaktest" ) )
733 Sys_Printf( "Leaktest enabled\n" );
736 else if( !strcmp( argv[ i ], "-verboseentities" ) )
738 Sys_Printf( "Verbose entities enabled\n" );
739 verboseEntities = qtrue;
741 else if( !strcmp( argv[ i ], "-nocurves" ) )
743 Sys_Printf( "Ignoring curved surfaces (patches)\n" );
744 noCurveBrushes = qtrue;
746 else if( !strcmp( argv[ i ], "-notjunc" ) )
748 Sys_Printf( "T-junction fixing disabled\n" );
751 else if( !strcmp( argv[ i ], "-fakemap" ) )
753 Sys_Printf( "Generating fakemap.map\n" );
756 else if( !strcmp( argv[ i ], "-samplesize" ) )
758 sampleSize = atoi( argv[ i + 1 ] );
762 Sys_Printf( "Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
764 else if( !strcmp( argv[ i ], "-minsamplesize" ) )
766 minSampleSize = atoi( argv[ i + 1 ] );
767 if( minSampleSize < 1 )
770 Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
772 else if( !strcmp( argv[ i ], "-custinfoparms") )
774 Sys_Printf( "Custom info parms enabled\n" );
775 useCustomInfoParms = qtrue;
779 else if( !strcmp( argv[ i ], "-rename" ) )
781 Sys_Printf( "Appending _bsp suffix to misc_model shaders (SOF2)\n" );
782 renameModelShaders = qtrue;
786 else if( !strcmp( argv[ i ], "-ne" ) )
788 normalEpsilon = atof( argv[ i + 1 ] );
790 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
792 else if( !strcmp( argv[ i ], "-de" ) )
794 distanceEpsilon = atof( argv[ i + 1 ] );
796 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
798 else if( !strcmp( argv[ i ], "-mv" ) )
800 maxLMSurfaceVerts = atoi( argv[ i + 1 ] );
801 if( maxLMSurfaceVerts < 3 )
802 maxLMSurfaceVerts = 3;
803 if( maxLMSurfaceVerts > maxSurfaceVerts )
804 maxSurfaceVerts = maxLMSurfaceVerts;
806 Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
808 else if( !strcmp( argv[ i ], "-mi" ) )
810 maxSurfaceIndexes = atoi( argv[ i + 1 ] );
811 if( maxSurfaceIndexes < 3 )
812 maxSurfaceIndexes = 3;
814 Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
816 else if( !strcmp( argv[ i ], "-np" ) )
818 npDegrees = atof( argv[ i + 1 ] );
819 if( npDegrees < 0.0f )
821 else if( npDegrees > 0.0f )
822 Sys_Printf( "Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees );
825 else if( !strcmp( argv[ i ], "-snap" ) )
827 bevelSnap = atoi( argv[ i + 1 ]);
832 Sys_Printf( "Snapping brush bevel planes to %d units\n", bevelSnap );
834 else if( !strcmp( argv[ i ], "-texrange" ) )
836 texRange = atoi( argv[ i + 1 ]);
840 Sys_Printf( "Limiting per-surface texture range to %d texels\n", texRange );
842 else if( !strcmp( argv[ i ], "-nohint" ) )
844 Sys_Printf( "Hint brushes disabled\n" );
847 else if( !strcmp( argv[ i ], "-flat" ) )
849 Sys_Printf( "Flatshading enabled\n" );
852 else if( !strcmp( argv[ i ], "-celshader" ) )
856 sprintf( globalCelShader, "textures/%s", argv[ i ] );
858 *globalCelShader = 0;
859 Sys_Printf( "Global cel shader set to \"%s\"\n", globalCelShader );
861 else if( !strcmp( argv[ i ], "-meta" ) )
863 Sys_Printf( "Creating meta surfaces from brush faces\n" );
866 else if( !strcmp( argv[ i ], "-metaadequatescore" ) )
868 metaAdequateScore = atoi( argv[ i + 1 ]);
869 if( metaAdequateScore < 0 )
870 metaAdequateScore = -1;
872 if( metaAdequateScore >= 0 )
873 Sys_Printf( "Setting ADEQUATE meta score to %d (see surface_meta.c)\n", metaAdequateScore );
875 else if( !strcmp( argv[ i ], "-metagoodscore" ) )
877 metaGoodScore = atoi( argv[ i + 1 ]);
878 if( metaGoodScore < 0 )
881 if( metaGoodScore >= 0 )
882 Sys_Printf( "Setting GOOD meta score to %d (see surface_meta.c)\n", metaGoodScore );
884 else if( !strcmp( argv[ i ], "-metamaxbboxdistance" ) )
886 metaMaxBBoxDistance = atof( argv[ i + 1 ]);
887 if( metaMaxBBoxDistance < 0 )
888 metaMaxBBoxDistance = -1;
890 if( metaMaxBBoxDistance >= 0 )
891 Sys_Printf( "Setting meta maximum bounding box distance to %f\n", metaMaxBBoxDistance );
893 else if( !strcmp( argv[ i ], "-patchmeta" ) )
895 Sys_Printf( "Creating meta surfaces from patches\n" );
898 else if( !strcmp( argv[ i ], "-flares" ) )
900 Sys_Printf( "Flare surfaces enabled\n" );
903 else if( !strcmp( argv[ i ], "-noflares" ) )
905 Sys_Printf( "Flare surfaces disabled\n" );
908 else if( !strcmp( argv[ i ], "-skyfix" ) )
910 Sys_Printf( "GL_CLAMP sky fix/hack/workaround enabled\n" );
913 else if( !strcmp( argv[ i ], "-debugsurfaces" ) )
915 Sys_Printf( "emitting debug surfaces\n" );
916 debugSurfaces = qtrue;
918 else if( !strcmp( argv[ i ], "-debuginset" ) )
920 Sys_Printf( "Debug surface triangle insetting enabled\n" );
923 else if( !strcmp( argv[ i ], "-debugportals" ) )
925 Sys_Printf( "Debug portal surfaces enabled\n" );
926 debugPortals = qtrue;
928 else if( !strcmp( argv[ i ], "-sRGBtex" ) )
931 Sys_Printf( "Textures are in sRGB\n" );
933 else if( !strcmp( argv[ i ], "-nosRGBtex" ) )
935 texturesRGB = qfalse;
936 Sys_Printf( "Textures are linear\n" );
938 else if( !strcmp( argv[ i ], "-sRGBcolor" ) )
941 Sys_Printf( "Colors are in sRGB\n" );
943 else if( !strcmp( argv[ i ], "-nosRGBcolor" ) )
946 Sys_Printf( "Colors are linear\n" );
948 else if( !strcmp( argv[ i ], "-altsplit" ) )
950 Sys_Printf( "Alternate BSP splitting (by 27) enabled\n" );
951 bspAlternateSplitWeights = qtrue;
953 else if( !strcmp( argv[ i ], "-deep" ) )
955 Sys_Printf( "Deep BSP tree generation enabled\n" );
958 else if( !strcmp( argv[ i ], "-maxarea" ) )
960 Sys_Printf( "Max Area face surface generation enabled\n" );
961 maxAreaFaceSurface = qtrue;
963 else if( !strcmp( argv[ i ], "-bsp" ) )
964 Sys_Printf( "-bsp argument unnecessary\n" );
967 Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] );
971 /* fixme: print more useful usage here */
972 if( i != (argc - 1) )
973 Error( "usage: q3map [options] mapfile" );
975 /* copy source name */
976 strcpy( source, ExpandArg( argv[ i ] ) );
977 StripExtension( source );
979 /* ydnar: set default sample size */
980 SetDefaultSampleSize( sampleSize );
982 /* delete portal, line and surface files */
983 sprintf( path, "%s.prt", source );
985 sprintf( path, "%s.lin", source );
987 //% sprintf( path, "%s.srf", source ); /* ydnar */
991 strcpy( name, ExpandArg( argv[ i ] ) );
992 if( strcmp( name + strlen( name ) - 4, ".reg" ) )
994 /* if we are doing a full map, delete the last saved region map */
995 sprintf( path, "%s.reg", source );
997 DefaultExtension( name, ".map" ); /* might be .reg */
1000 /* if onlyents, just grab the entites and resave */
1010 /* load original file from temp spot in case it was renamed by the editor on the way in */
1011 if( strlen( tempSource ) > 0 )
1012 LoadMapFile( tempSource, qfalse, qfalse );
1014 LoadMapFile( name, qfalse, qfalse );
1016 /* div0: inject command line parameters */
1017 InjectCommandLine(argv, 1, argc - 1);
1019 /* ydnar: decal setup */
1022 /* ydnar: cloned brush model entities */
1023 SetCloneModelNumbers();
1025 /* process world and submodels */
1028 /* set light styles from targetted light entities */
1031 /* process in game advertisements */
1032 ProcessAdvertisements();
1034 /* finish and write bsp */
1037 /* remove temp map source file if appropriate */
1038 if( strlen( tempSource ) > 0)
1039 remove( tempSource );
1041 /* return to sender */