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." );
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] );
106 Error( "Ad cell %d has an unsupported Ad Surface type.", bspAds[numBSPAds].cellId );
112 Error( "Maximum number of map advertisements exceeded." );
118 Sys_FPrintf( SYS_VRB, "%9d in-game advertisements\n", numBSPAds );
122 SetCloneModelNumbers() - ydnar
123 sets the model numbers for brush entities
126 static void SetCloneModelNumbers( void ){
129 char modelValue[ 10 ];
130 const char *value, *value2, *value3;
133 /* start with 1 (worldspawn is model 0) */
135 for ( i = 1; i < numEntities; i++ )
137 /* only entities with brushes or patches get a model number */
138 if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) {
142 /* is this a clone? */
143 value = ValueForKey( &entities[ i ], "_ins" );
144 if ( value[ 0 ] == '\0' ) {
145 value = ValueForKey( &entities[ i ], "_instance" );
147 if ( value[ 0 ] == '\0' ) {
148 value = ValueForKey( &entities[ i ], "_clone" );
150 if ( value[ 0 ] != '\0' ) {
154 /* add the model key */
155 sprintf( modelValue, "*%d", models );
156 SetKeyValue( &entities[ i ], "model", modelValue );
158 /* increment model count */
163 for ( i = 1; i < numEntities; i++ )
165 /* only entities with brushes or patches get a model number */
166 if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) {
170 /* is this a clone? */
171 value = ValueForKey( &entities[ i ], "_ins" );
172 if ( value[ 0 ] == '\0' ) {
173 value = ValueForKey( &entities[ i ], "_instance" );
175 if ( value[ 0 ] == '\0' ) {
176 value = ValueForKey( &entities[ i ], "_clone" );
178 if ( value[ 0 ] == '\0' ) {
182 /* find an entity with matching clone name */
183 for ( j = 0; j < numEntities; j++ )
185 /* is this a clone parent? */
186 value2 = ValueForKey( &entities[ j ], "_clonename" );
187 if ( value2[ 0 ] == '\0' ) {
192 if ( strcmp( value, value2 ) == 0 ) {
193 /* get the model num */
194 value3 = ValueForKey( &entities[ j ], "model" );
195 if ( value3[ 0 ] == '\0' ) {
196 Sys_Printf( "WARNING: Cloned entity %s referenced entity without model\n", value2 );
199 models = atoi( &value2[ 1 ] );
201 /* add the model key */
202 sprintf( modelValue, "*%d", models );
203 SetKeyValue( &entities[ i ], "model", modelValue );
205 /* nuke the brushes/patches for this entity (fixme: leak!) */
206 entities[ i ].brushes = NULL;
207 entities[ i ].patches = NULL;
216 FixBrushSides() - ydnar
217 matches brushsides back to their appropriate drawsurface and shader
220 static void FixBrushSides( entity_t *e ){
222 mapDrawSurface_t *ds;
224 bspBrushSide_t *side;
228 Sys_FPrintf( SYS_VRB, "--- FixBrushSides ---\n" );
230 /* walk list of drawsurfaces */
231 for ( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
233 /* get surface and try to early out */
234 ds = &mapDrawSurfs[ i ];
235 if ( ds->outputNum < 0 ) {
239 /* walk sideref list */
240 for ( sideRef = ds->sideRef; sideRef != NULL; sideRef = sideRef->next )
242 /* get bsp brush side */
243 if ( sideRef->side == NULL || sideRef->side->outputNum < 0 ) {
246 side = &bspBrushSides[ sideRef->side->outputNum ];
248 /* set drawsurface */
249 side->surfaceNum = ds->outputNum;
250 //% Sys_FPrintf( SYS_VRB, "DS: %7d Side: %7d ", ds->outputNum, sideRef->side->outputNum );
253 if ( strcmp( bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader ) ) {
254 //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader );
255 side->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
265 creates a full bsp + surfaces for the worldspawn entity
268 void ProcessWorldModel( const char *portalFilePath, const char *lineFilePath ){
273 qboolean ignoreLeaks, leaked;
274 xmlNodePtr polyline, leaknode;
275 char level[ 2 ], shader[ 1024 ];
279 /* sets integer blockSize from worldspawn "_blocksize" key if it exists */
280 value = ValueForKey( &entities[ 0 ], "_blocksize" );
281 if ( value[ 0 ] == '\0' ) {
282 value = ValueForKey( &entities[ 0 ], "blocksize" );
284 if ( value[ 0 ] == '\0' ) {
285 value = ValueForKey( &entities[ 0 ], "chopsize" ); /* sof2 */
287 if ( value[ 0 ] != '\0' ) {
289 s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] );
291 /* handle legacy case */
293 blockSize[ 1 ] = blockSize[ 0 ];
294 blockSize[ 2 ] = blockSize[ 0 ];
297 Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] );
299 /* sof2: ignore leaks? */
300 value = ValueForKey( &entities[ 0 ], "_ignoreleaks" ); /* ydnar */
301 if ( value[ 0 ] == '\0' ) {
302 value = ValueForKey( &entities[ 0 ], "ignoreleaks" );
304 if ( value[ 0 ] == '1' ) {
308 ignoreLeaks = qfalse;
311 /* begin worldspawn model */
314 e->firstDrawSurf = 0;
317 ClearMetaTriangles();
319 /* check for patches with adjacent edges that need to lod together */
320 PatchMapDrawSurfs( e );
322 /* build an initial bsp tree using all of the sides of all of the structural brushes */
323 faces = MakeStructuralBSPFaceList( entities[ 0 ].brushes );
324 tree = FaceBSP( faces );
325 MakeTreePortals( tree );
326 FilterStructuralBrushesIntoTree( e, tree );
328 /* see if the bsp is completely enclosed */
329 leakStatus = FloodEntities( tree );
331 if ( leakStatus == FLOODENTITIES_LEAKED ) {
332 leakStatus = FLOODENTITIES_GOOD;
336 if ( leakStatus == FLOODENTITIES_GOOD ) {
343 Sys_FPrintf( SYS_NOXML, "**********************\n" );
344 Sys_FPrintf( SYS_NOXML, "******* leaked *******\n" );
345 Sys_FPrintf( SYS_NOXML, "**********************\n" );
346 polyline = LeakFile( tree, lineFilePath );
347 leaknode = xmlNewNode( NULL, (xmlChar*)"message" );
348 xmlNodeSetContent( leaknode, (xmlChar*)"MAP LEAKED\n" );
349 xmlAddChild( leaknode, polyline );
350 level[0] = (int) '0' + SYS_ERR;
352 xmlSetProp( leaknode, (xmlChar*)"level", (xmlChar*) &level );
353 xml_SendNode( leaknode );
355 Sys_Printf( "--- MAP LEAKED, ABORTING LEAKTEST ---\n" );
360 if ( leakStatus != FLOODENTITIES_EMPTY ) { /* if no entities exist, this would accidentally the whole map, and that IS bad */
361 /* rebuild a better bsp tree using only the sides that are visible from the inside */
362 FillOutside( tree->headnode );
364 /* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
365 ClipSidesIntoTree( e, tree );
367 /* build a visible face tree (same thing as the initial bsp tree but after reducing the faces) */
368 faces = MakeVisibleBSPFaceList( entities[ 0 ].brushes );
370 tree = FaceBSP( faces );
371 MakeTreePortals( tree );
372 FilterStructuralBrushesIntoTree( e, tree );
374 /* ydnar: flood again for skybox */
375 if ( skyboxPresent ) {
376 FloodEntities( tree );
380 /* save out information for visibility processing */
381 NumberClusters( tree );
383 WritePortalFile( tree, portalFilePath );
386 /* flood from entities */
389 /* create drawsurfs for triangle models */
390 AddTriangleModels( e );
392 /* create drawsurfs for surface models */
393 AddEntitySurfaceModels( e );
395 /* generate bsp brushes from map brushes */
396 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
398 /* add references to the detail brushes */
399 FilterDetailBrushesIntoTree( e, tree );
401 /* drawsurfs that cross fog boundaries will need to be split along the fog boundary */
403 FogDrawSurfaces( e );
406 /* subdivide each drawsurf as required by shader tesselation */
407 if ( !nosubdivide ) {
408 SubdivideFaceSurfaces( e, tree );
411 /* add in any vertexes required to fix t-junctions */
416 /* ydnar: classify the surfaces */
417 ClassifyEntitySurfaces( e );
419 /* ydnar: project decals */
420 MakeEntityDecals( e );
422 /* ydnar: meta surfaces */
423 MakeEntityMetaTriangles( e );
424 SmoothMetaTriangles();
426 MergeMetaTriangles();
428 /* ydnar: debug portals */
429 if ( debugPortals ) {
430 MakeDebugPortalSurfs( tree );
433 /* ydnar: fog hull */
434 value = ValueForKey( &entities[ 0 ], "_foghull" );
435 if ( value[ 0 ] != '\0' ) {
436 sprintf( shader, "textures/%s", value );
437 MakeFogHullSurfs( e, tree, shader );
440 /* ydnar: bug 645: do flares for lights */
441 for ( i = 0; i < numEntities && emitFlares; i++ )
443 entity_t *light, *target;
444 const char *value, *flareShader;
445 vec3_t origin, targetOrigin, normal, color;
450 light = &entities[ i ];
451 value = ValueForKey( light, "classname" );
452 if ( !strcmp( value, "light" ) ) {
453 /* get flare shader */
454 flareShader = ValueForKey( light, "_flareshader" );
455 value = ValueForKey( light, "_flare" );
456 if ( flareShader[ 0 ] != '\0' || value[ 0 ] != '\0' ) {
458 GetVectorForKey( light, "origin", origin );
459 GetVectorForKey( light, "_color", color );
460 lightStyle = IntForKey( light, "_style" );
461 if ( lightStyle == 0 ) {
462 lightStyle = IntForKey( light, "style" );
465 /* handle directional spotlights */
466 value = ValueForKey( light, "target" );
467 if ( value[ 0 ] != '\0' ) {
468 /* get target light */
469 target = FindTargetEntity( value );
470 if ( target != NULL ) {
471 GetVectorForKey( target, "origin", targetOrigin );
472 VectorSubtract( targetOrigin, origin, normal );
473 VectorNormalize( normal, normal );
477 //% VectorClear( normal );
478 VectorSet( normal, 0, 0, -1 );
482 color[0] = Image_LinearFloatFromsRGBFloat( color[0] );
483 color[1] = Image_LinearFloatFromsRGBFloat( color[1] );
484 color[2] = Image_LinearFloatFromsRGBFloat( color[2] );
487 /* create the flare surface (note shader defaults automatically) */
488 DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle );
493 /* add references to the final drawsurfs in the apropriate clusters */
494 FilterDrawsurfsIntoTree( e, tree );
496 /* match drawsurfaces back to original brushsides (sof2) */
500 EndModel( e, tree->headnode );
508 creates bsp + surfaces for other brush models
511 void ProcessSubModel( void ){
518 /* start a brush model */
520 e = &entities[ mapEntityNum ];
521 e->firstDrawSurf = numMapDrawSurfs;
524 ClearMetaTriangles();
526 /* check for patches with adjacent edges that need to lod together */
527 PatchMapDrawSurfs( e );
529 /* allocate a tree */
531 node->planenum = PLANENUM_LEAF;
533 tree->headnode = node;
535 /* add the sides to the tree */
536 ClipSidesIntoTree( e, tree );
538 /* ydnar: create drawsurfs for triangle models */
539 AddTriangleModels( e );
541 /* create drawsurfs for surface models */
542 AddEntitySurfaceModels( e );
544 /* generate bsp brushes from map brushes */
545 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
547 /* just put all the brushes in headnode */
548 for ( b = e->brushes; b; b = b->next )
551 bc->next = node->brushlist;
552 node->brushlist = bc;
555 /* subdivide each drawsurf as required by shader tesselation */
556 if ( !nosubdivide ) {
557 SubdivideFaceSurfaces( e, tree );
560 /* add in any vertexes required to fix t-junctions */
565 /* ydnar: classify the surfaces and project lightmaps */
566 ClassifyEntitySurfaces( e );
568 /* ydnar: project decals */
569 MakeEntityDecals( e );
571 /* ydnar: meta surfaces */
572 MakeEntityMetaTriangles( e );
573 SmoothMetaTriangles();
575 MergeMetaTriangles();
577 /* add references to the final drawsurfs in the apropriate clusters */
578 FilterDrawsurfsIntoTree( e, tree );
580 /* match drawsurfaces back to original brushsides (sof2) */
592 process world + other models into the bsp
595 void ProcessModels( const char *portalFilePath, const char *lineFilePath ){
600 /* preserve -v setting */
601 oldVerbose = verbose;
603 /* start a new bsp */
606 /* create map fogs */
609 /* walk entity list */
610 for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
613 entity = &entities[ mapEntityNum ];
614 if ( entity->brushes == NULL && entity->patches == NULL ) {
618 /* process the model */
619 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
620 if ( mapEntityNum == 0 ) {
621 ProcessWorldModel(portalFilePath, lineFilePath);
627 /* potentially turn off the deluge of text */
628 verbose = verboseEntities;
631 /* restore -v setting */
632 verbose = oldVerbose;
637 /* vortex: emit meta stats */
645 this is probably broken unless teamed with a radiant version that preserves entity order
648 void OnlyEnts( const char *BSPFilePath ){
649 char save_cmdline[1024], save_version[1024], save_gridsize[1024];
653 Sys_Printf( "--- OnlyEnts ---\n" );
655 LoadBSPFile( BSPFilePath );
658 p = ValueForKey( &entities[0], "_q3map2_cmdline" );
659 strncpy( save_cmdline, p, sizeof( save_cmdline ) );
660 save_cmdline[sizeof( save_cmdline ) - 1] = 0;
661 p = ValueForKey( &entities[0], "_q3map2_version" );
662 strncpy( save_version, p, sizeof( save_version ) );
663 save_version[sizeof( save_version ) - 1] = 0;
664 p = ValueForKey( &entities[0], "gridsize" );
665 strncpy( save_gridsize, p, sizeof( save_gridsize ) );
666 save_gridsize[sizeof( save_gridsize ) - 1] = 0;
671 LoadMapFile( name, qfalse, qfalse );
675 if ( *save_cmdline ) {
676 SetKeyValue( &entities[0], "_q3map2_cmdline", save_cmdline );
678 if ( *save_version ) {
679 SetKeyValue( &entities[0], "_q3map2_version", save_version );
681 if ( *save_gridsize ) {
682 SetKeyValue( &entities[0], "gridsize", save_gridsize );
685 numBSPEntities = numEntities;
688 WriteBSPFile( BSPFilePath );
695 handles creation of a bsp from a map file
698 int BSPMain( int argc, char **argv ){
700 char path[ 1024 ], tempSource[ 1024 ];
701 qboolean onlyents = qfalse;
702 char BSPFilePath [ 1024 ];
703 char lineFilePath [ 1024 ];
704 char portalFilePath [ 1024 ];
705 char surfaceFilePath [ 1024 ];
708 portalFilePath[0] = 0;
709 surfaceFilePath[0] = 0;
713 Sys_Printf( "--- BSP ---\n" );
715 SetDrawSurfacesBuffer();
716 mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
717 memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
720 tempSource[ 0 ] = '\0';
721 globalCelShader[0] = 0;
723 /* set standard game flags */
724 maxSurfaceVerts = game->maxSurfaceVerts;
725 maxSurfaceIndexes = game->maxSurfaceIndexes;
726 emitFlares = game->emitFlares;
727 texturesRGB = game->texturesRGB;
728 colorsRGB = game->colorsRGB;
730 /* process arguments */
731 for ( i = 1; i < ( argc - 1 ); i++ )
733 if ( !strcmp( argv[ i ], "-onlyents" ) ) {
734 Sys_Printf( "Running entity-only compile\n" );
737 else if ( !strcmp( argv[ i ], "-tempname" ) ) {
738 strcpy( tempSource, argv[ ++i ] );
740 else if ( !strcmp( argv[ i ], "-tmpout" ) ) {
741 strcpy( outbase, "/tmp" );
743 else if ( !strcmp( argv[ i ], "-nowater" ) ) {
744 Sys_Printf( "Disabling water\n" );
747 else if ( !strcmp( argv[ i ], "-keeplights" ) ) {
749 Sys_Printf( "Leaving light entities on map after compile\n" );
751 else if ( !strcmp( argv[ i ], "-nodetail" ) ) {
752 Sys_Printf( "Ignoring detail brushes\n" ) ;
755 else if ( !strcmp( argv[ i ], "-fulldetail" ) ) {
756 Sys_Printf( "Turning detail brushes into structural brushes\n" );
759 else if ( !strcmp( argv[ i ], "-nofog" ) ) {
760 Sys_Printf( "Fog volumes disabled\n" );
763 else if ( !strcmp( argv[ i ], "-nosubdivide" ) ) {
764 Sys_Printf( "Disabling brush face subdivision\n" );
767 else if ( !strcmp( argv[ i ], "-leaktest" ) ) {
768 Sys_Printf( "Leaktest enabled\n" );
771 else if ( !strcmp( argv[ i ], "-verboseentities" ) ) {
772 Sys_Printf( "Verbose entities enabled\n" );
773 verboseEntities = qtrue;
775 else if ( !strcmp( argv[ i ], "-nocurves" ) ) {
776 Sys_Printf( "Ignoring curved surfaces (patches)\n" );
777 noCurveBrushes = qtrue;
779 else if ( !strcmp( argv[ i ], "-notjunc" ) ) {
780 Sys_Printf( "T-junction fixing disabled\n" );
783 else if ( !strcmp( argv[ i ], "-fakemap" ) ) {
784 Sys_Printf( "Generating fakemap.map\n" );
787 else if ( !strcmp( argv[ i ], "-samplesize" ) ) {
788 sampleSize = atoi( argv[ i + 1 ] );
789 if ( sampleSize < 1 ) {
793 Sys_Printf( "Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
795 else if ( !strcmp( argv[ i ], "-minsamplesize" ) ) {
796 minSampleSize = atoi( argv[ i + 1 ] );
797 if ( minSampleSize < 1 ) {
801 Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
803 else if ( !strcmp( argv[ i ], "-custinfoparms" ) ) {
804 Sys_Printf( "Custom info parms enabled\n" );
805 useCustomInfoParms = qtrue;
809 else if ( !strcmp( argv[ i ], "-rename" ) ) {
810 Sys_Printf( "Appending _bsp suffix to misc_model shaders (SOF2)\n" );
811 renameModelShaders = qtrue;
815 else if ( !strcmp( argv[ i ], "-ne" ) ) {
816 normalEpsilon = atof( argv[ i + 1 ] );
818 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
820 else if ( !strcmp( argv[ i ], "-de" ) ) {
821 distanceEpsilon = atof( argv[ i + 1 ] );
823 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
825 else if ( !strcmp( argv[ i ], "-mv" ) ) {
826 maxLMSurfaceVerts = atoi( argv[ i + 1 ] );
827 if ( maxLMSurfaceVerts < 3 ) {
828 maxLMSurfaceVerts = 3;
830 if ( maxLMSurfaceVerts > maxSurfaceVerts ) {
831 maxSurfaceVerts = maxLMSurfaceVerts;
834 Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
836 else if ( !strcmp( argv[ i ], "-mi" ) ) {
837 maxSurfaceIndexes = atoi( argv[ i + 1 ] );
838 if ( maxSurfaceIndexes < 3 ) {
839 maxSurfaceIndexes = 3;
842 Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
844 else if ( !strcmp( argv[ i ], "-np" ) ) {
845 npDegrees = atof( argv[ i + 1 ] );
846 if ( npDegrees < 0.0f ) {
849 else if ( npDegrees > 0.0f ) {
850 Sys_Printf( "Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees );
854 else if ( !strcmp( argv[ i ], "-snap" ) ) {
855 bevelSnap = atoi( argv[ i + 1 ] );
856 if ( bevelSnap < 0 ) {
860 if ( bevelSnap > 0 ) {
861 Sys_Printf( "Snapping brush bevel planes to %d units\n", bevelSnap );
864 else if ( !strcmp( argv[ i ], "-texrange" ) ) {
865 texRange = atoi( argv[ i + 1 ] );
866 if ( texRange < 0 ) {
870 Sys_Printf( "Limiting per-surface texture range to %d texels\n", texRange );
872 else if ( !strcmp( argv[ i ], "-nohint" ) ) {
873 Sys_Printf( "Hint brushes disabled\n" );
876 else if ( !strcmp( argv[ i ], "-flat" ) ) {
877 Sys_Printf( "Flatshading enabled\n" );
880 else if ( !strcmp( argv[ i ], "-celshader" ) ) {
883 sprintf( globalCelShader, "textures/%s", argv[ i ] );
886 *globalCelShader = 0;
888 Sys_Printf( "Global cel shader set to \"%s\"\n", globalCelShader );
890 else if ( !strcmp( argv[ i ], "-meta" ) ) {
891 Sys_Printf( "Creating meta surfaces from brush faces\n" );
894 else if ( !strcmp( argv[ i ], "-metaadequatescore" ) ) {
895 metaAdequateScore = atoi( argv[ i + 1 ] );
896 if ( metaAdequateScore < 0 ) {
897 metaAdequateScore = -1;
900 if ( metaAdequateScore >= 0 ) {
901 Sys_Printf( "Setting ADEQUATE meta score to %d (see surface_meta.c)\n", metaAdequateScore );
904 else if ( !strcmp( argv[ i ], "-metagoodscore" ) ) {
905 metaGoodScore = atoi( argv[ i + 1 ] );
906 if ( metaGoodScore < 0 ) {
910 if ( metaGoodScore >= 0 ) {
911 Sys_Printf( "Setting GOOD meta score to %d (see surface_meta.c)\n", metaGoodScore );
914 else if ( !strcmp( argv[ i ], "-metamaxbboxdistance" ) ) {
915 metaMaxBBoxDistance = atof( argv[ i + 1 ] );
916 if ( metaMaxBBoxDistance < 0 ) {
917 metaMaxBBoxDistance = -1;
920 if ( metaMaxBBoxDistance >= 0 ) {
921 Sys_Printf( "Setting meta maximum bounding box distance to %f\n", metaMaxBBoxDistance );
924 else if ( !strcmp( argv[ i ], "-patchmeta" ) ) {
925 Sys_Printf( "Creating meta surfaces from patches\n" );
928 else if ( !strcmp( argv[ i ], "-flares" ) ) {
929 Sys_Printf( "Flare surfaces enabled\n" );
932 else if ( !strcmp( argv[ i ], "-noflares" ) ) {
933 Sys_Printf( "Flare surfaces disabled\n" );
936 else if ( !strcmp( argv[ i ], "-skyfix" ) ) {
937 Sys_Printf( "GL_CLAMP sky fix/hack/workaround enabled\n" );
940 else if ( !strcmp( argv[ i ], "-debugsurfaces" ) ) {
941 Sys_Printf( "emitting debug surfaces\n" );
942 debugSurfaces = qtrue;
944 else if ( !strcmp( argv[ i ], "-debuginset" ) ) {
945 Sys_Printf( "Debug surface triangle insetting enabled\n" );
948 else if ( !strcmp( argv[ i ], "-debugportals" ) ) {
949 Sys_Printf( "Debug portal surfaces enabled\n" );
950 debugPortals = qtrue;
952 else if ( !strcmp( argv[ i ], "-sRGBtex" ) ) {
954 Sys_Printf( "Textures are in sRGB\n" );
956 else if ( !strcmp( argv[ i ], "-nosRGBtex" ) ) {
957 texturesRGB = qfalse;
958 Sys_Printf( "Textures are linear\n" );
960 else if ( !strcmp( argv[ i ], "-sRGBcolor" ) ) {
962 Sys_Printf( "Colors are in sRGB\n" );
964 else if ( !strcmp( argv[ i ], "-nosRGBcolor" ) ) {
966 Sys_Printf( "Colors are linear\n" );
968 else if ( !strcmp( argv[ i ], "-nosRGB" ) ) {
969 texturesRGB = qfalse;
970 Sys_Printf( "Textures are linear\n" );
972 Sys_Printf( "Colors are linear\n" );
974 else if ( !strcmp( argv[ i ], "-altsplit" ) ) {
975 Sys_Printf( "Alternate BSP splitting (by 27) enabled\n" );
976 bspAlternateSplitWeights = qtrue;
978 else if ( !strcmp( argv[ i ], "-deep" ) ) {
979 Sys_Printf( "Deep BSP tree generation enabled\n" );
982 else if ( !strcmp( argv[ i ], "-maxarea" ) ) {
983 Sys_Printf( "Max Area face surface generation enabled\n" );
984 maxAreaFaceSurface = qtrue;
986 else if ( !strcmp( argv[ i ], "-bspfile" ) )
988 strcpy( BSPFilePath, argv[i + 1] );
990 Sys_Printf( "Use %s as bsp file\n", BSPFilePath );
992 else if ( !strcmp( argv[ i ], "-linfile" ) )
994 strcpy( lineFilePath, argv[i + 1] );
996 Sys_Printf( "Use %s as line file\n", lineFilePath );
998 else if ( !strcmp( argv[ i ], "-prtfile" ) )
1000 strcpy( portalFilePath, argv[i + 1] );
1002 Sys_Printf( "Use %s as portal file\n", portalFilePath );
1004 else if ( !strcmp( argv[ i ], "-srffile" ) )
1006 strcpy( surfaceFilePath, argv[i + 1] );
1008 Sys_Printf( "Use %s as surface file\n", surfaceFilePath );
1010 else if ( !strcmp( argv[ i ], "-bsp" ) ) {
1011 Sys_Printf( "-bsp argument unnecessary\n" );
1015 Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] );
1019 /* fixme: print more useful usage here */
1020 if ( i != ( argc - 1 ) ) {
1021 Error( "usage: q3map [options] mapfile" );
1024 /* copy source name */
1025 strcpy( source, ExpandArg( argv[ i ] ) );
1026 StripExtension( source );
1028 /* ydnar: set default sample size */
1029 SetDefaultSampleSize( sampleSize );
1031 if (!BSPFilePath[0]) {
1032 sprintf( BSPFilePath, "%s.bsp", source );
1034 if (!lineFilePath[0]) {
1035 sprintf( lineFilePath, "%s.lin", source );
1037 if (!portalFilePath[0]) {
1038 sprintf( portalFilePath, "%s.prt", source );
1040 if (!surfaceFilePath[0]) {
1041 sprintf( surfaceFilePath, "%s.srf", source );
1044 /* delete portal, line and surface files */
1045 remove( portalFilePath );
1046 remove( lineFilePath );
1047 //% remove( surfaceFilePath ) /* ydnar */
1049 /* expand mapname */
1050 strcpy( name, ExpandArg( argv[ i ] ) );
1051 if ( strcmp( name + strlen( name ) - 4, ".reg" ) ) {
1052 /* if we are doing a full map, delete the last saved region map */
1053 sprintf( path, "%s.reg", source );
1055 DefaultExtension( name, ".map" ); /* might be .reg */
1058 /* if onlyents, just grab the entites and resave */
1060 OnlyEnts( BSPFilePath );
1067 /* load original file from temp spot in case it was renamed by the editor on the way in */
1068 if ( strlen( tempSource ) > 0 ) {
1069 LoadMapFile( tempSource, qfalse, qfalse );
1072 LoadMapFile( name, qfalse, qfalse );
1075 /* div0: inject command line parameters */
1076 InjectCommandLine( argv, 1, argc - 1 );
1078 /* ydnar: decal setup */
1081 /* ydnar: cloned brush model entities */
1082 SetCloneModelNumbers();
1084 /* process world and submodels */
1085 ProcessModels( portalFilePath, lineFilePath );
1087 /* set light styles from targetted light entities */
1090 /* process in game advertisements */
1091 ProcessAdvertisements();
1093 /* finish and write bsp */
1094 EndBSPFile( qtrue, BSPFilePath, surfaceFilePath );
1096 /* remove temp map source file if appropriate */
1097 if ( strlen( tempSource ) > 0 ) {
1098 remove( tempSource );
1101 /* return to sender */