]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/writebsp.c
q3map2: make Smokin'Guns code not requiring a rebuild
[xonotic/netradiant.git] / tools / quake3 / q3map2 / writebsp.c
index 9cfa577baeb8459de4e28c3aae6e6feaf9b6a7ab..3fbed1cc64dfb25a1f4a705baf50e9e22aa1d53c 100644 (file)
@@ -36,8 +36,7 @@
 /* dependencies */
 #include "q3map2.h"
 
-#ifdef SMOKINGUNS
-#define NUM_PREFIXINFO 11 //very important
+
 
 //prefixInfo-stats
 typedef struct {
@@ -45,21 +44,22 @@ typedef struct {
        int             surfaceFlags;
 } prefixInfo_t;
 
-
 static prefixInfo_t prefixInfo[] = {
-       { "metal",      Q_SURF_METAL},
-       { "wood",       Q_SURF_WOOD},
-       { "cloth",      Q_SURF_CLOTH},
-       { "dirt",       Q_SURF_DIRT},
-       { "glass",      Q_SURF_GLASS},
-       { "plant",      Q_SURF_PLANT},
-       { "sand",       Q_SURF_SAND},
-       { "snow",       Q_SURF_SNOW},
-       { "stone",      Q_SURF_STONE},
-       { "water",      Q_SURF_WATER},
-       { "grass",      Q_SURF_GRASS},
+       { "metal",      TEX_SURF_METAL},
+       { "wood",       TEX_SURF_WOOD},
+       { "cloth",      TEX_SURF_CLOTH},
+       { "dirt",       TEX_SURF_DIRT},
+       { "glass",      TEX_SURF_GLASS},
+       { "plant",      TEX_SURF_PLANT},
+       { "sand",       TEX_SURF_SAND},
+       { "snow",       TEX_SURF_SNOW},
+       { "stone",      TEX_SURF_STONE},
+       { "water",      TEX_SURF_WATER},
+       { "grass",      TEX_SURF_GRASS},
 };
 
+#define NUM_PREFIXINFO 11 /* very important */
+
 //Added by Spoon to recognize surfaceparms by shadernames
 int GetSurfaceParm(const char *tex){
        char surf[MAX_QPATH], tex2[MAX_QPATH];
@@ -67,7 +67,7 @@ int GetSurfaceParm(const char *tex){
 
        strcpy(tex2, tex);
 
-       //find last dir
+       /* find last dir */
        for(i = 0; i < 64 && tex2[i] != '\0'; i++){
                if(tex2[i] == '\\' || tex2[i] == '/')
                        j=i+1;
@@ -81,7 +81,7 @@ int GetSurfaceParm(const char *tex){
        }
        surf[i] = '\0';
 
-       //Sys_Printf("%s\n", surf);
+       /* Sys_Printf("%s\n", surf); */
 
        for(i=0; i < NUM_PREFIXINFO; i++){
                if(!Q_stricmp(surf, prefixInfo[i].name)){
@@ -90,7 +90,6 @@ int GetSurfaceParm(const char *tex){
        }
        return 0;
 }
-#endif
 
 
 
@@ -112,15 +111,17 @@ int EmitShader( const char *shader, int *contentFlags, int *surfaceFlags ){
        /* try to find an existing shader */
        for ( i = 0; i < numBSPShaders; i++ )
        {
-               /* ydnar: handle custom surface/content flags */
-#ifndef SMOKINGUNS
-               if ( surfaceFlags != NULL && bspShaders[ i ].surfaceFlags != *surfaceFlags ) {
-                       continue;
-               }
-               if ( contentFlags != NULL && bspShaders[ i ].contentFlags != *contentFlags ) {
-                       continue;
+               /* if not Smokin'Guns like tex file */
+               if ( !game->texFile )
+               {
+                       /* ydnar: handle custom surface/content flags */
+                       if ( surfaceFlags != NULL && bspShaders[ i ].surfaceFlags != *surfaceFlags ) {
+                               continue;
+                       }
+                       if ( contentFlags != NULL && bspShaders[ i ].contentFlags != *contentFlags ) {
+                               continue;
+                       }
                }
-#endif
 
                /* compare name */
                if ( !Q_stricmp( shader, bspShaders[ i ].shader ) ) {
@@ -137,20 +138,26 @@ int EmitShader( const char *shader, int *contentFlags, int *surfaceFlags ){
        numBSPShaders++;
        strcpy( bspShaders[ i ].shader, shader );
        bspShaders[ i ].surfaceFlags = si->surfaceFlags;
-#ifdef SMOKINGUNS
-       bspShaders[ i ].surfaceFlags |= GetSurfaceParm(si->shader);
-#endif
-       bspShaders[ i ].contentFlags = si->contentFlags;
 
-       /* handle custom content/surface flags */
-#ifndef SMOKINGUNS
-       if ( surfaceFlags != NULL ) {
-               bspShaders[ i ].surfaceFlags = *surfaceFlags;
+       if ( game->texFile )
+       {
+               /* Smokin'Guns like tex file */
+               bspShaders[ i ].surfaceFlags |= GetSurfaceParm(si->shader);
        }
-       if ( contentFlags != NULL ) {
-               bspShaders[ i ].contentFlags = *contentFlags;
+
+       bspShaders[ i ].contentFlags = si->contentFlags;
+
+       /* if not Smokin'Guns like tex file */
+       if ( !game->texFile )
+       {
+               /* handle custom content/surface flags */
+               if ( surfaceFlags != NULL ) {
+                       bspShaders[ i ].surfaceFlags = *surfaceFlags;
+               }
+               if ( contentFlags != NULL ) {
+                       bspShaders[ i ].contentFlags = *contentFlags;
+               }
        }
-#endif
 
        /* recursively emit any damage shaders */
        if ( si->damageShader != NULL && si->damageShader[ 0 ] != '\0' ) {
@@ -458,60 +465,76 @@ void BeginBSPFile( void ){
 
 
 
-#ifdef SMOKINGUNS
-//added by spoon to get back the changed surfaceflags
-void RestoreSurfaceFlags(char *filename){
+/*
+   RestoreSurfaceFlags()
+   read Smokin'Guns like tex file
+   added by spoon to get back the changed surfaceflags
+ */
+
+void RestoreSurfaceFlags( char *filename ) {
        int i;
-       FILE    *texfile;
-       int             surfaceFlags[MAX_MAP_DRAW_SURFS];
-       int             numTexInfos;
+       FILE *texfile;
+       int surfaceFlags[ MAX_MAP_DRAW_SURFS ];
+       int numTexInfos;
+
+       /* first parse the tex file */
+       texfile = fopen( filename, "r" );
 
-       //first parse the tex-file
-       texfile = fopen(filename, "r");
-       if(texfile){
-               fscanf( texfile, "TEXFILE\n%i\n", &numTexInfos);
-               //Sys_Printf("%i\n", numTexInfos);
+       if ( texfile ) {
+               fscanf( texfile, "TEXFILE\n%i\n", &numTexInfos );
 
-               for(i=0; i<numTexInfos; i++){
+               /* Sys_Printf( "%i\n", numTexInfos ); */
+
+               for ( i = 0; i < numTexInfos; i++ ) {
                        vec3_t color;
-                       fscanf( texfile, "%i %f %f %f\n", &surfaceFlags[i],
-                               &color[0], &color[1], &color[2]);
-                       bspShaders[i].surfaceFlags = surfaceFlags[i];
-                       //Sys_Printf("%i\n", surfaceFlags[i]);
+
+                       fscanf( texfile, "%i %f %f %f\n", &surfaceFlags[ i ],
+                               &color[ 0 ], &color[ 1 ], &color[ 2 ]);
+
+                       bspShaders[ i ].surfaceFlags = surfaceFlags[ i ];
+
+                       /* Sys_Printf( "%i\n", surfaceFlags[ i ] ); */
                }
-       } else
+       } else {
                Sys_Printf("couldn't find %s not tex-file is now writed without surfaceFlags!\n", filename);
+       }
 }
 
-void WriteTexFile( char* name){
-       FILE                    *texfile;
-       char                    filename[1024];
-       int                             i;
 
-       sprintf (filename, "%s.tex", name);
 
-       if(!compile_map){
-               RestoreSurfaceFlags(filename);
+/*
+   WriteTexFile()
+   write Smokin'Guns like tex file
+   added by spoon
+ */
+
+void WriteTexFile( char* filename ) {
+       FILE *texfile;
+       int i;
+
+       if ( !compile_map ) {
+               RestoreSurfaceFlags( filename );
        }
 
-       Sys_Printf("Writing %s ...\n", filename);
-       texfile = fopen (filename, "w");
+       Sys_Printf( "Writing %s ...\n", filename );
 
-       fprintf( texfile, "TEXFILE\n");
+       texfile = fopen ( filename, "w" );
 
-       fprintf( texfile, "%i\n", numBSPShaders);
-       for ( i = 0 ; i < numBSPShaders ; i++ ) {
-               shaderInfo_t    *se = ShaderInfoForShader(bspShaders[i].shader);
+       fprintf( texfile, "TEXFILE\n" );
+
+       fprintf( texfile, "%i\n", numBSPShaders );
 
-               fprintf( texfile, "\n%i %f %f %f", bspShaders[i].surfaceFlags,
-                       se->color[0], se->color[1], se->color[2]);
+       for ( i = 0 ; i < numBSPShaders ; i++ ) {
+               shaderInfo_t *se = ShaderInfoForShader( bspShaders[ i ].shader );
 
+               fprintf( texfile, "\n%i %f %f %f", bspShaders[ i ].surfaceFlags,
+                       se->color[ 0 ], se->color[ 1 ], se->color[ 2 ] );
 
-               bspShaders[i].surfaceFlags = i;
+               bspShaders[ i ].surfaceFlags = i;
        }
-       fclose(texfile);
+
+       fclose( texfile );
 }
-#endif
 
 
 
@@ -533,10 +556,16 @@ void EndBSPFile( qboolean do_write, const char *BSPFilePath, const char *surface
                /* write the surface extra file */
                WriteSurfaceExtraFile( surfaceFilePath );
 
-#ifdef SMOKINGUNS
-               //only create tex file if it is the first compile
-               WriteTexFile (source);
-#endif
+               if ( game->texFile )
+               {
+                       char basename[ 1024 ];  
+                       char filename[ 1024 ];
+                       strncpy( basename, BSPFilePath, sizeof(basename) );
+                       sprintf( filename, "%s.tex", basename );
+
+                       /* only create tex file if it is the first compile */
+                       WriteTexFile( filename );
+               }
 
                /* write the bsp */
                Sys_Printf( "Writing %s\n", BSPFilePath );