1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: vcd_sound_check.cpp : Defines the entry point for the console application.
//
//=============================================================================//
#include <stdio.h>
#include <windows.h>
#include "tier0/dbg.h"
#include "tier1/utldict.h"
#include "filesystem.h"
#include "FileSystem_Tools.h"
#include "tier1/KeyValues.h"
#include "cmdlib.h"
#include "scriplib.h"
#include "vstdlib/random.h"
#include "choreoscene.h"
#include "choreoevent.h"
#include "iscenetokenprocessor.h"
#include "tier1/utlbuffer.h"
#include "tier1/checksum_crc.h"
#include "pacifier.h"
#include "SceneCache.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#include "ModelSoundsCache.h"
#include "Datacache/imdlcache.h"
#include "datacache/idatacache.h"
#include "studio.h"
#include "appframework/appframework.h"
#include "tier0/icommandline.h"
#include "istudiorender.h"
#include "materialsystem/imaterialsystem.h"
#include "vphysics_interface.h"
#include "icvar.h"
#include "vstdlib/cvar.h"
#include "eventlist.h"
// #define TESTING 1
bool uselogfile = false;
bool modelsoundscache = false;
bool scenecache = false;
bool virtualmodel = false;
bool buildxcds = false;
struct AnalysisData
{
CUtlSymbolTable symbols;
};
static AnalysisData g_Analysis;
static char g_szCurrentGameDir[ 512 ];
IFileSystem *filesystem = NULL;
IMDLCache *g_pMDLCache = NULL;
ISoundEmitterSystemBase *soundemitterbase = NULL;
static CUniformRandomStream g_Random;
IUniformRandomStream *random = &g_Random;
static bool spewed = false;
static CUtlCachedFileData< CSceneCache > g_SceneCache( "scene.cache", SCENECACHE_VERSION, 0, UTL_CACHED_FILE_USE_FILESIZE );
static CUtlCachedFileData< CModelSoundsCache > g_ModelSoundsCache( "modelsounds.cache", MODELSOUNDSCACHE_VERSION, 0, UTL_CACHED_FILE_USE_FILESIZE );
//-----------------------------------------------------------------------------
// FIXME: This trashy glue code is really not acceptable. Figure out a way of making it unnecessary.
//-----------------------------------------------------------------------------
const studiohdr_t *studiohdr_t::FindModel( void **cache, char const *pModelName ) const
{
MDLHandle_t handle = g_pMDLCache->FindMDL( pModelName );
*cache = (void*)handle;
return g_pMDLCache->GetStudioHdr( handle );
}
virtualmodel_t *studiohdr_t::GetVirtualModel( void ) const
{
return g_pMDLCache->GetVirtualModel( (MDLHandle_t)virtualModel );
}
byte *studiohdr_t::GetAnimBlock( int i ) const
{
return g_pMDLCache->GetAnimBlock( (MDLHandle_t)virtualModel, i );
}
int studiohdr_t::GetAutoplayList( unsigned short **pOut ) const
{
return g_pMDLCache->GetAutoplayList( (MDLHandle_t)virtualModel, pOut );
}
const studiohdr_t *virtualgroup_t::GetStudioHdr( void ) const
{
return g_pMDLCache->GetStudioHdr( (MDLHandle_t)cache );
}
//-----------------------------------------------------------------------------
// Purpose: Helper for parsing scene data file
//-----------------------------------------------------------------------------
class CSceneTokenProcessor : public ISceneTokenProcessor
{
public:
const char *CurrentToken( void );
bool GetToken( bool crossline );
bool TokenAvailable( void );
void Error( const char *fmt, ... );
};
//-----------------------------------------------------------------------------
// Purpose:
// Output : const char
//-----------------------------------------------------------------------------
const char *CSceneTokenProcessor::CurrentToken( void )
{
return token;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : crossline -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CSceneTokenProcessor::GetToken( bool crossline )
{
return ::GetToken( crossline ) ? true : false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CSceneTokenProcessor::TokenAvailable( void )
{
return ::TokenAvailable() ? true : false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *fmt -
// ... -
//-----------------------------------------------------------------------------
void CSceneTokenProcessor::Error( const char *fmt, ... )
{
char string[ 2048 ];
va_list argptr;
va_start( argptr, fmt );
Q_vsnprintf( string, sizeof(string), fmt, argptr );
va_end( argptr );
Warning( "%s", string );
Assert(0);
}
static CSceneTokenProcessor g_TokenProcessor;
SpewRetval_t SpewFunc( SpewType_t type, char const *pMsg )
{
spewed = true;
printf( "%s", pMsg );
OutputDebugString( pMsg );
if ( type == SPEW_ERROR )
{
printf( "\n" );
OutputDebugString( "\n" );
}
return SPEW_CONTINUE;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : depth -
// *fmt -
// ... -
//-----------------------------------------------------------------------------
void vprint( int depth, const char *fmt, ... )
{
char string[ 8192 ];
va_list va;
va_start( va, fmt );
vsprintf( string, fmt, va );
va_end( va );
FILE *fp = NULL;
if ( uselogfile )
{
fp = fopen( "log.txt", "ab" );
}
while ( depth-- > 0 )
{
printf( " " );
OutputDebugString( " " );
if ( fp )
{
fprintf( fp, " " );
}
}
::printf( "%s", string );
OutputDebugString( string );
if ( fp )
{
char *p = string;
while ( *p )
{
if ( *p == '\n' )
{
fputc( '\r', fp );
}
fputc( *p, fp );
p++;
}
fclose( fp );
}
}
void logprint( char const *logfile, const char *fmt, ... )
{
char string[ 8192 ];
va_list va;
va_start( va, fmt );
vsprintf( string, fmt, va );
va_end( va );
FILE *fp = NULL;
static bool first = true;
if ( first )
{
first = false;
fp = fopen( logfile, "wb" );
}
else
{
fp = fopen( logfile, "ab" );
}
if ( fp )
{
char *p = string;
while ( *p )
{
if ( *p == '\n' )
{
fputc( '\r', fp );
}
fputc( *p, fp );
p++;
}
fclose( fp );
}
}
void Con_Printf( const char *fmt, ... )
{
va_list args;
static char output[1024];
va_start( args, fmt );
vprintf( fmt, args );
vsprintf( output, fmt, args );
vprint( 0, output );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void printusage( void )
{
vprint( 0, "usage: makexvcd [options] -game gamedir\n\
\t-v = verbose output\n\
\t-m = rebuild modelsounds.cache\n\
\t-x = rebuild .xcd files\n\
\t-s = rebuild scene.cache\n\
\t-z = rebuild virtualmodel.cache (xbox only)\n\
\t-l = log to file log.txt\n\
\ne.g.: makexvcd -s -m -game episodic\n" );
// Exit app
exit( 1 );
}
void BuildFileList_R( CUtlVector< CUtlSymbol >& files, char const *dir, char const *extension )
{
WIN32_FIND_DATA wfd;
char directory[ 256 ];
char filename[ 256 ];
HANDLE ff;
Q_snprintf( directory, sizeof( directory ), "%s\\*.*", dir );
#if defined( TESTING )
if ( files.Count() > 100 )
return;
#endif
if ( ( ff = FindFirstFile( directory, &wfd ) ) == INVALID_HANDLE_VALUE )
return;
int extlen = strlen( extension );
do
{
#if defined( TESTING )
if ( files.Count() > 100 )
return;
#endif
if ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
if ( wfd.cFileName[ 0 ] == '.' )
continue;
// Recurse down directory
Q_snprintf( filename, sizeof( filename ), "%s\\%s", dir, wfd.cFileName );
BuildFileList_R( files, filename, extension );
}
else
{
int len = strlen( wfd.cFileName );
if ( len > extlen )
{
if ( !stricmp( &wfd.cFileName[ len - extlen ], extension ) )
{
char filename[ MAX_PATH ];
Q_snprintf( filename, sizeof( filename ), "%s\\%s", dir, wfd.cFileName );
_strlwr( filename );
Q_FixSlashes( filename );
CUtlSymbol sym = g_Analysis.symbols.AddString( filename );
files.AddToTail( sym );
if ( !( files.Count() % 3000 ) )
{
vprint( 0, "...found %i .%s files\n", files.Count(), extension );
}
}
}
}
} while ( FindNextFile( ff, &wfd ) );
}
void BuildFileList( char const *basedir, CUtlVector< CUtlSymbol >& files, char const *rootdir, char const *extension )
{
files.RemoveAll();
char root[ 512 ];
Q_snprintf( root, sizeof( root ), "%s\\%s", basedir, rootdir );
BuildFileList_R( files, root, extension );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CheckLogFile( void )
{
if ( uselogfile )
{
_unlink( "log.txt" );
vprint( 0, " Outputting to log.txt\n" );
}
}
void PrintHeader()
{
vprint( 0, "Valve Software - CompileVCD.exe (%s)\n", __DATE__ );
vprint( 0, "--- Binary .vcd compiler ---\n" );
}
//-----------------------------------------------------------------------------
// Purpose: For each .wav file in the list, see if any vcd file in the list references it
// First build an index of .wav to .vcd mappings, then search wav list and print results
// Input : vcdfiles -
// wavfiles -
//-----------------------------------------------------------------------------
struct VCDList
{
VCDList()
{
}
VCDList( const VCDList& src )
{
int c = src.vcds.Count();
for ( int i = 0 ; i < c; i++ )
{
vcds.AddToTail( src.vcds[ i ] );
}
}
VCDList& operator =( const VCDList& src )
{
if ( this == &src )
return *this;
int c = src.vcds.Count();
for ( int i = 0 ; i < c; i++ )
{
vcds.AddToTail( src.vcds[ i ] );
}
return *this;
}
CUtlVector< CUtlSymbol > vcds;
};
void AppendDisposition( CUtlVector< CUtlSymbol >& disposition, char const *fmt, ... )
{
char string[ 2048 ];
va_list argptr;
va_start( argptr, fmt );
_vsnprintf( string, sizeof( string ), fmt, argptr );
va_end( argptr );
CUtlSymbol sym;
sym = string;
disposition.AddToTail( sym );
}
CChoreoScene *BlockingLoadScene( char const *vcdname )
{
// Load the .vcd
char scenefile[ MAX_PATH ];
Q_snprintf( scenefile, sizeof( scenefile ), "%s\\%s", g_szCurrentGameDir, vcdname );
LoadScriptFile( scenefile );
CChoreoScene *scene = ChoreoLoadScene( scenefile, NULL, &g_TokenProcessor, Con_Printf );
return scene;
}
void ProcessVCD( char const *vcdname, CUtlVector< CUtlSymbol >& disposition )
{
if ( verbose )
{
vprint( 0, "Processing '%s'\n", vcdname );
}
bool rebuild = false;
FileHandle_t fh = filesystem->Open( vcdname, "rb", "GAME" );
if ( fh == FILESYSTEM_INVALID_HANDLE )
{
Error( "Couldn't open '%s' for reading.", vcdname );
return;
}
size_t bufSize = filesystem->Size( fh );
char *buffer = new char[ bufSize + 1 ];
filesystem->Read( buffer, bufSize, fh );
filesystem->Close( fh );
buffer[ bufSize ] = 0;
CRC32_t crc;
CRC32_Init( &crc );
CRC32_ProcessBuffer( &crc, buffer, bufSize );
CRC32_Final( &crc );
delete[] buffer;
// Now load the file as a binary if it exists...
char binfile[ 512 ];
Q_strncpy( binfile, vcdname, sizeof( binfile ) );
Q_SetExtension( binfile, ".xcd", sizeof( binfile ) );
if ( buildxcds )
{
fh = filesystem->Open( binfile, "rb", "GAME" );
if ( fh == FILESYSTEM_INVALID_HANDLE )
{
AppendDisposition( disposition, "Built '%s'\n", binfile );
rebuild = true;
}
else
{
// Read the first bit of data and check
char crcdata[ 12 ];
filesystem->Read( crcdata, sizeof( crcdata ), fh );
filesystem->Close( fh );
CUtlBuffer buf;
buf.Put( crcdata, sizeof( crcdata ) );
CRC32_t fileCRC = 0;
if ( !CChoreoScene::GetCRCFromBuffer( buf, (unsigned int &)fileCRC ) )
{
AppendDisposition( disposition, "Rebuilt '%s' due to version change\n", binfile );
rebuild = true;
}
else
{
if ( fileCRC != crc )
{
AppendDisposition( disposition, "Rebuilt '%s' due to crc change\n", binfile );
rebuild = true;
}
}
}
}
// Validate the scene cache
g_SceneCache.RebuildItem( vcdname + strlen( g_szCurrentGameDir ) + 1 );
if ( !rebuild )
return;
// Remove current binary
if ( filesystem->FileExists( binfile, "GAME" ) )
{
_unlink( binfile );
}
// Load the .vcd
LoadScriptFile( (char *)vcdname );
CChoreoScene *scene = ChoreoLoadScene( vcdname, NULL, &g_TokenProcessor, Con_Printf );
if ( scene )
{
scene->SaveBinary( binfile, NULL, crc );
delete scene;
}
}
void CompileVCDs( CUtlVector< CUtlSymbol >& vcds )
{
CUtlVector< CUtlSymbol > disposition;
StartPacifier( "CompileVCDs" );
int i;
int c = vcds.Count();
for ( i = 0 ; i < c; ++i )
{
UpdatePacifier( (float)i / (float)c );
ProcessVCD( g_Analysis.symbols.String( vcds[ i ] ), disposition );
}
EndPacifier();
if ( verbose )
{
c = disposition.Count();
for ( i = 0; i < c; ++i )
{
Warning( "%s", disposition[ i ].String() );
}
}
}
static CUtlMap< CStudioHdr *, MDLHandle_t > g_ModelMap( 0, 0, DefLessFunc( CStudioHdr * ) );
CStudioHdr *ModelSoundsCache_LoadModel( char const *filename )
{
MDLHandle_t handle = g_pMDLCache->FindMDL( filename );
CStudioHdr *studioHdr = new CStudioHdr( g_pMDLCache->GetStudioHdr( handle ), g_pMDLCache );
g_ModelMap.Insert( studioHdr, handle );
if ( studioHdr->IsValid() )
return studioHdr;
return NULL;
}
void ModelSoundsCache_FinishModel( CStudioHdr *hdr )
{
int idx = g_ModelMap.Find( hdr );
if ( idx != g_ModelMap.InvalidIndex() )
{
g_pMDLCache->Release( g_ModelMap[ idx ] );
g_ModelMap.RemoveAt( idx );
}
delete hdr;
}
void ModelSoundsCache_PrecacheScriptSound( const char *soundname )
{
}
void ProcessMDL( char const *mdlname, CUtlVector< CUtlSymbol >& disposition )
{
if ( verbose )
{
vprint( 0, "Processing '%s'\n", mdlname );
}
if ( Q_stristr( mdlname, "ghostanim" ) )
{
int n =3 ;
}
// Validate the model sounds cache
g_ModelSoundsCache.RebuildItem( mdlname + strlen( g_szCurrentGameDir ) + 1 );
}
void CompileMDLs( CUtlVector< CUtlSymbol >& mdls )
{
CUtlVector< CUtlSymbol > disposition;
StartPacifier( "CompileMDLs" );
int i;
int c = mdls.Count();
for ( i = 0 ; i < c; ++i )
{
UpdatePacifier( (float)i / (float)c );
ProcessMDL( g_Analysis.symbols.String( mdls[ i ] ), disposition );
}
EndPacifier();
c = disposition.Count();
for ( i = 0; i < c; ++i )
{
Warning( "%s", disposition[ i ].String() );
}
}
//-----------------------------------------------------------------------------
// The application object
//-----------------------------------------------------------------------------
class CMakeCachesApp : public CSteamAppSystemGroup
{
public:
// Methods of IApplication
virtual bool Create();
virtual bool PreInit();
virtual int Main();
virtual void PostShutdown();
virtual void Destroy();
private:
// Sets up the search paths
bool SetupSearchPaths();
};
bool CMakeCachesApp::Create()
{
SpewOutputFunc( SpewFunc );
SpewActivate( "makexvcd", 2 );
// Add in the cvar factory
AppModule_t cvarModule = LoadModule( VStdLib_GetICVarFactory() );
AddSystem( cvarModule, VENGINE_CVAR_INTERFACE_VERSION );
AppSystemInfo_t appSystems[] =
{
{ "materialsystem.dll", MATERIAL_SYSTEM_INTERFACE_VERSION },
{ "studiorender.dll", STUDIO_RENDER_INTERFACE_VERSION },
{ "vphysics.dll", VPHYSICS_INTERFACE_VERSION },
{ "datacache.dll", DATACACHE_INTERFACE_VERSION },
{ "datacache.dll", MDLCACHE_INTERFACE_VERSION },
{ "datacache.dll", STUDIO_DATA_CACHE_INTERFACE_VERSION },
{ "soundemittersystem.dll", SOUNDEMITTERSYSTEM_INTERFACE_VERSION },
{ "", "" } // Required to terminate the list
};
if ( !AddSystems( appSystems ) )
return false;
g_pFileSystem = filesystem = (IFileSystem*)FindSystem( FILESYSTEM_INTERFACE_VERSION );
g_pMDLCache = (IMDLCache*)FindSystem( MDLCACHE_INTERFACE_VERSION );
soundemitterbase = (ISoundEmitterSystemBase*)FindSystem(SOUNDEMITTERSYSTEM_INTERFACE_VERSION);
g_pMaterialSystem = (IMaterialSystem*)FindSystem( MATERIAL_SYSTEM_INTERFACE_VERSION );
if ( !soundemitterbase || !g_pMDLCache || !filesystem || !g_pMaterialSystem )
{
Error("Unable to load required library interface!\n");
}
g_pMaterialSystem->SetShaderAPI( "shaderapiempty.dll" );
return true;
}
void CMakeCachesApp::Destroy()
{
g_pFileSystem = filesystem = NULL;
soundemitterbase = NULL;
g_pMDLCache = NULL;
}
//-----------------------------------------------------------------------------
// Sets up the game path
//-----------------------------------------------------------------------------
bool CMakeCachesApp::SetupSearchPaths()
{
CFSSteamSetupInfo steamInfo;
steamInfo.m_pDirectoryName = NULL;
steamInfo.m_bOnlyUseDirectoryName = false;
steamInfo.m_bToolsMode = true;
steamInfo.m_bSetSteamDLLPath = true;
steamInfo.m_bSteam = filesystem->IsSteam();
if ( FileSystem_SetupSteamEnvironment( steamInfo ) != FS_OK )
return false;
CFSMountContentInfo fsInfo;
fsInfo.m_pFileSystem = filesystem;
fsInfo.m_bToolsMode = true;
fsInfo.m_pDirectoryName = steamInfo.m_GameInfoPath;
if ( FileSystem_MountContent( fsInfo ) != FS_OK )
return false;
// Finally, load the search paths for the "GAME" path.
CFSSearchPathsInit searchPathsInit;
searchPathsInit.m_pDirectoryName = steamInfo.m_GameInfoPath;
searchPathsInit.m_pFileSystem = fsInfo.m_pFileSystem;
if ( FileSystem_LoadSearchPaths( searchPathsInit ) != FS_OK )
return false;
char platform[MAX_PATH];
Q_strncpy( platform, steamInfo.m_GameInfoPath, MAX_PATH );
Q_StripTrailingSlash( platform );
Q_strncat( platform, "/../platform", MAX_PATH, MAX_PATH );
fsInfo.m_pFileSystem->AddSearchPath( platform, "PLATFORM" );
// Set gamedir.
Q_MakeAbsolutePath( gamedir, sizeof( gamedir ), steamInfo.m_GameInfoPath );
Q_AppendSlash( gamedir, sizeof( gamedir ) );
return true;
}
//-----------------------------------------------------------------------------
// Init, shutdown
//-----------------------------------------------------------------------------
bool CMakeCachesApp::PreInit( )
{
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f, false, false, false, false );
filesystem->SetWarningFunc( Warning );
// Add paths...
if ( !SetupSearchPaths() )
return false;
return true;
}
void CMakeCachesApp::PostShutdown()
{
}
//-----------------------------------------------------------------------------
// main application
//-----------------------------------------------------------------------------
int CMakeCachesApp::Main()
{
for ( int i=1 ; i<CommandLine()->ParmCount() ; i++)
{
if ( CommandLine()->GetParm( i )[ 0 ] == '-' )
{
switch( CommandLine()->GetParm( i )[ 1 ] )
{
case 'l':
uselogfile = true;
break;
case 'v':
verbose = true;
break;
case 'g': // -game
++i;
break;
case 'm':
modelsoundscache = true;
break;
case 's':
scenecache = true;
break;
case 'x':
buildxcds = true;
break;
case 'z':
virtualmodel = true;
break;
default:
printusage();
break;
}
}
}
if ( CommandLine()->ParmCount() < 2 || ( i != CommandLine()->ParmCount() ) )
{
PrintHeader();
printusage();
}
CheckLogFile();
PrintHeader();
vprint( 0, " Compiling binary .vcd files to .xvcd ...\n" );
char vcddir[ 256 ];
char modelsdir[ 256 ];
Q_snprintf( vcddir, sizeof( vcddir ), "scenes", CommandLine()->GetParm( i - 1 ) );
Q_snprintf( modelsdir, sizeof( modelsdir ), "models", CommandLine()->GetParm( i - 1 ) );
if ( !strstr( vcddir, "scenes" ) )
{
vprint( 0, ".vcd dir %s looks invalid (format: u:/game/hl2/scenes)\n", vcddir );
return 0;
}
if ( !strstr( modelsdir, "models" ) )
{
vprint( 0, ".mdl dir %s looks invalid (format: u:/game/hl2/models)\n", modelsdir );
return 0;
}
char binaries[MAX_PATH];
Q_strncpy( binaries, gamedir, MAX_PATH );
Q_StripTrailingSlash( binaries );
Q_strncat( binaries, "/../bin", MAX_PATH, MAX_PATH );
filesystem->AddSearchPath( binaries, "EXECUTABLE_PATH");
soundemitterbase->ModInit();
// Delete the scene cache file
if ( scenecache ) filesystem->RemoveFile( "scene.cache", "MOD" );
if ( modelsoundscache ) filesystem->RemoveFile( "modelsounds.cache", "MOD" );
if ( virtualmodel ) filesystem->RemoveFile( "virtualmodel.cache", "MOD" );
CUtlSymbolTable pathStrings;
CUtlVector< CUtlSymbol > searchList;
char searchPaths[ 512 ];
filesystem->GetSearchPath( "GAME", true, searchPaths, sizeof( searchPaths ) );
// We want to walk them in reverse order so newer files are "overrides" for older ones, so we add them to a list in reverse order
for ( char *path = strtok( searchPaths, ";" ); path; path = strtok( NULL, ";" ) )
{
char dir[ 512 ];
Q_strncpy( dir, path, sizeof( dir ) );
Q_FixSlashes( dir );
Q_strlower( dir );
Q_StripTrailingSlash( dir );
CUtlSymbol sym = pathStrings.AddString( dir );
// Push them on head so we can walk them in reverse order
searchList.AddToHead( sym );
}
if ( scenecache )
{
g_SceneCache.Init();
}
if ( modelsoundscache )
{
g_ModelSoundsCache.Init();
g_pMDLCache->InitPreloadData( true );
}
EventList_RegisterSharedEvents();
for ( int sp = 0; sp < searchList.Count(); ++sp )
{
char const *basedir = pathStrings.String( searchList[ sp ] );
Q_strncpy( g_szCurrentGameDir, basedir, sizeof( g_szCurrentGameDir ) );
vprint( 0, "Processing gamedir %s\n", basedir );
if ( scenecache )
{
vprint( 1, "Building list of .vcd files\n" );
CUtlVector< CUtlSymbol > vcdfiles;
BuildFileList( basedir, vcdfiles, vcddir, ".vcd" );
vprint( 1, "found %i .vcd files\n", vcdfiles.Count() );
CompileVCDs( vcdfiles );
}
if ( modelsoundscache )
{
vprint( 1, "Building list of .mdl files\n" );
CUtlVector< CUtlSymbol > mdlfiles;
BuildFileList( basedir, mdlfiles, modelsdir, ".mdl" );
vprint( 1, "found %i .mdl files\n", mdlfiles.Count() );
CompileMDLs( mdlfiles );
}
}
if ( scenecache )
{
if ( g_SceneCache.IsDirty() )
{
g_SceneCache.Save();
}
g_SceneCache.Shutdown();
}
if ( modelsoundscache )
{
if ( g_ModelSoundsCache.IsDirty() )
{
g_ModelSoundsCache.Save();
}
g_ModelSoundsCache.Shutdown();
g_pMDLCache->ShutdownPreloadData();
}
soundemitterbase->ModShutdown();
return 0;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : argc -
// argv[] -
// Output : int
//-----------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
CommandLine()->CreateCmdLine( argc, argv );
CMakeCachesApp sceneManagerApp;
CSteamApplication steamApplication( &sceneManagerApp );
int nRetVal = steamApplication.Run();
return nRetVal;
}
|