2 Copyright (C) 1999-2007 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
22 #include "globaldefs.h"
26 #endif // GDEF_OS_WINDOWS
34 qboolean g_stripify = qtrue;
35 qboolean g_release; // don't grab, copy output data to new tree
36 char g_releasedir[1024]; // c:\quake2\baseq2, etc
37 qboolean g_archive; // don't grab, copy source data to new tree
38 char g_only[256]; // if set, only grab this cd
39 qboolean g_skipmodel; // set true when a cd is not g_only
41 // bogus externs for some TA hacks (common/ using them against q3map)
43 // some old defined that was in cmdlib lost during merge
47 #define strlwr strlower
48 #endif // !GDEF_OS_WINDOWS
51 =======================================================
55 =======================================================
58 unsigned Com_BlockChecksum( void *buffer, int length );
73 packfile_t pfiles[16384];
76 packheader_t pakheader;
82 Filename should be gamedir reletive.
83 Either copies the file to the release dir, or adds it to
87 void ReleaseFile( char *filename ){
95 sprintf( source, "%s%s", gamedir, filename );
96 sprintf( dest, "%s/%s", g_releasedir, filename );
97 printf( "copying to %s\n", dest );
98 QCopyFile( source, dest );
113 ShaderFiles_t s_shaderFiles;
115 void FindShaderFiles( char *filename ){
118 char linebuffer[1024];
121 char *diffuseExtensions[] =
128 char *otherExtensions[] =
136 s_shaderFiles.num = 0;
138 strcpy( stripped, filename );
139 if ( strrchr( stripped, '.' ) ) {
140 *strrchr( stripped, '.' ) = 0;
142 strcat( stripped, ".shader" );
144 if ( FileExists( stripped ) ) {
146 char mapa[512], mapb[512];
148 strcpy( s_shaderFiles.names[s_shaderFiles.num], stripped );
152 len = LoadFile( stripped, (void **)&buf );
156 while ( p - buf < len )
161 while ( *p == ' ' || *p == '\n' || *p == '\t' )
164 // grab rest of the line
165 while ( *p != 0 && *p != '\n' )
176 strlwr( linebuffer );
178 // see if the line specifies an opaque map or blendmap
179 if ( strstr( linebuffer, "opaquemap" ) == linebuffer ||
180 strstr( linebuffer, "blendmap" ) == linebuffer ) {
185 mapa[0] = mapb[0] = 0;
187 // skip past the keyword
188 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
191 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
194 // grab first map name
196 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
198 mapa[j] = linebuffer[i];
205 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
208 // grab second map name
210 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
212 mapb[j] = linebuffer[i];
219 if ( mapa[0] != 0 && mapa[0] != '-' ) {
220 sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapa );
223 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;
236 // look for diffuse maps
237 for ( i = 0; i < 3; i++ )
239 strcpy( buffer, stripped );
240 strcat( buffer, diffuseExtensions[i] );
241 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 ) ) {
252 strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
263 Copies all needed files for a shader to the release directory
266 void ReleaseShader( char *filename ){
272 sprintf( fullpath, "%s%s", gamedir, filename );
274 FindShaderFiles( fullpath );
276 for ( i = 0; i < s_shaderFiles.num; i++ )
278 strcpy( stripped, s_shaderFiles.names[i] );
279 if ( strstr( stripped, gamedir ) ) {
280 memmove( stripped, stripped + strlen( gamedir ), strlen( stripped ) );
282 sprintf( dest, "%s/%s", g_releasedir, stripped );
283 printf( "copying to %s\n", dest );
284 QCopyFile( s_shaderFiles.names[i], dest );
292 This is only used to cause a file to be copied during a release
293 build (default.cfg, maps, etc)
296 void Cmd_File( void ){
298 ReleaseFile( token );
309 void PackDirectory_r( char *dir ){
310 struct _finddata_t fileinfo;
312 char dirstring[1024];
315 sprintf( dirstring, "%s%s/*.*", gamedir, dir );
317 handle = _findfirst( dirstring, &fileinfo );
318 if ( handle == -1 ) {
324 sprintf( filename, "%s/%s", dir, fileinfo.name );
325 if ( fileinfo.attrib & _A_SUBDIR ) { // directory
326 if ( fileinfo.name[0] != '.' ) { // don't pak . and ..
327 PackDirectory_r( filename );
331 // copy or pack the file
332 ReleaseFile( filename );
333 } while ( _findnext( handle, &fileinfo ) != -1 );
335 _findclose( handle );
339 #include <sys/types.h>
343 #include <sys/dirent.h>
346 void PackDirectory_r( char *dir ){
348 struct direct **namelist, *ent;
350 struct dirent **namelist, *ent;
357 char dirstring[1024];
360 sprintf( dirstring, "%s%s", gamedir, dir );
361 count = scandir( dirstring, &namelist, NULL, NULL );
363 for ( i = 0 ; i < count ; i++ )
368 if ( name[0] == '.' ) {
372 sprintf( fullname, "%s/%s", dir, name );
373 sprintf( dirstring, "%s%s/%s", gamedir, dir, name );
375 if ( stat( dirstring, &st ) == -1 ) {
376 Error( "fstating %s", pf->name );
378 if ( st.st_mode & S_IFDIR ) { // directory
379 PackDirectory_r( fullname );
383 // copy or pack the file
384 ReleaseFile( fullname );
394 This is only used to cause a directory to be copied during a
395 release build (sounds, etc)
398 void Cmd_Dir( void ){
400 PackDirectory_r( token );
403 //========================================================================
405 #define MAX_RTEX 16384
407 char rtex[MAX_RTEX][64];
409 void ReleaseTexture( char *name ){
413 for ( i = 0 ; i < numrtex ; i++ )
414 if ( !Q_stricmp( name, rtex[i] ) ) {
418 if ( numrtex == MAX_RTEX ) {
419 Error( "numrtex == MAX_RTEX" );
422 strcpy( rtex[i], name );
425 sprintf( path, "textures/%s.wal", name );
433 Only relevent for release and pak files.
434 Releases the .bsp files for the maps, and scans all of the files to
435 build a list of all textures used, which are then released.
438 void Cmd_Maps( void ){
441 while ( TokenAvailable() )
444 sprintf( map, "maps/%s.bsp", token );
451 // get all the texture references
452 sprintf( map, "%smaps/%s.bsp", gamedir, token );
458 //==============================================================
465 void ParseScript( void ){
469 { // look for a line starting with a $ command
474 if ( token[0] == '$' ) {
477 while ( TokenAvailable() )
484 if ( !strcmp( token, "$modelname" ) ) {
487 else if ( !strcmp( token, "$base" ) ) {
490 else if ( !strcmp( token, "$exit" ) ) {
493 else if ( !strcmp( token, "$3dsconvert" ) ) {
496 else if ( !strcmp( token, "$spritebase" ) ) {
499 else if ( !strcmp( token, "$cd" ) ) {
502 else if ( !strcmp( token, "$origin" ) ) {
505 else if ( !strcmp( token, "$scale" ) ) {
508 else if ( !strcmp( token, "$frame" ) ) {
511 else if ( !strcmp( token, "$skin" ) ) {
514 else if ( !strcmp( token, "$spriteshader" ) ) {
517 else if ( !strcmp( token, "$aseconvert" ) ) {
518 Cmd_ASEConvert( qfalse );
520 else if ( !strcmp( token, "$aseanimconvert" ) ) {
521 Cmd_ASEConvert( qtrue );
527 else if ( !strcmp( token, "$grab" ) ) {
530 else if ( !strcmp( token, "$raw" ) ) {
533 else if ( !strcmp( token, "$colormap" ) ) {
536 else if ( !strcmp( token, "$environment" ) ) {
543 else if ( !strcmp( token, "$video" ) ) {
549 else if ( !strcmp( token, "$file" ) ) {
552 else if ( !strcmp( token, "$dir" ) ) {
555 else if ( !strcmp( token, "$maps" ) ) {
559 Error( "bad command %s\n", token );
564 //=======================================================
573 int main( int argc, char **argv ){
574 static int i; // VC4.2 compiler bug if auto...
577 // using GtkRadiant's versioning next to Id's versioning
578 printf( "Q3Data - (c) 1999 Id Software Inc.\n" );
579 printf( RADIANT_NAME " - v" RADIANT_VERSION " " __DATE__ "\n" );
581 ExpandWildcards( &argc, &argv );
583 for ( i = 1 ; i < argc ; i++ )
585 if ( !strcmp( argv[i], "-archive" ) ) {
587 strcpy( archivedir, argv[i + 1] );
588 printf( "Archiving source to: %s\n", archivedir );
591 else if ( !strcmp( argv[i], "-release" ) ) {
593 strcpy( g_releasedir, argv[i + 1] );
594 printf( "Copy output to: %s\n", g_releasedir );
597 else if ( !strcmp( argv[i], "-nostrips" ) ) {
599 printf( "Not optimizing for strips\n" );
601 else if ( !strcmp( argv[i], "-writedir" ) ) {
602 strcpy( writedir, argv[i + 1] );
603 printf( "Write output to: %s\n", writedir );
606 else if ( !strcmp( argv[i], "-verbose" ) ) {
609 else if ( !strcmp( argv[i], "-dump" ) ) {
610 printf( "Dumping contents of: '%s'\n", argv[i + 1] );
611 if ( strstr( argv[i + 1], ".md3" ) ) {
612 MD3_Dump( argv[i + 1] );
616 Error( "Do not know how to dump the contents of '%s'\n", argv[i + 1] );
620 else if ( !strcmp( argv[i], "-3dsconvert" ) ) {
621 // NOTE TTimo this is broken, tried on a sample .3ds
622 // what happens .. it calls the Convert3DStoMD3,
623 // which calls the scriptlib function in non initialized state .. and crashes
624 printf( "Converting %s.3DS to %s.MD3\n", argv[i + 1], argv[i + 1] );
625 SetQdirFromPath( argv[i + 1] );
626 vfsInitDirectory( gamedir );
627 Convert3DStoMD3( argv[i + 1] );
630 else if ( !strcmp( argv[i], "-only" ) ) {
631 strcpy( g_only, argv[i + 1] );
632 printf( "Only grabbing %s\n", g_only );
635 else if ( !strcmp( argv[i], "-gamedir" ) ) {
636 strcpy( gamedir, argv[i + 1] );
639 else if ( argv[i][0] == '-' ) {
640 Error( "Unknown option \"%s\"", argv[i] );
648 Error( "usage: q3data [-archive <directory>] [-dump <file.md3>] [-release <directory>] [-only <model>] [-3dsconvert <file.3ds>] [-verbose] [file.qdt]" );
651 for ( ; i < argc ; i++ )
653 printf( "--------------- %s ---------------\n", argv[i] );
655 strcpy( path, argv[i] );
656 DefaultExtension( path, ".qdt" );
658 SetQdirFromPath( path );
661 // q3data went through a partial conversion to use the vfs
662 // it was never actually tested before 1.1.1
663 // the code is still mostly using direct file access calls
664 vfsInitDirectory( gamedir );
665 LoadScriptFile( ExpandArg( path ), -1 );
672 // write out the last model
673 FinishModel( TYPE_UNKNOWN );