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
27 qboolean g_compress_pak;
28 qboolean g_release; // don't grab, copy output data to new tree
29 qboolean g_pak; // if true, copy to pak instead of release
30 char g_releasedir[1024]; // c:\quake2\baseq2, etc
31 qboolean g_archive; // don't grab, copy source data to new tree
33 char g_only[256]; // if set, only grab this cd
34 qboolean g_skipmodel; // set true when a cd is not g_only
35 int g_forcemodel = MODEL_AUTO;
36 qboolean g_verbose = false;
37 qboolean g_allow_newskin = true;
38 qboolean g_ignoreTriUV = false;
39 qboolean g_publishOutput = false;
41 char *ext_3ds = "3ds";
42 char *ext_tri = "tri";
45 char g_materialFile[256] = "none"; // default for Heretic2
47 extern char *g_publishDir;
49 extern qboolean g_nomkdir;
52 =======================================================
56 =======================================================
72 packfile_t pfiles[16384];
75 packheader_t pakheader;
84 void BeginPak( char *outname ){
89 pakfile = SafeOpenWrite( outname );
91 // leave space for header
92 SafeWrite( pakfile, &pakheader, sizeof( pakheader ) );
102 Filename should be gamedir reletive.
103 Either copies the file to the release dir, or adds it to
107 void ReleaseFile( char *filename ){
117 sprintf( source, "%s%s", gamedir, filename );
119 if ( !g_pak ) { // copy it
120 sprintf( dest, "%s/%s", g_releasedir, filename );
121 printf( "copying to %s\n", dest );
122 QCopyFile( source, dest );
127 printf( "paking %s\n", filename );
128 if ( strlen( filename ) >= sizeof( pf->name ) ) {
129 Error( "Filename too long for pak: %s", filename );
132 len = LoadFile( source, (void **)&buf );
134 // segment moved to old.c
136 strcpy( pf->name, filename );
137 pf->filepos = LittleLong( ftell( pakfile ) );
138 pf->filelen = LittleLong( len );
141 SafeWrite( pakfile, buf, len );
152 void FinishPak( void ){
162 pakheader.id[0] = 'P';
163 pakheader.id[1] = 'A';
164 pakheader.id[2] = 'C';
165 pakheader.id[3] = 'K';
166 dirlen = (byte *)pf - (byte *)pfiles;
167 pakheader.dirofs = LittleLong( ftell( pakfile ) );
168 pakheader.dirlen = LittleLong( dirlen );
170 checksum = Com_BlockChecksum( (void *)pfiles, dirlen );
172 SafeWrite( pakfile, pfiles, dirlen );
174 i = ftell( pakfile );
176 fseek( pakfile, 0, SEEK_SET );
177 SafeWrite( pakfile, &pakheader, sizeof( pakheader ) );
181 printf( "%i files packed in %i bytes\n",d, i );
182 printf( "checksum: 0x%x\n", checksum );
190 This is only used to cause a file to be copied during a release
191 build (default.cfg, maps, etc)
194 void Cmd_File( void ){
195 GetScriptToken( false );
196 ReleaseFile( token );
207 void PackDirectory_r( char *dir ){
208 struct _finddata_t fileinfo;
210 char dirstring[1024];
213 sprintf( dirstring, "%s%s/*.*", gamedir, dir );
215 handle = _findfirst( dirstring, &fileinfo );
216 if ( handle == -1 ) {
222 sprintf( filename, "%s/%s", dir, fileinfo.name );
223 if ( fileinfo.attrib & _A_SUBDIR ) { // directory
224 if ( fileinfo.name[0] != '.' ) { // don't pak . and ..
225 PackDirectory_r( filename );
229 // copy or pack the file
230 ReleaseFile( filename );
231 } while ( _findnext( handle, &fileinfo ) != -1 );
233 _findclose( handle );
237 #include <sys/types.h>
244 void PackDirectory_r( char *dir ){
246 struct direct **namelist, *ent;
248 struct dirent **namelist, *ent;
255 char dirstring[1024];
258 sprintf( dirstring, "%s%s", gamedir, dir );
259 count = scandir( dirstring, &namelist, NULL, NULL );
261 for ( i = 0 ; i < count ; i++ )
266 if ( name[0] == '.' ) {
270 sprintf( fullname, "%s/%s", dir, name );
271 sprintf( dirstring, "%s%s/%s", gamedir, dir, name );
273 if ( stat( dirstring, &st ) == -1 ) {
274 Error( "fstating %s", pf->name );
276 if ( st.st_mode & S_IFDIR ) { // directory
277 PackDirectory_r( fullname );
281 // copy or pack the file
282 ReleaseFile( fullname );
292 This is only used to cause a directory to be copied during a
293 release build (sounds, etc)
296 void Cmd_Dir( void ){
297 GetScriptToken( false );
298 PackDirectory_r( token );
301 //========================================================================
303 #define MAX_RTEX 16384
305 char rtex[MAX_RTEX][64];
307 void ReleaseTexture( char *name ){
311 for ( i = 0 ; i < numrtex ; i++ )
312 if ( !Q_strcasecmp( name, rtex[i] ) ) {
316 if ( numrtex == MAX_RTEX ) {
317 Error( "numrtex == MAX_RTEX" );
320 strcpy( rtex[i], name );
323 sprintf( path, "textures/%s.wal", name );
331 Only relevent for release and pak files.
332 Releases the .bsp files for the maps, and scans all of the files to
333 build a list of all textures used, which are then released.
336 void Cmd_Maps( void ){
340 while ( ScriptTokenAvailable() )
342 GetScriptToken( false );
343 sprintf( map, "maps/%s.bsp", token );
350 // get all the texture references
351 sprintf( map, "%smaps/%s.bsp", gamedir, token );
352 LoadBSPFileTexinfo( map );
353 for ( i = 0 ; i < numtexinfo ; i++ )
354 ReleaseTexture( texinfo[i].texture );
359 //==============================================================
366 void ParseScript( void ){
370 { // look for a line starting with a $ command
371 GetScriptToken( true );
375 if ( token[0] == '$' ) {
378 while ( ScriptTokenAvailable() )
379 GetScriptToken( false );
385 if ( !strcmp( token, "$modelname" ) ) {
386 MODELCMD_Modelname( MODEL_MD2 );
388 else if ( !strcmp( token, "$cd" ) ) {
389 MODELCMD_Cd( MODEL_MD2 );
391 else if ( !strcmp( token, "$origin" ) ) {
392 MODELCMD_Origin( MODEL_MD2 );
394 else if ( !strcmp( token, "$cluster" ) ) {
395 MODELCMD_Cluster( MODEL_MD2 );
397 else if ( !strcmp( token, "$base" ) ) {
398 MODELCMD_Base( MODEL_MD2 );
400 else if ( !strcmp( token, "$scale" ) ) {
401 MODELCMD_ScaleUp( MODEL_MD2 );
403 else if ( !strcmp( token, "$frame" ) ) {
404 MODELCMD_Frame( MODEL_MD2 );
406 else if ( !strcmp( token, "$skin" ) ) {
407 MODELCMD_Skin( MODEL_MD2 );
409 else if ( !strcmp( token, "$skinsize" ) ) {
410 MODELCMD_Skinsize( MODEL_MD2 );
413 // flexible model commands
415 else if ( !strcmp( token, "$fm_modelname" ) ) {
416 MODELCMD_Modelname( MODEL_FM );
418 else if ( !strcmp( token, "$fm_base" ) ) {
419 MODELCMD_Base( MODEL_FM );
421 else if ( !strcmp( token, "$fm_basest" ) ) {
422 MODELCMD_BaseST( MODEL_FM );
424 else if ( !strcmp( token, "$fm_cd" ) ) {
425 MODELCMD_Cd( MODEL_FM );
427 else if ( !strcmp( token, "$fm_origin" ) ) {
428 MODELCMD_Origin( MODEL_FM );
430 else if ( !strcmp( token, "$fm_cluster" ) ) {
431 MODELCMD_Cluster( MODEL_FM );
433 else if ( !strcmp( token, "$fm_skeleton" ) ) {
434 MODELCMD_Skeleton( MODEL_FM );
436 else if ( !strcmp( token, "$fm_scale" ) ) {
437 MODELCMD_ScaleUp( MODEL_FM );
439 else if ( !strcmp( token, "$fm_frame" ) ) {
440 MODELCMD_Frame( MODEL_FM );
442 else if ( !strcmp( token, "$fm_skeletal_frame" ) ) { // left in for compadibility with qdt already using fm_skeletal_frame
443 MODELCMD_Frame( MODEL_FM );
445 else if ( !strcmp( token, "$fm_skin" ) ) {
446 MODELCMD_Skin( MODEL_FM );
448 else if ( !strcmp( token, "$fm_skinsize" ) ) {
449 MODELCMD_Skinsize( MODEL_FM );
451 else if ( !strcmp( token, "$fm_begin_group" ) ) {
452 MODELCMD_BeginGroup( MODEL_FM );
454 else if ( !strcmp( token, "$fm_end_group" ) ) {
455 MODELCMD_EndGroup( MODEL_FM );
457 else if ( !strcmp( token, "$fm_referenced" ) ) {
458 MODELCMD_Referenced( MODEL_FM );
460 else if ( !strcmp( token, "$fm_node_order" ) ) {
461 MODELCMD_NodeOrder( MODEL_FM );
467 else if ( !strcmp( token, "$spritename" ) ) {
470 else if ( !strcmp( token, "$sprdir" ) ) {
473 else if ( !strcmp( token, "$load" ) ) {
476 else if ( !strcmp( token, "$spriteframe" ) ) {
482 else if ( !strcmpi( token, "$grab" ) ) {
485 else if ( !strcmpi( token, "$raw" ) ) {
488 else if ( !strcmpi( token, "$colormap" ) ) {
491 else if ( !strcmpi( token, "$mippal" ) ) {
494 else if ( !strcmpi( token, "$mipdir" ) ) {
497 else if ( !strcmpi( token, "$mip" ) ) {
500 else if ( !strcmp( token, "$environment" ) ) {
506 else if ( !strcmp( token, "$picdir" ) ) {
509 else if ( !strcmp( token, "$pic" ) ) {
515 else if ( !strcmp( token, "$bookdir" ) ) {
518 else if ( !strcmp( token, "$book" ) ) {
524 else if ( !strcmp( token, "$texturemix" ) ) {
530 else if ( !strcmp( token, "$video" ) ) {
536 else if ( !strcmp( token, "$file" ) ) {
539 else if ( !strcmp( token, "$dir" ) ) {
542 else if ( !strcmp( token, "$maps" ) ) {
545 else if ( !strcmp( token, "$alphalight" ) ) {
548 else if ( !strcmp( token, "$inverse16table" ) ) {
549 Cmd_Inverse16Table();
552 Error( "bad command %s\n", token );
557 //=======================================================
564 int main( int argc, char **argv ){
568 double starttime, endtime;
570 printf( "Qdata Plus : "__TIME__ " "__DATE__ "\n" );
572 starttime = I_FloatTime();
576 ExpandWildcards( &argc, &argv );
578 for ( i = 1 ; i < argc ; i++ )
580 if ( !strcmp( argv[i], "-archive" ) ) {
581 // -archive f:/quake2/release/dump_11_30
583 strcpy( archivedir, argv[i + 1] );
584 printf( "Archiving source to: %s\n", archivedir );
587 else if ( !strcmp( argv[i], "-release" ) ) {
589 strcpy( g_releasedir, argv[i + 1] );
590 printf( "Copy output to: %s\n", g_releasedir );
593 else if ( !strcmp( argv[i], "-base" ) ) {
597 else if ( !strcmp( argv[i], "-compress" ) ) {
598 g_compress_pak = true;
599 printf( "Compressing pakfile\n" );
601 else if ( !strcmp( argv[i], "-pak" ) ) {
604 printf( "Building pakfile: %s\n", argv[i + 1] );
605 BeginPak( argv[i + 1] );
608 else if ( !strcmp( argv[i], "-only" ) ) {
609 strcpy( g_only, argv[i + 1] );
610 printf( "Only grabbing %s\n", g_only );
613 else if ( !strcmpi( argv[i], "-keypress" ) ) {
616 else if ( !strcmp( argv[i], "-3ds" ) ) {
618 printf( "loading .3ds files\n" );
620 else if ( !strcmp( argv[i], "-materialfile" ) ) {
621 strcpy( g_materialFile, argv[i + 1] );
622 printf( "Setting material file to %s\n", g_materialFile );
625 /* else if (!strcmpi(argv[i], "-newgen"))
629 printf("run new triangle grouping routine here\n");
630 NewGen(argv[i+1],argv[i+2],atoi(argv[i+3]),atoi(argv[i+4]));
634 printf("qdata -newskin <base.hrc> <skin.pcx> width height\n");
638 */ else if ( !strcmpi( argv[i], "-genskin" ) ) {
640 if ( i < argc - 3 ) {
641 GenSkin( argv[i],argv[i + 1],atol( argv[i + 2] ),atol( argv[i + 3] ) );
645 printf( "qdata -genskin <base.hrc> <skin.pcx> <desired width> <desired height>\n" );
650 else if ( !strcmpi( argv[i], "-noopts" ) ) {
651 g_no_opimizations = true;
652 printf( "not performing optimizations\n" );
654 else if ( !strcmpi( argv[i], "-md2" ) ) {
655 g_forcemodel = MODEL_MD2;
657 else if ( !strcmpi( argv[i], "-fm" ) ) {
658 g_forcemodel = MODEL_FM;
660 else if ( !strcmpi( argv[i], "-verbose" ) ) {
663 else if ( !strcmpi( argv[i], "-oldskin" ) ) {
664 g_allow_newskin = false;
666 else if ( !strcmpi( argv[i], "-ignoreUV" ) ) {
667 g_ignoreTriUV = true;
669 else if ( !strcmpi( argv[i], "-publish" ) ) {
670 g_publishOutput = true;
672 else if ( !strcmpi( argv[i], "-nomkdir" ) ) {
675 else if ( argv[i][0] == '-' ) {
676 Error( "Unknown option \"%s\"", argv[i] );
684 Error( "usage: qdata [-archive <directory>]\n"
685 " [-release <directory>]\n"
686 " [-base <directory>]\n"
692 " [-materialfile <file>]\n"
703 " qdata -genskin <base.hrc> <skin.pcx> <desired width> <desired height>" );
707 trifileext = ext_3ds;
710 trifileext = ext_tri;
713 for ( ; i < argc ; i++ )
715 printf( "--------------- %s ---------------\n", argv[i] );
717 strcpy( path, argv[i] );
718 DefaultExtension( path, ".qdt" );
719 DefaultExtension( g_materialFile, ".mat" );
720 SetQdirFromPath( path );
722 printf( "workingdir='%s'\n", gamedir );
725 g_outputDir = basedir;
728 printf( "outputdir='%s'\n", g_outputDir );
730 QFile_ReadMaterialTypes( g_materialFile );
731 LoadScriptFile( ExpandArg( path ) );
738 // write out the last model
744 if ( total_textures ) {
746 printf( "Total textures processed: %d\n",total_textures );
747 printf( "Average size: %d x %d\n",total_x / total_textures, total_y / total_textures );
754 endtime = I_FloatTime();
755 printf( "Time elapsed: %f\n", endtime - starttime );
757 if ( g_dokeypress ) {
758 printf( "Success! ... Hit a key: " );