Erwan
- Fix issue 97. Please review. How about performance ?
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#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 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.
|
||||
#define MAX_CACHE_OBJECTS 300
|
||||
#define MAX_CACHE_ATTEMPTS 10
|
||||
|
||||
@@ -30,7 +30,7 @@ void GameStateShop::Start()
|
||||
|
||||
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.
|
||||
altThumb[0] = resources.RetrieveTexture("artifact_thumb.jpg", RETRIEVE_LOCK);
|
||||
@@ -125,7 +125,6 @@ void GameStateShop::load(){
|
||||
void GameStateShop::End()
|
||||
{
|
||||
JRenderer::GetInstance()->EnableVSync(false);
|
||||
resources.Release(mBg);
|
||||
resources.Release(bgTexture);
|
||||
|
||||
//Release alternate thumbnails.
|
||||
|
||||
@@ -287,6 +287,7 @@ bool WCachedTexture::Attempt(string filename, int submode, int & error){
|
||||
|
||||
//Failure.
|
||||
if(!texture){
|
||||
error = CACHE_ERROR_BAD;
|
||||
if(!fileExists(realname.c_str()))
|
||||
error = CACHE_ERROR_404;
|
||||
return false;
|
||||
|
||||
@@ -971,53 +971,18 @@ cacheItem* WCache<cacheItem, cacheActual>::AttemptNew(string filename, int submo
|
||||
|
||||
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()) {
|
||||
//No such file. Fail on first try.
|
||||
if(mError == CACHE_ERROR_404){
|
||||
SAFE_DELETE(item);
|
||||
return NULL;
|
||||
}
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
if(!item->Attempt(filename,submode,mError) || !item->isGood()) {
|
||||
//No such file. Fail
|
||||
if(mError == CACHE_ERROR_404){
|
||||
SAFE_DELETE(item);
|
||||
return NULL;
|
||||
}
|
||||
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);
|
||||
mError = CACHE_ERROR_BAD;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
//Probably not enough memory: cleanup and try again
|
||||
Cleanup();
|
||||
if(!item->Attempt(filename,submode,mError) || !item->isGood()) {
|
||||
SAFE_DELETE(item);
|
||||
mError = CACHE_ERROR_BAD;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1214,7 +1179,12 @@ bool WCache<cacheItem, cacheActual>::Cleanup(){
|
||||
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())
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user