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 );
462 color[0] = Image_LinearFloatFromsRGBFloat(color[0]);
463 color[1] = Image_LinearFloatFromsRGBFloat(color[1]);
464 color[2] = Image_LinearFloatFromsRGBFloat(color[2]);
467 /* create the flare surface (note shader defaults automatically) */
468 DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle );
473 /* add references to the final drawsurfs in the apropriate clusters */
474 FilterDrawsurfsIntoTree( e, tree );
476 /* match drawsurfaces back to original brushsides (sof2) */
480 EndModel( e, tree->headnode );
488 creates bsp + surfaces for other brush models
491 void ProcessSubModel( void )
499 /* start a brush model */
501 e = &entities[ mapEntityNum ];
502 e->firstDrawSurf = numMapDrawSurfs;
505 ClearMetaTriangles();
507 /* check for patches with adjacent edges that need to lod together */
508 PatchMapDrawSurfs( e );
510 /* allocate a tree */
512 node->planenum = PLANENUM_LEAF;
514 tree->headnode = node;
516 /* add the sides to the tree */
517 ClipSidesIntoTree( e, tree );
519 /* ydnar: create drawsurfs for triangle models */
520 AddTriangleModels( e );
522 /* create drawsurfs for surface models */
523 AddEntitySurfaceModels( e );
525 /* generate bsp brushes from map brushes */
526 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
528 /* just put all the brushes in headnode */
529 for( b = e->brushes; b; b = b->next )
532 bc->next = node->brushlist;
533 node->brushlist = bc;
536 /* subdivide each drawsurf as required by shader tesselation */
538 SubdivideFaceSurfaces( e, tree );
540 /* add in any vertexes required to fix t-junctions */
544 /* ydnar: classify the surfaces and project lightmaps */
545 ClassifyEntitySurfaces( e );
547 /* ydnar: project decals */
548 MakeEntityDecals( e );
550 /* ydnar: meta surfaces */
551 MakeEntityMetaTriangles( e );
552 SmoothMetaTriangles();
554 MergeMetaTriangles();
556 /* add references to the final drawsurfs in the apropriate clusters */
557 FilterDrawsurfsIntoTree( e, tree );
559 /* match drawsurfaces back to original brushsides (sof2) */
571 process world + other models into the bsp
574 void ProcessModels( void )
580 /* preserve -v setting */
581 oldVerbose = verbose;
583 /* start a new bsp */
586 /* create map fogs */
589 /* walk entity list */
590 for( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
593 entity = &entities[ mapEntityNum ];
594 if( entity->brushes == NULL && entity->patches == NULL )
597 /* process the model */
598 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
599 if( mapEntityNum == 0 )
604 /* potentially turn off the deluge of text */
605 verbose = verboseEntities;
608 /* restore -v setting */
609 verbose = oldVerbose;
614 /* vortex: emit meta stats */
622 this is probably broken unless teamed with a radiant version that preserves entity order
625 void OnlyEnts( void )
629 char save_cmdline[1024], save_version[1024], save_gridsize[1024];
633 Sys_Printf( "--- OnlyEnts ---\n" );
635 sprintf( out, "%s.bsp", source );
639 p = ValueForKey(&entities[0], "_q3map2_cmdline");
640 strncpy(save_cmdline, p, sizeof(save_cmdline));
641 save_cmdline[sizeof(save_cmdline)-1] = 0;
642 p = ValueForKey(&entities[0], "_q3map2_version");
643 strncpy(save_version, p, sizeof(save_version));
644 save_version[sizeof(save_version)-1] = 0;
645 p = ValueForKey(&entities[0], "gridsize");
646 strncpy(save_gridsize, p, sizeof(save_gridsize));
647 save_gridsize[sizeof(save_gridsize)-1] = 0;
652 LoadMapFile( name, qfalse, qfalse );
657 SetKeyValue(&entities[0], "_q3map2_cmdline", save_cmdline);
659 SetKeyValue(&entities[0], "_q3map2_version", save_version);
661 SetKeyValue(&entities[0], "gridsize", save_gridsize);
663 numBSPEntities = numEntities;
673 handles creation of a bsp from a map file
676 int BSPMain( int argc, char **argv )
679 char path[ 1024 ], tempSource[ 1024 ];
680 qboolean onlyents = qfalse;
684 Sys_Printf( "--- BSP ---\n" );
686 SetDrawSurfacesBuffer();
687 mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
688 memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
691 tempSource[ 0 ] = '\0';
692 globalCelShader[0] = 0;
694 /* set standard game flags */
695 maxSurfaceVerts = game->maxSurfaceVerts;
696 maxSurfaceIndexes = game->maxSurfaceIndexes;
697 emitFlares = game->emitFlares;
698 texturesRGB = game->texturesRGB;
699 colorsRGB = game->colorsRGB;
701 /* process arguments */
702 for( i = 1; i < (argc - 1); i++ )
704 if( !strcmp( argv[ i ], "-onlyents" ) )
706 Sys_Printf( "Running entity-only compile\n" );
709 else if( !strcmp( argv[ i ], "-tempname" ) )
710 strcpy( tempSource, argv[ ++i ] );
711 else if( !strcmp( argv[ i ], "-tmpout" ) )
712 strcpy( outbase, "/tmp" );
713 else if( !strcmp( argv[ i ], "-nowater" ) )
715 Sys_Printf( "Disabling water\n" );
718 else if( !strcmp( argv[ i ], "-keeplights" ))
721 Sys_Printf( "Leaving light entities on map after compile\n" );
723 else if( !strcmp( argv[ i ], "-nodetail" ) )
725 Sys_Printf( "Ignoring detail brushes\n") ;
728 else if( !strcmp( argv[ i ], "-fulldetail" ) )
730 Sys_Printf( "Turning detail brushes into structural brushes\n" );
733 else if( !strcmp( argv[ i ], "-nofog" ) )
735 Sys_Printf( "Fog volumes disabled\n" );
738 else if( !strcmp( argv[ i ], "-nosubdivide" ) )
740 Sys_Printf( "Disabling brush face subdivision\n" );
743 else if( !strcmp( argv[ i ], "-leaktest" ) )
745 Sys_Printf( "Leaktest enabled\n" );
748 else if( !strcmp( argv[ i ], "-verboseentities" ) )
750 Sys_Printf( "Verbose entities enabled\n" );
751 verboseEntities = qtrue;
753 else if( !strcmp( argv[ i ], "-nocurves" ) )
755 Sys_Printf( "Ignoring curved surfaces (patches)\n" );
756 noCurveBrushes = qtrue;
758 else if( !strcmp( argv[ i ], "-notjunc" ) )
760 Sys_Printf( "T-junction fixing disabled\n" );
763 else if( !strcmp( argv[ i ], "-fakemap" ) )
765 Sys_Printf( "Generating fakemap.map\n" );
768 else if( !strcmp( argv[ i ], "-samplesize" ) )
770 sampleSize = atoi( argv[ i + 1 ] );
774 Sys_Printf( "Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
776 else if( !strcmp( argv[ i ], "-minsamplesize" ) )
778 minSampleSize = atoi( argv[ i + 1 ] );
779 if( minSampleSize < 1 )
782 Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
784 else if( !strcmp( argv[ i ], "-custinfoparms") )
786 Sys_Printf( "Custom info parms enabled\n" );
787 useCustomInfoParms = qtrue;
791 else if( !strcmp( argv[ i ], "-rename" ) )
793 Sys_Printf( "Appending _bsp suffix to misc_model shaders (SOF2)\n" );
794 renameModelShaders = qtrue;
798 else if( !strcmp( argv[ i ], "-ne" ) )
800 normalEpsilon = atof( argv[ i + 1 ] );
802 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
804 else if( !strcmp( argv[ i ], "-de" ) )
806 distanceEpsilon = atof( argv[ i + 1 ] );
808 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
810 else if( !strcmp( argv[ i ], "-mv" ) )
812 maxLMSurfaceVerts = atoi( argv[ i + 1 ] );
813 if( maxLMSurfaceVerts < 3 )
814 maxLMSurfaceVerts = 3;
815 if( maxLMSurfaceVerts > maxSurfaceVerts )
816 maxSurfaceVerts = maxLMSurfaceVerts;
818 Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
820 else if( !strcmp( argv[ i ], "-mi" ) )
822 maxSurfaceIndexes = atoi( argv[ i + 1 ] );
823 if( maxSurfaceIndexes < 3 )
824 maxSurfaceIndexes = 3;
826 Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
828 else if( !strcmp( argv[ i ], "-np" ) )
830 npDegrees = atof( argv[ i + 1 ] );
831 if( npDegrees < 0.0f )
833 else if( npDegrees > 0.0f )
834 Sys_Printf( "Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees );
837 else if( !strcmp( argv[ i ], "-snap" ) )
839 bevelSnap = atoi( argv[ i + 1 ]);
844 Sys_Printf( "Snapping brush bevel planes to %d units\n", bevelSnap );
846 else if( !strcmp( argv[ i ], "-texrange" ) )
848 texRange = atoi( argv[ i + 1 ]);
852 Sys_Printf( "Limiting per-surface texture range to %d texels\n", texRange );
854 else if( !strcmp( argv[ i ], "-nohint" ) )
856 Sys_Printf( "Hint brushes disabled\n" );
859 else if( !strcmp( argv[ i ], "-flat" ) )
861 Sys_Printf( "Flatshading enabled\n" );
864 else if( !strcmp( argv[ i ], "-celshader" ) )
868 sprintf( globalCelShader, "textures/%s", argv[ i ] );
870 *globalCelShader = 0;
871 Sys_Printf( "Global cel shader set to \"%s\"\n", globalCelShader );
873 else if( !strcmp( argv[ i ], "-meta" ) )
875 Sys_Printf( "Creating meta surfaces from brush faces\n" );
878 else if( !strcmp( argv[ i ], "-metaadequatescore" ) )
880 metaAdequateScore = atoi( argv[ i + 1 ]);
881 if( metaAdequateScore < 0 )
882 metaAdequateScore = -1;
884 if( metaAdequateScore >= 0 )
885 Sys_Printf( "Setting ADEQUATE meta score to %d (see surface_meta.c)\n", metaAdequateScore );
887 else if( !strcmp( argv[ i ], "-metagoodscore" ) )
889 metaGoodScore = atoi( argv[ i + 1 ]);
890 if( metaGoodScore < 0 )
893 if( metaGoodScore >= 0 )
894 Sys_Printf( "Setting GOOD meta score to %d (see surface_meta.c)\n", metaGoodScore );
896 else if( !strcmp( argv[ i ], "-metamaxbboxdistance" ) )
898 metaMaxBBoxDistance = atof( argv[ i + 1 ]);
899 if( metaMaxBBoxDistance < 0 )
900 metaMaxBBoxDistance = -1;
902 if( metaMaxBBoxDistance >= 0 )
903 Sys_Printf( "Setting meta maximum bounding box distance to %f\n", metaMaxBBoxDistance );
905 else if( !strcmp( argv[ i ], "-patchmeta" ) )
907 Sys_Printf( "Creating meta surfaces from patches\n" );
910 else if( !strcmp( argv[ i ], "-flares" ) )
912 Sys_Printf( "Flare surfaces enabled\n" );
915 else if( !strcmp( argv[ i ], "-noflares" ) )
917 Sys_Printf( "Flare surfaces disabled\n" );
920 else if( !strcmp( argv[ i ], "-skyfix" ) )
922 Sys_Printf( "GL_CLAMP sky fix/hack/workaround enabled\n" );
925 else if( !strcmp( argv[ i ], "-debugsurfaces" ) )
927 Sys_Printf( "emitting debug surfaces\n" );
928 debugSurfaces = qtrue;
930 else if( !strcmp( argv[ i ], "-debuginset" ) )
932 Sys_Printf( "Debug surface triangle insetting enabled\n" );
935 else if( !strcmp( argv[ i ], "-debugportals" ) )
937 Sys_Printf( "Debug portal surfaces enabled\n" );
938 debugPortals = qtrue;
940 else if( !strcmp( argv[ i ], "-sRGBtex" ) )
943 Sys_Printf( "Textures are in sRGB\n" );
945 else if( !strcmp( argv[ i ], "-nosRGBtex" ) )
947 texturesRGB = qfalse;
948 Sys_Printf( "Textures are linear\n" );
950 else if( !strcmp( argv[ i ], "-sRGBcolor" ) )
953 Sys_Printf( "Colors are in sRGB\n" );
955 else if( !strcmp( argv[ i ], "-nosRGBcolor" ) )
958 Sys_Printf( "Colors are linear\n" );
960 else if( !strcmp( argv[ i ], "-nosRGB" ) )
962 texturesRGB = qfalse;
963 Sys_Printf( "Textures are linear\n" );
965 Sys_Printf( "Colors are linear\n" );
967 else if( !strcmp( argv[ i ], "-altsplit" ) )
969 Sys_Printf( "Alternate BSP splitting (by 27) enabled\n" );
970 bspAlternateSplitWeights = qtrue;
972 else if( !strcmp( argv[ i ], "-deep" ) )
974 Sys_Printf( "Deep BSP tree generation enabled\n" );
977 else if( !strcmp( argv[ i ], "-maxarea" ) )
979 Sys_Printf( "Max Area face surface generation enabled\n" );
980 maxAreaFaceSurface = qtrue;
982 else if( !strcmp( argv[ i ], "-bsp" ) )
983 Sys_Printf( "-bsp argument unnecessary\n" );
986 Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] );
990 /* fixme: print more useful usage here */
991 if( i != (argc - 1) )
992 Error( "usage: q3map [options] mapfile" );
994 /* copy source name */
995 strcpy( source, ExpandArg( argv[ i ] ) );
996 StripExtension( source );
998 /* ydnar: set default sample size */
999 SetDefaultSampleSize( sampleSize );
1001 /* delete portal, line and surface files */
1002 sprintf( path, "%s.prt", source );
1004 sprintf( path, "%s.lin", source );
1006 //% sprintf( path, "%s.srf", source ); /* ydnar */
1009 /* expand mapname */
1010 strcpy( name, ExpandArg( argv[ i ] ) );
1011 if( strcmp( name + strlen( name ) - 4, ".reg" ) )
1013 /* if we are doing a full map, delete the last saved region map */
1014 sprintf( path, "%s.reg", source );
1016 DefaultExtension( name, ".map" ); /* might be .reg */
1019 /* if onlyents, just grab the entites and resave */
1029 /* load original file from temp spot in case it was renamed by the editor on the way in */
1030 if( strlen( tempSource ) > 0 )
1031 LoadMapFile( tempSource, qfalse, qfalse );
1033 LoadMapFile( name, qfalse, qfalse );
1035 /* div0: inject command line parameters */
1036 InjectCommandLine(argv, 1, argc - 1);
1038 /* ydnar: decal setup */
1041 /* ydnar: cloned brush model entities */
1042 SetCloneModelNumbers();
1044 /* process world and submodels */
1047 /* set light styles from targetted light entities */
1050 /* process in game advertisements */
1051 ProcessAdvertisements();
1053 /* finish and write bsp */
1056 /* remove temp map source file if appropriate */
1057 if( strlen( tempSource ) > 0)
1058 remove( tempSource );
1060 /* return to sender */