Jeck - partial revert of r1948, minor optimizations to where validate() is called.
This commit is contained in:
@@ -74,13 +74,11 @@ void GameStateDeckViewer::rebuildFilters(){
|
||||
if(displayed_deck != myDeck) source->swapSrc();
|
||||
filterMenu->Finish(true);
|
||||
updateStats();
|
||||
source->updateCounts();
|
||||
}
|
||||
void GameStateDeckViewer::updateFilters(){
|
||||
if(!displayed_deck) return;
|
||||
filterMenu->recolorFilter(useFilter-1);
|
||||
filterMenu->Finish(true);
|
||||
source->updateCounts();
|
||||
updateStats();
|
||||
return;
|
||||
}
|
||||
@@ -222,6 +220,8 @@ void GameStateDeckViewer::addRemove(MTGCard * card){
|
||||
myCollection->Add(card);
|
||||
}
|
||||
}
|
||||
myCollection->validate();
|
||||
myDeck->validate();
|
||||
stw.needUpdate = true;
|
||||
loadIndexes();
|
||||
}
|
||||
@@ -1028,14 +1028,8 @@ void GameStateDeckViewer::renderOnScreenMenu(){
|
||||
}
|
||||
|
||||
void GameStateDeckViewer::updateStats() {
|
||||
if (!stw.needUpdate || !myDeck) {
|
||||
if (!stw.needUpdate || !myDeck)
|
||||
return;
|
||||
}
|
||||
|
||||
//rmove filters away from the deck to count things correctly
|
||||
WCardFilter* backup = myDeck->unhookFilters();
|
||||
|
||||
myDeck->validate();
|
||||
stw.needUpdate = false;
|
||||
stw.cardCount = myDeck->getCount(WSrcDeck::UNFILTERED_COPIES);
|
||||
stw.countLands = myDeck->getCount(Constants::MTG_COLOR_LAND);
|
||||
@@ -1072,7 +1066,7 @@ void GameStateDeckViewer::updateStats() {
|
||||
}
|
||||
}
|
||||
|
||||
for(int ic=0;ic<myDeck->Size();ic++){
|
||||
for(int ic=0;ic<myDeck->Size(true);ic++){
|
||||
current = myDeck->getCard(ic);
|
||||
currentCost = current->data->getManaCost();
|
||||
convertedCost = currentCost->getConvertedCost();
|
||||
@@ -1188,10 +1182,6 @@ void GameStateDeckViewer::updateStats() {
|
||||
stw.noLandsProbInTurn[i] = noLuck(stw.cardCount, stw.countLands, 7+i)*100;
|
||||
stw.noCreaturesProbInTurn[i] = noLuck(stw.cardCount, stw.countCreatures, 7+i)*100;
|
||||
}
|
||||
|
||||
//put filters back;
|
||||
myDeck->addFilter(backup);
|
||||
myDeck->validate();
|
||||
}
|
||||
|
||||
// This should probably be cached in DeckDataWrapper
|
||||
@@ -1376,10 +1366,12 @@ int GameStateDeckViewer::loadDeck(int deckid){
|
||||
|
||||
// Check whether the cards in the deck are actually available in the player's collection:
|
||||
int cheatmode = options[Options::CHEATMODE].number;
|
||||
for(int i=0;i<myDeck->Size();i++){
|
||||
MTGCard * current = myDeck->getCard(i);
|
||||
bool bPure = true;
|
||||
for(int i=0;i<myDeck->Size(true);i++){
|
||||
MTGCard * current = myDeck->getCard(i,true);
|
||||
int howmanyinDeck = myDeck->count(current);
|
||||
for (int i = myCollection->count(current); i < howmanyinDeck; i++){
|
||||
bPure = false;
|
||||
if(cheatmode){ //Are we cheating?
|
||||
playerdata->collection->add(current); //Yup, add it to collection permanently.
|
||||
myCollection->Add(current);
|
||||
@@ -1391,6 +1383,10 @@ int GameStateDeckViewer::loadDeck(int deckid){
|
||||
}
|
||||
|
||||
myCollection->Remove(current,myDeck->count(current));
|
||||
}
|
||||
if(!bPure){
|
||||
myDeck->validate();
|
||||
myCollection->validate();
|
||||
}
|
||||
// Load deck statistics
|
||||
// TODO: Code cleanup (Copypasted with slight changes from GameStateMenu.cpp)
|
||||
@@ -1525,6 +1521,7 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
|
||||
pricelist->setPrice(card->getMTGId(),price*2);
|
||||
playerdata->collection->remove(card->getMTGId());
|
||||
displayed_deck->Remove(card,1);
|
||||
displayed_deck->validate();
|
||||
loadIndexes();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,6 @@ int WSrcCards::loadMatches(MTGAllCards* ac){
|
||||
}
|
||||
}
|
||||
validate();
|
||||
updateCounts();
|
||||
return count;
|
||||
}
|
||||
int WSrcCards::loadMatches(MTGDeck * deck){
|
||||
@@ -139,7 +138,6 @@ int WSrcCards::loadMatches(MTGDeck * deck){
|
||||
}
|
||||
}
|
||||
validate();
|
||||
updateCounts();
|
||||
return count;
|
||||
}
|
||||
int WSrcCards::loadMatches(WSrcCards* src, bool all){
|
||||
@@ -160,7 +158,6 @@ int WSrcCards::loadMatches(WSrcCards* src, bool all){
|
||||
}
|
||||
src->setOffset(oldp);
|
||||
validate();
|
||||
updateCounts();
|
||||
return count;
|
||||
}
|
||||
int WSrcCards::addRandomCards(MTGDeck * i, int howmany){
|
||||
@@ -276,6 +273,8 @@ void WSrcCards::Shuffle(){
|
||||
}
|
||||
void WSrcCards::validate(){
|
||||
validated.clear();
|
||||
updateCounts();
|
||||
if(!filtersRoot) return;
|
||||
for(size_t t=0;t<cards.size();t++){
|
||||
if(matchesFilters(cards[t]))
|
||||
validated.push_back(t);
|
||||
@@ -310,7 +309,6 @@ void WSrcCards::addFilter(WCardFilter * f) {
|
||||
else
|
||||
filtersRoot = NEW WCFilterAND(f,filtersRoot);
|
||||
validate();
|
||||
updateCounts();
|
||||
currentPos = 0;
|
||||
}
|
||||
float WSrcCards::filterFee(){
|
||||
@@ -385,7 +383,6 @@ int WSrcDeck::loadMatches(MTGDeck * deck){
|
||||
}
|
||||
}
|
||||
validate();
|
||||
updateCounts();
|
||||
return count;
|
||||
}
|
||||
void WSrcDeck::updateCounts(){
|
||||
@@ -406,26 +403,28 @@ void WSrcDeck::clearCounts(){
|
||||
}
|
||||
void WSrcDeck::addCount(MTGCard * c, int qty){
|
||||
if(!c || !c->data) return;
|
||||
map<int,int>::iterator cp = copies.find(c->getMTGId());
|
||||
|
||||
if(matchesFilters(c)){
|
||||
counts[FILTERED_COPIES]+=qty;
|
||||
counts[FILTERED_UNIQUE]+=qty;
|
||||
if(qty > 1 && cp != copies.end() && (*cp).second == qty ) counts[FILTERED_UNIQUE]++;
|
||||
else if(qty < 1 && (cp == copies.end() || (*cp).second == 0) ) counts[FILTERED_UNIQUE]--;
|
||||
}
|
||||
counts[UNFILTERED_COPIES] += qty;
|
||||
counts[UNFILTERED_UNIQUE]+=qty;
|
||||
if(qty > 1 && cp != copies.end() && (*cp).second == qty ) counts[UNFILTERED_UNIQUE]++;
|
||||
else if(qty < 1 && (cp == copies.end() || (*cp).second == 0) ) counts[UNFILTERED_UNIQUE]--;
|
||||
for(int i=Constants::MTG_COLOR_ARTIFACT;i<=Constants::MTG_COLOR_LAND;i++)
|
||||
if (c->data->hasColor(i)) counts[i]+= qty;
|
||||
if(counts[UNFILTERED_MIN_COPIES] < 0 || qty < counts[UNFILTERED_MIN_COPIES]) counts[UNFILTERED_MIN_COPIES] = qty;
|
||||
if(qty > counts[UNFILTERED_MAX_COPIES]) counts[UNFILTERED_MAX_COPIES] = qty;
|
||||
|
||||
}
|
||||
int WSrcDeck::Add(MTGCard * c, int quantity){
|
||||
if(!c)
|
||||
return 0;
|
||||
if(copies.find(c->getMTGId()) == copies.end())
|
||||
cards.push_back(c); //FIXME Make sure these two stay synced.
|
||||
if(!c) return 0;
|
||||
if(copies.find(c->getMTGId()) == copies.end()){
|
||||
cards.push_back(c);
|
||||
}
|
||||
copies[c->getMTGId()] += quantity;
|
||||
addCount(c,quantity);
|
||||
validate();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -444,7 +443,6 @@ int WSrcDeck::Remove(MTGCard * c, int quantity, bool erase){
|
||||
if(i != cards.end())
|
||||
cards.erase(i);
|
||||
}
|
||||
validate();
|
||||
addCount(c,-quantity);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user