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." );
76 if ( numBSPAds < MAX_MAP_ADVERTISEMENTS ) {
77 bspAds[numBSPAds].cellId = IntForKey( &entities[ i ], "cellId" );
78 strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) );
81 modelNum = atoi( modelKey );
82 adModel = &bspModels[modelNum];
84 if ( adModel->numBSPSurfaces != 1 ) {
85 Error( "Ad cell id %d has more than one surface.", bspAds[numBSPAds].cellId );
88 adSurface = &bspDrawSurfaces[adModel->firstBSPSurface];
90 // store the normal for use at run time.. all ad verts are assumed to
91 // have identical normals (because they should be a simple rectangle)
92 // so just use the first vert's normal
93 VectorCopy( bspDrawVerts[adSurface->firstVert].normal, bspAds[numBSPAds].normal );
95 // store the ad quad for quick use at run time
96 if ( adSurface->surfaceType == MST_PATCH ) {
97 int v0 = adSurface->firstVert + adSurface->patchHeight - 1;
98 int v1 = adSurface->firstVert + adSurface->numVerts - 1;
99 int v2 = adSurface->firstVert + adSurface->numVerts - adSurface->patchWidth;
100 int v3 = adSurface->firstVert;
101 VectorCopy( bspDrawVerts[v0].xyz, bspAds[numBSPAds].rect[0] );
102 VectorCopy( bspDrawVerts[v1].xyz, bspAds[numBSPAds].rect[1] );
103 VectorCopy( bspDrawVerts[v2].xyz, bspAds[numBSPAds].rect[2] );
104 VectorCopy( bspDrawVerts[v3].xyz, bspAds[numBSPAds].rect[3] );
107 Error( "Ad cell %d has an unsupported Ad Surface type.", bspAds[numBSPAds].cellId );
113 Error( "Maximum number of map advertisements exceeded." );
119 Sys_FPrintf( SYS_VRB, "%9d in-game advertisements\n", numBSPAds );
123 SetCloneModelNumbers() - ydnar
124 sets the model numbers for brush entities
127 static void SetCloneModelNumbers( void ){
130 char modelValue[ 10 ];
131 const char *value, *value2, *value3;
134 /* start with 1 (worldspawn is model 0) */
136 for ( i = 1; i < numEntities; i++ )
138 /* only entities with brushes or patches get a model number */
139 if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) {
143 /* is this a clone? */
144 value = ValueForKey( &entities[ i ], "_ins" );
145 if ( value[ 0 ] == '\0' ) {
146 value = ValueForKey( &entities[ i ], "_instance" );
148 if ( value[ 0 ] == '\0' ) {
149 value = ValueForKey( &entities[ i ], "_clone" );
151 if ( value[ 0 ] != '\0' ) {
155 /* add the model key */
156 sprintf( modelValue, "*%d", models );
157 SetKeyValue( &entities[ i ], "model", modelValue );
159 /* increment model count */
164 for ( i = 1; i < numEntities; i++ )
166 /* only entities with brushes or patches get a model number */
167 if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) {
171 /* is this a clone? */
172 value = ValueForKey( &entities[ i ], "_ins" );
173 if ( value[ 0 ] == '\0' ) {
174 value = ValueForKey( &entities[ i ], "_instance" );
176 if ( value[ 0 ] == '\0' ) {
177 value = ValueForKey( &entities[ i ], "_clone" );
179 if ( value[ 0 ] == '\0' ) {
183 /* find an entity with matching clone name */
184 for ( j = 0; j < numEntities; j++ )
186 /* is this a clone parent? */
187 value2 = ValueForKey( &entities[ j ], "_clonename" );
188 if ( value2[ 0 ] == '\0' ) {
193 if ( strcmp( value, value2 ) == 0 ) {
194 /* get the model num */
195 value3 = ValueForKey( &entities[ j ], "model" );
196 if ( value3[ 0 ] == '\0' ) {
197 Sys_FPrintf( SYS_WRN, "WARNING: Cloned entity %s referenced entity without model\n", value2 );
200 models = atoi( &value2[ 1 ] );
202 /* add the model key */
203 sprintf( modelValue, "*%d", models );
204 SetKeyValue( &entities[ i ], "model", modelValue );
206 /* nuke the brushes/patches for this entity (fixme: leak!) */
207 entities[ i ].brushes = NULL;
208 entities[ i ].patches = NULL;
217 FixBrushSides() - ydnar
218 matches brushsides back to their appropriate drawsurface and shader
221 static void FixBrushSides( entity_t *e ){
223 mapDrawSurface_t *ds;
225 bspBrushSide_t *side;
229 Sys_FPrintf( SYS_VRB, "--- FixBrushSides ---\n" );
231 /* walk list of drawsurfaces */
232 for ( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
234 /* get surface and try to early out */
235 ds = &mapDrawSurfs[ i ];
236 if ( ds->outputNum < 0 ) {
240 /* walk sideref list */
241 for ( sideRef = ds->sideRef; sideRef != NULL; sideRef = sideRef->next )
243 /* get bsp brush side */
244 if ( sideRef->side == NULL || sideRef->side->outputNum < 0 ) {
247 side = &bspBrushSides[ sideRef->side->outputNum ];
249 /* set drawsurface */
250 side->surfaceNum = ds->outputNum;
251 //% Sys_FPrintf( SYS_VRB, "DS: %7d Side: %7d ", ds->outputNum, sideRef->side->outputNum );
254 if ( strcmp( bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader ) ) {
255 //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader );
256 side->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
266 creates a full bsp + surfaces for the worldspawn entity
269 void ProcessWorldModel( const char *portalFilePath, const char *lineFilePath ){
274 qboolean ignoreLeaks, leaked;
275 xmlNodePtr polyline, leaknode;
276 char level[ 2 ], shader[ 1024 ];
280 /* sets integer blockSize from worldspawn "_blocksize" key if it exists */
281 value = ValueForKey( &entities[ 0 ], "_blocksize" );
282 if ( value[ 0 ] == '\0' ) {
283 value = ValueForKey( &entities[ 0 ], "blocksize" );
285 if ( value[ 0 ] == '\0' ) {
286 value = ValueForKey( &entities[ 0 ], "chopsize" ); /* sof2 */
288 if ( value[ 0 ] != '\0' ) {
290 s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] );
292 /* handle legacy case */
294 blockSize[ 1 ] = blockSize[ 0 ];
295 blockSize[ 2 ] = blockSize[ 0 ];
298 Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] );
300 /* sof2: ignore leaks? */
301 value = ValueForKey( &entities[ 0 ], "_ignoreleaks" ); /* ydnar */
302 if ( value[ 0 ] == '\0' ) {
303 value = ValueForKey( &entities[ 0 ], "ignoreleaks" );
305 if ( value[ 0 ] == '1' ) {
309 ignoreLeaks = qfalse;
312 /* begin worldspawn model */
315 e->firstDrawSurf = 0;
318 ClearMetaTriangles();
320 /* check for patches with adjacent edges that need to lod together */
321 PatchMapDrawSurfs( e );
323 /* build an initial bsp tree using all of the sides of all of the structural brushes */
324 faces = MakeStructuralBSPFaceList( entities[ 0 ].brushes );
325 tree = FaceBSP( faces );
326 MakeTreePortals( tree );
327 FilterStructuralBrushesIntoTree( e, tree );
329 /* see if the bsp is completely enclosed */
330 leakStatus = FloodEntities( tree );
332 if ( leakStatus == FLOODENTITIES_LEAKED ) {
333 leakStatus = FLOODENTITIES_GOOD;
337 if ( leakStatus == FLOODENTITIES_GOOD ) {
344 Sys_FPrintf( SYS_NOXML, "**********************\n" );
345 Sys_FPrintf( SYS_NOXML, "******* leaked *******\n" );
346 Sys_FPrintf( SYS_NOXML, "**********************\n" );
347 polyline = LeakFile( tree, lineFilePath );
348 leaknode = xmlNewNode( NULL, (xmlChar*)"message" );
349 xmlNodeAddContent( leaknode, (xmlChar*)"MAP LEAKED\n" );
350 xmlAddChild( leaknode, polyline );
351 level[0] = (int) '0' + SYS_ERR;
353 xmlSetProp( leaknode, (xmlChar*)"level", (xmlChar*) &level );
354 xml_SendNode( leaknode );
356 Sys_Printf( "--- MAP LEAKED, ABORTING LEAKTEST ---\n" );
361 if ( leakStatus != FLOODENTITIES_EMPTY ) { /* if no entities exist, this would accidentally the whole map, and that IS bad */
362 /* rebuild a better bsp tree using only the sides that are visible from the inside */
363 FillOutside( tree->headnode );
365 /* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
366 ClipSidesIntoTree( e, tree );
368 /* build a visible face tree (same thing as the initial bsp tree but after reducing the faces) */
369 faces = MakeVisibleBSPFaceList( entities[ 0 ].brushes );
371 tree = FaceBSP( faces );
372 MakeTreePortals( tree );
373 FilterStructuralBrushesIntoTree( e, tree );
375 /* ydnar: flood again for skybox */
376 if ( skyboxPresent ) {
377 FloodEntities( tree );
381 /* save out information for visibility processing */
382 NumberClusters( tree );
384 WritePortalFile( tree, portalFilePath );
387 /* flood from entities */
390 /* create drawsurfs for triangle models */
391 AddTriangleModels( e );
393 /* create drawsurfs for surface models */
394 AddEntitySurfaceModels( e );
396 /* generate bsp brushes from map brushes */
397 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
399 /* add references to the detail brushes */
400 FilterDetailBrushesIntoTree( e, tree );
402 /* drawsurfs that cross fog boundaries will need to be split along the fog boundary */
404 FogDrawSurfaces( e );
407 /* subdivide each drawsurf as required by shader tesselation */
408 if ( !nosubdivide ) {
409 SubdivideFaceSurfaces( e, tree );
412 /* add in any vertexes required to fix t-junctions */
417 /* ydnar: classify the surfaces */
418 ClassifyEntitySurfaces( e );
420 /* ydnar: project decals */
421 MakeEntityDecals( e );
423 /* ydnar: meta surfaces */
424 MakeEntityMetaTriangles( e );
425 SmoothMetaTriangles();
427 MergeMetaTriangles();
429 /* ydnar: debug portals */
430 if ( debugPortals ) {
431 MakeDebugPortalSurfs( tree );
434 /* ydnar: fog hull */
435 value = ValueForKey( &entities[ 0 ], "_foghull" );
436 if ( value[ 0 ] != '\0' ) {
437 sprintf( shader, "textures/%s", value );
438 MakeFogHullSurfs( e, tree, shader );
441 /* ydnar: bug 645: do flares for lights */
442 for ( i = 0; i < numEntities && emitFlares; i++ )
444 entity_t *light, *target;
445 const char *value, *flareShader;
446 vec3_t origin, targetOrigin, normal, color;
451 light = &entities[ i ];
452 value = ValueForKey( light, "classname" );
453 if ( !strcmp( value, "light" ) ) {
454 /* get flare shader */
455 flareShader = ValueForKey( light, "_flareshader" );
456 value = ValueForKey( light, "_flare" );
457 if ( flareShader[ 0 ] != '\0' || value[ 0 ] != '\0' ) {
459 GetVectorForKey( light, "origin", origin );
460 GetVectorForKey( light, "_color", color );
461 lightStyle = IntForKey( light, "_style" );
462 if ( lightStyle == 0 ) {
463 lightStyle = IntForKey( light, "style" );
466 /* handle directional spotlights */
467 value = ValueForKey( light, "target" );
468 if ( value[ 0 ] != '\0' ) {
469 /* get target light */
470 target = FindTargetEntity( value );
471 if ( target != NULL ) {
472 GetVectorForKey( target, "origin", targetOrigin );
473 VectorSubtract( targetOrigin, origin, normal );
474 VectorNormalize( normal, normal );
478 //% VectorClear( normal );
479 VectorSet( normal, 0, 0, -1 );
483 color[0] = Image_LinearFloatFromsRGBFloat( color[0] );
484 color[1] = Image_LinearFloatFromsRGBFloat( color[1] );
485 color[2] = Image_LinearFloatFromsRGBFloat( color[2] );
488 /* create the flare surface (note shader defaults automatically) */
489 DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle );
494 /* add references to the final drawsurfs in the apropriate clusters */
495 FilterDrawsurfsIntoTree( e, tree );
497 /* match drawsurfaces back to original brushsides (sof2) */
501 EndModel( e, tree->headnode );
509 creates bsp + surfaces for other brush models
512 void ProcessSubModel( void ){
519 /* start a brush model */
521 e = &entities[ mapEntityNum ];
522 e->firstDrawSurf = numMapDrawSurfs;
525 ClearMetaTriangles();
527 /* check for patches with adjacent edges that need to lod together */
528 PatchMapDrawSurfs( e );
530 /* allocate a tree */
532 node->planenum = PLANENUM_LEAF;
534 tree->headnode = node;
536 /* add the sides to the tree */
537 ClipSidesIntoTree( e, tree );
539 /* ydnar: create drawsurfs for triangle models */
540 AddTriangleModels( e );
542 /* create drawsurfs for surface models */
543 AddEntitySurfaceModels( e );
545 /* generate bsp brushes from map brushes */
546 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
548 /* just put all the brushes in headnode */
549 for ( b = e->brushes; b; b = b->next )
552 bc->next = node->brushlist;
553 node->brushlist = bc;
556 /* subdivide each drawsurf as required by shader tesselation */
557 if ( !nosubdivide ) {
558 SubdivideFaceSurfaces( e, tree );
561 /* add in any vertexes required to fix t-junctions */
566 /* ydnar: classify the surfaces and project lightmaps */
567 ClassifyEntitySurfaces( e );
569 /* ydnar: project decals */
570 MakeEntityDecals( e );
572 /* ydnar: meta surfaces */
573 MakeEntityMetaTriangles( e );
574 SmoothMetaTriangles();
576 MergeMetaTriangles();
578 /* add references to the final drawsurfs in the apropriate clusters */
579 FilterDrawsurfsIntoTree( e, tree );
581 /* match drawsurfaces back to original brushsides (sof2) */
593 process world + other models into the bsp
596 void ProcessModels( const char *portalFilePath, const char *lineFilePath ){
601 /* preserve -v setting */
602 oldVerbose = verbose;
604 /* start a new bsp */
607 /* create map fogs */
610 /* walk entity list */
611 for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
614 entity = &entities[ mapEntityNum ];
615 if ( entity->brushes == NULL && entity->patches == NULL ) {
619 /* process the model */
620 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
621 if ( mapEntityNum == 0 ) {
622 ProcessWorldModel(portalFilePath, lineFilePath);
628 /* potentially turn off the deluge of text */
629 verbose = verboseEntities;
632 /* restore -v setting */
633 verbose = oldVerbose;
638 /* vortex: emit meta stats */
646 this is probably broken unless teamed with a radiant version that preserves entity order
649 void OnlyEnts( const char *BSPFilePath ){
650 char save_cmdline[1024], save_version[1024], save_gridsize[1024];
654 Sys_Printf( "--- OnlyEnts ---\n" );
656 LoadBSPFile( BSPFilePath );
659 p = ValueForKey( &entities[0], "_q3map2_cmdline" );
660 strncpy( save_cmdline, p, sizeof( save_cmdline ) );
661 save_cmdline[sizeof( save_cmdline ) - 1] = 0;
662 p = ValueForKey( &entities[0], "_q3map2_version" );
663 strncpy( save_version, p, sizeof( save_version ) );
664 save_version[sizeof( save_version ) - 1] = 0;
665 p = ValueForKey( &entities[0], "gridsize" );
666 strncpy( save_gridsize, p, sizeof( save_gridsize ) );
667 save_gridsize[sizeof( save_gridsize ) - 1] = 0;
672 LoadMapFile( name, qfalse, qfalse );
676 if ( *save_cmdline ) {
677 SetKeyValue( &entities[0], "_q3map2_cmdline", save_cmdline );
679 if ( *save_version ) {
680 SetKeyValue( &entities[0], "_q3map2_version", save_version );
682 if ( *save_gridsize ) {
683 SetKeyValue( &entities[0], "gridsize", save_gridsize );
686 numBSPEntities = numEntities;
689 WriteBSPFile( BSPFilePath );
696 handles creation of a bsp from a map file
699 int BSPMain( int argc, char **argv ){
701 char path[ 1024 ], tempSource[ 1024 ];
702 qboolean onlyents = qfalse;
703 char BSPFilePath [ 1024 ];
704 char lineFilePath [ 1024 ];
705 char portalFilePath [ 1024 ];
706 char surfaceFilePath [ 1024 ];
709 portalFilePath[0] = 0;
710 surfaceFilePath[0] = 0;
712 if ( argc >= 2 && !strcmp( argv[ 1 ], "-bsp" ) ) {
713 Sys_Printf( "-bsp argument unnecessary\n" );
719 Sys_Printf( "--- BSP ---\n" );
721 SetDrawSurfacesBuffer();
722 mapDrawSurfs = safe_malloc0( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
725 tempSource[ 0 ] = '\0';
726 globalCelShader[0] = 0;
728 /* set standard game flags */
729 maxSurfaceVerts = game->maxSurfaceVerts;
730 maxSurfaceIndexes = game->maxSurfaceIndexes;
731 emitFlares = game->emitFlares;
732 texturesRGB = game->texturesRGB;
733 colorsRGB = game->colorsRGB;
735 /* process arguments */
736 for ( i = 1; i < ( argc - 1 ); i++ )
738 if ( !strcmp( argv[ i ], "-onlyents" ) ) {
739 Sys_Printf( "Running entity-only compile\n" );
742 else if ( !strcmp( argv[ i ], "-tempname" ) ) {
743 strcpy( tempSource, argv[ ++i ] );
745 else if ( !strcmp( argv[ i ], "-tmpout" ) ) {
746 strcpy( outbase, "/tmp" );
748 else if ( !strcmp( argv[ i ], "-nowater" ) ) {
749 Sys_Printf( "Disabling water\n" );
752 else if ( !strcmp( argv[ i ], "-keeplights" ) ) {
754 Sys_Printf( "Leaving light entities on map after compile\n" );
756 else if ( !strcmp( argv[ i ], "-nodetail" ) ) {
757 Sys_Printf( "Ignoring detail brushes\n" ) ;
760 else if ( !strcmp( argv[ i ], "-fulldetail" ) ) {
761 Sys_Printf( "Turning detail brushes into structural brushes\n" );
764 else if ( !strcmp( argv[ i ], "-nofog" ) ) {
765 Sys_Printf( "Fog volumes disabled\n" );
768 else if ( !strcmp( argv[ i ], "-nosubdivide" ) ) {
769 Sys_Printf( "Disabling brush face subdivision\n" );
772 else if ( !strcmp( argv[ i ], "-leaktest" ) ) {
773 Sys_Printf( "Leaktest enabled\n" );
776 else if ( !strcmp( argv[ i ], "-verboseentities" ) ) {
777 Sys_Printf( "Verbose entities enabled\n" );
778 verboseEntities = qtrue;
780 else if ( !strcmp( argv[ i ], "-nocurves" ) ) {
781 Sys_Printf( "Ignoring curved surfaces (patches)\n" );
782 noCurveBrushes = qtrue;
784 else if ( !strcmp( argv[ i ], "-notjunc" ) ) {
785 Sys_Printf( "T-junction fixing disabled\n" );
788 else if ( !strcmp( argv[ i ], "-fakemap" ) ) {
789 Sys_Printf( "Generating fakemap.map\n" );
792 else if ( !strcmp( argv[ i ], "-samplesize" ) ) {
793 sampleSize = atoi( argv[ i + 1 ] );
794 if ( sampleSize < 1 ) {
798 Sys_Printf( "Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
800 else if ( !strcmp( argv[ i ], "-minsamplesize" ) ) {
801 minSampleSize = atoi( argv[ i + 1 ] );
802 if ( minSampleSize < 1 ) {
806 Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
808 else if ( !strcmp( argv[ i ], "-custinfoparms" ) ) {
809 Sys_Printf( "Custom info parms enabled\n" );
810 useCustomInfoParms = qtrue;
814 else if ( !strcmp( argv[ i ], "-rename" ) ) {
815 Sys_Printf( "Appending _bsp suffix to misc_model shaders (SOF2)\n" );
816 renameModelShaders = qtrue;
820 else if ( !strcmp( argv[ i ], "-ne" ) ) {
821 normalEpsilon = atof( argv[ i + 1 ] );
823 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
825 else if ( !strcmp( argv[ i ], "-de" ) ) {
826 distanceEpsilon = atof( argv[ i + 1 ] );
828 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
830 else if ( !strcmp( argv[ i ], "-fastmeta" ) ) {
831 maxLMSurfaceVerts = 64;
832 maxSurfaceVerts = 999;
833 maxSurfaceIndexes = 6000;
834 Sys_Printf( "Maximum per-surface vertex count set to %d\n", maxSurfaceVerts );
835 Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
836 Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
838 else if ( !strcmp( argv[ i ], "-maxsurfacevertices" ) ) {
839 maxSurfaceVerts = atoi( argv[ i + 1 ] );
840 if ( maxSurfaceVerts < 3 ) {
844 Sys_Printf( "Maximum per-surface vertex count set to %d\n", maxSurfaceVerts );
846 else if ( !strcmp( argv[ i ], "-maxsurfaceindexes" ) || !strcmp( argv[ i ], "-mi" ) ) {
847 maxSurfaceIndexes = atoi( argv[ i + 1 ] );
848 if ( maxSurfaceIndexes < 3 ) {
849 maxSurfaceIndexes = 3;
853 if ( !strcmp( argv[ i ], "-mi" ) ) {
854 Sys_Printf( "The -mi argument is deprecated, use \"-maxsurfaceindexes\" instead\n" );
857 Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
860 else if ( !strcmp( argv[ i ], "-maxlightmapvertices" ) || !strcmp( argv[ i ], "-mv" ) ) {
861 maxLMSurfaceVerts = atoi( argv[ i + 1 ] );
862 if ( maxLMSurfaceVerts < 3 ) {
863 maxLMSurfaceVerts = 3;
865 if ( maxLMSurfaceVerts > maxSurfaceVerts ) {
866 maxSurfaceVerts = maxLMSurfaceVerts;
870 if ( !strcmp( argv[ i ], "-mv" ) ) {
871 Sys_Printf( "The -mv argument is deprecated, use \"-maxlightmapvertices\" instead\n" );
874 Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
877 else if ( !strcmp( argv[ i ], "-np" ) ) {
878 npDegrees = atof( argv[ i + 1 ] );
879 if ( npDegrees < 0.0f ) {
882 else if ( npDegrees > 0.0f ) {
883 Sys_Printf( "Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees );
887 else if ( !strcmp( argv[ i ], "-snap" ) ) {
888 bevelSnap = atoi( argv[ i + 1 ] );
889 if ( bevelSnap < 0 ) {
893 if ( bevelSnap > 0 ) {
894 Sys_Printf( "Snapping brush bevel planes to %d units\n", bevelSnap );
897 else if ( !strcmp( argv[ i ], "-texrange" ) ) {
898 texRange = atoi( argv[ i + 1 ] );
899 if ( texRange < 0 ) {
903 Sys_Printf( "Limiting per-surface texture range to %d texels\n", texRange );
905 else if ( !strcmp( argv[ i ], "-nohint" ) ) {
906 Sys_Printf( "Hint brushes disabled\n" );
909 else if ( !strcmp( argv[ i ], "-flat" ) ) {
910 Sys_Printf( "Flatshading enabled\n" );
913 else if ( !strcmp( argv[ i ], "-celshader" ) ) {
916 sprintf( globalCelShader, "textures/%s", argv[ i ] );
919 *globalCelShader = 0;
921 Sys_Printf( "Global cel shader set to \"%s\"\n", globalCelShader );
923 else if ( !strcmp( argv[ i ], "-meta" ) ) {
924 Sys_Printf( "Creating meta surfaces from brush faces\n" );
927 else if ( !strcmp( argv[ i ], "-metaadequatescore" ) ) {
928 metaAdequateScore = atoi( argv[ i + 1 ] );
929 if ( metaAdequateScore < 0 ) {
930 metaAdequateScore = -1;
933 if ( metaAdequateScore >= 0 ) {
934 Sys_Printf( "Setting ADEQUATE meta score to %d (see surface_meta.c)\n", metaAdequateScore );
937 else if ( !strcmp( argv[ i ], "-metagoodscore" ) ) {
938 metaGoodScore = atoi( argv[ i + 1 ] );
939 if ( metaGoodScore < 0 ) {
943 if ( metaGoodScore >= 0 ) {
944 Sys_Printf( "Setting GOOD meta score to %d (see surface_meta.c)\n", metaGoodScore );
947 else if ( !strcmp( argv[ i ], "-metamaxbboxdistance" ) ) {
948 metaMaxBBoxDistance = atof( argv[ i + 1 ] );
949 if ( metaMaxBBoxDistance < 0 ) {
950 metaMaxBBoxDistance = -1;
953 if ( metaMaxBBoxDistance >= 0 ) {
954 Sys_Printf( "Setting meta maximum bounding box distance to %f\n", metaMaxBBoxDistance );
957 else if ( !strcmp( argv[ i ], "-patchmeta" ) ) {
958 Sys_Printf( "Creating meta surfaces from patches\n" );
961 else if ( !strcmp( argv[ i ], "-flares" ) ) {
962 Sys_Printf( "Flare surfaces enabled\n" );
965 else if ( !strcmp( argv[ i ], "-noflares" ) ) {
966 Sys_Printf( "Flare surfaces disabled\n" );
969 else if ( !strcmp( argv[ i ], "-skyfix" ) ) {
970 Sys_Printf( "GL_CLAMP sky fix/hack/workaround enabled\n" );
973 else if ( !strcmp( argv[ i ], "-debugsurfaces" ) ) {
974 Sys_Printf( "emitting debug surfaces\n" );
975 debugSurfaces = qtrue;
977 else if ( !strcmp( argv[ i ], "-debuginset" ) ) {
978 Sys_Printf( "Debug surface triangle insetting enabled\n" );
981 else if ( !strcmp( argv[ i ], "-debugportals" ) ) {
982 Sys_Printf( "Debug portal surfaces enabled\n" );
983 debugPortals = qtrue;
985 else if ( !strcmp( argv[ i ], "-sRGBtex" ) ) {
987 Sys_Printf( "Textures are in sRGB\n" );
989 else if ( !strcmp( argv[ i ], "-nosRGBtex" ) ) {
990 texturesRGB = qfalse;
991 Sys_Printf( "Textures are linear\n" );
993 else if ( !strcmp( argv[ i ], "-sRGBcolor" ) ) {
995 Sys_Printf( "Colors are in sRGB\n" );
997 else if ( !strcmp( argv[ i ], "-nosRGBcolor" ) ) {
999 Sys_Printf( "Colors are linear\n" );
1001 else if ( !strcmp( argv[ i ], "-nosRGB" ) ) {
1002 texturesRGB = qfalse;
1003 Sys_Printf( "Textures are linear\n" );
1005 Sys_Printf( "Colors are linear\n" );
1007 else if ( !strcmp( argv[ i ], "-altsplit" ) )
1009 Sys_Printf( "Alternate BSP splitting (by 27) enabled\n" );
1010 bspAlternateSplitWeights = qtrue;
1012 else if ( !strcmp( argv[ i ], "-deep" ) )
1014 Sys_Printf( "Deep BSP tree generation enabled\n" );
1017 else if ( !strcmp( argv[ i ], "-maxarea" ) ) {
1018 Sys_Printf( "Max Area face surface generation enabled\n" );
1019 maxAreaFaceSurface = qtrue;
1021 else if ( !strcmp( argv[ i ], "-bspfile" ) )
1023 strcpy( BSPFilePath, argv[i + 1] );
1025 Sys_Printf( "Use %s as bsp file\n", BSPFilePath );
1027 else if ( !strcmp( argv[ i ], "-linfile" ) )
1029 strcpy( lineFilePath, argv[i + 1] );
1031 Sys_Printf( "Use %s as line file\n", lineFilePath );
1033 else if ( !strcmp( argv[ i ], "-prtfile" ) )
1035 strcpy( portalFilePath, argv[i + 1] );
1037 Sys_Printf( "Use %s as portal file\n", portalFilePath );
1039 else if ( !strcmp( argv[ i ], "-srffile" ) )
1041 strcpy( surfaceFilePath, argv[i + 1] );
1043 Sys_Printf( "Use %s as surface file\n", surfaceFilePath );
1046 Sys_FPrintf( SYS_WRN, "WARNING: Unknown option \"%s\"\n", argv[ i ] );
1050 /* fixme: print more useful usage here */
1051 if ( i != ( argc - 1 ) ) {
1052 Error( "usage: q3map [options] mapfile" );
1055 /* copy source name */
1056 strcpy( source, ExpandArg( argv[ i ] ) );
1057 StripExtension( source );
1059 /* ydnar: set default sample size */
1060 SetDefaultSampleSize( sampleSize );
1062 if (!BSPFilePath[0]) {
1063 sprintf( BSPFilePath, "%s.bsp", source );
1065 if (!lineFilePath[0]) {
1066 sprintf( lineFilePath, "%s.lin", source );
1068 if (!portalFilePath[0]) {
1069 sprintf( portalFilePath, "%s.prt", source );
1071 if (!surfaceFilePath[0]) {
1072 sprintf( surfaceFilePath, "%s.srf", source );
1075 /* delete portal, line and surface files */
1076 remove( portalFilePath );
1077 remove( lineFilePath );
1078 //% remove( surfaceFilePath ) /* ydnar */
1080 /* expand mapname */
1081 strcpy( name, ExpandArg( argv[ i ] ) );
1082 if ( strcmp( name + strlen( name ) - 4, ".reg" ) ) {
1083 /* if we are doing a full map, delete the last saved region map */
1084 sprintf( path, "%s.reg", source );
1086 DefaultExtension( name, ".map" ); /* might be .reg */
1089 /* if onlyents, just grab the entites and resave */
1091 OnlyEnts( BSPFilePath );
1098 /* load original file from temp spot in case it was renamed by the editor on the way in */
1099 if ( strlen( tempSource ) > 0 ) {
1100 LoadMapFile( tempSource, qfalse, qfalse );
1103 LoadMapFile( name, qfalse, qfalse );
1106 /* div0: inject command line parameters */
1107 InjectCommandLine( argv, 1, argc - 1 );
1109 /* ydnar: decal setup */
1112 /* ydnar: cloned brush model entities */
1113 SetCloneModelNumbers();
1115 /* process world and submodels */
1116 ProcessModels( portalFilePath, lineFilePath );
1118 /* set light styles from targetted light entities */
1121 /* process in game advertisements */
1122 ProcessAdvertisements();
1124 /* finish and write bsp */
1125 EndBSPFile( qtrue, BSPFilePath, surfaceFilePath );
1127 /* remove temp map source file if appropriate */
1128 if ( strlen( tempSource ) > 0 ) {
1129 remove( tempSource );
1132 /* return to sender */