2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 qboolean g_stripify = qtrue;
32 qboolean g_release; // don't grab, copy output data to new tree
33 char g_releasedir[1024]; // c:\quake2\baseq2, etc
34 qboolean g_archive; // don't grab, copy source data to new tree
35 char g_only[256]; // if set, only grab this cd
36 qboolean g_skipmodel; // set true when a cd is not g_only
38 // bogus externs for some TA hacks (common/ using them against q3map)
40 // some old defined that was in cmdlib lost during merge
43 #if defined (__linux__) || defined (__APPLE__)
44 #define strlwr strlower
48 =======================================================
52 =======================================================
55 unsigned Com_BlockChecksum (void *buffer, int length);
70 packfile_t pfiles[16384];
73 packheader_t pakheader;
79 Filename should be gamedir reletive.
80 Either copies the file to the release dir, or adds it to
84 void ReleaseFile (char *filename)
92 sprintf (source, "%s%s", gamedir, filename);
93 sprintf (dest, "%s/%s", g_releasedir, filename);
94 printf ("copying to %s\n", dest);
95 QCopyFile (source, dest);
110 ShaderFiles_t s_shaderFiles;
112 void FindShaderFiles( char *filename )
116 char linebuffer[1024];
119 char *diffuseExtensions[] =
126 char *otherExtensions[] =
134 s_shaderFiles.num = 0;
136 strcpy( stripped, filename );
137 if ( strrchr( stripped, '.' ) )
138 *strrchr( stripped, '.' ) = 0;
139 strcat( stripped, ".shader" );
141 if ( FileExists( stripped ) )
144 char mapa[512], mapb[512];
146 strcpy( s_shaderFiles.names[s_shaderFiles.num], stripped );
150 len = LoadFile( stripped, (void **)&buf);
154 while ( p - buf < len )
159 while ( *p == ' ' || *p == '\n' || *p == '\t' )
162 // grab rest of the line
163 while ( *p != 0 && *p != '\n' )
173 strlwr( linebuffer );
175 // see if the line specifies an opaque map or blendmap
176 if ( strstr( linebuffer, "opaquemap" ) == linebuffer ||
177 strstr( linebuffer, "blendmap" ) == linebuffer )
183 mapa[0] = mapb[0] = 0;
185 // skip past the keyword
186 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
189 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
192 // grab first map name
194 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
196 mapa[j] = linebuffer[i];
203 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
206 // grab second map name
208 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
210 mapb[j] = linebuffer[i];
217 if ( mapa[0] != 0 && mapa[0] != '-' )
219 sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapa );
222 if ( mapb[0] != 0 && mapb[0] != '-' && mapb[0] != '^' && mapb[0] != '*' )
224 sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapb );
232 if ( strrchr( stripped, '.' ) )
233 *strrchr( stripped, '.' ) = 0;
235 // look for diffuse maps
236 for ( i = 0; i < 3; i++ )
238 strcpy( buffer, stripped );
239 strcat( buffer, diffuseExtensions[i] );
240 if ( FileExists( buffer ) )
242 strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
247 for ( i = 0; i < 3; i++ )
249 strcpy( buffer, stripped );
250 strcat( buffer, otherExtensions[i] );
251 if ( FileExists( buffer ) )
253 strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
264 Copies all needed files for a shader to the release directory
267 void ReleaseShader( char *filename )
274 sprintf( fullpath, "%s%s", gamedir, filename );
276 FindShaderFiles( fullpath );
278 for ( i = 0; i < s_shaderFiles.num; i++ )
280 strcpy( stripped, s_shaderFiles.names[i] );
281 if ( strstr( stripped, gamedir ) )
283 memmove( stripped, stripped+ strlen( gamedir ), strlen( stripped ) );
285 sprintf( dest, "%s/%s", g_releasedir, stripped );
286 printf ("copying to %s\n", dest );
287 QCopyFile( s_shaderFiles.names[i], dest );
295 This is only used to cause a file to be copied during a release
296 build (default.cfg, maps, etc)
313 void PackDirectory_r (char *dir)
315 struct _finddata_t fileinfo;
317 char dirstring[1024];
320 sprintf (dirstring, "%s%s/*.*", gamedir, dir);
322 handle = _findfirst (dirstring, &fileinfo);
328 sprintf (filename, "%s/%s", dir, fileinfo.name);
329 if (fileinfo.attrib & _A_SUBDIR)
331 if (fileinfo.name[0] != '.') // don't pak . and ..
332 PackDirectory_r (filename);
335 // copy or pack the file
336 ReleaseFile (filename);
337 } while (_findnext( handle, &fileinfo ) != -1);
343 #include <sys/types.h>
347 #include <sys/dirent.h>
350 void PackDirectory_r (char *dir)
353 struct direct **namelist, *ent;
355 struct dirent **namelist, *ent;
362 char dirstring[1024];
365 sprintf (dirstring, "%s%s", gamedir, dir);
366 count = scandir(dirstring, &namelist, NULL, NULL);
368 for (i=0 ; i<count ; i++)
376 sprintf (fullname, "%s/%s", dir, name);
377 sprintf (dirstring, "%s%s/%s", gamedir, dir, name);
379 if (stat (dirstring, &st) == -1)
380 Error ("fstating %s", pf->name);
381 if (st.st_mode & S_IFDIR)
383 PackDirectory_r (fullname);
387 // copy or pack the file
388 ReleaseFile (fullname);
398 This is only used to cause a directory to be copied during a
399 release build (sounds, etc)
405 PackDirectory_r (token);
408 //========================================================================
410 #define MAX_RTEX 16384
412 char rtex[MAX_RTEX][64];
414 void ReleaseTexture (char *name)
419 for (i=0 ; i<numrtex ; i++)
420 if (!Q_stricmp(name, rtex[i]))
423 if (numrtex == MAX_RTEX)
424 Error ("numrtex == MAX_RTEX");
426 strcpy (rtex[i], name);
429 sprintf (path, "textures/%s.wal", name);
437 Only relevent for release and pak files.
438 Releases the .bsp files for the maps, and scans all of the files to
439 build a list of all textures used, which are then released.
446 while (TokenAvailable ())
449 sprintf (map, "maps/%s.bsp", token);
455 // get all the texture references
456 sprintf (map, "%smaps/%s.bsp", gamedir, token);
462 //==============================================================
469 void ParseScript (void)
474 { // look for a line starting with a $ command
480 while (TokenAvailable())
487 if (!strcmp (token, "$modelname"))
489 else if (!strcmp (token, "$base"))
491 else if ( !strcmp( token, "$exit" ) )
493 else if ( !strcmp( token, "$3dsconvert" ) )
495 else if (!strcmp (token, "$spritebase"))
497 else if (!strcmp (token, "$cd"))
499 else if (!strcmp (token, "$origin"))
501 else if (!strcmp (token, "$scale"))
503 else if (!strcmp (token, "$frame"))
505 else if (!strcmp (token, "$skin" ))
507 else if (!strcmp (token, "$spriteshader"))
509 else if (!strcmp( token, "$aseconvert" ))
510 Cmd_ASEConvert( qfalse );
511 else if (!strcmp( token, "$aseanimconvert" ) )
512 Cmd_ASEConvert( qtrue );
517 else if (!strcmp (token, "$grab"))
519 else if (!strcmp (token, "$raw"))
521 else if (!strcmp (token, "$colormap"))
523 else if (!strcmp (token, "$environment"))
529 else if (!strcmp (token, "$video"))
534 else if (!strcmp (token, "$file"))
536 else if (!strcmp (token, "$dir"))
538 else if (!strcmp (token, "$maps"))
541 Error ("bad command %s\n", token);
545 //=======================================================
554 int main (int argc, char **argv)
556 static int i; // VC4.2 compiler bug if auto...
559 // using GtkRadiant's versioning next to Id's versioning
560 printf ("Q3Data - (c) 1999 Id Software Inc.\n");
561 printf ("NetRadiant - v" RADIANT_VERSION " " __DATE__ "\n");
563 ExpandWildcards (&argc, &argv);
565 for (i=1 ; i<argc ; i++)
567 if (!strcmp(argv[i], "-archive"))
570 strcpy (archivedir, argv[i+1]);
571 printf ("Archiving source to: %s\n", archivedir);
574 else if (!strcmp(argv[i], "-release"))
577 strcpy (g_releasedir, argv[i+1]);
578 printf ("Copy output to: %s\n", g_releasedir);
581 else if ( !strcmp( argv[i], "-nostrips" ) )
584 printf( "Not optimizing for strips\n" );
586 else if ( !strcmp( argv[i], "-writedir" ) )
588 strcpy( writedir, argv[i+1] );
589 printf( "Write output to: %s\n", writedir );
592 else if ( !strcmp( argv[i], "-verbose" ) )
596 else if ( !strcmp( argv[i], "-dump" ) )
598 printf( "Dumping contents of: '%s'\n", argv[i+1] );
599 if ( strstr( argv[i+1], ".md3" ) )
601 MD3_Dump( argv[i+1] );
605 Error( "Do not know how to dump the contents of '%s'\n", argv[i+1] );
609 else if ( !strcmp( argv[i], "-3dsconvert" ) )
611 // NOTE TTimo this is broken, tried on a sample .3ds
612 // what happens .. it calls the Convert3DStoMD3,
613 // which calls the scriptlib function in non initialized state .. and crashes
614 printf( "Converting %s.3DS to %s.MD3\n", argv[i+1], argv[i+1] );
615 SetQdirFromPath( argv[i+1] );
616 vfsInitDirectory( gamedir );
617 Convert3DStoMD3( argv[i+1] );
620 else if (!strcmp(argv[i], "-only"))
622 strcpy (g_only, argv[i+1]);
623 printf ("Only grabbing %s\n", g_only);
626 else if (!strcmp(argv[i], "-gamedir"))
628 strcpy(gamedir, argv[i+1]);
631 else if (argv[i][0] == '-')
632 Error ("Unknown option \"%s\"", argv[i]);
638 Error ("usage: q3data [-archive <directory>] [-dump <file.md3>] [-release <directory>] [-only <model>] [-3dsconvert <file.3ds>] [-verbose] [file.qdt]");
640 for ( ; i<argc ; i++)
642 printf ("--------------- %s ---------------\n", argv[i]);
644 strcpy (path, argv[i]);
645 DefaultExtension (path, ".qdt");
647 SetQdirFromPath (path);
649 // q3data went through a partial conversion to use the vfs
650 // it was never actually tested before 1.1.1
651 // the code is still mostly using direct file access calls
652 vfsInitDirectory( gamedir );
653 LoadScriptFile (ExpandArg(path), -1);
660 // write out the last model
661 FinishModel ( TYPE_UNKNOWN );