My Project
|
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... | |
AssetFileEntry * | GetFile (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 CAssetManifest & | GetSingleton () |
get the global singleton object | |
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>
void CAssetManifest::AddEntry | ( | const char * | filename | ) |
add an entry to the list.
filename | string with format [relative path],md5,fileSize |
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.
void CAssetManifest::CleanUp | ( | ) |
clean up all loaded files.
bool CAssetManifest::DoesFileExist | ( | const char * | filename | ) |
check whether file exist.
file name is case insensitive
bool CAssetManifest::DoesFileExist | ( | const string & | filename | ) |
check whether file exist.
file name is case insensitive
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.
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.
filename | file name of the file to search such as "model/building/tree.x". file name is case insensitive |
bUseReplaceMap | default to true. whether to use CFileReplaceMap::GetSingleton() to replace the input filename. |
|
inline |
if false, manifest will be temporarily disabled and all GetFile() and DoesFileExist() functions will not return anything.
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.
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