]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/bsp.c
Backing out commit 483. Going to set linker flags instead.
[xonotic/netradiant.git] / tools / quake3 / q3map2 / bsp.c
index ed3d243079cacf2b6df87f94e90281b378fa3997..aeaf73635c618d713f3e04fd87e105d2e482c17c 100644 (file)
@@ -1,4 +1,5 @@
-/*
+/* -------------------------------------------------------------------------------
+
 Copyright (C) 1999-2007 id Software, Inc. and contributors.
 For a list of contributors, see the accompanying CONTRIBUTORS file.
 
@@ -44,6 +45,76 @@ functions
 ------------------------------------------------------------------------------- */
 
 
+/*
+ProcessAdvertisements()
+copies advertisement info into the BSP structures
+*/
+
+static void ProcessAdvertisements( void ) {
+       int                                     i;
+       const char*                     className;
+       const char*                     modelKey;
+       int                                     modelNum;
+       bspModel_t*                     adModel;
+       bspDrawSurface_t*       adSurface;
+
+       Sys_FPrintf( SYS_VRB, "--- ProcessAdvertisements ---\n" );
+
+       for( i = 0; i < numEntities; i++ ) {
+
+               /* is an advertisement? */
+               className = ValueForKey( &entities[ i ], "classname" );
+
+               if( !Q_stricmp( "advertisement", className ) ) {
+                       
+                       modelKey = ValueForKey( &entities[ i ], "model" );
+
+                       if( strlen( modelKey ) > MAX_QPATH - 1 ) {
+                               Error( "Model Key for entity exceeds ad struct string length." );
+                       } else {
+                               if( numBSPAds < MAX_MAP_ADVERTISEMENTS ) {
+                                       bspAds[numBSPAds].cellId = IntForKey( &entities[ i ], "cellId" );
+                                       strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) );
+
+                                       modelKey++;
+                                       modelNum = atoi( modelKey );
+                                       adModel = &bspModels[modelNum];
+                                       
+                                       if( adModel->numBSPSurfaces != 1 ) {
+                                               Error( "Ad cell id %d has more than one surface.", bspAds[numBSPAds].cellId );
+                                       }
+
+                                       adSurface = &bspDrawSurfaces[adModel->firstBSPSurface];
+                                       
+                                       // store the normal for use at run time.. all ad verts are assumed to 
+                                       // have identical normals (because they should be a simple rectangle)
+                                       // so just use the first vert's normal
+                                       VectorCopy( bspDrawVerts[adSurface->firstVert].normal, bspAds[numBSPAds].normal );
+
+                                       // store the ad quad for quick use at run time
+                                       if( adSurface->surfaceType == MST_PATCH ) {
+                                               int v0 = adSurface->firstVert + adSurface->patchHeight - 1;
+                                               int v1 = adSurface->firstVert + adSurface->numVerts - 1;
+                                               int v2 = adSurface->firstVert + adSurface->numVerts - adSurface->patchWidth;
+                                               int v3 = adSurface->firstVert;
+                                               VectorCopy( bspDrawVerts[v0].xyz, bspAds[numBSPAds].rect[0] );
+                                               VectorCopy( bspDrawVerts[v1].xyz, bspAds[numBSPAds].rect[1] );
+                                               VectorCopy( bspDrawVerts[v2].xyz, bspAds[numBSPAds].rect[2] );
+                                               VectorCopy( bspDrawVerts[v3].xyz, bspAds[numBSPAds].rect[3] );
+                                       } else {
+                                               Error( "Ad cell %d has an unsupported Ad Surface type.", bspAds[numBSPAds].cellId );
+                                       }
+
+                                       numBSPAds++;
+                               } else {
+                                       Error( "Maximum number of map advertisements exceeded." );
+                               }
+                       }
+               }
+       }
+
+       Sys_FPrintf( SYS_VRB, "%9d in-game advertisements\n", numBSPAds );
+}
 
 /*
 SetCloneModelNumbers() - ydnar
@@ -586,7 +657,9 @@ int BSPMain( int argc, char **argv )
        
        tempSource[ 0 ] = '\0';
        
-       /* set flares flag */
+       /* set standard game flags */
+       maxSurfaceVerts = game->maxSurfaceVerts;
+       maxSurfaceIndexes = game->maxSurfaceIndexes;
        emitFlares = game->emitFlares;
        
        /* process arguments */
@@ -687,11 +760,13 @@ int BSPMain( int argc, char **argv )
                }
                else if( !strcmp( argv[ i ],  "-mv" ) )
                {
-                       maxSurfaceVerts = atoi( argv[ i + 1 ] );
-                       if( maxSurfaceVerts < 3 )
-                               maxSurfaceVerts = 3;
+                       maxLMSurfaceVerts = atoi( argv[ i + 1 ] );
+                       if( maxLMSurfaceVerts < 3 )
+                               maxLMSurfaceVerts = 3;
+                       if( maxLMSurfaceVerts > maxSurfaceVerts )
+                               maxSurfaceVerts = maxLMSurfaceVerts;
                        i++;
-                       Sys_Printf( "Maximum per-surface vertex count set to %d\n", maxSurfaceVerts );
+                       Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
                }
                else if( !strcmp( argv[ i ],  "-mi" ) )
                {
@@ -840,6 +915,9 @@ int BSPMain( int argc, char **argv )
        /* set light styles from targetted light entities */
        SetLightStyles();
        
+       /* process in game advertisements */
+       ProcessAdvertisements();
+
        /* finish and write bsp */
        EndBSPFile();