Implemented a lazy load pattern for the deck stats - when the DeckMenu is displaying decks, it calls LoadStats() for only the ones visible in the list. This helps reduces the lag that occurs each time we attempt to load all the AI decks during match selection.
This still could be improved - DeckMetaData's constructor loads an MTGDeck object to parse out the name of a deck from its file. This means that we crack open 106 files on the first attempt to show the list of opponent decks. I started optimizing this, but reverted, as the list itself is sorted alphabetically. Currently, with these mods, it's still taking 4 1/2 seconds on my psp to load the opponent list on the first go around. While at it, did some cleanup - removed the need for passing around a player pointer in some of the DeckStat functions, etc.
This commit is contained in:
@@ -17,20 +17,21 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
vector<DeckMetaData *> playerDeckOrderList;
|
||||
vector<DeckMetaData *> aiDeckOrderList;
|
||||
vector<DeckMetaData*> playerDeckOrderList;
|
||||
vector<DeckMetaData*> aiDeckOrderList;
|
||||
|
||||
map<string, StatsWrapper *> playerDeckStatsMap;
|
||||
map<string, StatsWrapper *> aiDeckStatsMap;
|
||||
map<string, StatsWrapper*> playerDeckStatsMap;
|
||||
map<string, StatsWrapper*> aiDeckStatsMap;
|
||||
|
||||
void updateMetaDataList(vector<DeckMetaData *>* refList, bool isAI);
|
||||
vector<DeckMetaData *> * getPlayerDeckOrderList();
|
||||
vector<DeckMetaData *> * getAIDeckOrderList();
|
||||
void updateMetaDataList(vector<DeckMetaData*>* refList, bool isAI);
|
||||
vector<DeckMetaData*> * getPlayerDeckOrderList();
|
||||
vector<DeckMetaData*> * getAIDeckOrderList();
|
||||
|
||||
DeckMetaData * getDeckMetaDataById( int deckId, bool isAI );
|
||||
StatsWrapper * getExtendedStatsForDeckId( int deckId, MTGAllCards *collection, bool isAI );
|
||||
StatsWrapper * getExtendedDeckStats( DeckMetaData *selectedDeck, MTGAllCards *collection, bool isAI );
|
||||
static DeckManager * GetInstance();
|
||||
DeckMetaData* getDeckMetaDataById(int deckId, bool isAI);
|
||||
DeckMetaData* getDeckMetaDataByFilename(const std::string& filename, bool isAI);
|
||||
StatsWrapper* getExtendedStatsForDeckId(int deckId, MTGAllCards* collection, bool isAI);
|
||||
StatsWrapper* getExtendedDeckStats(DeckMetaData* selectedDeck, MTGAllCards* collection, bool isAI);
|
||||
static DeckManager* GetInstance();
|
||||
static void EndInstance();
|
||||
|
||||
//convenience method to get the difficulty rating between two decks. This should be refined a little more
|
||||
|
||||
@@ -17,22 +17,21 @@ enum DECK_DIFFICULTY
|
||||
class DeckMetaData
|
||||
{
|
||||
private:
|
||||
string _filename;
|
||||
|
||||
string _desc;
|
||||
string _name;
|
||||
int _deckid;
|
||||
string _avatarFilename;
|
||||
string mFilename;
|
||||
string mDescription;
|
||||
string mName;
|
||||
int mDeckId;
|
||||
string mAvatarFilename;
|
||||
|
||||
// statistical information
|
||||
int mGamesPlayed, mVictories, mPercentVictories, mDifficulty;
|
||||
|
||||
int _nbGamesPlayed, _victories, _percentVictories, _difficulty;
|
||||
DeckMetaData();
|
||||
|
||||
public:
|
||||
DeckMetaData();
|
||||
DeckMetaData(string filename, Player * statsPlayer);
|
||||
void load(string filename);
|
||||
void loadStatsForPlayer(Player * statsPlayer, string deckStatsFileName = "");
|
||||
DeckMetaData(const string& filename);
|
||||
void LoadDeck();
|
||||
void LoadStats();
|
||||
|
||||
// Accessors
|
||||
string getFilename();
|
||||
@@ -49,6 +48,13 @@ public:
|
||||
int getDifficulty();
|
||||
string getDifficultyString();
|
||||
|
||||
void Invalidate();
|
||||
|
||||
string mStatsFilename;
|
||||
string mPlayerDeck;
|
||||
bool mDeckLoaded;
|
||||
bool mStatsLoaded;
|
||||
bool mIsAI;
|
||||
};
|
||||
|
||||
class DeckMetaDataList
|
||||
@@ -58,10 +64,9 @@ private:
|
||||
|
||||
public:
|
||||
void invalidate(string filename);
|
||||
DeckMetaData * get(string filename, Player * statsPlayer = NULL);
|
||||
DeckMetaData * get(string filename);
|
||||
~DeckMetaDataList();
|
||||
static DeckMetaDataList * decksMetaData;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -34,11 +34,9 @@ public:
|
||||
static DeckStats * GetInstance();
|
||||
static void EndInstance();
|
||||
void saveStats(Player * player, Player * opponent, GameObserver * game);
|
||||
void save(const char * filename);
|
||||
void save(Player * player);
|
||||
void load(const char * filename);
|
||||
void load(Player * player);
|
||||
void cleanStats();
|
||||
void save(const std::string& filename);
|
||||
void load(const std::string& filename);
|
||||
|
||||
~DeckStats();
|
||||
int percentVictories(string opponentsDeckFile);
|
||||
int percentVictories();
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
static vector<DeckMetaData *> fillDeckMenu(DeckMenu * _menu, const string& path, const string& smallDeckPrefix = "", Player * statsPlayer = NULL, int maxDecks = 0);
|
||||
|
||||
// build a vector of decks with the information passsed in.
|
||||
static vector<DeckMetaData *> getValidDeckMetaData(const string& path, const string& smallDeckPrefix = "", Player * statsPlayer = NULL, int maxDecks = 0);
|
||||
static vector<DeckMetaData *> BuildDeckList(const string& path, const string& smallDeckPrefix = "", Player * statsPlayer = NULL, int maxDecks = 0);
|
||||
|
||||
// build menu items based on the vector<DeckMetaData *>
|
||||
static void renderDeckMenu(SimpleMenu * _menu, const vector<DeckMetaData *>& deckMetaDataList);
|
||||
|
||||
@@ -90,8 +90,6 @@ private:
|
||||
float mSlide;
|
||||
int mAlpha;
|
||||
int mStage;
|
||||
int nbDecks;
|
||||
int deckNum;
|
||||
int useFilter;
|
||||
JMusic * bgMusic;
|
||||
JQuad * backQuad;
|
||||
|
||||
@@ -100,6 +100,11 @@ public:
|
||||
}
|
||||
|
||||
void loadAvatar(string file);
|
||||
|
||||
/**
|
||||
** Returns the path to the stats file of currently selected deck.
|
||||
*/
|
||||
std::string GetCurrentDeckStatsFile();
|
||||
};
|
||||
|
||||
class HumanPlayer: public Player
|
||||
|
||||
Reference in New Issue
Block a user