1 /* -------------------------------------------------------------------------------;
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 -------------------------------------------------------------------------------
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
27 ------------------------------------------------------------------------------- */
43 returns a pseudorandom number between 0 and 1
47 return (vec_t) rand() / RAND_MAX;
51 char *Q_strncpyz( char *dst, const char *src, size_t len ) {
56 strncpy( dst, src, len );
57 dst[ len - 1 ] = '\0';
62 char *Q_strcat( char *dst, size_t dlen, const char *src ) {
63 size_t n = strlen( dst );
66 abort(); /* buffer overflow */
69 return Q_strncpyz( dst + n, src, dlen - n );
73 char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
74 size_t n = strlen( dst );
77 abort(); /* buffer overflow */
80 return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
89 static void ExitQ3Map( void ){
91 if ( mapDrawSurfs != NULL ) {
100 typedef struct minimap_s
106 float *sample_offsets;
107 float sharpen_boxmult;
108 float sharpen_centermult;
109 float boost, brightness, contrast;
111 float *sharpendata1f;
115 static minimap_t minimap;
117 qboolean BrushIntersectionWithLine( bspBrush_t *brush, vec3_t start, vec3_t dir, float *t_in, float *t_out ){
119 qboolean in = qfalse, out = qfalse;
120 bspBrushSide_t *sides = &bspBrushSides[brush->firstSide];
122 for ( i = 0; i < brush->numSides; ++i )
124 bspPlane_t *p = &bspPlanes[sides[i].planeNum];
125 float sn = DotProduct( start, p->normal );
126 float dn = DotProduct( dir, p->normal );
128 if ( sn > p->dist ) {
129 return qfalse; // outside!
134 float t = ( p->dist - sn ) / dn;
136 if ( !in || t > *t_in ) {
139 // as t_in can only increase, and t_out can only decrease, early out
140 if ( out && *t_in >= *t_out ) {
147 if ( !out || t < *t_out ) {
150 // as t_in can only increase, and t_out can only decrease, early out
151 if ( in && *t_in >= *t_out ) {
161 static float MiniMapSample( float x, float y ){
179 for ( i = 0; i < minimap.model->numBSPBrushes; ++i )
181 bi = minimap.model->firstBSPBrush + i;
182 if ( opaqueBrushes[bi >> 3] & ( 1 << ( bi & 7 ) ) ) {
185 // sort out mins/maxs of the brush
186 s = &bspBrushSides[b->firstSide];
187 if ( x < -bspPlanes[s[0].planeNum].dist ) {
190 if ( x > +bspPlanes[s[1].planeNum].dist ) {
193 if ( y < -bspPlanes[s[2].planeNum].dist ) {
196 if ( y > +bspPlanes[s[3].planeNum].dist ) {
200 if ( BrushIntersectionWithLine( b, org, dir, &t0, &t1 ) ) {
210 void RandomVector2f( float v[2] ){
213 v[0] = 2 * Random() - 1;
214 v[1] = 2 * Random() - 1;
216 while ( v[0] * v[0] + v[1] * v[1] > 1 );
219 static void MiniMapRandomlySupersampled( int y ){
221 float *p = &minimap.data1f[y * minimap.width];
222 float ymin = minimap.mins[1] + minimap.size[1] * ( y / (float) minimap.height );
223 float dx = minimap.size[0] / (float) minimap.width;
224 float dy = minimap.size[1] / (float) minimap.height;
228 for ( x = 0; x < minimap.width; ++x )
230 float xmin = minimap.mins[0] + minimap.size[0] * ( x / (float) minimap.width );
233 for ( i = 0; i < minimap.samples; ++i )
235 RandomVector2f( uv );
236 thisval = MiniMapSample(
237 xmin + ( uv[0] + 0.5 ) * dx, /* exaggerated random pattern for better results */
238 ymin + ( uv[1] + 0.5 ) * dy /* exaggerated random pattern for better results */
242 val /= minimap.samples * minimap.size[2];
247 static void MiniMapSupersampled( int y ){
249 float *p = &minimap.data1f[y * minimap.width];
250 float ymin = minimap.mins[1] + minimap.size[1] * ( y / (float) minimap.height );
251 float dx = minimap.size[0] / (float) minimap.width;
252 float dy = minimap.size[1] / (float) minimap.height;
254 for ( x = 0; x < minimap.width; ++x )
256 float xmin = minimap.mins[0] + minimap.size[0] * ( x / (float) minimap.width );
259 for ( i = 0; i < minimap.samples; ++i )
261 float thisval = MiniMapSample(
262 xmin + minimap.sample_offsets[2 * i + 0] * dx,
263 ymin + minimap.sample_offsets[2 * i + 1] * dy
267 val /= minimap.samples * minimap.size[2];
272 static void MiniMapNoSupersampling( int y ){
274 float *p = &minimap.data1f[y * minimap.width];
275 float ymin = minimap.mins[1] + minimap.size[1] * ( ( y + 0.5 ) / (float) minimap.height );
277 for ( x = 0; x < minimap.width; ++x )
279 float xmin = minimap.mins[0] + minimap.size[0] * ( ( x + 0.5 ) / (float) minimap.width );
280 *p++ = MiniMapSample( xmin, ymin ) / minimap.size[2];
284 static void MiniMapSharpen( int y ){
286 qboolean up = ( y > 0 );
287 qboolean down = ( y < minimap.height - 1 );
288 float *p = &minimap.data1f[y * minimap.width];
289 float *q = &minimap.sharpendata1f[y * minimap.width];
291 for ( x = 0; x < minimap.width; ++x )
293 qboolean left = ( x > 0 );
294 qboolean right = ( x < minimap.width - 1 );
295 float val = p[0] * minimap.sharpen_centermult;
298 val += p[-1 - minimap.width] * minimap.sharpen_boxmult;
300 if ( left && down ) {
301 val += p[-1 + minimap.width] * minimap.sharpen_boxmult;
304 val += p[+1 - minimap.width] * minimap.sharpen_boxmult;
306 if ( right && down ) {
307 val += p[+1 + minimap.width] * minimap.sharpen_boxmult;
311 val += p[-1] * minimap.sharpen_boxmult;
314 val += p[+1] * minimap.sharpen_boxmult;
317 val += p[-minimap.width] * minimap.sharpen_boxmult;
320 val += p[+minimap.width] * minimap.sharpen_boxmult;
328 static void MiniMapContrastBoost( int y ){
330 float *q = &minimap.data1f[y * minimap.width];
331 for ( x = 0; x < minimap.width; ++x )
333 *q = *q * minimap.boost / ( ( minimap.boost - 1 ) * *q + 1 );
338 static void MiniMapBrightnessContrast( int y ){
340 float *q = &minimap.data1f[y * minimap.width];
341 for ( x = 0; x < minimap.width; ++x )
343 *q = *q * minimap.contrast + minimap.brightness;
348 void MiniMapMakeMinsMaxs( vec3_t mins_in, vec3_t maxs_in, float border, qboolean keepaspect ){
349 vec3_t mins, maxs, extend;
350 VectorCopy( mins_in, mins );
351 VectorCopy( maxs_in, maxs );
353 // line compatible to nexuiz mapinfo
354 Sys_Printf( "size %f %f %f %f %f %f\n", mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2] );
357 VectorSubtract( maxs, mins, extend );
358 if ( extend[1] > extend[0] ) {
359 mins[0] -= ( extend[1] - extend[0] ) * 0.5;
360 maxs[0] += ( extend[1] - extend[0] ) * 0.5;
364 mins[1] -= ( extend[0] - extend[1] ) * 0.5;
365 maxs[1] += ( extend[0] - extend[1] ) * 0.5;
369 /* border: amount of black area around the image */
370 /* input: border, 1-2*border, border but we need border/(1-2*border) */
372 VectorSubtract( maxs, mins, extend );
373 VectorScale( extend, border / ( 1 - 2 * border ), extend );
375 VectorSubtract( mins, extend, mins );
376 VectorAdd( maxs, extend, maxs );
378 VectorCopy( mins, minimap.mins );
379 VectorSubtract( maxs, mins, minimap.size );
381 // line compatible to nexuiz mapinfo
382 Sys_Printf( "size_texcoords %f %f %f %f %f %f\n", mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2] );
386 MiniMapSetupBrushes()
387 determines solid non-sky brushes in the world
390 void MiniMapSetupBrushes( void ){
391 SetupBrushesFlags( C_SOLID | C_SKY, C_SOLID, 0, 0 );
392 // at least one must be solid
394 // not all may be nodraw
397 qboolean MiniMapEvaluateSampleOffsets( int *bestj, int *bestk, float *bestval ){
401 *bestj = *bestk = -1;
402 *bestval = 3; /* max possible val is 2 */
404 for ( j = 0; j < minimap.samples; ++j )
405 for ( k = j + 1; k < minimap.samples; ++k )
407 dx = minimap.sample_offsets[2 * j + 0] - minimap.sample_offsets[2 * k + 0];
408 dy = minimap.sample_offsets[2 * j + 1] - minimap.sample_offsets[2 * k + 1];
421 val = dx * dx + dy * dy;
422 if ( val < *bestval ) {
432 void MiniMapMakeSampleOffsets(){
434 float val, valj, valk, sx, sy, rx, ry;
436 Sys_Printf( "Generating good sample offsets (this may take a while)...\n" );
438 /* start with entirely random samples */
439 for ( i = 0; i < minimap.samples; ++i )
441 minimap.sample_offsets[2 * i + 0] = Random();
442 minimap.sample_offsets[2 * i + 1] = Random();
445 for ( i = 0; i < 1000; ++i )
447 if ( MiniMapEvaluateSampleOffsets( &j, &k, &val ) ) {
448 sx = minimap.sample_offsets[2 * j + 0];
449 sy = minimap.sample_offsets[2 * j + 1];
450 minimap.sample_offsets[2 * j + 0] = rx = Random();
451 minimap.sample_offsets[2 * j + 1] = ry = Random();
452 if ( !MiniMapEvaluateSampleOffsets( &jj, &kk, &valj ) ) {
455 minimap.sample_offsets[2 * j + 0] = sx;
456 minimap.sample_offsets[2 * j + 1] = sy;
458 sx = minimap.sample_offsets[2 * k + 0];
459 sy = minimap.sample_offsets[2 * k + 1];
460 minimap.sample_offsets[2 * k + 0] = rx;
461 minimap.sample_offsets[2 * k + 1] = ry;
462 if ( !MiniMapEvaluateSampleOffsets( &jj, &kk, &valk ) ) {
465 minimap.sample_offsets[2 * k + 0] = sx;
466 minimap.sample_offsets[2 * k + 1] = sy;
470 /* valj is the greatest */
471 minimap.sample_offsets[2 * j + 0] = rx;
472 minimap.sample_offsets[2 * j + 1] = ry;
477 /* valj is the greater and it is useless - forget it */
483 /* valk is the greatest */
484 minimap.sample_offsets[2 * k + 0] = rx;
485 minimap.sample_offsets[2 * k + 1] = ry;
490 /* valk is the greater and it is useless - forget it */
500 void MergeRelativePath( char *out, const char *absolute, const char *relative ){
501 const char *endpos = absolute + strlen( absolute );
502 while ( endpos != absolute && ( endpos[-1] == '/' || endpos[-1] == '\\' ) )
504 while ( relative[0] == '.' && relative[1] == '.' && ( relative[2] == '/' || relative[2] == '\\' ) )
507 while ( endpos != absolute )
510 if ( *endpos == '/' || *endpos == '\\' ) {
514 while ( endpos != absolute && ( endpos[-1] == '/' || endpos[-1] == '\\' ) )
517 memcpy( out, absolute, endpos - absolute );
518 out[endpos - absolute] = '/';
519 strcpy( out + ( endpos - absolute + 1 ), relative );
522 int MiniMapBSPMain( int argc, char **argv ){
523 char minimapFilename[1024];
526 char relativeMinimapFilename[1024];
528 float minimapSharpen;
540 Sys_Printf( "Usage: q3map [-v] -minimap [-size n] [-sharpen f] [-samples n | -random n] [-o filename.tga] [-minmax Xmin Ymin Zmin Xmax Ymax Zmax] <mapname>\n" );
544 /* load the BSP first */
545 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
546 StripExtension( source );
547 DefaultExtension( source, ".bsp" );
548 Sys_Printf( "Loading %s\n", source );
549 //BeginMapShaderFile( source ); //do not delete q3map2_*.shader on minimap generation
551 LoadBSPFile( source );
553 minimap.model = &bspModels[0];
554 VectorCopy( minimap.model->mins, mins );
555 VectorCopy( minimap.model->maxs, maxs );
557 *minimapFilename = 0;
558 minimapSharpen = game->miniMapSharpen;
559 minimap.width = minimap.height = game->miniMapSize;
560 border = game->miniMapBorder;
561 keepaspect = game->miniMapKeepAspect;
562 mode = game->miniMapMode;
566 minimap.sample_offsets = NULL;
568 minimap.brightness = 0.0;
569 minimap.contrast = 1.0;
571 /* process arguments */
572 for ( i = 1; i < ( argc - 1 ); i++ )
574 if ( !strcmp( argv[ i ], "-size" ) ) {
575 minimap.width = minimap.height = atoi( argv[i + 1] );
577 Sys_Printf( "Image size set to %i\n", minimap.width );
579 else if ( !strcmp( argv[ i ], "-sharpen" ) ) {
580 minimapSharpen = atof( argv[i + 1] );
582 Sys_Printf( "Sharpening coefficient set to %f\n", minimapSharpen );
584 else if ( !strcmp( argv[ i ], "-samples" ) ) {
585 minimap.samples = atoi( argv[i + 1] );
587 Sys_Printf( "Samples set to %i\n", minimap.samples );
588 if ( minimap.sample_offsets ) {
589 free( minimap.sample_offsets );
591 minimap.sample_offsets = malloc( 2 * sizeof( *minimap.sample_offsets ) * minimap.samples );
592 MiniMapMakeSampleOffsets();
594 else if ( !strcmp( argv[ i ], "-random" ) ) {
595 minimap.samples = atoi( argv[i + 1] );
597 Sys_Printf( "Random samples set to %i\n", minimap.samples );
598 if ( minimap.sample_offsets ) {
599 free( minimap.sample_offsets );
601 minimap.sample_offsets = NULL;
603 else if ( !strcmp( argv[ i ], "-border" ) ) {
604 border = atof( argv[i + 1] );
606 Sys_Printf( "Border set to %f\n", border );
608 else if ( !strcmp( argv[ i ], "-keepaspect" ) ) {
610 Sys_Printf( "Keeping aspect ratio by letterboxing\n", border );
612 else if ( !strcmp( argv[ i ], "-nokeepaspect" ) ) {
614 Sys_Printf( "Not keeping aspect ratio\n", border );
616 else if ( !strcmp( argv[ i ], "-o" ) ) {
617 strcpy( minimapFilename, argv[i + 1] );
619 Sys_Printf( "Output file name set to %s\n", minimapFilename );
621 else if ( !strcmp( argv[ i ], "-minmax" ) && i < ( argc - 7 ) ) {
622 mins[0] = atof( argv[i + 1] );
623 mins[1] = atof( argv[i + 2] );
624 mins[2] = atof( argv[i + 3] );
625 maxs[0] = atof( argv[i + 4] );
626 maxs[1] = atof( argv[i + 5] );
627 maxs[2] = atof( argv[i + 6] );
629 Sys_Printf( "Map mins/maxs overridden\n" );
631 else if ( !strcmp( argv[ i ], "-gray" ) ) {
632 mode = MINIMAP_MODE_GRAY;
633 Sys_Printf( "Writing as white-on-black image\n" );
635 else if ( !strcmp( argv[ i ], "-black" ) ) {
636 mode = MINIMAP_MODE_BLACK;
637 Sys_Printf( "Writing as black alpha image\n" );
639 else if ( !strcmp( argv[ i ], "-white" ) ) {
640 mode = MINIMAP_MODE_WHITE;
641 Sys_Printf( "Writing as white alpha image\n" );
643 else if ( !strcmp( argv[ i ], "-boost" ) && i < ( argc - 2 ) ) {
644 minimap.boost = atof( argv[i + 1] );
646 Sys_Printf( "Contrast boost set to %f\n", minimap.boost );
648 else if ( !strcmp( argv[ i ], "-brightness" ) && i < ( argc - 2 ) ) {
649 minimap.brightness = atof( argv[i + 1] );
651 Sys_Printf( "Brightness set to %f\n", minimap.brightness );
653 else if ( !strcmp( argv[ i ], "-contrast" ) && i < ( argc - 2 ) ) {
654 minimap.contrast = atof( argv[i + 1] );
656 Sys_Printf( "Contrast set to %f\n", minimap.contrast );
658 else if ( !strcmp( argv[ i ], "-autolevel" ) ) {
660 Sys_Printf( "Auto level enabled\n", border );
662 else if ( !strcmp( argv[ i ], "-noautolevel" ) ) {
664 Sys_Printf( "Auto level disabled\n", border );
668 MiniMapMakeMinsMaxs( mins, maxs, border, keepaspect );
670 if ( !*minimapFilename ) {
671 ExtractFileBase( source, basename );
672 ExtractFilePath( source, path );
673 sprintf( relativeMinimapFilename, game->miniMapNameFormat, basename );
674 MergeRelativePath( minimapFilename, path, relativeMinimapFilename );
675 Sys_Printf( "Output file name automatically set to %s\n", minimapFilename );
677 ExtractFilePath( minimapFilename, path );
680 if ( minimapSharpen >= 0 ) {
681 minimap.sharpen_centermult = 8 * minimapSharpen + 1;
682 minimap.sharpen_boxmult = -minimapSharpen;
685 minimap.data1f = safe_malloc( minimap.width * minimap.height * sizeof( *minimap.data1f ) );
686 data4b = safe_malloc( minimap.width * minimap.height * 4 );
687 if ( minimapSharpen >= 0 ) {
688 minimap.sharpendata1f = safe_malloc( minimap.width * minimap.height * sizeof( *minimap.data1f ) );
691 MiniMapSetupBrushes();
693 if ( minimap.samples <= 1 ) {
694 Sys_Printf( "\n--- MiniMapNoSupersampling (%d) ---\n", minimap.height );
695 RunThreadsOnIndividual( minimap.height, qtrue, MiniMapNoSupersampling );
699 if ( minimap.sample_offsets ) {
700 Sys_Printf( "\n--- MiniMapSupersampled (%d) ---\n", minimap.height );
701 RunThreadsOnIndividual( minimap.height, qtrue, MiniMapSupersampled );
705 Sys_Printf( "\n--- MiniMapRandomlySupersampled (%d) ---\n", minimap.height );
706 RunThreadsOnIndividual( minimap.height, qtrue, MiniMapRandomlySupersampled );
710 if ( minimap.boost != 1.0 ) {
711 Sys_Printf( "\n--- MiniMapContrastBoost (%d) ---\n", minimap.height );
712 RunThreadsOnIndividual( minimap.height, qtrue, MiniMapContrastBoost );
716 Sys_Printf( "\n--- MiniMapAutoLevel (%d) ---\n", minimap.height );
717 float mi = 1, ma = 0;
722 for ( y = 0; y < minimap.height; ++y )
723 for ( x = 0; x < minimap.width; ++x )
735 o = mi / ( ma - mi );
738 // brightness + contrast * v
740 // brightness + contrast * (v * s - o)
742 // (brightness - contrast * o) + (contrast * s) * v
743 minimap.brightness = minimap.brightness - minimap.contrast * o;
744 minimap.contrast *= s;
746 Sys_Printf( "Auto level: Brightness changed to %f\n", minimap.brightness );
747 Sys_Printf( "Auto level: Contrast changed to %f\n", minimap.contrast );
750 Sys_Printf( "Auto level: failed because all pixels are the same value\n" );
754 if ( minimap.brightness != 0 || minimap.contrast != 1 ) {
755 Sys_Printf( "\n--- MiniMapBrightnessContrast (%d) ---\n", minimap.height );
756 RunThreadsOnIndividual( minimap.height, qtrue, MiniMapBrightnessContrast );
759 if ( minimap.sharpendata1f ) {
760 Sys_Printf( "\n--- MiniMapSharpen (%d) ---\n", minimap.height );
761 RunThreadsOnIndividual( minimap.height, qtrue, MiniMapSharpen );
762 q = minimap.sharpendata1f;
769 Sys_Printf( "\nConverting..." );
773 case MINIMAP_MODE_GRAY:
775 for ( y = 0; y < minimap.height; ++y )
776 for ( x = 0; x < minimap.width; ++x )
783 if ( v > 255.0 / 256.0 ) {
789 Sys_Printf( " writing to %s...", minimapFilename );
790 WriteTGAGray( minimapFilename, data4b, minimap.width, minimap.height );
792 case MINIMAP_MODE_BLACK:
794 for ( y = 0; y < minimap.height; ++y )
795 for ( x = 0; x < minimap.width; ++x )
802 if ( v > 255.0 / 256.0 ) {
811 Sys_Printf( " writing to %s...", minimapFilename );
812 WriteTGA( minimapFilename, data4b, minimap.width, minimap.height );
814 case MINIMAP_MODE_WHITE:
816 for ( y = 0; y < minimap.height; ++y )
817 for ( x = 0; x < minimap.width; ++x )
824 if ( v > 255.0 / 256.0 ) {
833 Sys_Printf( " writing to %s...", minimapFilename );
834 WriteTGA( minimapFilename, data4b, minimap.width, minimap.height );
838 Sys_Printf( " done.\n" );
840 /* return to sender */
850 calculates an md4 checksum for a block of data
853 static int MD4BlockChecksum( void *buffer, int length ){
854 return Com_BlockChecksum( buffer, length );
859 resets an aas checksum to match the given BSP
862 int FixAAS( int argc, char **argv ){
863 int length, checksum;
866 char aas[ 1024 ], **ext;
878 Sys_Printf( "Usage: q3map -fixaas [-v] <mapname>\n" );
882 /* do some path mangling */
883 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
884 StripExtension( source );
885 DefaultExtension( source, ".bsp" );
888 Sys_Printf( "--- FixAAS ---\n" );
891 Sys_Printf( "Loading %s\n", source );
892 length = LoadFile( source, &buffer );
894 /* create bsp checksum */
895 Sys_Printf( "Creating checksum...\n" );
896 checksum = LittleLong( MD4BlockChecksum( buffer, length ) );
898 /* write checksum to aas */
903 strcpy( aas, source );
904 StripExtension( aas );
906 Sys_Printf( "Trying %s\n", aas );
910 file = fopen( aas, "r+b" );
914 if ( fwrite( &checksum, 4, 1, file ) != 1 ) {
915 Error( "Error writing checksum to %s", aas );
920 /* return to sender */
928 analyzes a Quake engine BSP file
931 typedef struct abspHeader_s
936 bspLump_t lumps[ 1 ]; /* unknown size */
940 typedef struct abspLumpTest_s
947 int AnalyzeBSP( int argc, char **argv ){
948 abspHeader_t *header;
949 int size, i, version, offset, length, lumpInt, count;
953 char lumpString[ 1024 ], source[ 1024 ];
954 qboolean lumpSwap = qfalse;
955 abspLumpTest_t *lumpTest;
956 static abspLumpTest_t lumpTests[] =
958 { sizeof( bspPlane_t ), 6, "IBSP LUMP_PLANES" },
959 { sizeof( bspBrush_t ), 1, "IBSP LUMP_BRUSHES" },
960 { 8, 6, "IBSP LUMP_BRUSHSIDES" },
961 { sizeof( bspBrushSide_t ), 6, "RBSP LUMP_BRUSHSIDES" },
962 { sizeof( bspModel_t ), 1, "IBSP LUMP_MODELS" },
963 { sizeof( bspNode_t ), 2, "IBSP LUMP_NODES" },
964 { sizeof( bspLeaf_t ), 1, "IBSP LUMP_LEAFS" },
965 { 104, 3, "IBSP LUMP_DRAWSURFS" },
966 { 44, 3, "IBSP LUMP_DRAWVERTS" },
967 { 4, 6, "IBSP LUMP_DRAWINDEXES" },
968 { 128 * 128 * 3, 1, "IBSP LUMP_LIGHTMAPS" },
969 { 256 * 256 * 3, 1, "IBSP LUMP_LIGHTMAPS (256 x 256)" },
970 { 512 * 512 * 3, 1, "IBSP LUMP_LIGHTMAPS (512 x 512)" },
977 Sys_Printf( "Usage: q3map -analyze [-lumpswap] [-v] <mapname>\n" );
981 /* process arguments */
982 for ( i = 1; i < ( argc - 1 ); i++ )
984 /* -format map|ase|... */
985 if ( !strcmp( argv[ i ], "-lumpswap" ) ) {
986 Sys_Printf( "Swapped lump structs enabled\n" );
991 /* clean up map name */
992 strcpy( source, ExpandArg( argv[ i ] ) );
993 Sys_Printf( "Loading %s\n", source );
996 size = LoadFile( source, (void**) &header );
997 if ( size == 0 || header == NULL ) {
998 Sys_Printf( "Unable to load %s.\n", source );
1002 /* analyze ident/version */
1003 memcpy( ident, header->ident, 4 );
1005 version = LittleLong( header->version );
1007 Sys_Printf( "Identity: %s\n", ident );
1008 Sys_Printf( "Version: %d\n", version );
1009 Sys_Printf( "---------------------------------------\n" );
1011 /* analyze each lump */
1012 for ( i = 0; i < 100; i++ )
1014 /* call of duty swapped lump pairs */
1016 offset = LittleLong( header->lumps[ i ].length );
1017 length = LittleLong( header->lumps[ i ].offset );
1020 /* standard lump pairs */
1023 offset = LittleLong( header->lumps[ i ].offset );
1024 length = LittleLong( header->lumps[ i ].length );
1028 lump = (byte*) header + offset;
1029 lumpInt = LittleLong( (int) *( (int*) lump ) );
1030 lumpFloat = LittleFloat( (float) *( (float*) lump ) );
1031 memcpy( lumpString, (char*) lump, ( (size_t)length < sizeof( lumpString ) ? (size_t)length : sizeof( lumpString ) - 1 ) );
1032 lumpString[ sizeof( lumpString ) - 1 ] = '\0';
1034 /* print basic lump info */
1035 Sys_Printf( "Lump: %d\n", i );
1036 Sys_Printf( "Offset: %d bytes\n", offset );
1037 Sys_Printf( "Length: %d bytes\n", length );
1039 /* only operate on valid lumps */
1041 /* print data in 4 formats */
1042 Sys_Printf( "As hex: %08X\n", lumpInt );
1043 Sys_Printf( "As int: %d\n", lumpInt );
1044 Sys_Printf( "As float: %f\n", lumpFloat );
1045 Sys_Printf( "As string: %s\n", lumpString );
1047 /* guess lump type */
1048 if ( lumpString[ 0 ] == '{' && lumpString[ 2 ] == '"' ) {
1049 Sys_Printf( "Type guess: IBSP LUMP_ENTITIES\n" );
1051 else if ( strstr( lumpString, "textures/" ) ) {
1052 Sys_Printf( "Type guess: IBSP LUMP_SHADERS\n" );
1056 /* guess based on size/count */
1057 for ( lumpTest = lumpTests; lumpTest->radix > 0; lumpTest++ )
1059 if ( ( length % lumpTest->radix ) != 0 ) {
1062 count = length / lumpTest->radix;
1063 if ( count < lumpTest->minCount ) {
1066 Sys_Printf( "Type guess: %s (%d x %d)\n", lumpTest->name, count, lumpTest->radix );
1071 Sys_Printf( "---------------------------------------\n" );
1074 if ( offset + length >= size ) {
1080 Sys_Printf( "Lump count: %d\n", i + 1 );
1081 Sys_Printf( "File size: %d bytes\n", size );
1083 /* return to caller */
1091 emits statistics about the bsp file
1094 int BSPInfo( int count, char **fileNames ){
1096 char source[ 1024 ], ext[ 64 ];
1103 Sys_Printf( "No files to dump info for.\n" );
1107 /* enable info mode */
1110 /* walk file list */
1111 for ( i = 0; i < count; i++ )
1113 Sys_Printf( "---------------------------------\n" );
1115 /* mangle filename and get size */
1116 strcpy( source, fileNames[ i ] );
1117 ExtractFileExtension( source, ext );
1118 if ( !Q_stricmp( ext, "map" ) ) {
1119 StripExtension( source );
1121 DefaultExtension( source, ".bsp" );
1122 f = fopen( source, "rb" );
1124 size = Q_filelength( f );
1131 /* load the bsp file and print lump sizes */
1132 Sys_Printf( "%s\n", source );
1133 LoadBSPFile( source );
1134 PrintBSPFileSizes();
1138 Sys_Printf( " total %9d\n", size );
1139 Sys_Printf( " %9d KB\n", size / 1024 );
1140 Sys_Printf( " %9d MB\n", size / ( 1024 * 1024 ) );
1142 Sys_Printf( "---------------------------------\n" );
1150 static void ExtrapolateTexcoords( const float *axyz, const float *ast, const float *bxyz, const float *bst, const float *cxyz, const float *cst, const float *axyz_new, float *ast_out, const float *bxyz_new, float *bst_out, const float *cxyz_new, float *cst_out ){
1151 vec4_t scoeffs, tcoeffs;
1157 VectorSubtract( bxyz, axyz, dab );
1158 VectorSubtract( cxyz, axyz, dac );
1159 CrossProduct( dab, dac, norm );
1163 // s(v + norm) = s(v) when n ortho xyz
1165 // s(v) = DotProduct(v, scoeffs) + scoeffs[3]
1168 // scoeffs * (axyz, 1) == ast[0]
1169 // scoeffs * (bxyz, 1) == bst[0]
1170 // scoeffs * (cxyz, 1) == cst[0]
1171 // scoeffs * (norm, 0) == 0
1172 // scoeffs * [axyz, 1 | bxyz, 1 | cxyz, 1 | norm, 0] = [ast[0], bst[0], cst[0], 0]
1173 solvematrix[0] = axyz[0];
1174 solvematrix[4] = axyz[1];
1175 solvematrix[8] = axyz[2];
1176 solvematrix[12] = 1;
1177 solvematrix[1] = bxyz[0];
1178 solvematrix[5] = bxyz[1];
1179 solvematrix[9] = bxyz[2];
1180 solvematrix[13] = 1;
1181 solvematrix[2] = cxyz[0];
1182 solvematrix[6] = cxyz[1];
1183 solvematrix[10] = cxyz[2];
1184 solvematrix[14] = 1;
1185 solvematrix[3] = norm[0];
1186 solvematrix[7] = norm[1];
1187 solvematrix[11] = norm[2];
1188 solvematrix[15] = 0;
1190 md = m4_det( solvematrix );
1191 if ( md * md < 1e-10 ) {
1192 Sys_Printf( "Cannot invert some matrix, some texcoords aren't extrapolated!" );
1196 m4x4_invert( solvematrix );
1198 scoeffs[0] = ast[0];
1199 scoeffs[1] = bst[0];
1200 scoeffs[2] = cst[0];
1202 m4x4_transform_vec4( solvematrix, scoeffs );
1203 tcoeffs[0] = ast[1];
1204 tcoeffs[1] = bst[1];
1205 tcoeffs[2] = cst[1];
1207 m4x4_transform_vec4( solvematrix, tcoeffs );
1209 ast_out[0] = scoeffs[0] * axyz_new[0] + scoeffs[1] * axyz_new[1] + scoeffs[2] * axyz_new[2] + scoeffs[3];
1210 ast_out[1] = tcoeffs[0] * axyz_new[0] + tcoeffs[1] * axyz_new[1] + tcoeffs[2] * axyz_new[2] + tcoeffs[3];
1211 bst_out[0] = scoeffs[0] * bxyz_new[0] + scoeffs[1] * bxyz_new[1] + scoeffs[2] * bxyz_new[2] + scoeffs[3];
1212 bst_out[1] = tcoeffs[0] * bxyz_new[0] + tcoeffs[1] * bxyz_new[1] + tcoeffs[2] * bxyz_new[2] + tcoeffs[3];
1213 cst_out[0] = scoeffs[0] * cxyz_new[0] + scoeffs[1] * cxyz_new[1] + scoeffs[2] * cxyz_new[2] + scoeffs[3];
1214 cst_out[1] = tcoeffs[0] * cxyz_new[0] + tcoeffs[1] * cxyz_new[1] + tcoeffs[2] * cxyz_new[2] + tcoeffs[3];
1219 amaze and confuse your enemies with wierd scaled maps!
1222 int ScaleBSPMain( int argc, char **argv ){
1230 float *old_xyzst = NULL;
1231 float spawn_ref = 0;
1236 Sys_Printf( "Usage: q3map [-v] -scale [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
1241 for ( i = 1; i < argc - 2; ++i )
1243 if ( !strcmp( argv[i], "-tex" ) ) {
1246 else if ( !strcmp( argv[i], "-spawn_ref" ) ) {
1247 spawn_ref = atof( argv[i + 1] );
1256 // if(argc-2 >= i) // always true
1257 scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] );
1258 if ( argc - 3 >= i ) {
1259 scale[1] = scale[0] = atof( argv[ argc - 3 ] );
1261 if ( argc - 4 >= i ) {
1262 scale[0] = atof( argv[ argc - 4 ] );
1265 uniform = ( ( scale[0] == scale[1] ) && ( scale[1] == scale[2] ) );
1267 if ( scale[0] == 0.0f || scale[1] == 0.0f || scale[2] == 0.0f ) {
1268 Sys_Printf( "Usage: q3map [-v] -scale [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
1269 Sys_Printf( "Non-zero scale value required.\n" );
1273 /* do some path mangling */
1274 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
1275 StripExtension( source );
1276 DefaultExtension( source, ".bsp" );
1279 Sys_Printf( "Loading %s\n", source );
1280 LoadBSPFile( source );
1284 Sys_Printf( "--- ScaleBSP ---\n" );
1285 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
1287 /* scale entity keys */
1288 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
1291 GetVectorForKey( &entities[ i ], "origin", vec );
1292 if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) {
1293 if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
1294 vec[2] += spawn_ref;
1299 if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
1300 vec[2] -= spawn_ref;
1302 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
1303 SetKeyValue( &entities[ i ], "origin", str );
1306 a = FloatForKey( &entities[ i ], "angle" );
1307 if ( a == -1 || a == -2 ) { // z scale
1310 else if ( fabs( sin( DEG2RAD( a ) ) ) < 0.707 ) {
1317 /* scale door lip */
1318 f = FloatForKey( &entities[ i ], "lip" );
1321 sprintf( str, "%f", f );
1322 SetKeyValue( &entities[ i ], "lip", str );
1325 /* scale plat height */
1326 f = FloatForKey( &entities[ i ], "height" );
1329 sprintf( str, "%f", f );
1330 SetKeyValue( &entities[ i ], "height", str );
1333 // TODO maybe allow a definition file for entities to specify which values are scaled how?
1337 for ( i = 0; i < numBSPModels; i++ )
1339 bspModels[ i ].mins[0] *= scale[0];
1340 bspModels[ i ].mins[1] *= scale[1];
1341 bspModels[ i ].mins[2] *= scale[2];
1342 bspModels[ i ].maxs[0] *= scale[0];
1343 bspModels[ i ].maxs[1] *= scale[1];
1344 bspModels[ i ].maxs[2] *= scale[2];
1348 for ( i = 0; i < numBSPNodes; i++ )
1350 bspNodes[ i ].mins[0] *= scale[0];
1351 bspNodes[ i ].mins[1] *= scale[1];
1352 bspNodes[ i ].mins[2] *= scale[2];
1353 bspNodes[ i ].maxs[0] *= scale[0];
1354 bspNodes[ i ].maxs[1] *= scale[1];
1355 bspNodes[ i ].maxs[2] *= scale[2];
1359 for ( i = 0; i < numBSPLeafs; i++ )
1361 bspLeafs[ i ].mins[0] *= scale[0];
1362 bspLeafs[ i ].mins[1] *= scale[1];
1363 bspLeafs[ i ].mins[2] *= scale[2];
1364 bspLeafs[ i ].maxs[0] *= scale[0];
1365 bspLeafs[ i ].maxs[1] *= scale[1];
1366 bspLeafs[ i ].maxs[2] *= scale[2];
1370 Sys_Printf( "Using texture unlocking (and probably breaking texture alignment a lot)\n" );
1371 old_xyzst = safe_malloc( sizeof( *old_xyzst ) * numBSPDrawVerts * 5 );
1372 for ( i = 0; i < numBSPDrawVerts; i++ )
1374 old_xyzst[5 * i + 0] = bspDrawVerts[i].xyz[0];
1375 old_xyzst[5 * i + 1] = bspDrawVerts[i].xyz[1];
1376 old_xyzst[5 * i + 2] = bspDrawVerts[i].xyz[2];
1377 old_xyzst[5 * i + 3] = bspDrawVerts[i].st[0];
1378 old_xyzst[5 * i + 4] = bspDrawVerts[i].st[1];
1382 /* scale drawverts */
1383 for ( i = 0; i < numBSPDrawVerts; i++ )
1385 bspDrawVerts[i].xyz[0] *= scale[0];
1386 bspDrawVerts[i].xyz[1] *= scale[1];
1387 bspDrawVerts[i].xyz[2] *= scale[2];
1388 bspDrawVerts[i].normal[0] /= scale[0];
1389 bspDrawVerts[i].normal[1] /= scale[1];
1390 bspDrawVerts[i].normal[2] /= scale[2];
1391 VectorNormalize( bspDrawVerts[i].normal, bspDrawVerts[i].normal );
1395 for ( i = 0; i < numBSPDrawSurfaces; i++ )
1397 switch ( bspDrawSurfaces[i].surfaceType )
1401 if ( bspDrawSurfaces[i].numIndexes % 3 ) {
1402 Error( "Not a triangulation!" );
1404 for ( j = bspDrawSurfaces[i].firstIndex; j < bspDrawSurfaces[i].firstIndex + bspDrawSurfaces[i].numIndexes; j += 3 )
1406 int ia = bspDrawIndexes[j] + bspDrawSurfaces[i].firstVert, ib = bspDrawIndexes[j + 1] + bspDrawSurfaces[i].firstVert, ic = bspDrawIndexes[j + 2] + bspDrawSurfaces[i].firstVert;
1407 bspDrawVert_t *a = &bspDrawVerts[ia], *b = &bspDrawVerts[ib], *c = &bspDrawVerts[ic];
1408 float *oa = &old_xyzst[ia * 5], *ob = &old_xyzst[ib * 5], *oc = &old_xyzst[ic * 5];
1413 ExtrapolateTexcoords(
1428 for ( i = 0; i < numBSPPlanes; i++ )
1430 bspPlanes[ i ].dist *= scale[0];
1435 for ( i = 0; i < numBSPPlanes; i++ )
1437 bspPlanes[ i ].normal[0] /= scale[0];
1438 bspPlanes[ i ].normal[1] /= scale[1];
1439 bspPlanes[ i ].normal[2] /= scale[2];
1440 f = 1 / VectorLength( bspPlanes[i].normal );
1441 VectorScale( bspPlanes[i].normal, f, bspPlanes[i].normal );
1442 bspPlanes[ i ].dist *= f;
1446 /* scale gridsize */
1447 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
1448 if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) {
1449 VectorCopy( gridSize, vec );
1454 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
1455 SetKeyValue( &entities[ 0 ], "gridsize", str );
1457 /* inject command line parameters */
1458 InjectCommandLine( argv, 0, argc - 1 );
1462 StripExtension( source );
1463 DefaultExtension( source, "_s.bsp" );
1464 Sys_Printf( "Writing %s\n", source );
1465 WriteBSPFile( source );
1467 /* return to sender */
1474 shifts a map: for testing physics with huge coordinates
1477 int ShiftBSPMain( int argc, char **argv ){
1482 float spawn_ref = 0;
1487 Sys_Printf( "Usage: q3map [-v] -shift [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
1491 for ( i = 1; i < argc - 2; ++i )
1493 if ( !strcmp( argv[i], "-tex" ) ) {
1495 else if ( !strcmp( argv[i], "-spawn_ref" ) ) {
1496 spawn_ref = atof( argv[i + 1] );
1505 // if(argc-2 >= i) // always true
1506 scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] );
1507 if ( argc - 3 >= i ) {
1508 scale[1] = scale[0] = atof( argv[ argc - 3 ] );
1510 if ( argc - 4 >= i ) {
1511 scale[0] = atof( argv[ argc - 4 ] );
1515 /* do some path mangling */
1516 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
1517 StripExtension( source );
1518 DefaultExtension( source, ".bsp" );
1521 Sys_Printf( "Loading %s\n", source );
1522 LoadBSPFile( source );
1526 Sys_Printf( "--- ShiftBSP ---\n" );
1527 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
1529 /* shift entity keys */
1530 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
1533 GetVectorForKey( &entities[ i ], "origin", vec );
1534 if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) {
1535 if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
1536 vec[2] += spawn_ref;
1541 if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
1542 vec[2] -= spawn_ref;
1544 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
1545 SetKeyValue( &entities[ i ], "origin", str );
1551 for ( i = 0; i < numBSPModels; i++ )
1553 bspModels[ i ].mins[0] += scale[0];
1554 bspModels[ i ].mins[1] += scale[1];
1555 bspModels[ i ].mins[2] += scale[2];
1556 bspModels[ i ].maxs[0] += scale[0];
1557 bspModels[ i ].maxs[1] += scale[1];
1558 bspModels[ i ].maxs[2] += scale[2];
1562 for ( i = 0; i < numBSPNodes; i++ )
1564 bspNodes[ i ].mins[0] += scale[0];
1565 bspNodes[ i ].mins[1] += scale[1];
1566 bspNodes[ i ].mins[2] += scale[2];
1567 bspNodes[ i ].maxs[0] += scale[0];
1568 bspNodes[ i ].maxs[1] += scale[1];
1569 bspNodes[ i ].maxs[2] += scale[2];
1573 for ( i = 0; i < numBSPLeafs; i++ )
1575 bspLeafs[ i ].mins[0] += scale[0];
1576 bspLeafs[ i ].mins[1] += scale[1];
1577 bspLeafs[ i ].mins[2] += scale[2];
1578 bspLeafs[ i ].maxs[0] += scale[0];
1579 bspLeafs[ i ].maxs[1] += scale[1];
1580 bspLeafs[ i ].maxs[2] += scale[2];
1583 /* shift drawverts */
1584 for ( i = 0; i < numBSPDrawVerts; i++ )
1586 bspDrawVerts[i].xyz[0] += scale[0];
1587 bspDrawVerts[i].xyz[1] += scale[1];
1588 bspDrawVerts[i].xyz[2] += scale[2];
1595 for ( i = 0; i < numBSPPlanes; i++ )
1597 //find point on plane
1598 for ( j=0; j<3; j++ ){
1599 if ( fabs( bspPlanes[ i ].normal[j] ) > 0.5 ){
1600 point[j] = bspPlanes[ i ].dist / bspPlanes[ i ].normal[j];
1601 point[(j+1)%3] = point[(j+2)%3] = 0;
1606 for ( j=0; j<3; j++ ){
1607 point[j] += scale[j];
1609 //calc new plane dist
1610 bspPlanes[ i ].dist = DotProduct( point, bspPlanes[ i ].normal );
1613 /* scale gridsize */
1615 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
1616 if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) {
1617 VectorCopy( gridSize, vec );
1622 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
1623 SetKeyValue( &entities[ 0 ], "gridsize", str );
1625 /* inject command line parameters */
1626 InjectCommandLine( argv, 0, argc - 1 );
1630 StripExtension( source );
1631 DefaultExtension( source, "_sh.bsp" );
1632 Sys_Printf( "Writing %s\n", source );
1633 WriteBSPFile( source );
1635 /* return to sender */
1640 void FixDOSName( char *src ){
1641 if ( src == NULL ) {
1647 if ( *src == '\\' ) {
1655 Check if newcoming texture is unique and not excluded
1657 void tex2list( char* texlist, int *texnum, char* EXtex, int *EXtexnum ){
1659 if ( token[0] == '\0') return;
1660 StripExtension( token );
1661 FixDOSName( token );
1662 for ( i = 0; i < *texnum; i++ ){
1663 if ( !Q_stricmp( texlist + i*65, token ) ) return;
1665 for ( i = 0; i < *EXtexnum; i++ ){
1666 if ( !Q_stricmp( EXtex + i*65, token ) ) return;
1668 strcpy ( texlist + (*texnum)*65, token );
1674 void tex2list2( char* texlist, int *texnum, char* EXtex, int *EXtexnum, char* rEXtex, int *rEXtexnum ){
1676 if ( token[0] == '\0') return;
1677 //StripExtension( token );
1678 char* dot = strrchr( token, '.' );
1680 if ( Q_stricmp( dot, ".tga" ) && Q_stricmp( dot, ".jpg" ) && Q_stricmp( dot, ".png" ) ){
1681 Sys_Printf( "WARNING4: %s : weird or missing extension in shader\n", token );
1687 FixDOSName( token );
1688 strcpy ( texlist + (*texnum)*65, token );
1689 strcat( token, ".tga" );
1692 for ( i = 0; i < *texnum; i++ ){
1693 if ( !Q_stricmp( texlist + i*65, texlist + (*texnum)*65 ) ) return;
1695 for ( i = 0; i < *EXtexnum; i++ ){
1696 if ( !Q_stricmp( EXtex + i*65, texlist + (*texnum)*65 ) ) return;
1698 for ( i = 0; i < *rEXtexnum; i++ ){
1699 if ( !Q_stricmp( rEXtex + i*65, texlist + (*texnum)*65 ) ) return;
1707 Check if newcoming res is unique
1709 void res2list( char* data, int *num ){
1711 if ( strlen( data + (*num)*65 ) > 64 ){
1712 Sys_Printf( "WARNING6: %s : path too long.\n", data + (*num)*65 );
1714 while ( *( data + (*num)*65 ) == '\\' || *( data + (*num)*65 ) == '/' ){
1715 char* cut = data + (*num)*65 + 1;
1716 strcpy( data + (*num)*65, cut );
1718 if ( *( data + (*num)*65 ) == '\0') return;
1719 for ( i = 0; i < *num; i++ ){
1720 if ( !Q_stricmp( data + i*65, data + (*num)*65 ) ) return;
1726 void parseEXblock ( char* data, int *num, const char *exName ){
1727 if ( !GetToken( qtrue ) || strcmp( token, "{" ) ) {
1728 Error( "ReadExclusionsFile: %s, line %d: { not found", exName, scriptline );
1732 if ( !GetToken( qtrue ) ) {
1735 if ( !strcmp( token, "}" ) ) {
1738 if ( token[0] == '{' ) {
1739 Error( "ReadExclusionsFile: %s, line %d: brace, opening twice in a row.", exName, scriptline );
1743 strcpy( data + (*num)*65, token );
1749 char q3map2path[1024];
1752 map autopackager, works for Q3 type of shaders and ents
1755 int pk3BSPMain( int argc, char **argv ){
1757 qboolean dbg = qfalse, png = qfalse, packFAIL = qfalse;
1759 /* process arguments */
1760 for ( i = 1; i < ( argc - 1 ); i++ ){
1761 if ( !strcmp( argv[ i ], "-dbg" ) ) {
1764 else if ( !strcmp( argv[ i ], "-png" ) ) {
1769 /* do some path mangling */
1770 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
1771 StripExtension( source );
1772 DefaultExtension( source, ".bsp" );
1775 Sys_Printf( "Loading %s\n", source );
1776 LoadBSPFile( source );
1780 char packname[ 1024 ], packFailName[ 1024 ], base[ 1024 ], nameOFmap[ 1024 ], temp[ 1024 ];
1783 strcpy( base, source );
1784 StripExtension( base );
1786 /* extract map name */
1787 len = strlen( base ) - 1;
1788 while ( len > 0 && base[ len ] != '/' && base[ len ] != '\\' )
1790 strcpy( nameOFmap, &base[ len + 1 ] );
1793 qboolean drawsurfSHs[1024] = { qfalse };
1795 for ( i = 0; i < numBSPDrawSurfaces; i++ ){
1796 /* can't exclude nodraw patches here (they want shaders :0!) */
1797 //if ( !( bspDrawSurfaces[i].surfaceType == 2 && bspDrawSurfaces[i].numIndexes == 0 ) ) drawsurfSHs[bspDrawSurfaces[i].shaderNum] = qtrue;
1798 drawsurfSHs[ bspDrawSurfaces[i].shaderNum ] = qtrue;
1799 //Sys_Printf( "%s\n", bspShaders[bspDrawSurfaces[i].shaderNum].shader );
1802 int pk3ShadersN = 0;
1803 char* pk3Shaders = (char *)calloc( 1024*65, sizeof( char ) );
1805 char* pk3Sounds = (char *)calloc( 1024*65, sizeof( char ) );
1806 int pk3ShaderfilesN = 0;
1807 char* pk3Shaderfiles = (char *)calloc( 1024*65, sizeof( char ) );
1808 int pk3TexturesN = 0;
1809 char* pk3Textures = (char *)calloc( 1024*65, sizeof( char ) );
1811 char* pk3Videos = (char *)calloc( 1024*65, sizeof( char ) );
1815 for ( i = 0; i < numBSPShaders; i++ ){
1816 if ( drawsurfSHs[i] ){
1817 strcpy( pk3Shaders + pk3ShadersN*65, bspShaders[i].shader );
1818 res2list( pk3Shaders, &pk3ShadersN );
1820 //Sys_Printf( "%s\n", bspShaders[i].shader );
1826 for ( ep = entities[0].epairs; ep != NULL; ep = ep->next )
1828 if ( !Q_strncasecmp( ep->key, "vertexremapshader", 17 ) ) {
1829 sscanf( ep->value, "%*[^;] %*[;] %s", pk3Shaders + pk3ShadersN*65 );
1830 res2list( pk3Shaders, &pk3ShadersN );
1833 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[0], "music" ) );
1834 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' ){
1835 FixDOSName( pk3Sounds + pk3SoundsN*65 );
1836 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
1837 res2list( pk3Sounds, &pk3SoundsN );
1840 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
1842 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[i], "noise" ) );
1843 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' && *( pk3Sounds + pk3SoundsN*65 ) != '*' ){
1844 FixDOSName( pk3Sounds + pk3SoundsN*65 );
1845 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
1846 res2list( pk3Sounds, &pk3SoundsN );
1849 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "func_plat" ) ){
1850 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_strt.wav");
1851 res2list( pk3Sounds, &pk3SoundsN );
1852 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_end.wav");
1853 res2list( pk3Sounds, &pk3SoundsN );
1855 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "target_push" ) ){
1856 if ( !(IntForKey( &entities[i], "spawnflags") & 1) ){
1857 strcpy( pk3Sounds + pk3SoundsN*65, "sound/misc/windfly.wav");
1858 res2list( pk3Sounds, &pk3SoundsN );
1861 strcpy( pk3Shaders + pk3ShadersN*65, ValueForKey( &entities[i], "targetShaderNewName" ) );
1862 res2list( pk3Shaders, &pk3ShadersN );
1866 sprintf( pk3Shaders + pk3ShadersN*65, "levelshots/%s", nameOFmap );
1867 res2list( pk3Shaders, &pk3ShadersN );
1871 Sys_Printf( "\n\tDrawsurface+ent calls....%i\n", pk3ShadersN );
1872 for ( i = 0; i < pk3ShadersN; i++ ){
1873 Sys_Printf( "%s\n", pk3Shaders + i*65 );
1875 Sys_Printf( "\n\tSounds....%i\n", pk3SoundsN );
1876 for ( i = 0; i < pk3SoundsN; i++ ){
1877 Sys_Printf( "%s\n", pk3Sounds + i*65 );
1881 vfsListShaderFiles( pk3Shaderfiles, &pk3ShaderfilesN );
1884 Sys_Printf( "\n\tSchroider fileses.....%i\n", pk3ShaderfilesN );
1885 for ( i = 0; i < pk3ShaderfilesN; i++ ){
1886 Sys_Printf( "%s\n", pk3Shaderfiles + i*65 );
1891 /* load exclusions file */
1892 int ExTexturesN = 0;
1893 char* ExTextures = (char *)calloc( 4096*65, sizeof( char ) );
1895 char* ExShaders = (char *)calloc( 4096*65, sizeof( char ) );
1897 char* ExSounds = (char *)calloc( 4096*65, sizeof( char ) );
1898 int ExShaderfilesN = 0;
1899 char* ExShaderfiles = (char *)calloc( 4096*65, sizeof( char ) );
1901 char* ExVideos = (char *)calloc( 4096*65, sizeof( char ) );
1902 int ExPureTexturesN = 0;
1903 char* ExPureTextures = (char *)calloc( 4096*65, sizeof( char ) );
1905 char* ExReasonShader[4096] = { NULL };
1906 char* ExReasonShaderFile[4096] = { NULL };
1908 char exName[ 1024 ];
1912 strcpy( exName, q3map2path );
1913 char *cut = strrchr( exName, '\\' );
1914 char *cut2 = strrchr( exName, '/' );
1915 if ( cut == NULL && cut2 == NULL ){
1916 Sys_Printf( "WARNING: Unable to load exclusions file.\n" );
1919 if ( cut2 > cut ) cut = cut2;
1921 strcat( exName, game->arg );
1922 strcat( exName, ".exclude" );
1924 Sys_Printf( "Loading %s\n", exName );
1925 size = TryLoadFile( exName, (void**) &buffer );
1927 Sys_Printf( "WARNING: Unable to find exclusions file %s.\n", exName );
1931 /* parse the file */
1932 ParseFromMemory( (char *) buffer, size );
1937 /* test for end of file */
1938 if ( !GetToken( qtrue ) ) {
1943 if ( !Q_stricmp( token, "textures" ) ){
1944 parseEXblock ( ExTextures, &ExTexturesN, exName );
1946 else if ( !Q_stricmp( token, "shaders" ) ){
1947 parseEXblock ( ExShaders, &ExShadersN, exName );
1949 else if ( !Q_stricmp( token, "shaderfiles" ) ){
1950 parseEXblock ( ExShaderfiles, &ExShaderfilesN, exName );
1952 else if ( !Q_stricmp( token, "sounds" ) ){
1953 parseEXblock ( ExSounds, &ExSoundsN, exName );
1955 else if ( !Q_stricmp( token, "videos" ) ){
1956 parseEXblock ( ExVideos, &ExVideosN, exName );
1959 Error( "ReadExclusionsFile: %s, line %d: unknown block name!\nValid ones are: textures, shaders, shaderfiles, sounds, videos.", exName, scriptline );
1963 /* free the buffer */
1966 for ( i = 0; i < ExTexturesN; i++ ){
1967 for ( j = 0; j < ExShadersN; j++ ){
1968 if ( !Q_stricmp( ExTextures + i*65, ExShaders + j*65 ) ){
1972 if ( j == ExShadersN ){
1973 strcpy ( ExPureTextures + ExPureTexturesN*65, ExTextures + i*65 );
1981 Sys_Printf( "\n\tExTextures....%i\n", ExTexturesN );
1982 for ( i = 0; i < ExTexturesN; i++ ) Sys_Printf( "%s\n", ExTextures + i*65 );
1983 Sys_Printf( "\n\tExPureTextures....%i\n", ExPureTexturesN );
1984 for ( i = 0; i < ExPureTexturesN; i++ ) Sys_Printf( "%s\n", ExPureTextures + i*65 );
1985 Sys_Printf( "\n\tExShaders....%i\n", ExShadersN );
1986 for ( i = 0; i < ExShadersN; i++ ) Sys_Printf( "%s\n", ExShaders + i*65 );
1987 Sys_Printf( "\n\tExShaderfiles....%i\n", ExShaderfilesN );
1988 for ( i = 0; i < ExShaderfilesN; i++ ) Sys_Printf( "%s\n", ExShaderfiles + i*65 );
1989 Sys_Printf( "\n\tExSounds....%i\n", ExSoundsN );
1990 for ( i = 0; i < ExSoundsN; i++ ) Sys_Printf( "%s\n", ExSounds + i*65 );
1991 Sys_Printf( "\n\tExVideos....%i\n", ExVideosN );
1992 for ( i = 0; i < ExVideosN; i++ ) Sys_Printf( "%s\n", ExVideos + i*65 );
1995 /* can exclude pure textures right now, shouldn't create shaders for them anyway */
1996 for ( i = 0; i < pk3ShadersN ; i++ ){
1997 for ( j = 0; j < ExPureTexturesN ; j++ ){
1998 if ( !Q_stricmp( pk3Shaders + i*65, ExPureTextures + j*65 ) ){
1999 *( pk3Shaders + i*65 ) = '\0';
2005 //Parse Shader Files
2007 endofscript = qtrue;
2009 for ( i = 0; i < pk3ShaderfilesN; i++ ){
2010 qboolean wantShader = qfalse, wantShaderFile = qfalse, ShaderFileExcluded = qfalse;
2012 char* reasonShader = NULL;
2013 char* reasonShaderFile = NULL;
2015 /* load the shader */
2016 sprintf( temp, "%s/%s", game->shaderPath, pk3Shaderfiles + i*65 );
2017 SilentLoadScriptFile( temp, 0 );
2018 if( dbg ) Sys_Printf( "\n\tentering %s\n", pk3Shaderfiles + i*65 );
2020 /* do wanna le shader file? */
2021 for ( j = 0; j < ExShaderfilesN; j++ ){
2022 if ( !Q_stricmp( ExShaderfiles + j*65, pk3Shaderfiles + i*65 ) ){
2023 ShaderFileExcluded = qtrue;
2024 reasonShaderFile = ExShaderfiles + j*65;
2029 /* check if shader file has to be excluded */
2030 while ( !ShaderFileExcluded )
2032 /* test for end of file */
2033 if ( !GetToken( qtrue ) ) {
2037 /* does it contain restricted shaders/textures? */
2038 for ( j = 0; j < ExShadersN; j++ ){
2039 if ( !Q_stricmp( ExShaders + j*65, token ) ){
2040 ShaderFileExcluded = qtrue;
2041 reasonShader = ExShaders + j*65;
2045 if ( ShaderFileExcluded )
2047 for ( j = 0; j < ExPureTexturesN; j++ ){
2048 if ( !Q_stricmp( ExPureTextures + j*65, token ) ){
2049 ShaderFileExcluded = qtrue;
2050 reasonShader = ExPureTextures + j*65;
2054 if ( ShaderFileExcluded )
2057 /* handle { } section */
2058 if ( !GetToken( qtrue ) ) {
2061 if ( strcmp( token, "{" ) ) {
2062 Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s\nFile location be: %s",
2063 temp, scriptline, token, g_strLoadedFileLocation );
2068 /* get the next token */
2069 if ( !GetToken( qtrue ) ) {
2072 if ( !strcmp( token, "}" ) ) {
2075 /* parse stage directives */
2076 if ( !strcmp( token, "{" ) ) {
2079 if ( !GetToken( qtrue ) ) {
2082 if ( !strcmp( token, "}" ) ) {
2090 /* tokenize it again */
2091 SilentLoadScriptFile( temp, 0 );
2094 /* test for end of file */
2095 if ( !GetToken( qtrue ) ) {
2099 if( dbg ) Sys_Printf( "%s\n", token );
2101 /* do wanna le shader? */
2102 wantShader = qfalse;
2103 for ( j = 0; j < pk3ShadersN; j++ ){
2104 if ( !Q_stricmp( pk3Shaders + j*65, token) ){
2111 /* handle { } section */
2112 if ( !GetToken( qtrue ) ) {
2115 if ( strcmp( token, "{" ) ) {
2116 Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s\nFile location be: %s",
2117 temp, scriptline, token, g_strLoadedFileLocation );
2120 qboolean hasmap = qfalse;
2123 /* get the next token */
2124 if ( !GetToken( qtrue ) ) {
2127 if ( !strcmp( token, "}" ) ) {
2132 /* -----------------------------------------------------------------
2133 shader stages (passes)
2134 ----------------------------------------------------------------- */
2136 /* parse stage directives */
2137 if ( !strcmp( token, "{" ) ) {
2140 if ( !GetToken( qtrue ) ) {
2143 if ( !strcmp( token, "}" ) ) {
2146 if ( !strcmp( token, "{" ) ) {
2147 Sys_Printf( "WARNING9: %s : line %d : opening brace inside shader stage\n", temp, scriptline );
2149 if ( !Q_stricmp( token, "mapComp" ) || !Q_stricmp( token, "mapNoComp" ) || !Q_stricmp( token, "animmapcomp" ) || !Q_stricmp( token, "animmapnocomp" ) ){
2150 Sys_Printf( "WARNING7: %s : line %d : unsupported '%s' map directive\n", temp, scriptline, token );
2152 /* skip the shader */
2153 if ( !wantShader ) continue;
2155 /* digest any images */
2156 if ( !Q_stricmp( token, "map" ) ||
2157 !Q_stricmp( token, "clampMap" ) ) {
2161 if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) {
2162 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
2165 else if ( !Q_stricmp( token, "animMap" ) ||
2166 !Q_stricmp( token, "clampAnimMap" ) ) {
2168 GetToken( qfalse );// skip num
2169 while ( TokenAvailable() ){
2171 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
2174 else if ( !Q_stricmp( token, "videoMap" ) ){
2177 FixDOSName( token );
2178 if ( strchr( token, '/' ) == NULL && strchr( token, '\\' ) == NULL ){
2179 sprintf( temp, "video/%s", token );
2180 strcpy( token, temp );
2182 FixDOSName( token );
2183 for ( j = 0; j < pk3VideosN; j++ ){
2184 if ( !Q_stricmp( pk3Videos + j*65, token ) ){
2188 for ( j = 0; j < ExVideosN; j++ ){
2189 if ( !Q_stricmp( ExVideos + j*65, token ) ){
2193 strcpy ( pk3Videos + pk3VideosN*65, token );
2200 else if ( !Q_strncasecmp( token, "implicit", 8 ) ){
2201 Sys_Printf( "WARNING5: %s : line %d : unsupported %s shader\n", temp, scriptline, token );
2203 /* skip the shader */
2204 else if ( !wantShader ) continue;
2206 /* -----------------------------------------------------------------
2207 surfaceparm * directives
2208 ----------------------------------------------------------------- */
2210 /* match surfaceparm */
2211 else if ( !Q_stricmp( token, "surfaceparm" ) ) {
2213 if ( !Q_stricmp( token, "nodraw" ) ) {
2214 wantShader = qfalse;
2215 *( pk3Shaders + shader*65 ) = '\0';
2219 /* skyparms <outer image> <cloud height> <inner image> */
2220 else if ( !Q_stricmp( token, "skyParms" ) ) {
2222 /* get image base */
2225 /* ignore bogus paths */
2226 if ( Q_stricmp( token, "-" ) && Q_stricmp( token, "full" ) ) {
2227 strcpy ( temp, token );
2228 sprintf( token, "%s_up", temp );
2229 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
2230 sprintf( token, "%s_dn", temp );
2231 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
2232 sprintf( token, "%s_lf", temp );
2233 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
2234 sprintf( token, "%s_rt", temp );
2235 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
2236 sprintf( token, "%s_bk", temp );
2237 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
2238 sprintf( token, "%s_ft", temp );
2239 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
2241 /* skip rest of line */
2245 else if ( !Q_stricmp( token, "fogparms" ) ){
2252 for ( j = 0; j < ExShadersN; j++ ){
2253 if ( !Q_stricmp( ExShaders + j*65, pk3Shaders + shader*65 ) ){
2254 wantShader = qfalse;
2255 *( pk3Shaders + shader*65 ) = '\0';
2260 wantShader = qfalse;
2263 if ( ShaderFileExcluded ){
2264 if ( reasonShaderFile != NULL ){
2265 ExReasonShaderFile[ shader ] = reasonShaderFile;
2268 ExReasonShaderFile[ shader ] = ( char* ) calloc( 65, sizeof( char ) );
2269 strcpy( ExReasonShaderFile[ shader ], pk3Shaderfiles + i*65 );
2271 ExReasonShader[ shader ] = reasonShader;
2274 wantShaderFile = qtrue;
2275 *( pk3Shaders + shader*65 ) = '\0';
2280 if ( !wantShaderFile ){
2281 *( pk3Shaderfiles + i*65 ) = '\0';
2288 //wanted shaders from excluded .shaders
2290 for ( i = 0; i < pk3ShadersN; i++ ){
2291 if ( *( pk3Shaders + i*65 ) != '\0' && ( ExReasonShader[i] != NULL || ExReasonShaderFile[i] != NULL ) ){
2292 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
2294 if ( ExReasonShader[i] != NULL ){
2295 Sys_Printf( " reason: is located in %s,\n containing restricted shader %s\n", ExReasonShaderFile[i], ExReasonShader[i] );
2298 Sys_Printf( " reason: is located in restricted %s\n", ExReasonShaderFile[i] );
2300 *( pk3Shaders + i*65 ) = '\0';
2303 //pure textures (shader ones are done)
2304 for ( i = 0; i < pk3ShadersN; i++ ){
2305 if ( *( pk3Shaders + i*65 ) != '\0' ){
2306 FixDOSName( pk3Shaders + i*65 );
2307 for ( j = 0; j < pk3TexturesN; j++ ){
2308 if ( !Q_stricmp( pk3Shaders + i*65, pk3Textures + j*65 ) ){
2309 *( pk3Shaders + i*65 ) = '\0';
2313 if ( *( pk3Shaders + i*65 ) == '\0' ) continue;
2314 for ( j = 0; j < ExTexturesN; j++ ){
2315 if ( !Q_stricmp( pk3Shaders + i*65, ExTextures + j*65 ) ){
2316 *( pk3Shaders + i*65 ) = '\0';
2324 for ( i = 0; i < pk3SoundsN; i++ ){
2325 for ( j = 0; j < ExSoundsN; j++ ){
2326 if ( !Q_stricmp( pk3Sounds + i*65, ExSounds + j*65 ) ){
2327 *( pk3Sounds + i*65 ) = '\0';
2334 sprintf( packname, "%s/%s_autopacked.pk3", EnginePath, nameOFmap );
2336 sprintf( packFailName, "%s/%s_FAILEDpack.pk3", EnginePath, nameOFmap );
2337 remove( packFailName );
2339 Sys_Printf( "\n--- ZipZip ---\n" );
2341 Sys_Printf( "\n\tShader referenced textures....\n" );
2343 for ( i = 0; i < pk3TexturesN; i++ ){
2345 sprintf( temp, "%s.png", pk3Textures + i*65 );
2346 if ( vfsPackFile( temp, packname, 10 ) ){
2347 Sys_Printf( "++%s\n", temp );
2351 sprintf( temp, "%s.tga", pk3Textures + i*65 );
2352 if ( vfsPackFile( temp, packname, 10 ) ){
2353 Sys_Printf( "++%s\n", temp );
2356 sprintf( temp, "%s.jpg", pk3Textures + i*65 );
2357 if ( vfsPackFile( temp, packname, 10 ) ){
2358 Sys_Printf( "++%s\n", temp );
2361 Sys_Printf( " !FAIL! %s\n", pk3Textures + i*65 );
2365 Sys_Printf( "\n\tPure textures....\n" );
2367 for ( i = 0; i < pk3ShadersN; i++ ){
2368 if ( *( pk3Shaders + i*65 ) != '\0' ){
2370 sprintf( temp, "%s.png", pk3Shaders + i*65 );
2371 if ( vfsPackFile( temp, packname, 10 ) ){
2372 Sys_Printf( "++%s\n", temp );
2376 sprintf( temp, "%s.tga", pk3Shaders + i*65 );
2377 if ( vfsPackFile( temp, packname, 10 ) ){
2378 Sys_Printf( "++%s\n", temp );
2381 sprintf( temp, "%s.jpg", pk3Shaders + i*65 );
2382 if ( vfsPackFile( temp, packname, 10 ) ){
2383 Sys_Printf( "++%s\n", temp );
2386 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
2387 if ( i != pk3ShadersN - 1 ) packFAIL = qtrue; //levelshot typically
2391 Sys_Printf( "\n\tShaizers....\n" );
2393 for ( i = 0; i < pk3ShaderfilesN; i++ ){
2394 if ( *( pk3Shaderfiles + i*65 ) != '\0' ){
2395 sprintf( temp, "%s/%s", game->shaderPath, pk3Shaderfiles + i*65 );
2396 if ( vfsPackFile( temp, packname, 10 ) ){
2397 Sys_Printf( "++%s\n", temp );
2400 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
2405 Sys_Printf( "\n\tSounds....\n" );
2407 for ( i = 0; i < pk3SoundsN; i++ ){
2408 if ( *( pk3Sounds + i*65 ) != '\0' ){
2409 if ( vfsPackFile( pk3Sounds + i*65, packname, 10 ) ){
2410 Sys_Printf( "++%s\n", pk3Sounds + i*65 );
2413 Sys_Printf( " !FAIL! %s\n", pk3Sounds + i*65 );
2418 Sys_Printf( "\n\tVideos....\n" );
2420 for ( i = 0; i < pk3VideosN; i++ ){
2421 if ( vfsPackFile( pk3Videos + i*65, packname, 10 ) ){
2422 Sys_Printf( "++%s\n", pk3Videos + i*65 );
2425 Sys_Printf( " !FAIL! %s\n", pk3Videos + i*65 );
2429 Sys_Printf( "\n\t.bsp and stuff\n" );
2431 sprintf( temp, "maps/%s.bsp", nameOFmap );
2432 //if ( vfsPackFile( temp, packname, 10 ) ){
2433 if ( vfsPackFile_Absolute_Path( source, temp, packname, 10 ) ){
2434 Sys_Printf( "++%s\n", temp );
2437 Sys_Printf( " !FAIL! %s\n", temp );
2441 sprintf( temp, "maps/%s.aas", nameOFmap );
2442 if ( vfsPackFile( temp, packname, 10 ) ){
2443 Sys_Printf( "++%s\n", temp );
2446 Sys_Printf( " !FAIL! %s\n", temp );
2449 sprintf( temp, "scripts/%s.arena", nameOFmap );
2450 if ( vfsPackFile( temp, packname, 10 ) ){
2451 Sys_Printf( "++%s\n", temp );
2454 Sys_Printf( " !FAIL! %s\n", temp );
2457 sprintf( temp, "scripts/%s.defi", nameOFmap );
2458 if ( vfsPackFile( temp, packname, 10 ) ){
2459 Sys_Printf( "++%s\n", temp );
2462 Sys_Printf( " !FAIL! %s\n", temp );
2466 Sys_Printf( "\nSaved to %s\n", packname );
2469 rename( packname, packFailName );
2470 Sys_Printf( "\nSaved to %s\n", packFailName );
2472 /* return to sender */
2479 repack multiple maps, strip out only required shaders
2480 works for Q3 type of shaders and ents
2483 int repackBSPMain( int argc, char **argv ){
2484 int i, j, len, compLevel = 0;
2485 qboolean dbg = qfalse, png = qfalse;
2487 /* process arguments */
2488 for ( i = 1; i < ( argc - 1 ); i++ ){
2489 if ( !strcmp( argv[ i ], "-dbg" ) ) {
2492 else if ( !strcmp( argv[ i ], "-png" ) ) {
2495 else if ( !strcmp( argv[ i ], "-complevel" ) ) {
2496 compLevel = atoi( argv[ i + 1 ] );
2498 if ( compLevel < -1 ) compLevel = -1;
2499 if ( compLevel > 10 ) compLevel = 10;
2500 Sys_Printf( "Compression level set to %i\n", compLevel );
2504 /* load exclusions file */
2505 int ExTexturesN = 0;
2506 char* ExTextures = (char *)calloc( 4096*65, sizeof( char ) );
2508 char* ExShaders = (char *)calloc( 4096*65, sizeof( char ) );
2510 char* ExSounds = (char *)calloc( 4096*65, sizeof( char ) );
2511 int ExShaderfilesN = 0;
2512 char* ExShaderfiles = (char *)calloc( 4096*65, sizeof( char ) );
2514 char* ExVideos = (char *)calloc( 4096*65, sizeof( char ) );
2515 int ExPureTexturesN = 0;
2516 char* ExPureTextures = (char *)calloc( 4096*65, sizeof( char ) );
2519 char exName[ 1024 ];
2523 strcpy( exName, q3map2path );
2524 char *cut = strrchr( exName, '\\' );
2525 char *cut2 = strrchr( exName, '/' );
2526 if ( cut == NULL && cut2 == NULL ){
2527 Sys_Printf( "WARNING: Unable to load exclusions file.\n" );
2530 if ( cut2 > cut ) cut = cut2;
2532 strcat( exName, game->arg );
2533 strcat( exName, ".exclude" );
2535 Sys_Printf( "Loading %s\n", exName );
2536 size = TryLoadFile( exName, (void**) &buffer );
2538 Sys_Printf( "WARNING: Unable to find exclusions file %s.\n", exName );
2542 /* parse the file */
2543 ParseFromMemory( (char *) buffer, size );
2548 /* test for end of file */
2549 if ( !GetToken( qtrue ) ) {
2554 if ( !Q_stricmp( token, "textures" ) ){
2555 parseEXblock ( ExTextures, &ExTexturesN, exName );
2557 else if ( !Q_stricmp( token, "shaders" ) ){
2558 parseEXblock ( ExShaders, &ExShadersN, exName );
2560 else if ( !Q_stricmp( token, "shaderfiles" ) ){
2561 parseEXblock ( ExShaderfiles, &ExShaderfilesN, exName );
2563 else if ( !Q_stricmp( token, "sounds" ) ){
2564 parseEXblock ( ExSounds, &ExSoundsN, exName );
2566 else if ( !Q_stricmp( token, "videos" ) ){
2567 parseEXblock ( ExVideos, &ExVideosN, exName );
2570 Error( "ReadExclusionsFile: %s, line %d: unknown block name!\nValid ones are: textures, shaders, shaderfiles, sounds, videos.", exName, scriptline );
2574 /* free the buffer */
2577 for ( i = 0; i < ExTexturesN; i++ ){
2578 for ( j = 0; j < ExShadersN; j++ ){
2579 if ( !Q_stricmp( ExTextures + i*65, ExShaders + j*65 ) ){
2583 if ( j == ExShadersN ){
2584 strcpy ( ExPureTextures + ExPureTexturesN*65, ExTextures + i*65 );
2592 Sys_Printf( "\n\tExTextures....%i\n", ExTexturesN );
2593 for ( i = 0; i < ExTexturesN; i++ ) Sys_Printf( "%s\n", ExTextures + i*65 );
2594 Sys_Printf( "\n\tExPureTextures....%i\n", ExPureTexturesN );
2595 for ( i = 0; i < ExPureTexturesN; i++ ) Sys_Printf( "%s\n", ExPureTextures + i*65 );
2596 Sys_Printf( "\n\tExShaders....%i\n", ExShadersN );
2597 for ( i = 0; i < ExShadersN; i++ ) Sys_Printf( "%s\n", ExShaders + i*65 );
2598 Sys_Printf( "\n\tExShaderfiles....%i\n", ExShaderfilesN );
2599 for ( i = 0; i < ExShaderfilesN; i++ ) Sys_Printf( "%s\n", ExShaderfiles + i*65 );
2600 Sys_Printf( "\n\tExSounds....%i\n", ExSoundsN );
2601 for ( i = 0; i < ExSoundsN; i++ ) Sys_Printf( "%s\n", ExSounds + i*65 );
2602 Sys_Printf( "\n\tExVideos....%i\n", ExVideosN );
2603 for ( i = 0; i < ExVideosN; i++ ) Sys_Printf( "%s\n", ExVideos + i*65 );
2609 /* load repack.exclude */
2610 int rExTexturesN = 0;
2611 char* rExTextures = (char *)calloc( 65536*65, sizeof( char ) );
2612 int rExShadersN = 0;
2613 char* rExShaders = (char *)calloc( 32768*65, sizeof( char ) );
2615 char* rExSounds = (char *)calloc( 8192*65, sizeof( char ) );
2616 int rExShaderfilesN = 0;
2617 char* rExShaderfiles = (char *)calloc( 4096*65, sizeof( char ) );
2619 char* rExVideos = (char *)calloc( 4096*65, sizeof( char ) );
2621 strcpy( exName, q3map2path );
2622 cut = strrchr( exName, '\\' );
2623 cut2 = strrchr( exName, '/' );
2624 if ( cut == NULL && cut2 == NULL ){
2625 Sys_Printf( "WARNING: Unable to load repack exclusions file.\n" );
2628 if ( cut2 > cut ) cut = cut2;
2630 strcat( exName, "repack.exclude" );
2632 Sys_Printf( "Loading %s\n", exName );
2633 size = TryLoadFile( exName, (void**) &buffer );
2635 Sys_Printf( "WARNING: Unable to find repack exclusions file %s.\n", exName );
2639 /* parse the file */
2640 ParseFromMemory( (char *) buffer, size );
2645 /* test for end of file */
2646 if ( !GetToken( qtrue ) ) {
2651 if ( !Q_stricmp( token, "textures" ) ){
2652 parseEXblock ( rExTextures, &rExTexturesN, exName );
2654 else if ( !Q_stricmp( token, "shaders" ) ){
2655 parseEXblock ( rExShaders, &rExShadersN, exName );
2657 else if ( !Q_stricmp( token, "shaderfiles" ) ){
2658 parseEXblock ( rExShaderfiles, &rExShaderfilesN, exName );
2660 else if ( !Q_stricmp( token, "sounds" ) ){
2661 parseEXblock ( rExSounds, &rExSoundsN, exName );
2663 else if ( !Q_stricmp( token, "videos" ) ){
2664 parseEXblock ( rExVideos, &rExVideosN, exName );
2667 Error( "ReadExclusionsFile: %s, line %d: unknown block name!\nValid ones are: textures, shaders, shaderfiles, sounds, videos.", exName, scriptline );
2671 /* free the buffer */
2677 Sys_Printf( "\n\trExTextures....%i\n", rExTexturesN );
2678 for ( i = 0; i < rExTexturesN; i++ ) Sys_Printf( "%s\n", rExTextures + i*65 );
2679 Sys_Printf( "\n\trExShaders....%i\n", rExShadersN );
2680 for ( i = 0; i < rExShadersN; i++ ) Sys_Printf( "%s\n", rExShaders + i*65 );
2681 Sys_Printf( "\n\trExShaderfiles....%i\n", rExShaderfilesN );
2682 for ( i = 0; i < rExShaderfilesN; i++ ) Sys_Printf( "%s\n", rExShaderfiles + i*65 );
2683 Sys_Printf( "\n\trExSounds....%i\n", rExSoundsN );
2684 for ( i = 0; i < rExSoundsN; i++ ) Sys_Printf( "%s\n", rExSounds + i*65 );
2685 Sys_Printf( "\n\trExVideos....%i\n", rExVideosN );
2686 for ( i = 0; i < rExVideosN; i++ ) Sys_Printf( "%s\n", rExVideos + i*65 );
2693 char* bspList = (char *)calloc( 8192*1024, sizeof( char ) );
2695 /* do some path mangling */
2696 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
2697 if ( !Q_stricmp( strrchr( source, '.' ), ".bsp" ) ){
2698 strcpy( bspList, source );
2702 /* load bsps paths list */
2703 Sys_Printf( "Loading %s\n", source );
2704 size = TryLoadFile( source, (void**) &buffer );
2706 Sys_Printf( "WARNING: Unable to open bsps paths list file %s.\n", source );
2709 /* parse the file */
2710 ParseFromMemory( (char *) buffer, size );
2715 /* test for end of file */
2716 if ( !GetToken( qtrue ) ) {
2719 strcpy( bspList + bspListN * 1024 , token );
2723 /* free the buffer */
2727 char packname[ 1024 ], nameOFrepack[ 1024 ], nameOFmap[ 1024 ], temp[ 1024 ];
2729 /* copy input file name */
2730 strcpy( temp, source );
2731 StripExtension( temp );
2733 /* extract input file name */
2734 len = strlen( temp ) - 1;
2735 while ( len > 0 && temp[ len ] != '/' && temp[ len ] != '\\' )
2737 strcpy( nameOFrepack, &temp[ len + 1 ] );
2741 int pk3ShadersN = 0;
2742 char* pk3Shaders = (char *)calloc( 65536*65, sizeof( char ) );
2744 char* pk3Sounds = (char *)calloc( 4096*65, sizeof( char ) );
2745 int pk3ShaderfilesN = 0;
2746 char* pk3Shaderfiles = (char *)calloc( 4096*65, sizeof( char ) );
2747 int pk3TexturesN = 0;
2748 char* pk3Textures = (char *)calloc( 65536*65, sizeof( char ) );
2750 char* pk3Videos = (char *)calloc( 1024*65, sizeof( char ) );
2752 for( j = 0; j < bspListN; j++ ){
2754 int pk3SoundsNold = pk3SoundsN;
2755 int pk3ShadersNold = pk3ShadersN;
2757 strcpy( source, bspList + j*1024 );
2758 StripExtension( source );
2759 DefaultExtension( source, ".bsp" );
2762 Sys_Printf( "\nLoading %s\n", source );
2763 PartialLoadBSPFile( source );
2767 strcpy( temp, source );
2768 StripExtension( temp );
2770 /* extract map name */
2771 len = strlen( temp ) - 1;
2772 while ( len > 0 && temp[ len ] != '/' && temp[ len ] != '\\' )
2774 strcpy( nameOFmap, &temp[ len + 1 ] );
2777 qboolean drawsurfSHs[1024] = { qfalse };
2779 for ( i = 0; i < numBSPDrawSurfaces; i++ ){
2780 drawsurfSHs[ bspDrawSurfaces[i].shaderNum ] = qtrue;
2783 for ( i = 0; i < numBSPShaders; i++ ){
2784 if ( drawsurfSHs[i] ){
2785 strcpy( pk3Shaders + pk3ShadersN*65, bspShaders[i].shader );
2786 res2list( pk3Shaders, &pk3ShadersN );
2792 for ( ep = entities[0].epairs; ep != NULL; ep = ep->next )
2794 if ( !Q_strncasecmp( ep->key, "vertexremapshader", 17 ) ) {
2795 sscanf( ep->value, "%*[^;] %*[;] %s", pk3Shaders + pk3ShadersN*65 );
2796 res2list( pk3Shaders, &pk3ShadersN );
2799 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[0], "music" ) );
2800 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' ){
2801 FixDOSName( pk3Sounds + pk3SoundsN*65 );
2802 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
2803 res2list( pk3Sounds, &pk3SoundsN );
2806 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
2808 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[i], "noise" ) );
2809 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' && *( pk3Sounds + pk3SoundsN*65 ) != '*' ){
2810 FixDOSName( pk3Sounds + pk3SoundsN*65 );
2811 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
2812 res2list( pk3Sounds, &pk3SoundsN );
2815 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "func_plat" ) ){
2816 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_strt.wav");
2817 res2list( pk3Sounds, &pk3SoundsN );
2818 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_end.wav");
2819 res2list( pk3Sounds, &pk3SoundsN );
2821 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "target_push" ) ){
2822 if ( !(IntForKey( &entities[i], "spawnflags") & 1) ){
2823 strcpy( pk3Sounds + pk3SoundsN*65, "sound/misc/windfly.wav");
2824 res2list( pk3Sounds, &pk3SoundsN );
2827 strcpy( pk3Shaders + pk3ShadersN*65, ValueForKey( &entities[i], "targetShaderNewName" ) );
2828 res2list( pk3Shaders, &pk3ShadersN );
2832 sprintf( pk3Shaders + pk3ShadersN*65, "levelshots/%s", nameOFmap );
2833 res2list( pk3Shaders, &pk3ShadersN );
2837 Sys_Printf( "\n\t+Drawsurface+ent calls....%i\n", pk3ShadersN - pk3ShadersNold );
2838 for ( i = pk3ShadersNold; i < pk3ShadersN; i++ ){
2839 Sys_Printf( "%s\n", pk3Shaders + i*65 );
2841 Sys_Printf( "\n\t+Sounds....%i\n", pk3SoundsN - pk3SoundsNold );
2842 for ( i = pk3SoundsNold; i < pk3SoundsN; i++ ){
2843 Sys_Printf( "%s\n", pk3Sounds + i*65 );
2847 if ( bspDrawVerts != 0 ) {
2848 free( bspDrawVerts );
2849 bspDrawVerts = NULL;
2850 //numBSPDrawVerts = 0;
2851 Sys_Printf( "freed BSPDrawVerts\n" );
2853 */ if ( bspDrawSurfaces != 0 ) {
2854 free( bspDrawSurfaces );
2855 bspDrawSurfaces = NULL;
2856 //numBSPDrawSurfaces = 0;
2857 //Sys_Printf( "freed bspDrawSurfaces\n" );
2859 /* if ( bspLightBytes != 0 ) {
2860 free( bspLightBytes );
2861 bspLightBytes = NULL;
2862 //numBSPLightBytes = 0;
2863 Sys_Printf( "freed BSPLightBytes\n" );
2865 if ( bspGridPoints != 0 ) {
2866 free( bspGridPoints );
2867 bspGridPoints = NULL;
2868 //numBSPGridPoints = 0;
2869 Sys_Printf( "freed BSPGridPoints\n" );
2871 if ( bspPlanes != 0 ) {
2874 Sys_Printf( "freed bspPlanes\n" );
2876 //allocatedBSPPlanes = 0;
2878 if ( bspBrushes != 0 ) {
2881 Sys_Printf( "freed bspBrushes\n" );
2882 //numBSPBrushes = 0;
2883 //allocatedBSPBrushes = 0;
2885 */ if ( entities != 0 ) {
2887 for ( i = 0; i < numBSPEntities && i < numEntities; i++ ){
2888 ep = entities[i].epairs;
2897 //Sys_Printf( "freed entities\n" );
2900 allocatedEntities = 0;
2902 /* if ( bspModels != 0 ) {
2905 Sys_Printf( "freed bspModels\n" );
2907 //allocatedBSPModels = 0;
2909 */ if ( bspShaders != 0 ) {
2912 //Sys_Printf( "freed bspShaders\n" );
2913 //numBSPShaders = 0;
2914 //allocatedBSPShaders = 0;
2916 if ( bspEntData != 0 ) {
2919 //Sys_Printf( "freed bspEntData\n" );
2920 //bspEntDataSize = 0;
2921 //allocatedBSPEntData = 0;
2923 /* if ( bspNodes != 0 ) {
2926 Sys_Printf( "freed bspNodes\n" );
2928 //allocatedBSPNodes = 0;
2930 if ( bspDrawIndexes != 0 ) {
2931 free( bspDrawIndexes );
2932 bspDrawIndexes = NULL;
2933 Sys_Printf( "freed bspDrawIndexes\n" );
2934 //numBSPDrawIndexes = 0;
2935 //allocatedBSPDrawIndexes = 0;
2937 if ( bspLeafSurfaces != 0 ) {
2938 free( bspLeafSurfaces );
2939 bspLeafSurfaces = NULL;
2940 Sys_Printf( "freed bspLeafSurfaces\n" );
2941 //numBSPLeafSurfaces = 0;
2942 //allocatedBSPLeafSurfaces = 0;
2944 if ( bspLeafBrushes != 0 ) {
2945 free( bspLeafBrushes );
2946 bspLeafBrushes = NULL;
2947 Sys_Printf( "freed bspLeafBrushes\n" );
2948 //numBSPLeafBrushes = 0;
2949 //allocatedBSPLeafBrushes = 0;
2951 if ( bspBrushSides != 0 ) {
2952 free( bspBrushSides );
2953 bspBrushSides = NULL;
2954 Sys_Printf( "freed bspBrushSides\n" );
2955 numBSPBrushSides = 0;
2956 allocatedBSPBrushSides = 0;
2958 if ( numBSPFogs != 0 ) {
2959 Sys_Printf( "freed numBSPFogs\n" );
2962 if ( numBSPAds != 0 ) {
2963 Sys_Printf( "freed numBSPAds\n" );
2966 if ( numBSPLeafs != 0 ) {
2967 Sys_Printf( "freed numBSPLeafs\n" );
2970 if ( numBSPVisBytes != 0 ) {
2971 Sys_Printf( "freed numBSPVisBytes\n" );
2978 vfsListShaderFiles( pk3Shaderfiles, &pk3ShaderfilesN );
2981 Sys_Printf( "\n\tSchroider fileses.....%i\n", pk3ShaderfilesN );
2982 for ( i = 0; i < pk3ShaderfilesN; i++ ){
2983 Sys_Printf( "%s\n", pk3Shaderfiles + i*65 );
2989 /* can exclude pure *base* textures right now, shouldn't create shaders for them anyway */
2990 for ( i = 0; i < pk3ShadersN ; i++ ){
2991 for ( j = 0; j < ExPureTexturesN ; j++ ){
2992 if ( !Q_stricmp( pk3Shaders + i*65, ExPureTextures + j*65 ) ){
2993 *( pk3Shaders + i*65 ) = '\0';
2998 /* can exclude repack.exclude shaders, assuming they got all their images */
2999 for ( i = 0; i < pk3ShadersN ; i++ ){
3000 for ( j = 0; j < rExShadersN ; j++ ){
3001 if ( !Q_stricmp( pk3Shaders + i*65, rExShaders + j*65 ) ){
3002 *( pk3Shaders + i*65 ) = '\0';
3008 //Parse Shader Files
3009 Sys_Printf( "\t\nParsing shaders....\n\n" );
3010 char shaderText[ 8192 ];
3011 char* allShaders = (char *)calloc( 16777216, sizeof( char ) );
3013 endofscript = qtrue;
3015 for ( i = 0; i < pk3ShaderfilesN; i++ ){
3016 qboolean wantShader = qfalse;
3019 /* load the shader */
3020 sprintf( temp, "%s/%s", game->shaderPath, pk3Shaderfiles + i*65 );
3021 if ( dbg ) Sys_Printf( "\n\tentering %s\n", pk3Shaderfiles + i*65 );
3022 SilentLoadScriptFile( temp, 0 );
3027 int line = scriptline;
3028 /* test for end of file */
3029 if ( !GetToken( qtrue ) ) {
3033 if( dbg ) Sys_Printf( "%s\n", token );
3035 strcpy( shaderText, token );
3037 if ( strchr( token, '\\') != NULL ){
3038 Sys_Printf( "WARNING1: %s : %s : shader name with backslash\n", pk3Shaderfiles + i*65, token );
3041 /* do wanna le shader? */
3042 wantShader = qfalse;
3043 for ( j = 0; j < pk3ShadersN; j++ ){
3044 if ( !Q_stricmp( pk3Shaders + j*65, token) ){
3051 for ( j = 0; j < rExTexturesN ; j++ ){
3052 if ( !Q_stricmp( pk3Shaders + shader*65, rExTextures + j*65 ) ){
3053 Sys_Printf( "WARNING3: %s : about to include shader for excluded texture\n", pk3Shaders + shader*65 );
3059 /* handle { } section */
3060 if ( !GetToken( qtrue ) ) {
3063 if ( strcmp( token, "{" ) ) {
3064 Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s\nFile location be: %s",
3065 temp, scriptline, token, g_strLoadedFileLocation );
3067 strcat( shaderText, "\n{" );
3068 qboolean hasmap = qfalse;
3073 /* get the next token */
3074 if ( !GetToken( qtrue ) ) {
3077 if ( !strcmp( token, "}" ) ) {
3078 strcat( shaderText, "\n}\n\n" );
3081 /* parse stage directives */
3082 if ( !strcmp( token, "{" ) ) {
3083 qboolean tokenready = qfalse;
3084 strcat( shaderText, "\n\t{" );
3087 /* detour of TokenAvailable() '~' */
3088 if ( tokenready ) tokenready = qfalse;
3089 else line = scriptline;
3090 if ( !GetToken( qtrue ) ) {
3093 if ( !strcmp( token, "}" ) ) {
3094 strcat( shaderText, "\n\t}" );
3097 if ( !strcmp( token, "{" ) ) {
3098 strcat( shaderText, "\n\t{" );
3099 Sys_Printf( "WARNING9: %s : line %d : opening brace inside shader stage\n", temp, scriptline );
3101 /* skip the shader */
3102 if ( !wantShader ) continue;
3104 /* digest any images */
3105 if ( !Q_stricmp( token, "map" ) ||
3106 !Q_stricmp( token, "clampMap" ) ) {
3107 strcat( shaderText, "\n\t\t" );
3108 strcat( shaderText, token );
3113 if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) {
3114 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
3116 strcat( shaderText, " " );
3117 strcat( shaderText, token );
3119 else if ( !Q_stricmp( token, "animMap" ) ||
3120 !Q_stricmp( token, "clampAnimMap" ) ) {
3121 strcat( shaderText, "\n\t\t" );
3122 strcat( shaderText, token );
3125 GetToken( qfalse );// skip num
3126 strcat( shaderText, " " );
3127 strcat( shaderText, token );
3128 while ( TokenAvailable() ){
3130 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
3131 strcat( shaderText, " " );
3132 strcat( shaderText, token );
3136 else if ( !Q_stricmp( token, "videoMap" ) ){
3137 strcat( shaderText, "\n\t\t" );
3138 strcat( shaderText, token );
3141 strcat( shaderText, " " );
3142 strcat( shaderText, token );
3143 FixDOSName( token );
3144 if ( strchr( token, '/' ) == NULL && strchr( token, '\\' ) == NULL ){
3145 sprintf( temp, "video/%s", token );
3146 strcpy( token, temp );
3148 FixDOSName( token );
3149 for ( j = 0; j < pk3VideosN; j++ ){
3150 if ( !Q_stricmp( pk3Videos + j*65, token ) ){
3154 for ( j = 0; j < ExVideosN; j++ ){
3155 if ( !Q_stricmp( ExVideos + j*65, token ) ){
3159 for ( j = 0; j < rExVideosN; j++ ){
3160 if ( !Q_stricmp( rExVideos + j*65, token ) ){
3164 strcpy ( pk3Videos + pk3VideosN*65, token );
3169 else if ( !Q_stricmp( token, "mapComp" ) || !Q_stricmp( token, "mapNoComp" ) || !Q_stricmp( token, "animmapcomp" ) || !Q_stricmp( token, "animmapnocomp" ) ){
3170 Sys_Printf( "WARNING7: %s : %s shader\n", pk3Shaders + shader*65, token );
3172 if ( line == scriptline ){
3173 strcat( shaderText, " " );
3174 strcat( shaderText, token );
3177 strcat( shaderText, "\n\t\t" );
3178 strcat( shaderText, token );
3181 else if ( line == scriptline ){
3182 strcat( shaderText, " " );
3183 strcat( shaderText, token );
3186 strcat( shaderText, "\n\t\t" );
3187 strcat( shaderText, token );
3191 /* skip the shader */
3192 else if ( !wantShader ) continue;
3194 /* -----------------------------------------------------------------
3195 surfaceparm * directives
3196 ----------------------------------------------------------------- */
3198 /* match surfaceparm */
3199 else if ( !Q_stricmp( token, "surfaceparm" ) ) {
3200 strcat( shaderText, "\n\tsurfaceparm " );
3202 strcat( shaderText, token );
3203 if ( !Q_stricmp( token, "nodraw" ) ) {
3204 wantShader = qfalse;
3205 *( pk3Shaders + shader*65 ) = '\0';
3209 /* skyparms <outer image> <cloud height> <inner image> */
3210 else if ( !Q_stricmp( token, "skyParms" ) ) {
3211 strcat( shaderText, "\n\tskyParms " );
3213 /* get image base */
3215 strcat( shaderText, token );
3217 /* ignore bogus paths */
3218 if ( Q_stricmp( token, "-" ) && Q_stricmp( token, "full" ) ) {
3219 strcpy ( temp, token );
3220 sprintf( token, "%s_up", temp );
3221 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
3222 sprintf( token, "%s_dn", temp );
3223 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
3224 sprintf( token, "%s_lf", temp );
3225 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
3226 sprintf( token, "%s_rt", temp );
3227 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
3228 sprintf( token, "%s_bk", temp );
3229 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
3230 sprintf( token, "%s_ft", temp );
3231 tex2list2( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN, rExTextures, &rExTexturesN );
3233 /* skip rest of line */
3235 strcat( shaderText, " " );
3236 strcat( shaderText, token );
3238 strcat( shaderText, " " );
3239 strcat( shaderText, token );
3241 else if ( !Q_strncasecmp( token, "implicit", 8 ) ){
3242 Sys_Printf( "WARNING5: %s : %s shader\n", pk3Shaders + shader*65, token );
3244 if ( line == scriptline ){
3245 strcat( shaderText, " " );
3246 strcat( shaderText, token );
3249 strcat( shaderText, "\n\t" );
3250 strcat( shaderText, token );
3253 else if ( !Q_stricmp( token, "fogparms" ) ){
3255 if ( line == scriptline ){
3256 strcat( shaderText, " " );
3257 strcat( shaderText, token );
3260 strcat( shaderText, "\n\t" );
3261 strcat( shaderText, token );
3264 else if ( line == scriptline ){
3265 strcat( shaderText, " " );
3266 strcat( shaderText, token );
3269 strcat( shaderText, "\n\t" );
3270 strcat( shaderText, token );
3276 for ( j = 0; j < ExShadersN; j++ ){
3277 if ( !Q_stricmp( ExShaders + j*65, pk3Shaders + shader*65 ) ){
3278 wantShader = qfalse;
3279 *( pk3Shaders + shader*65 ) = '\0';
3283 if ( wantShader && !hasmap ){
3284 Sys_Printf( "WARNING8: %s : shader has no known maps\n", pk3Shaders + shader*65 );
3285 wantShader = qfalse;
3286 *( pk3Shaders + shader*65 ) = '\0';
3289 strcat( allShaders, shaderText );
3290 *( pk3Shaders + shader*65 ) = '\0';
3295 /* TODO: RTCW's mapComp, mapNoComp, animmapcomp, animmapnocomp; nocompress?; ET's implicitmap, implicitblend, implicitmask */
3300 //pure textures (shader ones are done)
3301 for ( i = 0; i < pk3ShadersN; i++ ){
3302 if ( *( pk3Shaders + i*65 ) != '\0' ){
3303 if ( strchr( pk3Shaders + i*65, '\\') != NULL ){
3304 Sys_Printf( "WARNING2: %s : bsp shader path with backslash\n", pk3Shaders + i*65 );
3305 FixDOSName( pk3Shaders + i*65 );
3306 //what if theres properly slashed one in the list?
3307 for ( j = 0; j < pk3ShadersN; j++ ){
3308 if ( !Q_stricmp( pk3Shaders + i*65, pk3Shaders + j*65 ) && (i != j) ){
3309 *( pk3Shaders + i*65 ) = '\0';
3314 if ( *( pk3Shaders + i*65 ) == '\0' ) continue;
3315 for ( j = 0; j < pk3TexturesN; j++ ){
3316 if ( !Q_stricmp( pk3Shaders + i*65, pk3Textures + j*65 ) ){
3317 *( pk3Shaders + i*65 ) = '\0';
3321 if ( *( pk3Shaders + i*65 ) == '\0' ) continue;
3322 for ( j = 0; j < ExTexturesN; j++ ){
3323 if ( !Q_stricmp( pk3Shaders + i*65, ExTextures + j*65 ) ){
3324 *( pk3Shaders + i*65 ) = '\0';
3328 if ( *( pk3Shaders + i*65 ) == '\0' ) continue;
3329 for ( j = 0; j < rExTexturesN; j++ ){
3330 if ( !Q_stricmp( pk3Shaders + i*65, rExTextures + j*65 ) ){
3331 *( pk3Shaders + i*65 ) = '\0';
3339 for ( i = 0; i < pk3SoundsN; i++ ){
3340 for ( j = 0; j < ExSoundsN; j++ ){
3341 if ( !Q_stricmp( pk3Sounds + i*65, ExSounds + j*65 ) ){
3342 *( pk3Sounds + i*65 ) = '\0';
3346 if ( *( pk3Sounds + i*65 ) == '\0' ) continue;
3347 for ( j = 0; j < rExSoundsN; j++ ){
3348 if ( !Q_stricmp( pk3Sounds + i*65, rExSounds + j*65 ) ){
3349 *( pk3Sounds + i*65 ) = '\0';
3356 sprintf( temp, "%s/%s_strippedBYrepacker.shader", EnginePath, nameOFrepack );
3358 f = fopen( temp, "wb" );
3359 fwrite( allShaders, sizeof( char ), strlen( allShaders ), f );
3361 Sys_Printf( "Shaders saved to %s\n", temp );
3364 sprintf( packname, "%s/%s_repacked.pk3", EnginePath, nameOFrepack );
3367 Sys_Printf( "\n--- ZipZip ---\n" );
3369 Sys_Printf( "\n\tShader referenced textures....\n" );
3371 for ( i = 0; i < pk3TexturesN; i++ ){
3373 sprintf( temp, "%s.png", pk3Textures + i*65 );
3374 if ( vfsPackFile( temp, packname, compLevel ) ){
3375 Sys_Printf( "++%s\n", temp );
3379 sprintf( temp, "%s.tga", pk3Textures + i*65 );
3380 if ( vfsPackFile( temp, packname, compLevel ) ){
3381 Sys_Printf( "++%s\n", temp );
3384 sprintf( temp, "%s.jpg", pk3Textures + i*65 );
3385 if ( vfsPackFile( temp, packname, compLevel ) ){
3386 Sys_Printf( "++%s\n", temp );
3389 Sys_Printf( " !FAIL! %s\n", pk3Textures + i*65 );
3392 Sys_Printf( "\n\tPure textures....\n" );
3394 for ( i = 0; i < pk3ShadersN; i++ ){
3395 if ( *( pk3Shaders + i*65 ) != '\0' ){
3397 sprintf( temp, "%s.png", pk3Shaders + i*65 );
3398 if ( vfsPackFile( temp, packname, compLevel ) ){
3399 Sys_Printf( "++%s\n", temp );
3403 sprintf( temp, "%s.tga", pk3Shaders + i*65 );
3404 if ( vfsPackFile( temp, packname, compLevel ) ){
3405 Sys_Printf( "++%s\n", temp );
3408 sprintf( temp, "%s.jpg", pk3Shaders + i*65 );
3409 if ( vfsPackFile( temp, packname, compLevel ) ){
3410 Sys_Printf( "++%s\n", temp );
3413 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
3417 Sys_Printf( "\n\tSounds....\n" );
3419 for ( i = 0; i < pk3SoundsN; i++ ){
3420 if ( *( pk3Sounds + i*65 ) != '\0' ){
3421 if ( vfsPackFile( pk3Sounds + i*65, packname, compLevel ) ){
3422 Sys_Printf( "++%s\n", pk3Sounds + i*65 );
3425 Sys_Printf( " !FAIL! %s\n", pk3Sounds + i*65 );
3429 Sys_Printf( "\n\tVideos....\n" );
3431 for ( i = 0; i < pk3VideosN; i++ ){
3432 if ( vfsPackFile( pk3Videos + i*65, packname, compLevel ) ){
3433 Sys_Printf( "++%s\n", pk3Videos + i*65 );
3436 Sys_Printf( " !FAIL! %s\n", pk3Videos + i*65 );
3439 Sys_Printf( "\nSaved to %s\n", packname );
3441 /* return to sender */
3449 a stripped down ProcessModels
3451 void PseudoCompileBSP( qboolean need_tree ){
3453 char modelValue[10];
3462 SetDrawSurfacesBuffer();
3463 mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
3464 memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
3465 numMapDrawSurfs = 0;
3469 for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
3472 entity = &entities[ mapEntityNum ];
3473 if ( entity->brushes == NULL && entity->patches == NULL ) {
3477 if ( mapEntityNum != 0 ) {
3478 sprintf( modelValue, "*%d", models++ );
3479 SetKeyValue( entity, "model", modelValue );
3482 /* process the model */
3483 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
3486 entity->firstDrawSurf = numMapDrawSurfs;
3488 ClearMetaTriangles();
3489 PatchMapDrawSurfs( entity );
3491 if ( mapEntityNum == 0 && need_tree ) {
3492 faces = MakeStructuralBSPFaceList( entities[0].brushes );
3493 tree = FaceBSP( faces );
3494 node = tree->headnode;
3499 node->planenum = PLANENUM_LEAF;
3501 tree->headnode = node;
3504 /* a minimized ClipSidesIntoTree */
3505 for ( brush = entity->brushes; brush; brush = brush->next )
3507 /* walk the brush sides */
3508 for ( i = 0; i < brush->numsides; i++ )
3511 side = &brush->sides[ i ];
3512 if ( side->winding == NULL ) {
3516 if ( side->shaderInfo == NULL ) {
3519 /* save this winding as a visible surface */
3520 DrawSurfaceForSide( entity, brush, side, side->winding );
3525 ClassifyEntitySurfaces( entity );
3526 MakeEntityDecals( entity );
3527 MakeEntityMetaTriangles( entity );
3528 SmoothMetaTriangles();
3529 MergeMetaTriangles();
3531 FilterDrawsurfsIntoTree( entity, tree );
3533 FilterStructuralBrushesIntoTree( entity, tree );
3534 FilterDetailBrushesIntoTree( entity, tree );
3536 EmitBrushes( entity->brushes, &entity->firstBrush, &entity->numBrushes );
3537 EndModel( entity, node );
3539 EndBSPFile( qfalse );
3544 main argument processing function for bsp conversion
3547 int ConvertBSPMain( int argc, char **argv ){
3549 int ( *convertFunc )( char * );
3550 game_t *convertGame;
3552 qboolean map_allowed, force_bsp, force_map;
3556 convertFunc = ConvertBSPToASE;
3558 map_allowed = qfalse;
3564 Sys_Printf( "Usage: q3map -convert [-format <ase|obj|map_bp|map>] [-shadersasbitmap|-lightmapsastexcoord|-deluxemapsastexcoord] [-readbsp|-readmap [-meta|-patchmeta]] [-v] <mapname>\n" );
3568 /* process arguments */
3569 for ( i = 1; i < ( argc - 1 ); i++ )
3571 /* -format map|ase|... */
3572 if ( !strcmp( argv[ i ], "-format" ) ) {
3574 if ( !Q_stricmp( argv[ i ], "ase" ) ) {
3575 convertFunc = ConvertBSPToASE;
3576 map_allowed = qfalse;
3578 else if ( !Q_stricmp( argv[ i ], "obj" ) ) {
3579 convertFunc = ConvertBSPToOBJ;
3580 map_allowed = qfalse;
3582 else if ( !Q_stricmp( argv[ i ], "map_bp" ) ) {
3583 convertFunc = ConvertBSPToMap_BP;
3584 map_allowed = qtrue;
3586 else if ( !Q_stricmp( argv[ i ], "map" ) ) {
3587 convertFunc = ConvertBSPToMap;
3588 map_allowed = qtrue;
3592 convertGame = GetGame( argv[ i ] );
3593 map_allowed = qfalse;
3594 if ( convertGame == NULL ) {
3595 Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
3599 else if ( !strcmp( argv[ i ], "-ne" ) ) {
3600 normalEpsilon = atof( argv[ i + 1 ] );
3602 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
3604 else if ( !strcmp( argv[ i ], "-de" ) ) {
3605 distanceEpsilon = atof( argv[ i + 1 ] );
3607 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
3609 else if ( !strcmp( argv[ i ], "-shaderasbitmap" ) || !strcmp( argv[ i ], "-shadersasbitmap" ) ) {
3610 shadersAsBitmap = qtrue;
3612 else if ( !strcmp( argv[ i ], "-lightmapastexcoord" ) || !strcmp( argv[ i ], "-lightmapsastexcoord" ) ) {
3613 lightmapsAsTexcoord = qtrue;
3615 else if ( !strcmp( argv[ i ], "-deluxemapastexcoord" ) || !strcmp( argv[ i ], "-deluxemapsastexcoord" ) ) {
3616 lightmapsAsTexcoord = qtrue;
3619 else if ( !strcmp( argv[ i ], "-readbsp" ) ) {
3622 else if ( !strcmp( argv[ i ], "-readmap" ) ) {
3625 else if ( !strcmp( argv[ i ], "-meta" ) ) {
3628 else if ( !strcmp( argv[ i ], "-patchmeta" ) ) {
3632 else if ( !strcmp( argv[ i ], "-fast" ) ) {
3639 /* clean up map name */
3640 strcpy( source, ExpandArg( argv[i] ) );
3641 ExtractFileExtension( source, ext );
3643 if ( !map_allowed && !force_map ) {
3647 if ( force_map || ( !force_bsp && !Q_stricmp( ext, "map" ) && map_allowed ) ) {
3648 if ( !map_allowed ) {
3649 Sys_Printf( "WARNING: the requested conversion should not be done from .map files. Compile a .bsp first.\n" );
3651 StripExtension( source );
3652 DefaultExtension( source, ".map" );
3653 Sys_Printf( "Loading %s\n", source );
3654 LoadMapFile( source, qfalse, convertGame == NULL );
3655 PseudoCompileBSP( convertGame != NULL );
3659 StripExtension( source );
3660 DefaultExtension( source, ".bsp" );
3661 Sys_Printf( "Loading %s\n", source );
3662 LoadBSPFile( source );
3666 /* bsp format convert? */
3667 if ( convertGame != NULL ) {
3668 /* set global game */
3672 StripExtension( source );
3673 DefaultExtension( source, "_c.bsp" );
3674 Sys_Printf( "Writing %s\n", source );
3675 WriteBSPFile( source );
3677 /* return to sender */
3681 /* normal convert */
3682 return convertFunc( source );
3692 int main( int argc, char **argv ){
3697 /* we want consistent 'randomness' */
3701 start = I_FloatTime();
3703 /* this was changed to emit version number over the network */
3704 printf( Q3MAP_VERSION "\n" );
3707 atexit( ExitQ3Map );
3709 /* read general options first */
3710 for ( i = 1; i < argc; i++ )
3713 if ( !strcmp( argv[ i ], "-connect" ) ) {
3716 Broadcast_Setup( argv[ i ] );
3721 else if ( !strcmp( argv[ i ], "-v" ) ) {
3729 else if ( !strcmp( argv[ i ], "-force" ) ) {
3734 /* patch subdivisions */
3735 else if ( !strcmp( argv[ i ], "-subdivisions" ) ) {
3738 patchSubdivisions = atoi( argv[ i ] );
3740 if ( patchSubdivisions <= 0 ) {
3741 patchSubdivisions = 1;
3746 else if ( !strcmp( argv[ i ], "-threads" ) ) {
3749 numthreads = atoi( argv[ i ] );
3753 else if( !strcmp( argv[ i ], "-nocmdline" ) )
3755 Sys_Printf( "noCmdLine\n" );
3762 /* init model library */
3764 PicoSetMallocFunc( safe_malloc );
3765 PicoSetFreeFunc( free );
3766 PicoSetPrintFunc( PicoPrintFunc );
3767 PicoSetLoadFileFunc( PicoLoadFileFunc );
3768 PicoSetFreeFileFunc( free );
3770 /* set number of threads */
3773 /* generate sinusoid jitter table */
3774 for ( i = 0; i < MAX_JITTERS; i++ )
3776 jitters[ i ] = sin( i * 139.54152147 );
3777 //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
3780 /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
3781 and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
3783 Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
3784 Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
3785 Sys_Printf( "NetRadiant - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
3786 Sys_Printf( "%s\n", Q3MAP_MOTD );
3787 Sys_Printf( "%s\n", argv[0] );
3789 strcpy( q3map2path, argv[0] );//fuer autoPack func
3791 /* ydnar: new path initialization */
3792 InitPaths( &argc, argv );
3794 /* set game options */
3795 if ( !patchSubdivisions ) {
3796 patchSubdivisions = game->patchSubdivisions;
3799 /* check if we have enough options left to attempt something */
3801 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
3805 if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
3806 r = FixAAS( argc - 1, argv + 1 );
3810 else if ( !strcmp( argv[ 1 ], "-analyze" ) ) {
3811 r = AnalyzeBSP( argc - 1, argv + 1 );
3815 else if ( !strcmp( argv[ 1 ], "-info" ) ) {
3816 r = BSPInfo( argc - 2, argv + 2 );
3820 else if ( !strcmp( argv[ 1 ], "-vis" ) ) {
3821 r = VisMain( argc - 1, argv + 1 );
3825 else if ( !strcmp( argv[ 1 ], "-light" ) ) {
3826 r = LightMain( argc - 1, argv + 1 );
3830 else if ( !strcmp( argv[ 1 ], "-vlight" ) ) {
3831 Sys_Printf( "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
3832 argv[ 1 ] = "-fast"; /* eek a hack */
3833 r = LightMain( argc, argv );
3836 /* ydnar: lightmap export */
3837 else if ( !strcmp( argv[ 1 ], "-export" ) ) {
3838 r = ExportLightmapsMain( argc - 1, argv + 1 );
3841 /* ydnar: lightmap import */
3842 else if ( !strcmp( argv[ 1 ], "-import" ) ) {
3843 r = ImportLightmapsMain( argc - 1, argv + 1 );
3846 /* ydnar: bsp scaling */
3847 else if ( !strcmp( argv[ 1 ], "-scale" ) ) {
3848 r = ScaleBSPMain( argc - 1, argv + 1 );
3852 else if ( !strcmp( argv[ 1 ], "-shift" ) ) {
3853 r = ShiftBSPMain( argc - 1, argv + 1 );
3857 else if ( !strcmp( argv[ 1 ], "-pk3" ) ) {
3858 r = pk3BSPMain( argc - 1, argv + 1 );
3862 else if ( !strcmp( argv[ 1 ], "-repack" ) ) {
3863 r = repackBSPMain( argc - 1, argv + 1 );
3866 /* ydnar: bsp conversion */
3867 else if ( !strcmp( argv[ 1 ], "-convert" ) ) {
3868 r = ConvertBSPMain( argc - 1, argv + 1 );
3872 else if ( !strcmp( argv[ 1 ], "-minimap" ) ) {
3873 r = MiniMapBSPMain( argc - 1, argv + 1 );
3876 /* ydnar: otherwise create a bsp */
3878 r = BSPMain( argc, argv );
3882 end = I_FloatTime();
3883 Sys_Printf( "%9.0f seconds elapsed\n", end - start );
3885 /* shut down connection */
3886 Broadcast_Shutdown();
3888 /* return any error code */