diff --git a/projects/mtg/include/ActionLayer.h b/projects/mtg/include/ActionLayer.h index 869897adc..3a24f5214 100644 --- a/projects/mtg/include/ActionLayer.h +++ b/projects/mtg/include/ActionLayer.h @@ -24,6 +24,7 @@ class ActionLayer: public GuiLayer, public JGuiListener{ int unstopableRenderInProgress(); bool CheckUserInput(u32 key); ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL;}; + ~ActionLayer(); int isWaitingForAnswer(); int isReactingToTargetClick(Targetable * card); int receiveEvent(WEvent * event); diff --git a/projects/mtg/include/SimpleMenu.h b/projects/mtg/include/SimpleMenu.h index ddd167db8..e956b40de 100644 --- a/projects/mtg/include/SimpleMenu.h +++ b/projects/mtg/include/SimpleMenu.h @@ -33,6 +33,7 @@ class SimpleMenu:public JGuiController{ static unsigned int refCount; static JQuad *spadeR, *spadeL, *jewel, *side; + static JTexture *spadeRTex, *spadeLTex, *jewelTex, *sideTex; static JLBFont* titleFont; static hgeParticleSystem* stars; // This works only because of no multithreading @@ -51,6 +52,7 @@ class SimpleMenu:public JGuiController{ float selectionTargetY; bool closed; + static void destroy(); }; diff --git a/projects/mtg/include/TexturesCache.h b/projects/mtg/include/TexturesCache.h index 23f7e11a4..4a5d02e28 100644 --- a/projects/mtg/include/TexturesCache.h +++ b/projects/mtg/include/TexturesCache.h @@ -76,6 +76,7 @@ protected: ~SampleCache(); public: static SampleCache * GetInstance(); + static void DestroyInstance(); SampleCache(){lastTime = 0;}; JSample * getSample(string filename); diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index de9ad08d0..0f4e1967c 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -515,7 +515,7 @@ AIStats * AIPlayer::getStats(){ if (!stats){ char statFile[512]; sprintf(statFile, RESPATH"/ai/baka/stats/%s.stats", opponent()->deckFile.c_str()); - stats = new AIStats(this, statFile); + stats = NEW AIStats(this, statFile); } return stats; } diff --git a/projects/mtg/src/ActionLayer.cpp b/projects/mtg/src/ActionLayer.cpp index b17294d2f..af83bfbd3 100644 --- a/projects/mtg/src/ActionLayer.cpp +++ b/projects/mtg/src/ActionLayer.cpp @@ -216,3 +216,7 @@ void ActionLayer::ButtonPressed(int controllerid, int controlid){ menuObject = 0; } + +ActionLayer::~ActionLayer(){ + SAFE_DELETE(abilitiesMenu); +} \ No newline at end of file diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index 7d5c19b46..5de1d8fb6 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -170,6 +170,8 @@ void GameApp::Destroy() SAFE_DELETE(collection); } SAFE_DELETE(cache); + SampleCache::DestroyInstance(); + SAFE_DELETE(CommonRes); @@ -181,6 +183,10 @@ void GameApp::Destroy() SAFE_DELETE(music); delete(DeckStats::GetInstance()); + + SimpleMenu::destroy(); + + LOG("==Destroying GameApp Successful=="); } diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index 7ac6d576b..dbe85db6c 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -44,6 +44,7 @@ void GameStateOptions::End() { JRenderer::GetInstance()->EnableVSync(false); SAFE_DELETE(optionsList); + SAFE_DELETE(optionsMenu); } diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index a78741565..b099a10d1 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -77,12 +77,9 @@ void GameStateShop::End() SAFE_DELETE(shop); SAFE_DELETE(mBack); SAFE_DELETE(backTexture); - if(bgTexture) - SAFE_DELETE(bgTexture); - if(mBg) - SAFE_DELETE(mBg); - if(menu) - SAFE_DELETE(menu); + SAFE_DELETE(bgTexture); + SAFE_DELETE(mBg); + SAFE_DELETE(menu); } diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index d9d1b17be..8dbf2130c 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -30,11 +30,12 @@ MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idLi } MTGPlayerCards::~MTGPlayerCards(){ - if(library) delete library; - if(graveyard) delete graveyard; - if(hand) delete hand; - if(inPlay) delete inPlay; - if(stack) delete stack; + SAFE_DELETE(library); + SAFE_DELETE(graveyard); + SAFE_DELETE(hand); + SAFE_DELETE(inPlay); + SAFE_DELETE(stack); + SAFE_DELETE(removedFromGame); } void MTGPlayerCards::setOwner(Player * player){ @@ -62,7 +63,6 @@ void MTGPlayerCards::init(){ hand = NEW MTGHand(); inPlay = NEW MTGInPlay(); stack = NEW MTGStack(); - stack = NEW MTGStack(); removedFromGame = NEW MTGRemovedFromGame(); } diff --git a/projects/mtg/src/ShopItem.cpp b/projects/mtg/src/ShopItem.cpp index 9b4bdf24b..f9dd4a067 100644 --- a/projects/mtg/src/ShopItem.cpp +++ b/projects/mtg/src/ShopItem.cpp @@ -63,7 +63,6 @@ void ShopItem::Render(){ renderer->RenderQuad(quad,mX + SCREEN_WIDTH/2 + 20,5,0, 0.9f,0.9f); }else{ if (card) CardGui::alternateRender(card,NULL,mX + SCREEN_WIDTH/2 + 100 + 20,133,0, 0.9f); - //TODO } mFont->SetColor(ARGB(255,255,255,0)); }else{ @@ -80,18 +79,15 @@ void ShopItem::Render(){ void ShopItem::Update(float dt) { - if (mScale < mTargetScale) - { + if (mScale < mTargetScale){ mScale += 8.0f*dt; if (mScale > mTargetScale) - mScale = mTargetScale; - } - else if (mScale > mTargetScale) - { + mScale = mTargetScale; + }else if (mScale > mTargetScale){ mScale -= 8.0f*dt; if (mScale < mTargetScale) - mScale = mTargetScale; - } + mScale = mTargetScale; + } } @@ -157,9 +153,9 @@ void ShopItems::Update(float dt){ char buffer[4096]; sprintf(buffer,"%s : %i credits",item->getText(),price); if(!dialog){ - dialog = NEW SimpleMenu(1,this,GameApp::CommonRes->GetJLBFont(Constants::MENU_FONT),SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); - dialog->Add(1,"Yes"); - dialog->Add(2,"No"); + dialog = NEW SimpleMenu(1,this,GameApp::CommonRes->GetJLBFont(Constants::MENU_FONT),SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); + dialog->Add(1,"Yes"); + dialog->Add(2,"No"); } else{ dialog->Update(dt); @@ -220,7 +216,7 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){ item->quantity--; }else{ safeDeleteDisplay(); - display = new CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5); + display = NEW CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5); int curNbcards = playerdata->collection->totalCards(); //if (showPriceDialog == 0){ // //Starter Deck diff --git a/projects/mtg/src/SimpleMenu.cpp b/projects/mtg/src/SimpleMenu.cpp index 7a746544a..40447f351 100644 --- a/projects/mtg/src/SimpleMenu.cpp +++ b/projects/mtg/src/SimpleMenu.cpp @@ -18,6 +18,10 @@ JQuad* SimpleMenu::spadeR = NULL; JQuad* SimpleMenu::spadeL = NULL; JQuad* SimpleMenu::jewel = NULL; JQuad* SimpleMenu::side = NULL; +JTexture* SimpleMenu::spadeRTex = NULL; +JTexture* SimpleMenu::spadeLTex = NULL; +JTexture* SimpleMenu::jewelTex = NULL; +JTexture* SimpleMenu::sideTex = NULL; JLBFont* SimpleMenu::titleFont = NULL; hgeParticleSystem* SimpleMenu::stars = NULL; unsigned int SimpleMenu::refCount = 0; @@ -36,21 +40,22 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int title = _title; startId = 0; maxItems = _maxItems; - side = NULL; selectionT = 0; timeOpen = 0; closed = false; ++refCount; JRenderer* renderer = JRenderer::GetInstance(); - static JTexture* spadeLTex = renderer->LoadTexture(spadeLPath, TEX_TYPE_USE_VRAM); - static JTexture* spadeRTex = renderer->LoadTexture(spadeRPath, TEX_TYPE_USE_VRAM); - static JTexture* jewelTex = renderer->CreateTexture(5, 5, TEX_TYPE_USE_VRAM); - static JTexture* sideTex = renderer->LoadTexture(sidePath, TEX_TYPE_USE_VRAM); - if (NULL == spadeL) spadeL = NEW JQuad(spadeLTex, 2, 1, 16, 13); + + if (!spadeLTex) spadeLTex= renderer->LoadTexture(spadeLPath, TEX_TYPE_USE_VRAM); + if (!spadeRTex) spadeRTex = renderer->LoadTexture(spadeRPath, TEX_TYPE_USE_VRAM); + if (!jewelTex) jewelTex= renderer->CreateTexture(5, 5, TEX_TYPE_USE_VRAM); + if (!sideTex) sideTex = renderer->LoadTexture(sidePath, TEX_TYPE_USE_VRAM); +if (NULL == spadeL) spadeL = NEW JQuad(spadeLTex, 2, 1, 16, 13); if (NULL == spadeR) spadeR = NEW JQuad(spadeRTex, 2, 1, 16, 13); if (NULL == jewel) jewel = NEW JQuad(jewelTex, 1, 1, 3, 3); if (NULL == side) side = NEW JQuad(sideTex, 1, 1, 1, 7); + if (NULL == titleFont) { GameApp::CommonRes->LoadJLBFont(titleFontPath, 7); @@ -172,3 +177,15 @@ void SimpleMenu::Close() timeOpen = -1.0; stars->Stop(true); } + +void SimpleMenu::destroy(){ + SAFE_DELETE(SimpleMenu::spadeR); + SAFE_DELETE(SimpleMenu::spadeL); + SAFE_DELETE(SimpleMenu::jewel); + SAFE_DELETE(SimpleMenu::side); + SAFE_DELETE(SimpleMenu::spadeRTex); + SAFE_DELETE(SimpleMenu::spadeLTex); + SAFE_DELETE(SimpleMenu::jewelTex); + SAFE_DELETE(SimpleMenu::sideTex); + SAFE_DELETE(SimpleMenu::stars); +} \ No newline at end of file diff --git a/projects/mtg/src/TexturesCache.cpp b/projects/mtg/src/TexturesCache.cpp index 27aedbb0f..13c47e552 100644 --- a/projects/mtg/src/TexturesCache.cpp +++ b/projects/mtg/src/TexturesCache.cpp @@ -93,6 +93,7 @@ CardTexture::CardTexture(MTGCard * card, int _type): type(_type){ LOG("==Creating CardTexture Object"); char filename[100]; quad = NULL; + tex = NULL; nbpixels = 0; lastTime = 0; if (type == CACHE_THUMB){ @@ -103,7 +104,8 @@ CardTexture::CardTexture(MTGCard * card, int _type): type(_type){ #ifdef WIN32 OutputDebugString(filename); #endif - tex = JRenderer::GetInstance()->LoadTexture(filename, false); + if (fileExists(filename)) + tex = JRenderer::GetInstance()->LoadTexture(filename, false); if (tex){ quad = NEW JQuad(tex, 0.0f, 0.0f, tex->mWidth, tex->mHeight); nbpixels = tex->mTexHeight * tex->mTexWidth; @@ -177,3 +179,7 @@ void SampleCache::cleanCache(){ SampleCache::~SampleCache(){ cleanCache(); } + +void SampleCache::DestroyInstance(){ + SAFE_DELETE(mInstance); +} \ No newline at end of file