2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __FILE_MANIFEST_H__
|
|
|
|
#define __FILE_MANIFEST_H__
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
File and preload manifests.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
==============================================================
|
|
|
|
*/
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
class idFileManifest
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
idFileManifest()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
cacheTable.SetGranularity( 4096 );
|
|
|
|
cacheHash.SetGranularity( 4096 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
~idFileManifest() {}
|
|
|
|
|
|
|
|
bool LoadManifest( const char* fileName );
|
|
|
|
bool LoadManifestFromFile( idFile* file );
|
|
|
|
void WriteManifestFile( const char* fileName );
|
|
|
|
|
|
|
|
int NumFiles()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return cacheTable.Num();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
int FindFile( const char* fileName );
|
|
|
|
|
|
|
|
const idStr& GetFileNameByIndex( int idx ) const;
|
|
|
|
|
|
|
|
|
|
|
|
const char* GetManifestName()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return filename;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
void RemoveAll( const char* filename );
|
|
|
|
void AddFile( const char* filename );
|
|
|
|
|
|
|
|
void PopulateList( idStaticList< idStr, 16384 >& dest )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
dest.Clear();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < cacheTable.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
dest.Append( cacheTable[ i ] );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
void Print()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "dump for manifest %s\n", GetManifestName() );
|
|
|
|
idLib::Printf( "---------------------------------------\n" );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < NumFiles(); i++ )
|
|
|
|
{
|
|
|
|
const idStr& name = GetFileNameByIndex( i );
|
|
|
|
if( name.Find( ".idwav", false ) >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "%s\n", GetFileNameByIndex( i ).c_str() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
private:
|
|
|
|
idStrList cacheTable;
|
|
|
|
idHashIndex cacheHash;
|
|
|
|
idStr filename;
|
|
|
|
};
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
// image preload
|
|
|
|
struct imagePreload_s
|
|
|
|
{
|
|
|
|
imagePreload_s()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
filter = 0;
|
|
|
|
repeat = 0;
|
|
|
|
usage = 0;
|
|
|
|
cubeMap = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void Write( idFile* f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
f->WriteBig( filter );
|
|
|
|
f->WriteBig( repeat );
|
|
|
|
f->WriteBig( usage );
|
|
|
|
f->WriteBig( cubeMap );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void Read( idFile* f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
f->ReadBig( filter );
|
|
|
|
f->ReadBig( repeat );
|
|
|
|
f->ReadBig( usage );
|
|
|
|
f->ReadBig( cubeMap );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
bool operator==( const imagePreload_s& b ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( filter == b.filter && repeat == b.repeat && usage == b.usage && cubeMap == b.cubeMap );
|
|
|
|
}
|
|
|
|
int filter;
|
|
|
|
int repeat;
|
|
|
|
int usage;
|
|
|
|
int cubeMap;
|
|
|
|
};
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
enum preloadType_t
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PRELOAD_IMAGE,
|
|
|
|
PRELOAD_MODEL,
|
|
|
|
PRELOAD_SAMPLE,
|
|
|
|
PRELOAD_ANIM,
|
|
|
|
PRELOAD_COLLISION,
|
|
|
|
PRELOAD_PARTICLE
|
|
|
|
};
|
|
|
|
|
|
|
|
// preload
|
2012-11-28 15:47:07 +00:00
|
|
|
struct preloadEntry_s
|
|
|
|
{
|
|
|
|
preloadEntry_s()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
resType = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
bool operator==( const preloadEntry_s& b ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bool ret = ( resourceName.Icmp( b.resourceName ) == 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ret && resType == PRELOAD_IMAGE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// this should never matter but...
|
|
|
|
ret &= ( imgData == b.imgData );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void Write( idFile* outFile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
outFile->WriteBig( resType );
|
|
|
|
outFile->WriteString( resourceName );
|
|
|
|
imgData.Write( outFile );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
void Read( idFile* inFile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
inFile->ReadBig( resType );
|
|
|
|
inFile->ReadString( resourceName );
|
|
|
|
imgData.Read( inFile );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int resType; // type
|
|
|
|
idStr resourceName; // resource name
|
|
|
|
imagePreload_s imgData; // image specific data
|
|
|
|
};
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
struct preloadSort_t
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int idx;
|
|
|
|
int ofs;
|
|
|
|
};
|
2012-11-28 15:47:07 +00:00
|
|
|
class idSort_Preload : public idSort_Quick< preloadSort_t, idSort_Preload >
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
int Compare( const preloadSort_t& a, const preloadSort_t& b ) const
|
|
|
|
{
|
|
|
|
return a.ofs - b.ofs;
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
};
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
class idPreloadManifest
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
idPreloadManifest()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entries.SetGranularity( 2048 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
~idPreloadManifest() {}
|
|
|
|
|
|
|
|
bool LoadManifest( const char* fileName );
|
|
|
|
bool LoadManifestFromFile( idFile* file );
|
|
|
|
|
|
|
|
void WriteManifest( const char* fileName );
|
|
|
|
void WriteManifestToFile( idFile* outFile )
|
|
|
|
{
|
|
|
|
if( outFile == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
filename = outFile->GetName();
|
2012-11-28 15:47:07 +00:00
|
|
|
outFile->WriteBig( ( int )entries.Num() );
|
2012-11-26 18:58:24 +00:00
|
|
|
outFile->WriteString( filename );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < entries.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entries[ i ].Write( outFile );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
int NumResources() const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return entries.Num();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const preloadEntry_s& GetPreloadByIndex( int idx ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return entries[ idx ];
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const idStr& GetResourceNameByIndex( int idx ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return entries[ idx ].resourceName;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const char* GetManifestName() const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return filename;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
void Add( const preloadEntry_s& p )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entries.AddUnique( p );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
void AddSample( const char* _resourceName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
static preloadEntry_s pe;
|
|
|
|
pe.resType = PRELOAD_SAMPLE;
|
|
|
|
pe.resourceName = _resourceName;
|
|
|
|
entries.Append( pe );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void AddModel( const char* _resourceName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
static preloadEntry_s pe;
|
|
|
|
pe.resType = PRELOAD_MODEL;
|
|
|
|
pe.resourceName = _resourceName;
|
|
|
|
entries.Append( pe );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void AddParticle( const char* _resourceName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
static preloadEntry_s pe;
|
|
|
|
pe.resType = PRELOAD_PARTICLE;
|
|
|
|
pe.resourceName = _resourceName;
|
|
|
|
entries.Append( pe );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void AddAnim( const char* _resourceName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
static preloadEntry_s pe;
|
|
|
|
pe.resType = PRELOAD_ANIM;
|
|
|
|
pe.resourceName = _resourceName;
|
|
|
|
entries.Append( pe );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void AddCollisionModel( const char* _resourceName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
static preloadEntry_s pe;
|
|
|
|
pe.resType = PRELOAD_COLLISION;
|
|
|
|
pe.resourceName = _resourceName;
|
|
|
|
entries.Append( pe );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void AddImage( const char* _resourceName, int _filter, int _repeat, int _usage, int _cube )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
static preloadEntry_s pe;
|
|
|
|
pe.resType = PRELOAD_IMAGE;
|
|
|
|
pe.resourceName = _resourceName;
|
|
|
|
pe.imgData.filter = _filter;
|
|
|
|
pe.imgData.repeat = _repeat;
|
|
|
|
pe.imgData.usage = _usage;
|
|
|
|
pe.imgData.cubeMap = _cube;
|
|
|
|
entries.Append( pe );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entries.Clear();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
int FindResource( const char* name )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < entries.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( idStr::Icmp( name, entries[ i ].resourceName ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
void Print()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "dump for preload manifest %s\n", GetManifestName() );
|
|
|
|
idLib::Printf( "---------------------------------------\n" );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < NumResources(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idLib::Printf( "%s\n", GetResourceNameByIndex( i ).c_str() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
idList< preloadEntry_s > entries;
|
|
|
|
idStr filename;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* !__FILE_MANIFEST_H__ */
|