Jeck - More minor WResourceManager fixes.

* Locked resources are now guaranteed, though they currently share memory limits with the cache, so be certain to release them when you're done.
* RetrieveQuad now returns different quads for different resource names, regardless of if they share size and position.
This commit is contained in:
wagic.jeck
2009-09-03 22:41:25 +00:00
parent 0689b01536
commit 2a7d6819bb

View File

@@ -157,8 +157,14 @@ unsigned int WResourceManager::nowTime(){
} }
void WResourceManager::clearSamples(){ void WResourceManager::clearSamples(){
for(map<string,WCachedSample*>::iterator it = sampleCache.begin();it!=sampleCache.end();it++) map<string,WCachedSample*>::iterator next;
SAFE_DELETE(it->second); for(map<string,WCachedSample*>::iterator it = sampleCache.begin();it!=sampleCache.end();it=next){
next = it;
next++;
if(it->second && !it->second->isLocked())
SAFE_DELETE(it->second);
}
sampleCache.clear(); sampleCache.clear();
} }
@@ -298,8 +304,7 @@ void WResourceManager::FlattenTimes(){
bool WResourceManager::RemoveOldestTexture(){ bool WResourceManager::RemoveOldestTexture(){
map<string,WCachedTexture*>::iterator oldest; map<string,WCachedTexture*>::iterator oldest;
for(map<string,WCachedTexture*>::iterator it = textureCache.begin();it!=textureCache.end();it++){ for(map<string,WCachedTexture*>::iterator it = textureCache.begin();it!=textureCache.end();it++){
if(it->second && (it->second->lastTime < oldest->second->lastTime if(it->second && !it->second->isLocked() && it->second->lastTime < oldest->second->lastTime)
|| (oldest->second->isLocked() && !it->second->isLocked())))
oldest = it; oldest = it;
} }
@@ -319,7 +324,7 @@ bool WResourceManager::RemoveOldestSample(){
saved = sampleCache.begin(); saved = sampleCache.begin();
for(it = sampleCache.begin();it!=sampleCache.end();it++){ for(it = sampleCache.begin();it!=sampleCache.end();it++){
if(it->second->lastTime < saved->second->lastTime) if(it->second && !it->second->isLocked() && it->second->lastTime < saved->second->lastTime)
saved = it; saved = it;
} }
@@ -404,11 +409,11 @@ JQuad * WResourceManager::RetrieveCard(MTGCard * card, int type, int style){
} }
JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY, float width, float height, string resname, int style){ JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY, float width, float height, string resname, int style){
//Check our resources.
if(resname == "") if(resname == "")
resname = filename; resname = filename;
//No exactly existant quad //Check our managed resources.
JQuad * retval = GetQuad(resname); JQuad * retval = GetQuad(resname);
if(retval != NULL || style == RETRIEVE_RESOURCE) if(retval != NULL || style == RETRIEVE_RESOURCE)
return retval; return retval;
@@ -416,18 +421,7 @@ JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY,
//We have a managed resource named this! //We have a managed resource named this!
JTexture * jtex = GetTexture(filename); JTexture * jtex = GetTexture(filename);
if(jtex){ if(jtex){
//Check for an existing quad with this name and stats //Make this quad, overwriting any similarly resname'd quads.
JQuad * jq = GetQuad(resname);
if(jq && jq->mHeight == height && jq->mWidth == width && jq->mX == offX && jq->mY == offY)
return jq;
//Find a quad with these stats, regardless of name
for(vector<JQuad*>::iterator it=mQuadList.begin();it!=mQuadList.end();it++){
if((*it)->mHeight == height && (*it)->mWidth == width && (*it)->mX == offX && (*it)->mY == offY)
return (*it);
}
//Overwrite the existing quad, if any.
CreateQuad(resname,filename,offX,offY,width,height); CreateQuad(resname,filename,offX,offY,width,height);
return GetQuad(resname); return GetQuad(resname);
} }