Jeck - It wasn't emptying the cache properly, so this is a step in the right direction. I'll keep looking for more issues, though.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "MTGCard.h"
|
#include "MTGCard.h"
|
||||||
|
|
||||||
#define CACHE_SIZE_PIXELS 2000000
|
#define CACHE_SIZE_PIXELS 2000000
|
||||||
|
#define MAX_CACHE_OBJECTS 100
|
||||||
|
|
||||||
class WCachedResource{
|
class WCachedResource{
|
||||||
public:
|
public:
|
||||||
@@ -106,6 +107,7 @@ private:
|
|||||||
bool RemoveOldestTexture();
|
bool RemoveOldestTexture();
|
||||||
bool RemoveOldestSample();
|
bool RemoveOldestSample();
|
||||||
bool cleanup();
|
bool cleanup();
|
||||||
|
void clearSamples();
|
||||||
|
|
||||||
WCachedTexture * getCachedTexture(string filename, bool makenew = true, int mode = 0, int format = TEXTURE_FORMAT);
|
WCachedTexture * getCachedTexture(string filename, bool makenew = true, int mode = 0, int format = TEXTURE_FORMAT);
|
||||||
WCachedTexture * getCachedCard(MTGCard * card, int type = CACHE_CARD, bool makenew = true);
|
WCachedTexture * getCachedCard(MTGCard * card, int type = CACHE_CARD, bool makenew = true);
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ JQuad * CardGui::alternateThumbQuad(MTGCard * card){
|
|||||||
}
|
}
|
||||||
if(q && q->mTex)
|
if(q && q->mTex)
|
||||||
q->SetHotSpot(q->mTex->mWidth/2,q->mTex->mHeight/2);
|
q->SetHotSpot(q->mTex->mWidth/2,q->mTex->mHeight/2);
|
||||||
|
else q = q;
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +128,7 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){
|
|||||||
float scale = pos.actZ * 250 / q->mHeight;
|
float scale = pos.actZ * 250 / q->mHeight;
|
||||||
q->SetColor(ARGB((int)pos.actA,255,255,255));
|
q->SetColor(ARGB((int)pos.actA,255,255,255));
|
||||||
renderer->RenderQuad(q, pos.actX, pos.actY, pos.actT, scale, scale);
|
renderer->RenderQuad(q, pos.actX, pos.actY, pos.actT, scale, scale);
|
||||||
}
|
}else q = q;
|
||||||
// Write the title
|
// Write the title
|
||||||
JLBFont * font = resources.GetJLBFont("magic");
|
JLBFont * font = resources.GetJLBFont("magic");
|
||||||
float backup_scale = font->GetScale();
|
float backup_scale = font->GetScale();
|
||||||
|
|||||||
@@ -142,8 +142,8 @@ void GameStateMenu::Start(){
|
|||||||
|
|
||||||
bgTexture = resources.RetrieveTexture("menutitle.png", RETRIEVE_VRAM);
|
bgTexture = resources.RetrieveTexture("menutitle.png", RETRIEVE_VRAM);
|
||||||
movingWTexture = resources.RetrieveTexture("movingW.png", RETRIEVE_VRAM);
|
movingWTexture = resources.RetrieveTexture("movingW.png", RETRIEVE_VRAM);
|
||||||
mBg = resources.RetrieveQuad("menutitle.png"); // Create background quad for rendering.
|
mBg = resources.RetrieveQuad("menutitle.png", 0, 0, 256, 166); // Create background quad for rendering.
|
||||||
mMovingW = resources.RetrieveQuad("movingW.png");
|
mMovingW = resources.RetrieveQuad("movingW.png", 2, 2, 84, 62);
|
||||||
|
|
||||||
mBg->SetHotSpot(105,50);
|
mBg->SetHotSpot(105,50);
|
||||||
mMovingW->SetHotSpot(72,16);
|
mMovingW->SetHotSpot(72,16);
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ JTexture * WCachedTexture::GetTexture(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool WCachedTexture::ReleaseQuad(JQuad* quad){
|
bool WCachedTexture::ReleaseQuad(JQuad* quad){
|
||||||
//SAFE_DELETE(texture); WTF?
|
|
||||||
for(vector<JQuad*>::iterator i = trackedQuads.begin();i!=trackedQuads.end();i++){
|
for(vector<JQuad*>::iterator i = trackedQuads.begin();i!=trackedQuads.end();i++){
|
||||||
if((*i) == quad){
|
if((*i) == quad){
|
||||||
SAFE_DELETE(quad);
|
SAFE_DELETE(quad);
|
||||||
@@ -119,7 +118,8 @@ JSample * WCachedSample::GetSample(){
|
|||||||
bool WResourceManager::cleanup(){
|
bool WResourceManager::cleanup(){
|
||||||
int maxSize = options[Options::CACHESIZE].number * 100000;
|
int maxSize = options[Options::CACHESIZE].number * 100000;
|
||||||
if (!maxSize) maxSize = CACHE_SIZE_PIXELS;
|
if (!maxSize) maxSize = CACHE_SIZE_PIXELS;
|
||||||
while (totalsize > maxSize){
|
|
||||||
|
while (textureCache.size() > MAX_CACHE_OBJECTS - 1 || totalsize > maxSize){
|
||||||
int result = RemoveOldestTexture();
|
int result = RemoveOldestTexture();
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
}
|
}
|
||||||
@@ -134,23 +134,33 @@ unsigned int WResourceManager::nowTime(){
|
|||||||
return ++lastTime;
|
return ++lastTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WResourceManager::clearSamples(){
|
||||||
|
for(map<string,WCachedSample*>::iterator it = sampleCache.begin();it!=sampleCache.end();it++)
|
||||||
|
SAFE_DELETE(it->second);
|
||||||
|
sampleCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
WCachedSample * WResourceManager::getCachedSample(string filename, bool makenew){
|
WCachedSample * WResourceManager::getCachedSample(string filename, bool makenew){
|
||||||
WCachedSample * csample = sampleCache[filename];
|
WCachedSample * csample = sampleCache[filename];
|
||||||
|
|
||||||
//Failed to cache it!
|
//Failed to cache it!
|
||||||
if(!csample && makenew){
|
if(!csample && makenew){
|
||||||
csample = NEW WCachedSample();
|
|
||||||
|
|
||||||
//Space in cache, make new sample
|
//Space in cache, make new sample
|
||||||
if(cleanup()){
|
if(cleanup()){
|
||||||
|
csample = NEW WCachedSample();
|
||||||
csample->sample = ssLoadSample(filename.c_str());
|
csample->sample = ssLoadSample(filename.c_str());
|
||||||
|
//Clean the cache
|
||||||
|
if(!csample->sample && fileExists(sfxFile(filename).c_str())){
|
||||||
|
clearSamples();
|
||||||
|
csample->sample = ssLoadSample(filename.c_str());
|
||||||
|
}
|
||||||
//Failed.
|
//Failed.
|
||||||
if(!csample->sample){
|
if(!csample->sample){
|
||||||
for(map<string,WCachedSample*>::iterator it=sampleCache.begin();it!=sampleCache.end();it++)
|
for(map<string,WCachedSample*>::iterator it=sampleCache.begin();it!=sampleCache.end();it++)
|
||||||
if(it->second == NULL){
|
if(it->second == NULL){
|
||||||
sampleCache.erase(it);
|
sampleCache.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SAFE_DELETE(csample);
|
SAFE_DELETE(csample);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -168,22 +178,21 @@ WCachedTexture * WResourceManager::getCachedTexture(string filename, bool makene
|
|||||||
WCachedTexture * ctex = textureCache[filename];
|
WCachedTexture * ctex = textureCache[filename];
|
||||||
//Failed to cache it!
|
//Failed to cache it!
|
||||||
if(!ctex && makenew){
|
if(!ctex && makenew){
|
||||||
ctex = NEW WCachedTexture();
|
|
||||||
//Space in cache, make new texture
|
//Space in cache, make new texture
|
||||||
if(cleanup()){
|
if(cleanup()){
|
||||||
ctex->texture = JRenderer::GetInstance()->LoadTexture(graphicsFile(filename).c_str(),mode,format);
|
ctex = NEW WCachedTexture();
|
||||||
|
ctex->texture = JRenderer::GetInstance()->LoadTexture(graphicsFile(filename).c_str(),mode,format);
|
||||||
//Couldn't create texture, so fail.
|
|
||||||
if(!ctex->texture){
|
if(!ctex->texture){
|
||||||
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 == NULL){
|
if(it->second == NULL){
|
||||||
textureCache.erase(it);
|
textureCache.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
SAFE_DELETE(ctex);
|
||||||
SAFE_DELETE(ctex);
|
return NULL;
|
||||||
return NULL;
|
}
|
||||||
}
|
totalsize+=ctex->texture->mTexHeight *ctex->texture->mTexWidth;
|
||||||
ctex->hit();
|
ctex->hit();
|
||||||
textureCache[filename] = ctex;
|
textureCache[filename] = ctex;
|
||||||
}
|
}
|
||||||
@@ -202,22 +211,22 @@ WCachedTexture * WResourceManager:: getCachedCard(MTGCard * card, int type, bool
|
|||||||
WCachedTexture * ctex = textureCache[filename];
|
WCachedTexture * ctex = textureCache[filename];
|
||||||
//Failed to cache it!
|
//Failed to cache it!
|
||||||
if(!ctex && makenew){
|
if(!ctex && makenew){
|
||||||
ctex = NEW WCachedTexture();
|
|
||||||
//Space in cache, make new texture
|
//Space in cache, make new texture
|
||||||
if(cleanup()){
|
if(cleanup()){
|
||||||
|
ctex = NEW WCachedTexture();
|
||||||
ctex->texture = JRenderer::GetInstance()->LoadTexture(cardFile(filename,card->getSetName()).c_str());
|
ctex->texture = JRenderer::GetInstance()->LoadTexture(cardFile(filename,card->getSetName()).c_str());
|
||||||
|
|
||||||
//Couldn't create texture, so fail.
|
//Couldn't create texture, so fail.
|
||||||
if(!ctex->texture){
|
if(!ctex->texture){
|
||||||
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 == NULL){
|
if(it->second == NULL){
|
||||||
textureCache.erase(it);
|
textureCache.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SAFE_DELETE(ctex);
|
SAFE_DELETE(ctex);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
totalsize+=ctex->texture->mTexHeight *ctex->texture->mTexWidth;
|
||||||
ctex->hit();
|
ctex->hit();
|
||||||
textureCache[filename] = ctex;
|
textureCache[filename] = ctex;
|
||||||
}
|
}
|
||||||
@@ -264,6 +273,8 @@ bool WResourceManager::RemoveOldestTexture(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(oldest != textureCache.end()){
|
if(oldest != textureCache.end()){
|
||||||
|
if(oldest->second && oldest->second->texture)
|
||||||
|
totalsize-=oldest->second->texture->mTexHeight * oldest->second->texture->mTexWidth;
|
||||||
SAFE_DELETE(oldest->second)
|
SAFE_DELETE(oldest->second)
|
||||||
textureCache.erase(oldest);
|
textureCache.erase(oldest);
|
||||||
return true;
|
return true;
|
||||||
@@ -423,6 +434,7 @@ JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY,
|
|||||||
return tc->GetQuad(offX,offY,width,height);
|
return tc->GetQuad(offX,offY,width,height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Texture doesn't exist, so no quad.
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
void WResourceManager::Release(JTexture * tex){
|
void WResourceManager::Release(JTexture * tex){
|
||||||
|
|||||||
Reference in New Issue
Block a user