Jeck - Quad locking restored, minor cache fiddling.

* Restored quad locking to textures, but ignore quad locks when Release(JTexture*) is explicitly called. (I just copied and modified the code from the template, rather than do anything elegant). 
* Some minor fiddling with cache error states.
This commit is contained in:
wagic.jeck
2009-10-27 07:00:16 +00:00
parent daf3c249b7
commit fea10bdf21
3 changed files with 35 additions and 2 deletions

View File

@@ -66,6 +66,7 @@ public:
void Refresh(); void Refresh();
unsigned long size(); unsigned long size();
bool isGood(); bool isGood();
bool isLocked(); //Is the resource locked?
bool Attempt(string filename, int submode, int & error); bool Attempt(string filename, int submode, int & error);
bool compare(JTexture * t) {return (t == texture);}; bool compare(JTexture * t) {return (t == texture);};
JTexture * Actual(); //Return this texture as is. Does not make a new one. JTexture * Actual(); //Return this texture as is. Does not make a new one.

View File

@@ -84,6 +84,18 @@ WCachedTexture::~WCachedTexture(){
JTexture * WCachedTexture::Actual(){ JTexture * WCachedTexture::Actual(){
return texture; return texture;
} }
bool WCachedTexture::isLocked(){
if(locks != WRES_UNLOCKED)
return true;
for(vector<WTrackedQuad*>::iterator it=trackedQuads.begin();it!=trackedQuads.end();it++){
if((*it)->isLocked())
return true;
}
return false;
}
bool WCachedTexture::ReleaseQuad(JQuad* quad){ bool WCachedTexture::ReleaseQuad(JQuad* quad){
if(quad == NULL) if(quad == NULL)
return false; return false;

View File

@@ -333,7 +333,25 @@ void WResourceManager::Release(JTexture * tex){
if(!tex) if(!tex)
return; return;
textureWCache.Release(tex); //Copied direct from WCache::Release(). This is quick and dirty.
map<int,WCachedTexture*>::iterator it;
for(it=textureWCache.cache.begin();it!=textureWCache.cache.end();it++){
if(it->second && it->second->compare(tex))
break;
}
if(it == textureWCache.cache.end())
return; //Not here, can't release.
if(it->second){
it->second->unlock(); //Release one lock.
if(it->second->locks != WRES_UNLOCKED) //Normally we'd call isLocked, but this way ignores quads.
return; //Locked
}
textureWCache.Delete(it->second);
textureWCache.cache.erase(it);
return; //Released!
} }
void WResourceManager::Unmiss(string filename){ void WResourceManager::Unmiss(string filename){
@@ -977,6 +995,7 @@ cacheItem * WCache<cacheItem, cacheActual>::Retrieve(int id, string filename, in
} }
//Something went wrong. //Something went wrong.
RemoveItem(tc); RemoveItem(tc);
mError = CACHE_ERROR_BAD;
} }
//Record managed failure. Cache failure is recorded in Get(). //Record managed failure. Cache failure is recorded in Get().
@@ -1030,7 +1049,8 @@ cacheItem * WCache<cacheItem, cacheActual>::Get(int id, string filename, int sty
it = cache.find(lookup); it = cache.find(lookup);
//Well, we've found something... //Well, we've found something...
if(it != cache.end()){ if(it != cache.end()){
mError = CACHE_ERROR_NONE; //We found an entry in cache, so not an error. if(!it->second)
mError = CACHE_ERROR_404;
return it->second; //A hit, or maybe a miss. return it->second; //A hit, or maybe a miss.
} }
} }