Jeck - Improved cache size tracking.
This commit is contained in:
@@ -128,7 +128,7 @@ private:
|
||||
int lastTime;
|
||||
//Statistics of record.
|
||||
int nb_textures;
|
||||
int totalsize;
|
||||
long totalsize;
|
||||
};
|
||||
|
||||
extern WResourceManager resources;
|
||||
|
||||
@@ -160,7 +160,7 @@ void WResourceManager::ClearUnlocked(){
|
||||
}
|
||||
|
||||
bool WResourceManager::cleanup(){
|
||||
int maxSize = options[Options::CACHESIZE].number * 100000;
|
||||
long maxSize = options[Options::CACHESIZE].number * 100000;
|
||||
if (!maxSize) maxSize = CACHE_SIZE_PIXELS;
|
||||
|
||||
while (textureCache.size() > MAX_CACHE_OBJECTS - 1 || totalsize > maxSize){
|
||||
@@ -250,6 +250,9 @@ WCachedTexture * WResourceManager::getCachedTexture(string filename, bool makene
|
||||
return NULL;
|
||||
}
|
||||
totalsize+=ctex->texture->mTexHeight *ctex->texture->mTexWidth;
|
||||
char buf[512];
|
||||
sprintf(buf,"Cache size: %ld\n",totalsize);
|
||||
OutputDebugString(buf);
|
||||
ctex->hit();
|
||||
textureCache[filename] = ctex;
|
||||
}
|
||||
@@ -287,6 +290,9 @@ WCachedTexture * WResourceManager:: getCachedCard(MTGCard * card, int type, bool
|
||||
return NULL;
|
||||
}
|
||||
totalsize+=ctex->texture->mTexHeight *ctex->texture->mTexWidth;
|
||||
char buf[512];
|
||||
sprintf(buf,"Cache size: %ld\n",totalsize);
|
||||
OutputDebugString(buf);
|
||||
ctex->hit();
|
||||
textureCache[filename] = ctex;
|
||||
}
|
||||
@@ -525,6 +531,8 @@ void WResourceManager::Release(JTexture * tex){
|
||||
if(it != textureCache.end()){
|
||||
it->second->unlock();
|
||||
if(!it->second->isLocked()){
|
||||
if(it->second->texture)
|
||||
totalsize-=it->second->texture->mTexHeight * it->second->texture->mTexWidth;
|
||||
SAFE_DELETE(it->second);
|
||||
textureCache.erase(it);
|
||||
}
|
||||
@@ -1044,11 +1052,18 @@ void WResourceManager::Refresh(){
|
||||
if(it->second->isLocked())
|
||||
it->second->texture = oldtex;
|
||||
else{
|
||||
if(oldtex)
|
||||
totalsize -= oldtex->mTexHeight * oldtex->mTexWidth;
|
||||
|
||||
SAFE_DELETE(oldtex);
|
||||
SAFE_DELETE(it->second);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else{
|
||||
//Alright, log the new size.
|
||||
totalsize += it->second->texture->mTexHeight * it->second->texture->mTexWidth;
|
||||
}
|
||||
|
||||
//Relink quads to new texture.
|
||||
for(q = it->second->trackedQuads.begin(); q != it->second->trackedQuads.end(); q++){
|
||||
|
||||
Reference in New Issue
Block a user