From fbe2e44814ddb70989a4d784d651d5697633618f Mon Sep 17 00:00:00 2001 From: "techdragon.nguyen@gmail.com" Date: Sat, 8 Oct 2011 00:56:07 +0000 Subject: [PATCH] fixed memory leak in double tap gesture fixed some compiler warnings removed dead and useless code --- JGE/src/JOBJModel.cpp | 2 +- JGE/src/iOS/EAGLView.m | 3 +- projects/mtg/src/AIPlayer.cpp | 5 +-- projects/mtg/src/AIPlayerBaka.cpp | 10 ++---- projects/mtg/src/ActionLayer.cpp | 7 +++-- projects/mtg/src/AllAbilities.cpp | 4 +-- projects/mtg/src/GameOptions.cpp | 6 ---- projects/mtg/src/GameStateMenu.cpp | 2 +- projects/mtg/src/GuiLayers.cpp | 13 +++++--- projects/mtg/src/MTGAbility.cpp | 12 +------ projects/mtg/src/MTGGameZones.cpp | 1 + projects/mtg/src/Tasks.cpp | 1 - projects/mtg/src/WGui.cpp | 5 ++- projects/mtg/wagic.xcodeproj/project.pbxproj | 33 ++++++++++++++++---- 14 files changed, 53 insertions(+), 51 deletions(-) diff --git a/JGE/src/JOBJModel.cpp b/JGE/src/JOBJModel.cpp index 07ba098a1..d30a0ed7b 100644 --- a/JGE/src/JOBJModel.cpp +++ b/JGE/src/JOBJModel.cpp @@ -109,7 +109,7 @@ bool JOBJModel::Load(const char *modelName, const char *textureName) face.mVertCount = 0; char *p = strchr(tmpLine, ' '); - char *pNext = p; + char *pNext = NULL; int vertIdx, texIdx, norIdx; diff --git a/JGE/src/iOS/EAGLView.m b/JGE/src/iOS/EAGLView.m index 9c8e2ef61..d6efbaf47 100755 --- a/JGE/src/iOS/EAGLView.m +++ b/JGE/src/iOS/EAGLView.m @@ -225,6 +225,7 @@ void DestroyGame(void) [menuKeyRecognizer release]; [selectKeyRecognizer release]; + [doubleTapRecognizer release]; [singleTapRecognizer release]; } @@ -282,7 +283,7 @@ void DestroyGame(void) //The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder: - (id)initWithCoder:(NSCoder*)coder { - if ((self = [super initWithCoder:coder])) + if (( self = [super initWithCoder:coder] )) { self = [self initialize]; } diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index e5afff1bf..5f5c3a65c 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -87,7 +87,7 @@ int AIAction::clickMultiAct(vector& actionTargets) { GameObserver * g = owner->getObserver(); TargetChooser * tc = g->getCurrentTargetChooser(); - bool sourceIncluded = false; + if(!tc) return 0; for(size_t f = 0;f < actionTargets.size();f++) { @@ -96,7 +96,6 @@ int AIAction::clickMultiAct(vector& actionTargets) { g->cardClick(card); actionTargets.erase(actionTargets.begin() + f); - sourceIncluded = true; } } std::random_shuffle(actionTargets.begin(), actionTargets.end()); @@ -157,7 +156,6 @@ int AIPlayer::Act(float dt) int AIPlayer::clickMultiTarget(TargetChooser * tc, vector& potentialTargets) { - bool sourceIncluded = false; for(int f = 0;f < int(potentialTargets.size());f++) { MTGCardInstance * card = ((MTGCardInstance *) potentialTargets[f]); @@ -167,7 +165,6 @@ int AIPlayer::clickMultiTarget(TargetChooser * tc, vector& potentia clickstream.push(NEW AIAction(this, card)); DebugTrace("Ai clicked source as a target: " << (card ? card->name : "None" ) << endl ); potentialTargets.erase(potentialTargets.begin() + f); - sourceIncluded = true; } if(pTarget && pTarget->typeAsTarget() == TARGET_PLAYER) { diff --git a/projects/mtg/src/AIPlayerBaka.cpp b/projects/mtg/src/AIPlayerBaka.cpp index 287719845..15b9272f6 100644 --- a/projects/mtg/src/AIPlayerBaka.cpp +++ b/projects/mtg/src/AIPlayerBaka.cpp @@ -634,7 +634,6 @@ MTGCardInstance * AIPlayerBaka::chooseCard(TargetChooser * tc, MTGCardInstance * } } } - playerZones = source->controller()->opponent()->game; } return NULL; } @@ -1042,7 +1041,6 @@ vector AIPlayerBaka::canPaySunBurst(ManaCost * cost) //Make sure we can use the ability if(fullColor == needColorConverted || fullColor == cost->getConvertedCost()) { - i = observer->mLayers->actionLayer()->manaObjects.size(); break; } MTGAbility * a = ((MTGAbility *) observer->mLayers->actionLayer()->manaObjects[i]); @@ -1078,6 +1076,7 @@ vector AIPlayerBaka::canPaySunBurst(ManaCost * cost) } } } + for(int i = fullColor;i < cost->getConvertedCost();i++) { for (size_t i = 0; i < observer->mLayers->actionLayer()->manaObjects.size(); i++) @@ -1833,13 +1832,8 @@ int AIPlayerBaka::computeActions() case Constants::MTG_PHASE_SECONDMAIN: { ManaCost * currentMana = getPotentialMana(); - bool potential = false; currentMana->add(this->getManaPool()); - if (currentMana->getConvertedCost()) - { - //if theres mana i can use there then potential is true. - potential = true; - } + nextCardToPlay = FindCardToPlay(currentMana, "land"); //look for the most expensive creature we can afford. If not found, try enchantment, then artifact, etc... const char* types[] = {"creature", "enchantment", "artifact", "sorcery", "instant"}; diff --git a/projects/mtg/src/ActionLayer.cpp b/projects/mtg/src/ActionLayer.cpp index 7ba8ce39d..9ecfb682c 100644 --- a/projects/mtg/src/ActionLayer.cpp +++ b/projects/mtg/src/ActionLayer.cpp @@ -35,9 +35,12 @@ int ActionLayer::removeFromGame(ActionElement * e) if (i == -1) return 0; //Should not happen, it means we deleted thesame object twice? AbilityFactory af(observer); - if(dynamic_cast(e)) + + MTGAbility * a = dynamic_cast(e); + + if (a != NULL) { - AManaProducer * manaObject = dynamic_cast(af.getCoreAbility((MTGAbility*)e)); + AManaProducer * manaObject = dynamic_cast(af.getCoreAbility(a)); if(manaObject) { for (size_t i = 0; i < manaObjects.size(); i++) diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 5ba1d4e08..76587c0b8 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -2311,7 +2311,6 @@ int MenuAbility::resolve() { this->triggered = 1; MTGAbility * a = this; - a->target = this->target; return a->addToGame(); } @@ -3522,7 +3521,7 @@ void APhaseAction::Update(float dt) MTGCardInstance * _target = NULL; if(target) _target = (MTGCardInstance *) target; - if(!sAbility.size() || (!target||(!_target->currentZone && _target != this->source))) + if(!sAbility.size() || (!target || _target != this->source)) { this->forceDestroy = 1; return; @@ -4159,7 +4158,6 @@ void ATutorialMessage::Render() posY += 30; f->DrawString(_(mMessage).c_str(), posX, posY); - posY += 20; f->SetScale(1); } diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index 57af806c0..2e5763f2f 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -420,9 +420,6 @@ GameOption& GameOptions::operator[](string optionName) GameOption * GameOptions::factorNewGameOption(string optionName, string value) { - if (optionName == "prx_rimom") - int a = 0; - GameOption * result =( Unlockable::unlockables.find(optionName) != Unlockable::unlockables.end()) ? NEW GameOptionAward() : NEW GameOption(); @@ -435,9 +432,6 @@ GameOption * GameOptions::factorNewGameOption(string optionName, string value) GameOption * GameOptions::get(string optionName) { - if (optionName == "prx_rimom") - int a = 0; - if (!unknownMap[optionName]) { unknownMap[optionName] = factorNewGameOption(optionName); diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index 883f426d6..e9a149eb1 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -747,7 +747,7 @@ void GameStateMenu::Render() } else { - mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT); + PIXEL_TYPE colors[] = { ARGB(255,3,3,0), ARGB(255,8,8,0), ARGB(255,21,21,10), ARGB(255,50,50,30), }; diff --git a/projects/mtg/src/GuiLayers.cpp b/projects/mtg/src/GuiLayers.cpp index b883f48ec..262606735 100644 --- a/projects/mtg/src/GuiLayers.cpp +++ b/projects/mtg/src/GuiLayers.cpp @@ -22,9 +22,12 @@ void GuiLayer::Add(JGuiObject *object) { mObjects.push_back(object); AbilityFactory af(observer); - if(dynamic_cast(object)) + + MTGAbility * a = dynamic_cast(object); + + if (a != NULL) { - AManaProducer * manaObject = dynamic_cast(af.getCoreAbility((MTGAbility*)object)); + AManaProducer * manaObject = dynamic_cast(af.getCoreAbility(a)); if(manaObject) { manaObjects.push_back(object); @@ -36,9 +39,11 @@ int GuiLayer::Remove(JGuiObject *object) { AbilityFactory af(observer); - if(dynamic_cast(object)) + MTGAbility * a = dynamic_cast(object); + + if (a != NULL) { - AManaProducer * manaObject = dynamic_cast(af.getCoreAbility((MTGAbility*)object)); + AManaProducer * manaObject = dynamic_cast(af.getCoreAbility(a)); if(manaObject) { for (size_t i = 0; i < manaObjects.size(); i++) diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 515b88f00..7a32f3e60 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -154,7 +154,7 @@ int AbilityFactory::parseCastRestrictions(MTGCardInstance * card, Player * playe firstAmount = ttc->countValidTargets(); firstAmount += mod; } - mod = 0; + SAFE_DELETE(ttc); } } @@ -911,9 +911,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (found != string::npos && storedString.empty()) { size_t real_end = s.find("))", found); - size_t end = s.find(",", found); - if (end == string::npos) - end = real_end; size_t stypesStartIndex = found + 12; storedString.append(s.substr(stypesStartIndex, real_end - stypesStartIndex).c_str()); s.erase(stypesStartIndex, real_end - stypesStartIndex); @@ -2158,9 +2155,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (found != string::npos && extraTransforms.empty()) { size_t real_end = transformsParamsString.find("))", found); - size_t end = transformsParamsString.find(",", found); - if (end == string::npos) - end = real_end; size_t stypesStartIndex = found + 12; extraTransforms.append(transformsParamsString.substr(stypesStartIndex, real_end - stypesStartIndex).c_str()); transformsParamsString.erase(stypesStartIndex, real_end - stypesStartIndex); @@ -2442,7 +2436,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG MTGAbility * AbilityFactory::parseUpkeepAbility(string s,MTGCardInstance * card,Spell * spell,int restrictions,int id) { - MTGAbility * a1 = NULL; bool Cumulative = false; size_t cumulative = s.find("cumulativeupcost"); if(cumulative != string::npos) @@ -2681,9 +2674,6 @@ int AbilityFactory::getAbilities(vector * v, Spell * spell, MTGCar card = spell->source; if (!card) return 0; - MTGCardInstance * target = card->target; - if (!target) - target = card; string magicText; if (dest) diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index d27159aa0..3af05d45a 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -759,6 +759,7 @@ void MTGLibrary::shuffleTopToBottom(int nbcards) { _cards[i] = cards[i - nb_cards]; } + // Logic error here: the final value of cards[i] will always be garbage. possible optimization: use vectors to push and pop for (int i = 0; i < nb_cards; i++) { cards[i] = _cards[i]; diff --git a/projects/mtg/src/Tasks.cpp b/projects/mtg/src/Tasks.cpp index 0b9228a47..f586fcf7d 100644 --- a/projects/mtg/src/Tasks.cpp +++ b/projects/mtg/src/Tasks.cpp @@ -519,7 +519,6 @@ void TaskList::Render() if (0 == tasks.size()) { f->DrawString(_("There are no tasks that need to be done. Come again tomorrow.").c_str(), posX, posY); - posY += 20; return; } diff --git a/projects/mtg/src/WGui.cpp b/projects/mtg/src/WGui.cpp index a181bd09d..8c7a18707 100644 --- a/projects/mtg/src/WGui.cpp +++ b/projects/mtg/src/WGui.cpp @@ -1100,9 +1100,8 @@ bool WGuiMenu::nextItem() while (potential < nbitems - 1 && items[potential]->Selectable() == false) potential++; - if (potential == nbitems || !items[potential]->Selectable()) - potential = -1; - else if (potential != currentItem && (!now || now->Leaving(buttonNext))) + + if (potential != currentItem && (!now || now->Leaving(buttonNext))) { currentItem = potential; items[currentItem]->Entering(buttonNext); diff --git a/projects/mtg/wagic.xcodeproj/project.pbxproj b/projects/mtg/wagic.xcodeproj/project.pbxproj index 72a825162..da1255b9b 100755 --- a/projects/mtg/wagic.xcodeproj/project.pbxproj +++ b/projects/mtg/wagic.xcodeproj/project.pbxproj @@ -3,10 +3,12 @@ archiveVersion = 1; classes = { }; - objectVersion = 45; + objectVersion = 46; objects = { /* Begin PBXBuildFile section */ + 122F4B501438D553003A9129 /* AIPlayerBaka.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 122F4B4E1438D553003A9129 /* AIPlayerBaka.cpp */; }; + 122F4B511438D553003A9129 /* AIPlayerBakaB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 122F4B4F1438D553003A9129 /* AIPlayerBakaB.cpp */; }; 127D4C6F1376B33200109AB4 /* mtg.txt in Resources */ = {isa = PBXBuildFile; fileRef = 127D4C6E1376B33200109AB4 /* mtg.txt */; }; 12B812341404B9E20092E303 /* !Pak0.cpk in Resources */ = {isa = PBXBuildFile; fileRef = 12B8121F1404B9E10092E303 /* !Pak0.cpk */; }; 12B812351404B9E20092E303 /* !Pak1.cpk in Resources */ = {isa = PBXBuildFile; fileRef = 12B812201404B9E10092E303 /* !Pak1.cpk */; }; @@ -180,6 +182,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 122F4B4E1438D553003A9129 /* AIPlayerBaka.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBaka.cpp; sourceTree = ""; }; + 122F4B4F1438D553003A9129 /* AIPlayerBakaB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBakaB.cpp; sourceTree = ""; }; 127D4C6E1376B33200109AB4 /* mtg.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = mtg.txt; path = bin/Res/sets/primitives/mtg.txt; sourceTree = ""; }; 12B8121F1404B9E10092E303 /* !Pak0.cpk */ = {isa = PBXFileReference; lastKnownFileType = file; path = "!Pak0.cpk"; sourceTree = ""; }; 12B812201404B9E10092E303 /* !Pak1.cpk */ = {isa = PBXFileReference; lastKnownFileType = file; path = "!Pak1.cpk"; sourceTree = ""; }; @@ -785,6 +789,8 @@ CEA376ED1291C60500B9016A /* src */ = { isa = PBXGroup; children = ( + 122F4B4E1438D553003A9129 /* AIPlayerBaka.cpp */, + 122F4B4F1438D553003A9129 /* AIPlayerBakaB.cpp */, 12B8124A1404BD0D0092E303 /* IconButton.cpp */, 12B8124C1404BD0D0092E303 /* ObjectAnalytics.cpp */, CE9E71EA1375A62300759DDC /* ModRules.cpp */, @@ -1052,8 +1058,11 @@ /* Begin PBXProject section */ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; + attributes = { + LastUpgradeCheck = 0420; + }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "wagic" */; - compatibilityVersion = "Xcode 3.1"; + compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( @@ -1249,6 +1258,8 @@ 12B8123F1404B9E20092E303 /* zstream.cpp in Sources */, 12B8124D1404BD0D0092E303 /* IconButton.cpp in Sources */, 12B8124F1404BD0D0092E303 /* ObjectAnalytics.cpp in Sources */, + 122F4B501438D553003A9129 /* AIPlayerBaka.cpp in Sources */, + 122F4B511438D553003A9129 /* AIPlayerBakaB.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1260,6 +1271,8 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -1290,6 +1303,8 @@ ); "New Setting" = ""; PRODUCT_NAME = wagic; + PROVISIONING_PROFILE = ""; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; SCAN_ALL_SOURCE_FILES_FOR_INCLUDES = NO; SDKROOT = iphoneos; }; @@ -1300,6 +1315,8 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CODE_SIGN_IDENTITY = "iPhone Distribution"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; COPY_PHASE_STRIP = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = testproject_Prefix.pch; @@ -1316,6 +1333,8 @@ "\"$(SDKROOT)/usr/lib/gcc/powerpc-apple-darwin9/4.0.1\"", ); PRODUCT_NAME = testproject; + PROVISIONING_PROFILE = ""; + "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -1325,16 +1344,18 @@ isa = XCBuildConfiguration; buildSettings = { ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEPLOYMENT_LOCATION = NO; DEPLOYMENT_POSTPROCESSING = NO; GCC_C_LANGUAGE_STANDARD = c99; GCC_PREPROCESSOR_DEFINITIONS = DEBUG; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../../Boost/boost; - PREBINDING = NO; - SDKROOT = iphoneos3.2; + PROVISIONING_PROFILE = ""; + SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1345,12 +1366,12 @@ ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; GCC_C_LANGUAGE_STANDARD = c99; + GCC_VERSION = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../../Boost/boost; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; - PREBINDING = NO; - SDKROOT = iphoneos4.2; + SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release;