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:
@@ -134,7 +134,7 @@ int Player::gainOrLoseLife(int value)
|
||||
game->receiveEvent(lifed);
|
||||
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
int Player::gainLife(int value)
|
||||
{
|
||||
@@ -144,7 +144,7 @@ int Player::gainLife(int value)
|
||||
return 0;
|
||||
}
|
||||
return gainOrLoseLife(value);
|
||||
};
|
||||
}
|
||||
|
||||
int Player::loseLife(int value)
|
||||
{
|
||||
@@ -154,21 +154,23 @@ int Player::loseLife(int value)
|
||||
return 0;
|
||||
}
|
||||
return gainOrLoseLife(-value);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
int Player::afterDamage()
|
||||
{
|
||||
return life;
|
||||
}
|
||||
|
||||
int Player::poisoned()
|
||||
{
|
||||
return poisonCount;
|
||||
}
|
||||
|
||||
int Player::damaged()
|
||||
{
|
||||
return damageCount;
|
||||
}
|
||||
|
||||
int Player::prevented()
|
||||
{
|
||||
return preventable;
|
||||
@@ -176,17 +178,17 @@ int Player::prevented()
|
||||
|
||||
void Player::takeMulligan()
|
||||
{
|
||||
MTGPlayerCards * currentPlayerZones = game;
|
||||
int cardsinhand = currentPlayerZones->hand->nb_cards;
|
||||
for (int i = 0; i < cardsinhand; i++) //Discard hand
|
||||
currentPlayerZones->putInZone(currentPlayerZones->hand->cards[0],
|
||||
currentPlayerZones->hand,
|
||||
currentPlayerZones->library);
|
||||
|
||||
currentPlayerZones->library->shuffle(); //Shuffle
|
||||
|
||||
for (int i = 0; i < (cardsinhand - 1); i++)
|
||||
game->drawFromLibrary();
|
||||
MTGPlayerCards * currentPlayerZones = game;
|
||||
int cardsinhand = currentPlayerZones->hand->nb_cards;
|
||||
for (int i = 0; i < cardsinhand; i++) //Discard hand
|
||||
currentPlayerZones->putInZone(currentPlayerZones->hand->cards[0],
|
||||
currentPlayerZones->hand,
|
||||
currentPlayerZones->library);
|
||||
|
||||
currentPlayerZones->library->shuffle(); //Shuffle
|
||||
|
||||
for (int i = 0; i < (cardsinhand - 1); i++)
|
||||
game->drawFromLibrary();
|
||||
//Draw hand with 1 less card penalty //almhum
|
||||
}
|
||||
|
||||
@@ -197,6 +199,13 @@ void Player::cleanupPhase()
|
||||
game->graveyard->cleanupPhase();
|
||||
}
|
||||
|
||||
std::string Player::GetCurrentDeckStatsFile()
|
||||
{
|
||||
std::ostringstream filename;
|
||||
filename << "stats/" << deckFileSmall << ".txt";
|
||||
return options.profileFile(filename.str());
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& out, const Player& p)
|
||||
{
|
||||
return out << p.getDisplayName();
|
||||
|
||||
Reference in New Issue
Block a user