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.
This commit is contained in:
@@ -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<string> AIDeckNames;
|
||||
static void loadAIDeckNames();
|
||||
static vector<string> sAIDeckNames;
|
||||
static void LoadAIDeckNames();
|
||||
static int getAIDeckCount();
|
||||
static string getAIDeckName(int id);
|
||||
// End of AI deck buffering code
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <JRenderer.h>
|
||||
#include <math.h>
|
||||
|
||||
vector<string> Task::AIDeckNames;
|
||||
vector<string> 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) : "<Undefined>";
|
||||
LoadAIDeckNames();
|
||||
return ((unsigned int) id <= sAIDeckNames.size()) ? sAIDeckNames.at(id - 1) : "<Undefined>";
|
||||
}
|
||||
|
||||
// End of AI deck buffering code
|
||||
|
||||
@@ -426,6 +426,7 @@
|
||||
<None Include="Makefile" />
|
||||
<None Include="Makefile.1xx" />
|
||||
<None Include="Makefile.3xx" />
|
||||
<None Include="My Amplifier Results\r000hs\r000hs.ampl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\ActionElement.h" />
|
||||
|
||||
@@ -614,6 +614,9 @@
|
||||
<None Include="Makefile" />
|
||||
<None Include="Makefile.1xx" />
|
||||
<None Include="Makefile.3xx" />
|
||||
<None Include="My Amplifier Results\r000hs\r000hs.ampl">
|
||||
<Filter>My Amplifier Results</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="src">
|
||||
@@ -622,5 +625,8 @@
|
||||
<Filter Include="inc">
|
||||
<UniqueIdentifier>{92d0309c-53b0-48a4-8b4d-07af74f87f0c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="My Amplifier Results">
|
||||
<UniqueIdentifier>{0d64b46c-731f-4756-af96-7f2e050e91d2}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user