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:
|
public:
|
||||||
// variable to store and method to obtain names of AI decks
|
// variable to store and method to obtain names of AI decks
|
||||||
//!! Todo: This should _really_ be handled elsewhere (dedicated class?)
|
//!! Todo: This should _really_ be handled elsewhere (dedicated class?)
|
||||||
static vector<string> AIDeckNames;
|
static vector<string> sAIDeckNames;
|
||||||
static void loadAIDeckNames();
|
static void LoadAIDeckNames();
|
||||||
static int getAIDeckCount();
|
static int getAIDeckCount();
|
||||||
static string getAIDeckName(int id);
|
static string getAIDeckName(int id);
|
||||||
// End of AI deck buffering code
|
// End of AI deck buffering code
|
||||||
|
|||||||
+15
-17
@@ -9,7 +9,7 @@
|
|||||||
#include <JRenderer.h>
|
#include <JRenderer.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
vector<string> Task::AIDeckNames;
|
vector<string> Task::sAIDeckNames;
|
||||||
|
|
||||||
/*---------------- Utils -----------------*/
|
/*---------------- Utils -----------------*/
|
||||||
// TODO: Move to dedicated file
|
// TODO: Move to dedicated file
|
||||||
@@ -187,42 +187,40 @@ void Task::passOneDay()
|
|||||||
|
|
||||||
// AI deck buffering code
|
// AI deck buffering code
|
||||||
|
|
||||||
void Task::loadAIDeckNames()
|
void Task::LoadAIDeckNames()
|
||||||
{
|
{
|
||||||
//check if cache is up to date
|
if (sAIDeckNames.empty())
|
||||||
if (AIDeckNames.size() == (unsigned int)(options[Options::AIDECKS_UNLOCKED].number)) return;
|
{
|
||||||
|
|
||||||
AIDeckNames.clear();
|
|
||||||
int found = 1;
|
int found = 1;
|
||||||
int nbDecks = 0;
|
int nbDecks = 0;
|
||||||
while (found && nbDecks < options[Options::AIDECKS_UNLOCKED].number)
|
while (found)
|
||||||
{
|
{
|
||||||
found = 0;
|
found = 0;
|
||||||
char buffer[512];
|
std::ostringstream stream;
|
||||||
sprintf(buffer, "%s/deck%i.txt", JGE_GET_RES("ai/baka").c_str(), nbDecks + 1);
|
stream << JGE_GET_RES("ai/baka") << "/deck" << nbDecks + 1 << ".txt";
|
||||||
|
if (fileExists(stream.str().c_str()))
|
||||||
if (fileExists(buffer))
|
|
||||||
{
|
{
|
||||||
found = 1;
|
found = 1;
|
||||||
nbDecks++;
|
nbDecks++;
|
||||||
// TODO: Creating MTGDeck only for getting decks name. Find an easier way.
|
// TODO: Creating MTGDeck only for getting decks name. Find an easier way.
|
||||||
MTGDeck * mtgd = NEW MTGDeck(buffer, NULL, 1);
|
MTGDeck * mtgd = NEW MTGDeck(stream.str().c_str(), NULL, 1);
|
||||||
AIDeckNames.push_back(mtgd->meta_name);
|
sAIDeckNames.push_back(mtgd->meta_name);
|
||||||
delete mtgd;
|
delete mtgd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Task::getAIDeckCount()
|
int Task::getAIDeckCount()
|
||||||
{
|
{
|
||||||
loadAIDeckNames();
|
LoadAIDeckNames();
|
||||||
return AIDeckNames.size();
|
return min((size_t) options[Options::AIDECKS_UNLOCKED].number, sAIDeckNames.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
string Task::getAIDeckName(int id)
|
string Task::getAIDeckName(int id)
|
||||||
{
|
{
|
||||||
loadAIDeckNames();
|
LoadAIDeckNames();
|
||||||
return ((unsigned int) id <= AIDeckNames.size()) ? AIDeckNames.at(id - 1) : "<Undefined>";
|
return ((unsigned int) id <= sAIDeckNames.size()) ? sAIDeckNames.at(id - 1) : "<Undefined>";
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of AI deck buffering code
|
// End of AI deck buffering code
|
||||||
|
|||||||
@@ -426,6 +426,7 @@
|
|||||||
<None Include="Makefile" />
|
<None Include="Makefile" />
|
||||||
<None Include="Makefile.1xx" />
|
<None Include="Makefile.1xx" />
|
||||||
<None Include="Makefile.3xx" />
|
<None Include="Makefile.3xx" />
|
||||||
|
<None Include="My Amplifier Results\r000hs\r000hs.ampl" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="include\ActionElement.h" />
|
<ClInclude Include="include\ActionElement.h" />
|
||||||
|
|||||||
@@ -614,6 +614,9 @@
|
|||||||
<None Include="Makefile" />
|
<None Include="Makefile" />
|
||||||
<None Include="Makefile.1xx" />
|
<None Include="Makefile.1xx" />
|
||||||
<None Include="Makefile.3xx" />
|
<None Include="Makefile.3xx" />
|
||||||
|
<None Include="My Amplifier Results\r000hs\r000hs.ampl">
|
||||||
|
<Filter>My Amplifier Results</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="src">
|
<Filter Include="src">
|
||||||
@@ -622,5 +625,8 @@
|
|||||||
<Filter Include="inc">
|
<Filter Include="inc">
|
||||||
<UniqueIdentifier>{92d0309c-53b0-48a4-8b4d-07af74f87f0c}</UniqueIdentifier>
|
<UniqueIdentifier>{92d0309c-53b0-48a4-8b4d-07af74f87f0c}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="My Amplifier Results">
|
||||||
|
<UniqueIdentifier>{0d64b46c-731f-4756-af96-7f2e050e91d2}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user