From 9005fd7af7ee8cc40dafa6cc2d89bd225ee5c028 Mon Sep 17 00:00:00 2001 From: "wrenczes@gmail.com" Date: Tue, 28 Dec 2010 06:31:50 +0000 Subject: [PATCH] Fixed a problem I noticed after adding Z's 6 new decks to my res folder: if the number of AI decks wasn't a multiple of 10, the game would slow to a crawl, since there was a check that compared the number of actual decks against the number of unlocked AI decks (which is always incremented by 10 when new decks are unlocked) to determine whether the list of AI deck names should be refreshed or not. This was a pointless check, since we can load all the names once, and simply use the unlocked AI count value when determining what decks to allow to be used during random match playing. This change restores the performance on psp back to where it was with 0.13.1, where the ai deck number happened to be a neat 100 count. --- projects/mtg/include/Tasks.h | 4 +-- projects/mtg/src/Tasks.cpp | 46 +++++++++++++-------------- projects/mtg/template.vcxproj | 1 + projects/mtg/template.vcxproj.filters | 6 ++++ 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/projects/mtg/include/Tasks.h b/projects/mtg/include/Tasks.h index be58b599d..c25b142d9 100644 --- a/projects/mtg/include/Tasks.h +++ b/projects/mtg/include/Tasks.h @@ -43,8 +43,8 @@ protected: public: // variable to store and method to obtain names of AI decks //!! Todo: This should _really_ be handled elsewhere (dedicated class?) - static vector AIDeckNames; - static void loadAIDeckNames(); + static vector sAIDeckNames; + static void LoadAIDeckNames(); static int getAIDeckCount(); static string getAIDeckName(int id); // End of AI deck buffering code diff --git a/projects/mtg/src/Tasks.cpp b/projects/mtg/src/Tasks.cpp index ab01caae7..dd1707620 100644 --- a/projects/mtg/src/Tasks.cpp +++ b/projects/mtg/src/Tasks.cpp @@ -9,7 +9,7 @@ #include #include -vector Task::AIDeckNames; +vector Task::sAIDeckNames; /*---------------- Utils -----------------*/ // TODO: Move to dedicated file @@ -187,42 +187,40 @@ void Task::passOneDay() // AI deck buffering code -void Task::loadAIDeckNames() +void Task::LoadAIDeckNames() { - //check if cache is up to date - if (AIDeckNames.size() == (unsigned int)(options[Options::AIDECKS_UNLOCKED].number)) return; - - AIDeckNames.clear(); - int found = 1; - int nbDecks = 0; - while (found && nbDecks < options[Options::AIDECKS_UNLOCKED].number) + if (sAIDeckNames.empty()) { - found = 0; - char buffer[512]; - sprintf(buffer, "%s/deck%i.txt", JGE_GET_RES("ai/baka").c_str(), nbDecks + 1); - - if (fileExists(buffer)) + int found = 1; + int nbDecks = 0; + while (found) { - found = 1; - nbDecks++; - // TODO: Creating MTGDeck only for getting decks name. Find an easier way. - MTGDeck * mtgd = NEW MTGDeck(buffer, NULL, 1); - AIDeckNames.push_back(mtgd->meta_name); - delete mtgd; + found = 0; + std::ostringstream stream; + stream << JGE_GET_RES("ai/baka") << "/deck" << nbDecks + 1 << ".txt"; + if (fileExists(stream.str().c_str())) + { + found = 1; + nbDecks++; + // TODO: Creating MTGDeck only for getting decks name. Find an easier way. + MTGDeck * mtgd = NEW MTGDeck(stream.str().c_str(), NULL, 1); + sAIDeckNames.push_back(mtgd->meta_name); + delete mtgd; + } } } } int Task::getAIDeckCount() { - loadAIDeckNames(); - return AIDeckNames.size(); + LoadAIDeckNames(); + return min((size_t) options[Options::AIDECKS_UNLOCKED].number, sAIDeckNames.size()); } string Task::getAIDeckName(int id) { - loadAIDeckNames(); - return ((unsigned int) id <= AIDeckNames.size()) ? AIDeckNames.at(id - 1) : ""; + LoadAIDeckNames(); + return ((unsigned int) id <= sAIDeckNames.size()) ? sAIDeckNames.at(id - 1) : ""; } // End of AI deck buffering code diff --git a/projects/mtg/template.vcxproj b/projects/mtg/template.vcxproj index 768ad8ab2..af8fd2675 100644 --- a/projects/mtg/template.vcxproj +++ b/projects/mtg/template.vcxproj @@ -426,6 +426,7 @@ + diff --git a/projects/mtg/template.vcxproj.filters b/projects/mtg/template.vcxproj.filters index 4dc205c89..61fc273ae 100644 --- a/projects/mtg/template.vcxproj.filters +++ b/projects/mtg/template.vcxproj.filters @@ -614,6 +614,9 @@ + + My Amplifier Results + @@ -622,5 +625,8 @@ {92d0309c-53b0-48a4-8b4d-07af74f87f0c} + + {0d64b46c-731f-4756-af96-7f2e050e91d2} + \ No newline at end of file