Jeck - Some logic fixes, reducing number of filesys calls when loading graphics. (Cards still check filesys way too often, but I'm working on that)

This commit is contained in:
wagic.jeck
2009-09-03 21:10:04 +00:00
parent b78d25d16b
commit 805a78e39d
+35 -23
View File
@@ -214,7 +214,11 @@ WCachedTexture * WResourceManager:: getCachedCard(MTGCard * card, int type, bool
//Space in cache, make new texture //Space in cache, make new texture
if(cleanup()){ if(cleanup()){
ctex = NEW WCachedTexture(); ctex = NEW WCachedTexture();
ctex->texture = JRenderer::GetInstance()->LoadTexture(cardFile(filename,card->getSetName()).c_str()); string cardfile = cardFile(filename,card->getSetName());
if(cardfile != "")
ctex->texture = JRenderer::GetInstance()->LoadTexture(cardfile.c_str());
else
ctex->texture = NULL;
//Couldn't create texture, so fail. //Couldn't create texture, so fail.
if(!ctex->texture){ if(!ctex->texture){
@@ -358,8 +362,10 @@ JQuad * WResourceManager::RetrieveCard(MTGCard * card, int type, int style){
tc = getCachedCard(card,type,true); tc = getCachedCard(card,type,true);
//Perform lock or unlock on entry. //Perform lock or unlock on entry.
if(style == RETRIEVE_LOCK) tc->lock(); if(tc != NULL){
else if(style == RETRIEVE_UNLOCK) tc->unlock(); if(style == RETRIEVE_LOCK) tc->lock();
else if(style == RETRIEVE_UNLOCK) tc->unlock();
}
//Texture exists! Get quad. //Texture exists! Get quad.
if(tc && tc->texture != NULL){ if(tc && tc->texture != NULL){
@@ -511,10 +517,11 @@ JTexture * WResourceManager::RetrieveTexture(string filename, int style){
} }
//Perform lock or unlock on entry. //Perform lock or unlock on entry.
if(style == RETRIEVE_LOCK || style == RETRIEVE_VRAM) tc->lock(); if(style != RETRIEVE_MANAGE && tc){
else if(style == RETRIEVE_UNLOCK) tc->unlock(); if(style == RETRIEVE_LOCK || style == RETRIEVE_VRAM) tc->lock();
//Make a new managed resource else if(style == RETRIEVE_UNLOCK) tc->unlock();
else if(style == RETRIEVE_MANAGE){ }
else{
//Remove cache hit from cache //Remove cache hit from cache
tc = textureCache[filename]; tc = textureCache[filename];
map<string,WCachedTexture*>::iterator it = textureCache.end(); map<string,WCachedTexture*>::iterator it = textureCache.end();
@@ -548,7 +555,7 @@ JSample * WResourceManager::RetrieveSample(string filename, int style){
return retval; return retval;
//Check cache. //Check cache.
WCachedSample * tc; WCachedSample * tc = NULL;
if(style != RETRIEVE_MANAGE){ if(style != RETRIEVE_MANAGE){
if(style == RETRIEVE_EXISTING) if(style == RETRIEVE_EXISTING)
@@ -558,10 +565,11 @@ JSample * WResourceManager::RetrieveSample(string filename, int style){
} }
//Perform lock or unlock on entry. //Perform lock or unlock on entry.
if(style == RETRIEVE_LOCK) tc->lock(); if(style != RETRIEVE_MANAGE && tc){
else if(style == RETRIEVE_UNLOCK) tc->unlock(); if(style == RETRIEVE_LOCK || style == RETRIEVE_VRAM) tc->lock();
//Make a new managed resource else if(style == RETRIEVE_UNLOCK) tc->unlock();
else if(style == RETRIEVE_MANAGE){ }
else{
//Remove cache hit from cache //Remove cache hit from cache
tc = sampleCache[filename]; tc = sampleCache[filename];
map<string,WCachedSample*>::iterator it; map<string,WCachedSample*>::iterator it;
@@ -602,7 +610,7 @@ string WResourceManager::graphicsFile(const string filename, const string specif
string theme = options[Options::ACTIVE_THEME].str; string theme = options[Options::ACTIVE_THEME].str;
std::transform(theme.begin(), theme.end(), theme.begin(), ::tolower); std::transform(theme.begin(), theme.end(), theme.begin(), ::tolower);
if(theme != "" || theme != "default"){ if(theme != "" && theme != "default"){
sprintf(buf,"themes/%s/%s",theme.c_str(),filename.c_str()); sprintf(buf,"themes/%s/%s",theme.c_str(),filename.c_str());
if(fileOK(buf,true)) if(fileOK(buf,true))
return buf; return buf;
@@ -656,7 +664,7 @@ string WResourceManager::cardFile(const string filename, const string setname, c
string theme = options[Options::ACTIVE_THEME].str; string theme = options[Options::ACTIVE_THEME].str;
std::transform(theme.begin(), theme.end(), theme.begin(), ::tolower); std::transform(theme.begin(), theme.end(), theme.begin(), ::tolower);
if(theme != "" || theme != "default"){ if(theme != "" && theme != "default"){
sprintf(buf,"themes/%s/%s/%s",theme.c_str(),sets,filename.c_str()); sprintf(buf,"themes/%s/%s/%s",theme.c_str(),sets,filename.c_str());
if(fileOK(buf,true)) if(fileOK(buf,true))
return buf; return buf;
@@ -681,13 +689,13 @@ string WResourceManager::cardFile(const string filename, const string setname, c
//Failure. Assume it's in a zip file? //Failure. Assume it's in a zip file?
char zipname[100]; char zipname[100];
sprintf(zipname, "Res/sets/%s/%s.zip", setname.c_str(),setname.c_str()); sprintf(zipname, "Res/sets/%s/%s.zip", setname.c_str(),setname.c_str());
if (fileExists(zipname)){ if (fileOK(zipname,false)){
fs->AttachZipFile(zipname); fs->AttachZipFile(zipname);
return filename; return filename;
} }
//Complete abject failure. Probably a crash... //Complete abject failure. Probably a crash...
return defdir; return "";
} }
string WResourceManager::musicFile(const string filename, const string specific){ string WResourceManager::musicFile(const string filename, const string specific){
@@ -704,7 +712,7 @@ string WResourceManager::musicFile(const string filename, const string specific)
string theme = options[Options::ACTIVE_THEME].str; string theme = options[Options::ACTIVE_THEME].str;
std::transform(theme.begin(), theme.end(), theme.begin(), ::tolower); std::transform(theme.begin(), theme.end(), theme.begin(), ::tolower);
if(theme != "" || theme != "default"){ if(theme != "" && theme != "default"){
sprintf(buf,"themes/%s/sound/%s",theme.c_str(),filename.c_str()); sprintf(buf,"themes/%s/sound/%s",theme.c_str(),filename.c_str());
if(fileOK(buf,true)) if(fileOK(buf,true))
return buf; return buf;
@@ -744,7 +752,7 @@ string WResourceManager::sfxFile(const string filename, const string specific){
string theme = options[Options::ACTIVE_THEME].str; string theme = options[Options::ACTIVE_THEME].str;
std::transform(theme.begin(), theme.end(), theme.begin(), ::tolower); std::transform(theme.begin(), theme.end(), theme.begin(), ::tolower);
if(theme != "" || theme != "default"){ if(theme != "" && theme != "default"){
sprintf(buf,"themes/%s/sound/sfx/%s",theme.c_str(),filename.c_str()); sprintf(buf,"themes/%s/sound/sfx/%s",theme.c_str(),filename.c_str());
if(fileOK(buf,true)) if(fileOK(buf,true))
return buf; return buf;
@@ -770,14 +778,18 @@ string WResourceManager::sfxFile(const string filename, const string specific){
} }
int WResourceManager::fileOK(string filename, bool relative){ int WResourceManager::fileOK(string filename, bool relative){
char fname[512];
if(relative){ if(relative){
char buf[512]; sprintf(fname,RESPATH"/%s",filename.c_str());
sprintf(buf,RESPATH"/%s",filename.c_str());
return fileExists(buf);
} }
return fileExists(filename.c_str()); std::ifstream fichier(fname);
if(fichier){
fichier.close();
return 1;
}
return 0;
} }
int WResourceManager::CreateTexture(const string &textureName) { int WResourceManager::CreateTexture(const string &textureName) {