doom3-bfg/neo/framework/File_Manifest.h

328 lines
7.2 KiB
C
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +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__
/*
==============================================================
File and preload manifests.
2012-11-26 18:58:24 +00:00
==============================================================
*/
class idFileManifest
{
2012-11-26 18:58:24 +00:00
public:
idFileManifest()
{
2012-11-26 18:58:24 +00:00
cacheTable.SetGranularity( 4096 );
cacheHash.SetGranularity( 4096 );
}
~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();
}
int FindFile( const char* fileName );
const idStr& GetFileNameByIndex( int idx ) const;
const char* GetManifestName()
{
2012-11-26 18:58:24 +00:00
return filename;
}
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();
for( int i = 0; i < cacheTable.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
dest.Append( cacheTable[ i ] );
}
}
void Print()
{
2012-11-26 18:58:24 +00:00
idLib::Printf( "dump for manifest %s\n", GetManifestName() );
idLib::Printf( "---------------------------------------\n" );
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-26 18:58:24 +00:00
private:
idStrList cacheTable;
idHashIndex cacheHash;
idStr filename;
};
// image preload
struct imagePreload_s
{
imagePreload_s()
{
2012-11-26 18:58:24 +00:00
filter = 0;
repeat = 0;
usage = 0;
cubeMap = 0;
}
void Write( idFile* f )
{
2012-11-26 18:58:24 +00:00
f->WriteBig( filter );
f->WriteBig( repeat );
f->WriteBig( usage );
f->WriteBig( cubeMap );
}
void Read( idFile* f )
{
2012-11-26 18:58:24 +00:00
f->ReadBig( filter );
f->ReadBig( repeat );
f->ReadBig( usage );
f->ReadBig( cubeMap );
}
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;
};
enum preloadType_t
{
2012-11-26 18:58:24 +00:00
PRELOAD_IMAGE,
PRELOAD_MODEL,
PRELOAD_SAMPLE,
PRELOAD_ANIM,
PRELOAD_COLLISION,
PRELOAD_PARTICLE
};
// preload
struct preloadEntry_s
{
preloadEntry_s()
{
2012-11-26 18:58:24 +00:00
resType = 0;
}
bool operator==( const preloadEntry_s& b ) const
{
2012-11-26 18:58:24 +00:00
bool ret = ( resourceName.Icmp( b.resourceName ) == 0 );
if( ret && resType == PRELOAD_IMAGE )
{
2012-11-26 18:58:24 +00:00
// this should never matter but...
ret &= ( imgData == b.imgData );
}
return ret;
}
void Write( idFile* outFile )
{
2012-11-26 18:58:24 +00:00
outFile->WriteBig( resType );
outFile->WriteString( resourceName );
imgData.Write( outFile );
}
void Read( idFile* inFile )
{
2012-11-26 18:58:24 +00:00
inFile->ReadBig( resType );
inFile->ReadString( resourceName );
imgData.Read( inFile );
}
2012-11-26 18:58:24 +00:00
int resType; // type
idStr resourceName; // resource name
imagePreload_s imgData; // image specific data
};
struct preloadSort_t
{
2012-11-26 18:58:24 +00:00
int idx;
int ofs;
};
class idSort_Preload : public idSort_Quick< preloadSort_t, idSort_Preload >
{
2012-11-26 18:58:24 +00:00
public:
int Compare( const preloadSort_t& a, const preloadSort_t& b ) const
{
return a.ofs - b.ofs;
}
2012-11-26 18:58:24 +00:00
};
class idPreloadManifest
{
2012-11-26 18:58:24 +00:00
public:
idPreloadManifest()
{
2012-11-26 18:58:24 +00:00
entries.SetGranularity( 2048 );
}
~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();
outFile->WriteBig( ( int )entries.Num() );
2012-11-26 18:58:24 +00:00
outFile->WriteString( filename );
for( int i = 0; i < entries.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
entries[ i ].Write( outFile );
}
}
int NumResources() const
{
2012-11-26 18:58:24 +00:00
return entries.Num();
}
const preloadEntry_s& GetPreloadByIndex( int idx ) const
{
2012-11-26 18:58:24 +00:00
return entries[ idx ];
}
const idStr& GetResourceNameByIndex( int idx ) const
{
2012-11-26 18:58:24 +00:00
return entries[ idx ].resourceName;
}
const char* GetManifestName() const
{
2012-11-26 18:58:24 +00:00
return filename;
}
void Add( const preloadEntry_s& p )
{
2012-11-26 18:58:24 +00:00
entries.AddUnique( p );
}
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
void Clear()
{
2012-11-26 18:58:24 +00:00
entries.Clear();
}
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;
}
void Print()
{
2012-11-26 18:58:24 +00:00
idLib::Printf( "dump for preload manifest %s\n", GetManifestName() );
idLib::Printf( "---------------------------------------\n" );
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__ */