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 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
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -971,53 +971,18 @@ 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++)
|
if(!item->Attempt(filename,submode,mError) || !item->isGood()) {
|
||||||
{
|
//No such file. Fail
|
||||||
//We use try/catch so any memory alloc'd in Attempt isn't lost.
|
if(mError == CACHE_ERROR_404){
|
||||||
try{
|
SAFE_DELETE(item);
|
||||||
//If we don't get a good item, remove oldest cache and continue trying.
|
return NULL;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(std::bad_alloc){
|
//Probably not enough memory: cleanup and try again
|
||||||
RemoveOldest();
|
Cleanup();
|
||||||
}
|
if(!item->Attempt(filename,submode,mError) || !item->isGood()) {
|
||||||
|
SAFE_DELETE(item);
|
||||||
//Succeeded
|
mError = CACHE_ERROR_BAD;
|
||||||
if(item->isGood())
|
return NULL;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user