10 qboolean g_stripify = qtrue;
11 qboolean g_release; // don't grab, copy output data to new tree
12 char g_releasedir[1024]; // c:\quake2\baseq2, etc
13 qboolean g_archive; // don't grab, copy source data to new tree
14 char g_only[256]; // if set, only grab this cd
15 qboolean g_skipmodel; // set true when a cd is not g_only
17 // bogus externs for some TA hacks (common/ using them against q3map)
19 // some old defined that was in cmdlib lost during merge
22 #if defined (__linux__) || defined (__APPLE__)
23 #define strlwr strlower
27 =======================================================
31 =======================================================
47 packfile_t pfiles[16384];
50 packheader_t pakheader;
56 Filename should be gamedir reletive.
57 Either copies the file to the release dir, or adds it to
61 void ReleaseFile (char *filename)
69 sprintf (source, "%s%s", gamedir, filename);
70 sprintf (dest, "%s/%s", g_releasedir, filename);
71 printf ("copying to %s\n", dest);
72 QCopyFile (source, dest);
87 ShaderFiles_t s_shaderFiles;
89 void FindShaderFiles( char *filename )
93 char linebuffer[1024];
96 char *diffuseExtensions[] =
103 char *otherExtensions[] =
111 s_shaderFiles.num = 0;
113 strcpy( stripped, filename );
114 if ( strrchr( stripped, '.' ) )
115 *strrchr( stripped, '.' ) = 0;
116 strcat( stripped, ".shader" );
118 if ( FileExists( stripped ) )
121 char mapa[512], mapb[512];
123 strcpy( s_shaderFiles.names[s_shaderFiles.num], stripped );
127 len = LoadFile( stripped, (void **)&buf);
131 while ( p - buf < len )
136 while ( *p == ' ' || *p == '\n' || *p == '\t' )
139 // grab rest of the line
140 while ( *p != 0 && *p != '\n' )
150 strlwr( linebuffer );
152 // see if the line specifies an opaque map or blendmap
153 if ( strstr( linebuffer, "opaquemap" ) == linebuffer ||
154 strstr( linebuffer, "blendmap" ) == linebuffer )
160 mapa[0] = mapb[0] = 0;
162 // skip past the keyword
163 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
166 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
169 // grab first map name
171 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
173 mapa[j] = linebuffer[i];
180 while ( ( linebuffer[i] == ' ' || linebuffer[i] == '\t' ) && linebuffer[i] )
183 // grab second map name
185 while ( linebuffer[i] != ' ' && linebuffer[i] != '\t' && linebuffer[i] )
187 mapb[j] = linebuffer[i];
194 if ( mapa[0] != 0 && mapa[0] != '-' )
196 sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapa );
199 if ( mapb[0] != 0 && mapb[0] != '-' && mapb[0] != '^' && mapb[0] != '*' )
201 sprintf( s_shaderFiles.names[s_shaderFiles.num], "%s%s", gamedir, mapb );
209 if ( strrchr( stripped, '.' ) )
210 *strrchr( stripped, '.' ) = 0;
212 // look for diffuse maps
213 for ( i = 0; i < 3; i++ )
215 strcpy( buffer, stripped );
216 strcat( buffer, diffuseExtensions[i] );
217 if ( FileExists( buffer ) )
219 strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
224 for ( i = 0; i < 3; i++ )
226 strcpy( buffer, stripped );
227 strcat( buffer, otherExtensions[i] );
228 if ( FileExists( buffer ) )
230 strcpy( s_shaderFiles.names[s_shaderFiles.num], buffer );
241 Copies all needed files for a shader to the release directory
244 void ReleaseShader( char *filename )
251 sprintf( fullpath, "%s%s", gamedir, filename );
253 FindShaderFiles( fullpath );
255 for ( i = 0; i < s_shaderFiles.num; i++ )
257 strcpy( stripped, s_shaderFiles.names[i] );
258 if ( strstr( stripped, gamedir ) )
260 memmove( stripped, stripped+ strlen( gamedir ), strlen( stripped ) );
262 sprintf( dest, "%s/%s", g_releasedir, stripped );
263 printf ("copying to %s\n", dest );
264 QCopyFile( s_shaderFiles.names[i], dest );
272 This is only used to cause a file to be copied during a release
273 build (default.cfg, maps, etc)
290 void PackDirectory_r (char *dir)
292 struct _finddata_t fileinfo;
294 char dirstring[1024];
297 sprintf (dirstring, "%s%s/*.*", gamedir, dir);
299 handle = _findfirst (dirstring, &fileinfo);
305 sprintf (filename, "%s/%s", dir, fileinfo.name);
306 if (fileinfo.attrib & _A_SUBDIR)
308 if (fileinfo.name[0] != '.') // don't pak . and ..
309 PackDirectory_r (filename);
312 // copy or pack the file
313 ReleaseFile (filename);
314 } while (_findnext( handle, &fileinfo ) != -1);
320 #include <sys/types.h>
324 #include <sys/dirent.h>
327 void PackDirectory_r (char *dir)
330 struct direct **namelist, *ent;
332 struct dirent **namelist, *ent;
339 char dirstring[1024];
342 sprintf (dirstring, "%s%s", gamedir, dir);
343 count = scandir(dirstring, &namelist, NULL, NULL);
345 for (i=0 ; i<count ; i++)
353 sprintf (fullname, "%s/%s", dir, name);
354 sprintf (dirstring, "%s%s/%s", gamedir, dir, name);
356 if (stat (dirstring, &st) == -1)
357 Error ("fstating %s", pf->name);
358 if (st.st_mode & S_IFDIR)
360 PackDirectory_r (fullname);
364 // copy or pack the file
365 ReleaseFile (fullname);
375 This is only used to cause a directory to be copied during a
376 release build (sounds, etc)
382 PackDirectory_r (token);
385 //========================================================================
387 #define MAX_RTEX 16384
389 char rtex[MAX_RTEX][64];
391 void ReleaseTexture (char *name)
396 for (i=0 ; i<numrtex ; i++)
397 if (!Q_stricmp(name, rtex[i]))
400 if (numrtex == MAX_RTEX)
401 Error ("numrtex == MAX_RTEX");
403 strcpy (rtex[i], name);
406 sprintf (path, "textures/%s.wal", name);
414 Only relevent for release and pak files.
415 Releases the .bsp files for the maps, and scans all of the files to
416 build a list of all textures used, which are then released.
423 while (TokenAvailable ())
426 sprintf (map, "maps/%s.bsp", token);
432 // get all the texture references
433 sprintf (map, "%smaps/%s.bsp", gamedir, token);
439 //==============================================================
446 void ParseScript (void)
451 { // look for a line starting with a $ command
457 while (TokenAvailable())
464 if (!strcmp (token, "$modelname"))
466 else if (!strcmp (token, "$base"))
468 else if ( !strcmp( token, "$exit" ) )
470 else if ( !strcmp( token, "$3dsconvert" ) )
472 else if (!strcmp (token, "$spritebase"))
474 else if (!strcmp (token, "$cd"))
476 else if (!strcmp (token, "$origin"))
478 else if (!strcmp (token, "$scale"))
480 else if (!strcmp (token, "$frame"))
482 else if (!strcmp (token, "$skin" ))
484 else if (!strcmp (token, "$spriteshader"))
486 else if (!strcmp( token, "$aseconvert" ))
487 Cmd_ASEConvert( qfalse );
488 else if (!strcmp( token, "$aseanimconvert" ) )
489 Cmd_ASEConvert( qtrue );
494 else if (!strcmp (token, "$grab"))
496 else if (!strcmp (token, "$raw"))
498 else if (!strcmp (token, "$colormap"))
500 else if (!strcmp (token, "$environment"))
506 else if (!strcmp (token, "$video"))
511 else if (!strcmp (token, "$file"))
513 else if (!strcmp (token, "$dir"))
515 else if (!strcmp (token, "$maps"))
518 Error ("bad command %s\n", token);
522 //=======================================================
531 int main (int argc, char **argv)
533 static int i; // VC4.2 compiler bug if auto...
536 // using GtkRadiant's versioning next to Id's versioning
537 printf ("Q3Data - (c) 1999 Id Software Inc.\n");
538 printf ("GtkRadiant - v" RADIANT_VERSION " " __DATE__ "\n");
540 ExpandWildcards (&argc, &argv);
542 for (i=1 ; i<argc ; i++)
544 if (!strcmp(argv[i], "-archive"))
547 strcpy (archivedir, argv[i+1]);
548 printf ("Archiving source to: %s\n", archivedir);
551 else if (!strcmp(argv[i], "-release"))
554 strcpy (g_releasedir, argv[i+1]);
555 printf ("Copy output to: %s\n", g_releasedir);
558 else if ( !strcmp( argv[i], "-nostrips" ) )
561 printf( "Not optimizing for strips\n" );
563 else if ( !strcmp( argv[i], "-writedir" ) )
565 strcpy( writedir, argv[i+1] );
566 printf( "Write output to: %s\n", writedir );
569 else if ( !strcmp( argv[i], "-verbose" ) )
573 else if ( !strcmp( argv[i], "-dump" ) )
575 printf( "Dumping contents of: '%s'\n", argv[i+1] );
576 if ( strstr( argv[i+1], ".md3" ) )
578 MD3_Dump( argv[i+1] );
582 Error( "Do not know how to dump the contents of '%s'\n", argv[i+1] );
586 else if ( !strcmp( argv[i], "-3dsconvert" ) )
588 // NOTE TTimo this is broken, tried on a sample .3ds
589 // what happens .. it calls the Convert3DStoMD3,
590 // which calls the scriptlib function in non initialized state .. and crashes
591 printf( "Converting %s.3DS to %s.MD3\n", argv[i+1], argv[i+1] );
592 SetQdirFromPath( argv[i+1] );
593 vfsInitDirectory( gamedir );
594 Convert3DStoMD3( argv[i+1] );
597 else if (!strcmp(argv[i], "-only"))
599 strcpy (g_only, argv[i+1]);
600 printf ("Only grabbing %s\n", g_only);
603 else if (!strcmp(argv[i], "-gamedir"))
605 strcpy(gamedir, argv[i+1]);
608 else if (argv[i][0] == '-')
609 Error ("Unknown option \"%s\"", argv[i]);
615 Error ("usage: q3data [-archive <directory>] [-dump <file.md3>] [-release <directory>] [-only <model>] [-3dsconvert <file.3ds>] [-verbose] [file.qdt]");
617 for ( ; i<argc ; i++)
619 printf ("--------------- %s ---------------\n", argv[i]);
621 strcpy (path, argv[i]);
622 DefaultExtension (path, ".qdt");
624 SetQdirFromPath (path);
626 // q3data went through a partial conversion to use the vfs
627 // it was never actually tested before 1.1.1
628 // the code is still mostly using direct file access calls
629 vfsInitDirectory( gamedir );
630 LoadScriptFile (ExpandArg(path), -1);
637 // write out the last model
638 FinishModel ( TYPE_UNKNOWN );