Jeck - Improved cache size tracking.

This commit is contained in:
wagic.jeck
2009-09-09 00:15:33 +00:00
parent a03c35e440
commit e3d86f0824
2 changed files with 1268 additions and 1253 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ private:
int lastTime; int lastTime;
//Statistics of record. //Statistics of record.
int nb_textures; int nb_textures;
int totalsize; long totalsize;
}; };
extern WResourceManager resources; extern WResourceManager resources;
+16 -1
View File
@@ -160,7 +160,7 @@ void WResourceManager::ClearUnlocked(){
} }
bool WResourceManager::cleanup(){ bool WResourceManager::cleanup(){
int maxSize = options[Options::CACHESIZE].number * 100000; long maxSize = options[Options::CACHESIZE].number * 100000;
if (!maxSize) maxSize = CACHE_SIZE_PIXELS; if (!maxSize) maxSize = CACHE_SIZE_PIXELS;
while (textureCache.size() > MAX_CACHE_OBJECTS - 1 || totalsize > maxSize){ while (textureCache.size() > MAX_CACHE_OBJECTS - 1 || totalsize > maxSize){
@@ -250,6 +250,9 @@ WCachedTexture * WResourceManager::getCachedTexture(string filename, bool makene
return NULL; return NULL;
} }
totalsize+=ctex->texture->mTexHeight *ctex->texture->mTexWidth; totalsize+=ctex->texture->mTexHeight *ctex->texture->mTexWidth;
char buf[512];
sprintf(buf,"Cache size: %ld\n",totalsize);
OutputDebugString(buf);
ctex->hit(); ctex->hit();
textureCache[filename] = ctex; textureCache[filename] = ctex;
} }
@@ -287,6 +290,9 @@ WCachedTexture * WResourceManager:: getCachedCard(MTGCard * card, int type, bool
return NULL; return NULL;
} }
totalsize+=ctex->texture->mTexHeight *ctex->texture->mTexWidth; totalsize+=ctex->texture->mTexHeight *ctex->texture->mTexWidth;
char buf[512];
sprintf(buf,"Cache size: %ld\n",totalsize);
OutputDebugString(buf);
ctex->hit(); ctex->hit();
textureCache[filename] = ctex; textureCache[filename] = ctex;
} }
@@ -525,6 +531,8 @@ void WResourceManager::Release(JTexture * tex){
if(it != textureCache.end()){ if(it != textureCache.end()){
it->second->unlock(); it->second->unlock();
if(!it->second->isLocked()){ if(!it->second->isLocked()){
if(it->second->texture)
totalsize-=it->second->texture->mTexHeight * it->second->texture->mTexWidth;
SAFE_DELETE(it->second); SAFE_DELETE(it->second);
textureCache.erase(it); textureCache.erase(it);
} }
@@ -1044,11 +1052,18 @@ void WResourceManager::Refresh(){
if(it->second->isLocked()) if(it->second->isLocked())
it->second->texture = oldtex; it->second->texture = oldtex;
else{ else{
if(oldtex)
totalsize -= oldtex->mTexHeight * oldtex->mTexWidth;
SAFE_DELETE(oldtex); SAFE_DELETE(oldtex);
SAFE_DELETE(it->second); SAFE_DELETE(it->second);
} }
continue; continue;
} }
else{
//Alright, log the new size.
totalsize += it->second->texture->mTexHeight * it->second->texture->mTexWidth;
}
//Relink quads to new texture. //Relink quads to new texture.
for(q = it->second->trackedQuads.begin(); q != it->second->trackedQuads.end(); q++){ for(q = it->second->trackedQuads.begin(); q != it->second->trackedQuads.end(); q++){