My Project
Public Member Functions | Static Public Member Functions | List of all members
ParaEngine::CAssetManifest Class Reference

Asset manifest manager. More...

#include <AssetManifest.h>

Public Member Functions

void LoadManifest ()
 
void PrepareCacheFolders ()
 
void LoadManifestFile (const string &filename)
 
bool DoesFileExist (const char *filename)
 check whether file exist. More...
 
bool DoesFileExist (const string &filename)
 check whether file exist. More...
 
int CheckSyncFile (const char *filename)
 if the file is not asset file, it returns 0. More...
 
AssetFileEntryGetFile (const string &filename, bool bUseReplaceMap=true, bool bIgnoreLocalFile=false)
 get a asset file entry based on file name. More...
 
void AddEntry (const char *filename)
 add an entry to the list. More...
 
void CleanUp ()
 clean up all loaded files. More...
 
void PrintStat ()
 print stat to log
 
bool IsEnabled ()
 if false, manifest will be temporarily disabled and all GetFile() and DoesFileExist() functions will not return anything. More...
 
void EnableManifest (bool bEnable=true)
 if false, manifest will be temporarily disabled and all GetFile() and DoesFileExist() functions will not return anything. More...
 
bool IsUseLocalFileFirst () const
 if true, GetFile() will return null, if a local disk or zip file is found even there is an entry in the assetmanifest. More...
 
void SetUseLocalFileFirst (bool val)
 

Static Public Member Functions

static CAssetManifestGetSingleton ()
 get the global singleton object
 

Detailed Description

Asset manifest manager.

When the application starts, we will read all "Assets_manifest*.txt" file under the root directory. Each file has following content

format is [relative path],md5,fileSize if the name ends with .z, it is zipped. This could be 4MB uncompressed in size md5 is checksum code of the file. fileSize is the compressed file size.

audio/music.mp3.z,3799134715,22032 model/building/tree.dds.z,2957514200,949 model/building/tree.x.z,2551621901,816 games/tutorial.swf,1157008036,171105

When one of the async loader try to load an application asset(texture, model, etc), it will first search in AssetManifest using the TO-LOWER-CASED asset path, such as (model/building/tree.x). if will then search the "temp/cache/" directory for a matching file

The file matching is done by comparing the line in the asset file with the filename in the cache directory, using their md5 and size.

audio/music.mp3.z,3799134715,22032 matches to file 379913471522032

Example Usage:
<verbatim>
AssetFileEntry* pEntry = CAssetManifest::GetSingleton().GetFile("Texture/somefile.dds");
if(pEntry && pEntry->DoesFileExist())
{

Load from file pEntry->GetLocalFileName(); } </verbatim>

Member Function Documentation

§ AddEntry()

void CAssetManifest::AddEntry ( const char *  filename)

add an entry to the list.

Parameters
filenamestring with format [relative path],md5,fileSize

§ CheckSyncFile()

int CAssetManifest::CheckSyncFile ( const char *  filename)

if the file is not asset file, it returns 0.

if the file is asset file, it will sync the file, if the file is not up to date. this function is synchronous. it may retry download if download failed such as md5 mismatch. If this function is called and failed multiple times, and HasReachedMaxRetryCount() is true, the function will do nothing and return false.

Returns
if the file is not asset file, it returns 0. if file is downloaded and up to date, it return 1. if asset file failed, it return -1

§ CleanUp()

void CAssetManifest::CleanUp ( )

clean up all loaded files.

§ DoesFileExist() [1/2]

bool CAssetManifest::DoesFileExist ( const char *  filename)

check whether file exist.

file name is case insensitive

§ DoesFileExist() [2/2]

bool CAssetManifest::DoesFileExist ( const string &  filename)

check whether file exist.

file name is case insensitive

§ EnableManifest()

void CAssetManifest::EnableManifest ( bool  bEnable = true)

if false, manifest will be temporarily disabled and all GetFile() and DoesFileExist() functions will not return anything.

default to true.

§ GetFile()

AssetFileEntry * CAssetManifest::GetFile ( const string &  filename,
bool  bUseReplaceMap = true,
bool  bIgnoreLocalFile = false 
)

get a asset file entry based on file name.

the actually file entity may be replaced by CFileReplaceMap::GetSingleton() [thread-safe]: it is thread safe only after manifest file and replace file map are loaded.

Parameters
filenamefile name of the file to search such as "model/building/tree.x". file name is case insensitive
bUseReplaceMapdefault to true. whether to use CFileReplaceMap::GetSingleton() to replace the input filename.
Returns
: if there is no update to date file, it will return NULL;

§ IsEnabled()

bool ParaEngine::CAssetManifest::IsEnabled ( )
inline

if false, manifest will be temporarily disabled and all GetFile() and DoesFileExist() functions will not return anything.

§ IsUseLocalFileFirst()

bool CAssetManifest::IsUseLocalFileFirst ( ) const

if true, GetFile() will return null, if a local disk or zip file is found even there is an entry in the assetmanifest.

§ PrepareCacheFolders()

void CAssetManifest::PrepareCacheFolders ( )

since FAT32 has a limit of 65535 files per folder, and if file name is long, it can be as few as 15000 files per folder. so I separate files into 36 folders according to file md5's first letter


The documentation for this class was generated from the following files: