- Fix issue 97. Please review. How about performance ?
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-10-15 13:58:35 +00:00
parent f95b46f256
commit 97a0732682
4 changed files with 20 additions and 50 deletions
+1 -1
View File
@@ -12,7 +12,7 @@
#define PSI_CACHE_SIZE 500000 // Size in bytes of the cahed particles #define PSI_CACHE_SIZE 500000 // Size in bytes of the cahed particles
#define TEXTURES_CACHE_MINSIZE 2000000 // Minimum size of the cache on the PSP. The program should complain if the cache ever gets smaller than this #define TEXTURES_CACHE_MINSIZE 2000000 // Minimum size of the cache on the PSP. The program should complain if the cache ever gets smaller than this
#define OPERATIONAL_SIZE 5000000 // Size required by Wagic for operational stuff. 3MB is not enough. The cache will usually try to take (Total Ram - Operational size) #define OPERATIONAL_SIZE 5000000 // Size required by Wagic for operational stuff. 3MB is not enough. The cache will usually try to take (Total Ram - Operational size)
#define MIN_LINEAR_RAM 1000000
//Hard Limits. //Hard Limits.
#define MAX_CACHE_OBJECTS 300 #define MAX_CACHE_OBJECTS 300
#define MAX_CACHE_ATTEMPTS 10 #define MAX_CACHE_ATTEMPTS 10
+1 -2
View File
@@ -30,7 +30,7 @@ void GameStateShop::Start()
mStage = STAGE_SHOP_SHOP; mStage = STAGE_SHOP_SHOP;
bgTexture = resources.RetrieveTexture("shop.jpg"); bgTexture = resources.RetrieveTexture("shop.jpg",RETRIEVE_LOCK);
//alternateRender doesn't lock, so lock our thumbnails for hgeDistort. //alternateRender doesn't lock, so lock our thumbnails for hgeDistort.
altThumb[0] = resources.RetrieveTexture("artifact_thumb.jpg", RETRIEVE_LOCK); altThumb[0] = resources.RetrieveTexture("artifact_thumb.jpg", RETRIEVE_LOCK);
@@ -125,7 +125,6 @@ void GameStateShop::load(){
void GameStateShop::End() void GameStateShop::End()
{ {
JRenderer::GetInstance()->EnableVSync(false); JRenderer::GetInstance()->EnableVSync(false);
resources.Release(mBg);
resources.Release(bgTexture); resources.Release(bgTexture);
//Release alternate thumbnails. //Release alternate thumbnails.
+1
View File
@@ -287,6 +287,7 @@ bool WCachedTexture::Attempt(string filename, int submode, int & error){
//Failure. //Failure.
if(!texture){ if(!texture){
error = CACHE_ERROR_BAD;
if(!fileExists(realname.c_str())) if(!fileExists(realname.c_str()))
error = CACHE_ERROR_404; error = CACHE_ERROR_404;
return false; return false;
+10 -40
View File
@@ -971,55 +971,20 @@ cacheItem* WCache<cacheItem, cacheActual>::AttemptNew(string filename, int submo
mError = CACHE_ERROR_NONE; mError = CACHE_ERROR_NONE;
for(int attempts = 0; attempts < MAX_CACHE_ATTEMPTS;attempts++)
{
//We use try/catch so any memory alloc'd in Attempt isn't lost.
try{
//If we don't get a good item, remove oldest cache and continue trying.
if(!item->Attempt(filename,submode,mError) || !item->isGood()) { if(!item->Attempt(filename,submode,mError) || !item->isGood()) {
//No such file. Fail on first try. //No such file. Fail
if(mError == CACHE_ERROR_404){ if(mError == CACHE_ERROR_404){
SAFE_DELETE(item); SAFE_DELETE(item);
return NULL; return NULL;
} }
throw std::bad_alloc(); //Probably not enough memory: cleanup and try again
} Cleanup();
} if(!item->Attempt(filename,submode,mError) || !item->isGood()) {
catch(std::bad_alloc){
RemoveOldest();
}
//Succeeded
if(item->isGood())
break;
}
//Still no result, so clear local cache, then try again.
if(!item->isGood()){
ClearUnlocked();
try{
if(!item->Attempt(filename,submode,mError) || !item->isGood())
throw std::bad_alloc();
}
catch(std::bad_alloc){
//Failed, so clear every cache we've got in prep for the next try.
resources.ClearUnlocked();
}
if(!item->isGood()){
try{
if(!item->Attempt(filename,submode,mError) || !item->isGood())
throw std::bad_alloc();
}
catch(std::bad_alloc){
//Complete failure. Trash this object and return NULL.
if(!item->isGood()){
SAFE_DELETE(item); SAFE_DELETE(item);
mError = CACHE_ERROR_BAD; mError = CACHE_ERROR_BAD;
return NULL; return NULL;
} }
} }
}
}
//Success! Enforce cache limits, then return. //Success! Enforce cache limits, then return.
mError = CACHE_ERROR_NONE; mError = CACHE_ERROR_NONE;
@@ -1214,7 +1179,12 @@ bool WCache<cacheItem, cacheActual>::Cleanup(){
RemoveMiss(); RemoveMiss();
} }
while (cacheItems > MAX_CACHE_OBJECTS || cacheItems > maxCached || cacheSize > maxCacheSize ){ while (cacheItems > MAX_CACHE_OBJECTS || cacheItems > maxCached || cacheSize > maxCacheSize
#if defined WIN32 || defined LINUX
#else
|| ramAvailableLineareMax() < MIN_LINEAR_RAM
#endif
){
if (!RemoveOldest()) if (!RemoveOldest())
return false; return false;
} }