- renamed WResourceManager::autoResize() to ResetCacheLimits(), since the function doesn't actually resize anything. It's merely setting clamping limits on when we should purge the cache.

- fixed the debug framerate calculation / drawing code (consolidated duplicated functions & variables mDelta vs a win-only mDeltaTime, no reason to have two), repositioned it to draw on the bottom left (it was colliding with other debug text for the cache info).
 - for debug testing purposes, added a #define override to force the image cache to work with less memory (I've picked 8 megs, which is what the psp seems to use - the normal default on win/linux is 20 megs).
This commit is contained in:
wrenczes@gmail.com
2010-11-09 19:01:38 +00:00
parent c1f8e95a11
commit 3eeb8a6465
6 changed files with 39 additions and 44 deletions

View File

@@ -84,7 +84,6 @@ class JGE
JApp *mApp; JApp *mApp;
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
float mDeltaTime;
JMusic *mCurrentMusic; JMusic *mCurrentMusic;
#else #else
public: public:
@@ -93,7 +92,7 @@ class JGE
#endif #endif
bool mDone; bool mDone;
float mDelta; float mDeltaTime;
bool mDebug; bool mDebug;
bool mPaused; bool mPaused;
char mDebuggingMsg[256]; char mDebuggingMsg[256];
@@ -155,6 +154,9 @@ class JGE
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
float GetDelta(); float GetDelta();
// override the current delta time.
void SetDelta(float delta);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Return frame rate. /// Return frame rate.
/// ///
@@ -320,10 +322,6 @@ class JGE
void Assert(const char *filename, long lineNumber); void Assert(const char *filename, long lineNumber);
#if defined (WIN32) || defined (LINUX)
void SetDelta(float delta);
#endif
protected: protected:
JGE(); JGE();
~JGE(); ~JGE();

View File

@@ -322,26 +322,9 @@ void JGE::Init()
LeftClickedProcessed(); LeftClickedProcessed();
} }
void JGE::SetDelta(float delta)
{
mDeltaTime = delta;
}
float JGE::GetDelta()
{
return mDeltaTime;
}
float JGE::GetFPS()
{
return 0.0f;
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
#else ///// PSP specific code #else ///// PSP specific code
void JGE::Init() void JGE::Init()
{ {
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
@@ -367,17 +350,6 @@ void JGE::Init()
mCriticalAssert = false; mCriticalAssert = false;
} }
float JGE::GetDelta()
{
return mDelta;
}
float JGE::GetFPS()
{
return 1.0f / mDelta;
}
u8 JGE::GetAnalogX() u8 JGE::GetAnalogX()
{ {
return JGEGetAnalogX(); return JGEGetAnalogX();
@@ -423,7 +395,7 @@ void JGE::Run()
{ {
sceRtcGetCurrentTick(&curr); sceRtcGetCurrentTick(&curr);
float dt = (curr - lastTime) / (float)gTickFrequency; float dt = (curr - lastTime) / (float)gTickFrequency;
mDelta = dt; mDeltaTime = dt;
sceCtrlPeekBufferPositive(&gCtrlPad, 1); sceCtrlPeekBufferPositive(&gCtrlPad, 1);
for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i) for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i)
{ {
@@ -468,6 +440,23 @@ int JGE::GetTime()
} }
void JGE::SetDelta(float delta)
{
mDeltaTime = delta;
}
float JGE::GetDelta()
{
return mDeltaTime;
}
float JGE::GetFPS()
{
return mDeltaTime > 0 ? 1.0f / mDeltaTime : 0;
}
JGE* JGE::GetInstance() JGE* JGE::GetInstance()
{ {
if (mInstance == NULL) mInstance = new JGE(); if (mInstance == NULL) mInstance = new JGE();

View File

@@ -188,7 +188,8 @@ public:
//Wrapped from JSoundSystem. TODO: Privatize. //Wrapped from JSoundSystem. TODO: Privatize.
JMusic * ssLoadMusic(const char *fileName); JMusic * ssLoadMusic(const char *fileName);
void autoResize(); //Recreates the cache size. //Resets the cache limits on when it starts to purge data.
void ResetCacheLimits();
void DebugRender(); void DebugRender();

View File

@@ -235,12 +235,12 @@ void GameApp::Destroy()
{ {
LOG("==Destroying GameApp=="); LOG("==Destroying GameApp==");
for (int i=GAME_STATE_MENU;i<=GAME_STATE_MAX-1;i++) for (int i=GAME_STATE_MENU;i<=GAME_STATE_MAX-1;i++)
{ {
if (mGameStates[i]){ if (mGameStates[i]){
mGameStates[i]->Destroy(); mGameStates[i]->Destroy();
SAFE_DELETE(mGameStates[i]); SAFE_DELETE(mGameStates[i]);
}
} }
}
if (collection){ if (collection){
collection->destroyAllCards(); collection->destroyAllCards();
@@ -361,7 +361,7 @@ void GameApp::Render()
sprintf(buf, "avg:%.02f - %.02f fps",totalFPS/nbUpdates, fps); sprintf(buf, "avg:%.02f - %.02f fps",totalFPS/nbUpdates, fps);
if (mFont) { if (mFont) {
mFont->SetColor(ARGB(255,255,255,255)); mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(buf,1,10); mFont->DrawString(buf, 10, SCREEN_HEIGHT-15);
} }
#endif #endif

View File

@@ -445,7 +445,7 @@ void GameStateMenu::Update(float dt)
genNbCardsStr(); genNbCardsStr();
resetDirectory(); resetDirectory();
//All major things have been loaded, resize the cache to use it as efficiently as possible //All major things have been loaded, resize the cache to use it as efficiently as possible
resources.autoResize(); resources.ResetCacheLimits();
} }
break; break;
case MENU_STATE_MAJOR_FIRST_TIME : case MENU_STATE_MAJOR_FIRST_TIME :

View File

@@ -13,6 +13,9 @@
#endif #endif
#include "WFont.h" #include "WFont.h"
//#define FORCE_LOW_CACHE_MEMORY
const unsigned int kConstrainedCacheLimit = 8 * 1024 * 1024;
extern bool neofont; extern bool neofont;
int idCounter = OTHERS_OFFSET; int idCounter = OTHERS_OFFSET;
WResourceManager resources; WResourceManager resources;
@@ -933,9 +936,13 @@ void WResourceManager::RemoveWFonts() {
mWFontMap.clear(); mWFontMap.clear();
} }
void WResourceManager::autoResize(){ void WResourceManager::ResetCacheLimits(){
#if defined WIN32 || defined LINUX #if defined WIN32 || defined LINUX
#ifdef FORCE_LOW_CACHE_MEMORY
textureWCache.Resize(kConstrainedCacheLimit, MAX_CACHE_OBJECTS);
#else
textureWCache.Resize(HUGE_CACHE_LIMIT,MAX_CACHE_OBJECTS); textureWCache.Resize(HUGE_CACHE_LIMIT,MAX_CACHE_OBJECTS);
#endif
#else #else
unsigned int ram = ramAvailable(); unsigned int ram = ramAvailable();
unsigned int myNewSize = ram - OPERATIONAL_SIZE + textureWCache.totalSize; unsigned int myNewSize = ram - OPERATIONAL_SIZE + textureWCache.totalSize;