From 2f3e6b56e5725c20a615e648cc1c766f6e4cfb65 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew" Date: Sun, 15 May 2011 14:38:41 +0000 Subject: [PATCH] - Fix for issue 660 (changelings have become slower) -- I removed the string comparison, which was expensive (the test is not necessary anymore, since it was "shielding" us from fake types (names), which are not creature subtypes, and therefore do not go through). I also moved one function call outside of the loop, just in case that wasn't optimized by the compiler. - Removed unused Subtypes.cpp function (I don't really want people to use it, it can be quite expensive if used incorrectly) - moved a test for issue 501 that has been fixed a while ago (we forgot to add the test to the test suite) --- projects/mtg/bin/Res/test/_tests.txt | 1 + .../test/{bugs => generic}/changeling_i501.txt | 0 projects/mtg/include/Subtypes.h | 1 - projects/mtg/src/AllAbilities.cpp | 10 ++-------- projects/mtg/src/MTGCardInstance.cpp | 17 ++++------------- projects/mtg/src/Subtypes.cpp | 6 ------ 6 files changed, 7 insertions(+), 28 deletions(-) rename projects/mtg/bin/Res/test/{bugs => generic}/changeling_i501.txt (100%) diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index d37aa73dd..5a8030db9 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -6,6 +6,7 @@ generic/becomes_transform_i559.txt generic/becomes_transform_i559_2.txt generic/bushido_1.txt generic/bushido_2.txt +generic/changeling_i501.txt generic/cycling.txt generic/cycling2.txt generic/deathtouch.txt diff --git a/projects/mtg/bin/Res/test/bugs/changeling_i501.txt b/projects/mtg/bin/Res/test/generic/changeling_i501.txt similarity index 100% rename from projects/mtg/bin/Res/test/bugs/changeling_i501.txt rename to projects/mtg/bin/Res/test/generic/changeling_i501.txt diff --git a/projects/mtg/include/Subtypes.h b/projects/mtg/include/Subtypes.h index 96e4f4b91..426e7d9eb 100644 --- a/projects/mtg/include/Subtypes.h +++ b/projects/mtg/include/Subtypes.h @@ -41,7 +41,6 @@ public: Subtypes(); int find(string subtype, bool forceAdd = true); string find(unsigned int id); - bool isSubtypeOfType(string subtype, string type); bool isSubtypeOfType(unsigned int subtype, unsigned int type); bool isSuperType(unsigned int type); bool isType(unsigned int type); diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 698462046..32cc20527 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -2426,18 +2426,12 @@ ATransformer::ATransformer(int id, MTGCardInstance * source, MTGCardInstance * t if (stypes.find("allsubtypes") != string::npos || stypes.find("removecreaturesubtypes") != string::npos) { - for (size_t i = 0; i getValuesById().size(); ++i) + const vector values = Subtypes::subtypesList->getValuesById(); + for (size_t i = 0; i isSubtypeOfType(i,Subtypes::TYPE_CREATURE)) continue; - //Erwan 2011/5/6 String comparison is expensive. Any way to do this in a cleaner way? - //this check is related to targetchooser instances of cards dynamically loaded subtypes. - //example(foreach(arbor elf)) adds this as a subtype for list ment. - //TODO find cheaper method - string s = Subtypes::subtypesList->find(i); - if (s.find(" ") != string::npos) - continue; types.push_back(i); } } diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index fe5ccca7d..48a1c1e85 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -173,23 +173,14 @@ void MTGCardInstance::initMTGCI() if (basicAbilities[(int)Constants::CHANGELING]) {//if the card is a changeling, it gains all creature subtypes - for (size_t i = 0; i getValuesById().size(); ++i) + const vector values = Subtypes::subtypesList->getValuesById(); + for (size_t i = 0; i < values.size(); ++i) { - if (hasSubtype(i)) - continue; - if (!Subtypes::subtypesList->isSubtypeOfType(i,Subtypes::TYPE_CREATURE)) continue; - //Erwan 2011/5/6 String comparison is expensive. Any way to do this in a cleaner way? - //this check is related to targetchooser instances of cards dynamically loaded subtypes. - //example(foreach(arbor elf)) adds this as a subtype for list ment. - //TODO find cheaper method - string s = Subtypes::subtypesList->find(i); - if (s.find(" ") != string::npos) - continue; - - addType(i); + //Don' want to send any event to the gameObserver inside of initMCGI, so calling the parent addType method instead of mine + CardPrimitive::addType(i); } } diff --git a/projects/mtg/src/Subtypes.cpp b/projects/mtg/src/Subtypes.cpp index de1045d3a..dfdd8b2c0 100644 --- a/projects/mtg/src/Subtypes.cpp +++ b/projects/mtg/src/Subtypes.cpp @@ -63,12 +63,6 @@ string Subtypes::find(unsigned int id) return valuesById[id - 1]; } -bool Subtypes::isSubtypeOfType(string subtype, string type) -{ - unsigned int subtypeInt = find(subtype); - unsigned int typeInt = find(type); - return isSubtypeOfType(subtypeInt, typeInt); -} bool Subtypes::isSubtypeOfType(unsigned int subtype, unsigned int type) { return (subtypesToType[subtype] == type);