From 33e79e234e377437af264ccc9a341352269b720a Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Sun, 19 Apr 2009 06:02:29 +0000 Subject: [PATCH] Erwan - Cache size is now an option --- JGE/src/JMP3.cpp | 18 ---------- projects/mtg/include/GameApp.h | 1 + projects/mtg/include/GameOptions.h | 1 + projects/mtg/include/GameStateMenu.h | 1 + projects/mtg/include/MTGGuiPlay.h | 1 - projects/mtg/include/ManaCost.h | 1 + projects/mtg/include/TexturesCache.h | 3 +- projects/mtg/src/AIPlayer.cpp | 6 ++-- projects/mtg/src/DeckStats.cpp | 11 ++++-- projects/mtg/src/GameApp.cpp | 17 ++++++++-- projects/mtg/src/GameStateMenu.cpp | 8 ++++- projects/mtg/src/GameStateOptions.cpp | 1 + projects/mtg/src/MTGGuiPlay.cpp | 49 +++++++++++++++------------ projects/mtg/src/ManaCost.cpp | 5 +++ projects/mtg/src/TexturesCache.cpp | 5 ++- 15 files changed, 76 insertions(+), 52 deletions(-) diff --git a/JGE/src/JMP3.cpp b/JGE/src/JMP3.cpp index 87730043b..4a9c17533 100644 --- a/JGE/src/JMP3.cpp +++ b/JGE/src/JMP3.cpp @@ -66,25 +66,20 @@ bool JMP3::fillBuffers() { } bool JMP3::load(const std::string& filename, int inBufferSize, int outBufferSize) { - printf("load\n"); m_inBufferSize = inBufferSize; - printf("1\n"); //m_inBuffer = new char[m_inBufferSize]; //if (!m_inBuffer) // return false; m_outBufferSize = outBufferSize; - printf("2\n"); //m_outBuffer = new short[outBufferSize]; //if (!m_outBuffer) // return false; - printf("3:%s\n",filename.c_str()); m_fileHandle = sceIoOpen(filename.c_str(), PSP_O_RDONLY, 0777); if (m_fileHandle < 0) return false; - printf("4\n"); int ret = sceMp3InitResource(); if (ret < 0) return false; @@ -108,53 +103,40 @@ bool JMP3::load(const std::string& filename, int inBufferSize, int outBufferSize initArgs.pcmBufSize = m_outBufferSize; initArgs.pcmBuf = (SceVoid*) m_outBuffer; - printf("5\n"); m_mp3Handle = sceMp3ReserveMp3Handle(&initArgs); if (m_mp3Handle < 0) return false; // Alright we are all set up, let's fill the first buffer. - printf("5.5\n"); bool _filled= fillBuffers(); if (! _filled) return false; - printf("end = %i, bufsize = %i, outSize = %i\n", fileSize, m_inBufferSize, m_outBufferSize); // Start this bitch up! - printf("6\n"); int start = sceMp3Init(m_mp3Handle); if (start < 0) return false; - printf("7\n"); m_numChannels = sceMp3GetMp3ChannelNum(m_mp3Handle); - printf("8\n"); m_samplingRate = sceMp3GetSamplingRate(m_mp3Handle); return true; } bool JMP3::unload() { - printf("unload 1\n"); if (m_channel >= 0) sceAudioSRCChRelease(); - printf("unload 2\n"); sceMp3ReleaseMp3Handle(m_mp3Handle); - printf("unload 3\n"); sceMp3TermResource(); - printf("unload 4\n"); sceIoClose(m_fileHandle); - printf("unload 5\n"); //delete[] m_inBuffer; - printf("unload 6\n"); //delete[] m_outBuffer; - printf("unload 7\n"); return true; } diff --git a/projects/mtg/include/GameApp.h b/projects/mtg/include/GameApp.h index 5f3f1d110..fbd1bc789 100644 --- a/projects/mtg/include/GameApp.h +++ b/projects/mtg/include/GameApp.h @@ -84,6 +84,7 @@ class GameApp: public JApp static JResourceManager * CommonRes; static hgeParticleSystem * Particles[6]; static int HasMusic; + static string systemError; static JMusic* music; }; diff --git a/projects/mtg/include/GameOptions.h b/projects/mtg/include/GameOptions.h index f76c34824..81d5ffcd9 100644 --- a/projects/mtg/include/GameOptions.h +++ b/projects/mtg/include/GameOptions.h @@ -11,6 +11,7 @@ using std::string; #define OPTIONS_DIFFICULTY_MODE_UNLOCKED "prx_handler" //huhu #define OPTIONS_MOMIR_MODE_UNLOCKED "prx_rimom" //haha #define OPTIONS_DIFFICULTY "difficulty" +#define OPTIONS_CACHESIZE "cacheSize" // WALDORF - added #define OPTIONS_INTERRUPT_SECONDS "interruptSeconds" diff --git a/projects/mtg/include/GameStateMenu.h b/projects/mtg/include/GameStateMenu.h index ff0d9147d..239481415 100644 --- a/projects/mtg/include/GameStateMenu.h +++ b/projects/mtg/include/GameStateMenu.h @@ -6,6 +6,7 @@ #include "../include/GameState.h" #include "../include/SimpleMenu.h" + class GameStateMenu: public GameState, public JGuiListener { private: diff --git a/projects/mtg/include/MTGGuiPlay.h b/projects/mtg/include/MTGGuiPlay.h index 259f17a7c..079f6a00a 100644 --- a/projects/mtg/include/MTGGuiPlay.h +++ b/projects/mtg/include/MTGGuiPlay.h @@ -26,7 +26,6 @@ class MTGGuiPlay: public PlayGuiObjectController { float mGlitterX, mGlitterY; JTexture * mPhaseBarTexture; JQuad * mIcons[7]; - JTexture * mIconsTexture; JTexture * mBgTex; JQuad * mBg; diff --git a/projects/mtg/include/ManaCost.h b/projects/mtg/include/ManaCost.h index 5846bee92..02b5a8c94 100644 --- a/projects/mtg/include/ManaCost.h +++ b/projects/mtg/include/ManaCost.h @@ -16,6 +16,7 @@ class ManaCost{ int cost[Constants::MTG_NB_COLORS+1]; ManaCostHybrid * hybrids[10]; unsigned int nbhybrids; + int extraCostsIsCopy; public: ExtraCosts * extraCosts; diff --git a/projects/mtg/include/TexturesCache.h b/projects/mtg/include/TexturesCache.h index 0d260389e..0a91c5305 100644 --- a/projects/mtg/include/TexturesCache.h +++ b/projects/mtg/include/TexturesCache.h @@ -2,7 +2,7 @@ #define _TEXTURES_CACHE_H #define MAX_CACHE_OBJECTS 100 -#define CACHE_SIZE_PIXELS 6000000 +#define CACHE_SIZE_PIXELS 2000000 #define CACHE_CARD 1 #define CACHE_THUMB 2 @@ -43,6 +43,7 @@ class TexturesCache{ int nb_textures; int delete_previous; int totalsize; + int maxSize; CardTexture * cache[MAX_CACHE_OBJECTS]; public: int isInCache(MTGCard * card, int type=CACHE_CARD); diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 347b4a704..a7c3c4b73 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -401,7 +401,7 @@ int AIPlayer::chooseAttackers(){ int AIPlayer::canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *ennemy){ if (ennemy->has(Constants::FIRSTSTRIKE) || ennemy->has(Constants::DOUBLESTRIKE)) return 0; if (!(card->has(Constants::FIRSTSTRIKE) || card->has(Constants::DOUBLESTRIKE))) return 0; - if (!card->power >= ennemy->toughness) return 0; + if (!(card->power >= ennemy->toughness)) return 0; return 1; } @@ -461,8 +461,8 @@ int AIPlayer::chooseBlockers(){ }else{ MTGCardInstance * attacker = card->defenser; if (opponentsToughness[attacker] <= 0 || - (card->toughness <= card->defenser->power && opponentForce*2 defenser)) || - card->defenser->nbOpponents()>1){ + (card->toughness <= attacker->power && opponentForce*2 nbOpponents()>1){ g->mLayers->actionLayer()->reactToClick(a,card); }else{ set = 1; diff --git a/projects/mtg/src/DeckStats.cpp b/projects/mtg/src/DeckStats.cpp index 885879083..d4b1fdf52 100644 --- a/projects/mtg/src/DeckStats.cpp +++ b/projects/mtg/src/DeckStats.cpp @@ -10,7 +10,10 @@ int DeckStat::percentVictories(){ } DeckStats * DeckStats::GetInstance(){ - if (!mInstance) mInstance = NEW DeckStats(); + if (!mInstance){ + mInstance = NEW DeckStats(); + + } return mInstance; } @@ -19,6 +22,7 @@ void DeckStats::cleanStats(){ for (it = stats.begin(); it != stats.end(); it++){ SAFE_DELETE(it->second); } + stats.clear(); } @@ -53,7 +57,10 @@ void DeckStats::load(const char * filename){ int games = atoi(s.c_str()); std::getline(file,s); int victories = atoi(s.c_str()); - stats[deckfile] = NEW DeckStat(games,victories); + map::iterator it = stats.find(deckfile); + if (it == stats.end()){ + stats[deckfile] = NEW DeckStat(games,victories); + } } file.close(); } diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index f39535b47..e0b591878 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -21,6 +21,7 @@ JResourceManager* GameApp::CommonRes = NEW JResourceManager(); hgeParticleSystem* GameApp::Particles[] = {NULL,NULL,NULL,NULL,NULL,NULL}; int GameApp::HasMusic = 1; JMusic * GameApp::music = NULL; +string GameApp::systemError = ""; GameState::GameState(GameApp* parent): mParent(parent) { @@ -105,6 +106,10 @@ void GameApp::Create() CommonRes->LoadJLBFont("graphics/magic",16); + CommonRes->CreateTexture("graphics/phasebar.png"); + CommonRes->CreateTexture("graphics/background.png"); + CommonRes->CreateTexture("graphics/back.jpg"); + //CommonRes->CreateTexture("graphics/interrupt.png"); //CommonRes->CreateQuad("interrupt", "graphics/interrupt.png", 0, 0, 256, 128); @@ -171,7 +176,7 @@ void GameApp::Destroy() } SAFE_DELETE(cache); SampleCache::DestroyInstance(); - + delete(DeckStats::GetInstance()); SAFE_DELETE(CommonRes); @@ -182,7 +187,7 @@ void GameApp::Destroy() SAFE_DELETE(music); - delete(DeckStats::GetInstance()); + SimpleMenu::destroy(); @@ -196,6 +201,7 @@ void GameApp::Destroy() void GameApp::Update() { + if (systemError.size()) return; JGE* mEngine = JGE::GetInstance(); if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonClick(PSP_CTRL_TRIANGLE)) { @@ -236,7 +242,12 @@ void GameApp::Update() void GameApp::Render() { - + if (systemError.size()){ + fprintf(stderr, systemError.c_str()); + JLBFont * mFont= CommonRes->GetJLBFont("graphics/simon"); + if (mFont) mFont->DrawString(systemError.c_str(),1,1); + return; + } if (mCurrentState != NULL) { mCurrentState->Render(); diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index 26b24ccc3..04e21c374 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -4,6 +4,7 @@ #include "../include/MenuItem.h" #include "../include/GameOptions.h" #include "../include/GameApp.h" +#include "../include/MTGCard.h" static const char* GAME_VERSION = "WTH?! 0.6.0 - by WilLoW"; #define ALPHA_WARNING 0 @@ -72,6 +73,8 @@ GameStateMenu::~GameStateMenu() {} void GameStateMenu::Create() { + + mDip = NULL; mReadConf = 0; mCurrentSetName[0] = 0; @@ -241,8 +244,10 @@ void GameStateMenu::Update(float dt) break; case MENU_STATE_MAJOR_MAINMENU : if (mGuiController!=NULL){ - mGuiController->Update(dt); + mGuiController->Update(dt); } + + break; case MENU_STATE_MAJOR_SUBMENU : subMenuController->Update(dt); @@ -407,6 +412,7 @@ void GameStateMenu::Render() } } + } diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index dbe85db6c..68004ede2 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -31,6 +31,7 @@ void GameStateOptions::Start() if (GameOptions::GetInstance()->values[OPTIONS_DIFFICULTY_MODE_UNLOCKED].getIntValue()) { optionsList->Add(NEW OptionItem(OPTIONS_DIFFICULTY, "Difficulty", 3, 1)); } + optionsList->Add(NEW OptionItem(OPTIONS_CACHESIZE, "Cache Size", 60, 5)); JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3"); optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170); optionsMenu->Add(1, "Save & Back to Main Menu"); diff --git a/projects/mtg/src/MTGGuiPlay.cpp b/projects/mtg/src/MTGGuiPlay.cpp index 9e5247b96..b8db82a74 100644 --- a/projects/mtg/src/MTGGuiPlay.cpp +++ b/projects/mtg/src/MTGGuiPlay.cpp @@ -26,7 +26,7 @@ MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id, offset = 0; - mPhaseBarTexture = JRenderer::GetInstance()->LoadTexture("graphics/phasebar.png", TEX_TYPE_USE_VRAM); + mPhaseBarTexture = GameApp::CommonRes->GetTexture("graphics/phasebar.png"); for (int i=0; i < 12; i++){ phaseIcons[2*i] = NEW JQuad(mPhaseBarTexture, i*28, 0, 28, 28); phaseIcons[2*i + 1] = NEW JQuad(mPhaseBarTexture, i*28, 28, 28, 28); @@ -36,26 +36,34 @@ MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id, mGlitterAlpha = -1; mFont= GameApp::CommonRes->GetJLBFont("graphics/simon"); - mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM); //load all the icon images - mIcons[Constants::MTG_COLOR_ARTIFACT] = NEW JQuad(mIconsTexture, 2+6*36, 38, 32, 32); - mIcons[Constants::MTG_COLOR_LAND] = NEW JQuad(mIconsTexture, 2+5*36, 38, 32, 32); - mIcons[Constants::MTG_COLOR_WHITE] = NEW JQuad(mIconsTexture, 2+4*36, 38, 32, 32); - mIcons[Constants::MTG_COLOR_RED] = NEW JQuad(mIconsTexture, 2+3*36, 38, 32, 32); - mIcons[Constants::MTG_COLOR_BLACK] = NEW JQuad(mIconsTexture, 2+2*36, 38, 32, 32); - mIcons[Constants::MTG_COLOR_BLUE] = NEW JQuad(mIconsTexture, 2+1*36, 38, 32, 32); - mIcons[Constants::MTG_COLOR_GREEN] = NEW JQuad(mIconsTexture, 2+0*36, 38, 32, 32); + mIcons[Constants::MTG_COLOR_ARTIFACT] = GameApp::CommonRes->GetQuad("c_artifact"); + mIcons[Constants::MTG_COLOR_LAND] = GameApp::CommonRes->GetQuad("c_land"); + mIcons[Constants::MTG_COLOR_WHITE] = GameApp::CommonRes->GetQuad("c_white"); + mIcons[Constants::MTG_COLOR_RED] = GameApp::CommonRes->GetQuad("c_red"); + mIcons[Constants::MTG_COLOR_BLACK] = GameApp::CommonRes->GetQuad("c_black"); + mIcons[Constants::MTG_COLOR_BLUE] = GameApp::CommonRes->GetQuad("c_blue"); + mIcons[Constants::MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green"); for (int i=0; i < 7; i++){ mIcons[i]->SetHotSpot(16,16); } - mBgTex = JRenderer::GetInstance()->LoadTexture("graphics/background.png", TEX_TYPE_USE_VRAM); - mBg = NEW JQuad(mBgTex, 0, 0, 480, 272); + mBgTex = GameApp::CommonRes->GetTexture("graphics/background.png"); + if (mBgTex) mBg = NEW JQuad(mBgTex, 0, 0, 480, 272); + else { + mBg = NULL; + GameApp::systemError = "error Loading Texture mBgTex in MTGGuiPlay intialization"; + } - mBgTex2 = JRenderer::GetInstance()->LoadTexture("graphics/back.jpg", TEX_TYPE_USE_VRAM); - mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255); - for (int i= 0; i < 4; i++){ - alphaBg[i] = 255; + mBgTex2 = GameApp::CommonRes->GetTexture("graphics/back.jpg"); + if (mBgTex2){ + mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255); + for (int i= 0; i < 4; i++){ + alphaBg[i] = 255; + } + }else{ + mBg2 = NULL; + GameApp::systemError = "error Loading Texture mBgTex2 in MTGGuiPlay intialization"; } alphaBg[0] = 0; AddPlayersGuiInfo(); @@ -401,20 +409,17 @@ void MTGGuiPlay::Render(){ MTGGuiPlay::~MTGGuiPlay(){ LOG("==Destroying MTGGuiPlay=="); delete mBg; - delete mBgTex; - for (int i=0; i < 7; i++){ - delete mIcons[i]; - } - delete mIconsTexture; + //delete mBgTex; + delete mGlitter; for (int i=0; i < 12; i++){ delete phaseIcons[2*i] ; delete phaseIcons[2*i + 1]; } - delete mPhaseBarTexture; + //delete mPhaseBarTexture; SAFE_DELETE(mBg2); - SAFE_DELETE(mBgTex2); + //SAFE_DELETE(mBgTex2); LOG("==Destroying MTGGuiPlay Successful=="); diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index 70e012de2..32cd30bb6 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -128,6 +128,9 @@ ManaCost::~ManaCost(){ for (unsigned int i = 0; i < nbhybrids ; i++){ SAFE_DELETE(hybrids[i]); } + if (!extraCostsIsCopy) { + SAFE_DELETE(extraCosts); + } } void ManaCost::x(){ @@ -141,6 +144,7 @@ void ManaCost::init(){ } nbhybrids = 0; extraCosts = NULL; + extraCostsIsCopy = 1; } @@ -156,6 +160,7 @@ void ManaCost::copy(ManaCost * _manaCost){ if (_manaCost->extraCosts){ //TODO Deep copy ? extraCosts = _manaCost->extraCosts; + extraCostsIsCopy = 1; } } diff --git a/projects/mtg/src/TexturesCache.cpp b/projects/mtg/src/TexturesCache.cpp index f7a37ab2d..68dc4474c 100644 --- a/projects/mtg/src/TexturesCache.cpp +++ b/projects/mtg/src/TexturesCache.cpp @@ -1,5 +1,6 @@ #include "../include/config.h" #include "../include/TexturesCache.h" +#include "../include/GameOptions.h" TexturesCache::TexturesCache(){ nb_textures = 0; @@ -9,6 +10,8 @@ TexturesCache::TexturesCache(){ for (int i=0; ivalues[OPTIONS_CACHESIZE].getIntValue() * 100000; + if (!maxSize) maxSize = CACHE_SIZE_PIXELS; #ifdef WIN32 char buf [4096]; sprintf(buf, " Init TextureCache : %p\n", this); @@ -61,7 +64,7 @@ void TexturesCache::removeQuad(int id){ } int TexturesCache::cleanup(){ - while (nb_textures >= MAX_CACHE_OBJECTS - 1 || totalsize > CACHE_SIZE_PIXELS){ + while (nb_textures >= MAX_CACHE_OBJECTS - 1 || totalsize > maxSize){ int i = getOldestQuad(); if (i == -1) return 0; removeQuad(i);