Jeck - partial revert of r1948, minor optimizations to where validate() is called.

This commit is contained in:
wagic.jeck
2010-03-02 03:05:26 +00:00
parent c09dabfdbf
commit 034e61e9fa
2 changed files with 25 additions and 30 deletions
+13 -16
View File
@@ -74,13 +74,11 @@ void GameStateDeckViewer::rebuildFilters(){
if(displayed_deck != myDeck) source->swapSrc(); if(displayed_deck != myDeck) source->swapSrc();
filterMenu->Finish(true); filterMenu->Finish(true);
updateStats(); updateStats();
source->updateCounts();
} }
void GameStateDeckViewer::updateFilters(){ void GameStateDeckViewer::updateFilters(){
if(!displayed_deck) return; if(!displayed_deck) return;
filterMenu->recolorFilter(useFilter-1); filterMenu->recolorFilter(useFilter-1);
filterMenu->Finish(true); filterMenu->Finish(true);
source->updateCounts();
updateStats(); updateStats();
return; return;
} }
@@ -222,6 +220,8 @@ void GameStateDeckViewer::addRemove(MTGCard * card){
myCollection->Add(card); myCollection->Add(card);
} }
} }
myCollection->validate();
myDeck->validate();
stw.needUpdate = true; stw.needUpdate = true;
loadIndexes(); loadIndexes();
} }
@@ -1028,14 +1028,8 @@ void GameStateDeckViewer::renderOnScreenMenu(){
} }
void GameStateDeckViewer::updateStats() { void GameStateDeckViewer::updateStats() {
if (!stw.needUpdate || !myDeck) { if (!stw.needUpdate || !myDeck)
return; return;
}
//rmove filters away from the deck to count things correctly
WCardFilter* backup = myDeck->unhookFilters();
myDeck->validate();
stw.needUpdate = false; stw.needUpdate = false;
stw.cardCount = myDeck->getCount(WSrcDeck::UNFILTERED_COPIES); stw.cardCount = myDeck->getCount(WSrcDeck::UNFILTERED_COPIES);
stw.countLands = myDeck->getCount(Constants::MTG_COLOR_LAND); 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); current = myDeck->getCard(ic);
currentCost = current->data->getManaCost(); currentCost = current->data->getManaCost();
convertedCost = currentCost->getConvertedCost(); convertedCost = currentCost->getConvertedCost();
@@ -1188,10 +1182,6 @@ void GameStateDeckViewer::updateStats() {
stw.noLandsProbInTurn[i] = noLuck(stw.cardCount, stw.countLands, 7+i)*100; stw.noLandsProbInTurn[i] = noLuck(stw.cardCount, stw.countLands, 7+i)*100;
stw.noCreaturesProbInTurn[i] = noLuck(stw.cardCount, stw.countCreatures, 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 // 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: // Check whether the cards in the deck are actually available in the player's collection:
int cheatmode = options[Options::CHEATMODE].number; int cheatmode = options[Options::CHEATMODE].number;
for(int i=0;i<myDeck->Size();i++){ bool bPure = true;
MTGCard * current = myDeck->getCard(i); for(int i=0;i<myDeck->Size(true);i++){
MTGCard * current = myDeck->getCard(i,true);
int howmanyinDeck = myDeck->count(current); int howmanyinDeck = myDeck->count(current);
for (int i = myCollection->count(current); i < howmanyinDeck; i++){ for (int i = myCollection->count(current); i < howmanyinDeck; i++){
bPure = false;
if(cheatmode){ //Are we cheating? if(cheatmode){ //Are we cheating?
playerdata->collection->add(current); //Yup, add it to collection permanently. playerdata->collection->add(current); //Yup, add it to collection permanently.
myCollection->Add(current); myCollection->Add(current);
@@ -1391,6 +1383,10 @@ int GameStateDeckViewer::loadDeck(int deckid){
} }
myCollection->Remove(current,myDeck->count(current)); myCollection->Remove(current,myDeck->count(current));
}
if(!bPure){
myDeck->validate();
myCollection->validate();
} }
// Load deck statistics // Load deck statistics
// TODO: Code cleanup (Copypasted with slight changes from GameStateMenu.cpp) // 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); pricelist->setPrice(card->getMTGId(),price*2);
playerdata->collection->remove(card->getMTGId()); playerdata->collection->remove(card->getMTGId());
displayed_deck->Remove(card,1); displayed_deck->Remove(card,1);
displayed_deck->validate();
loadIndexes(); loadIndexes();
} }
} }
+12 -14
View File
@@ -123,7 +123,6 @@ int WSrcCards::loadMatches(MTGAllCards* ac){
} }
} }
validate(); validate();
updateCounts();
return count; return count;
} }
int WSrcCards::loadMatches(MTGDeck * deck){ int WSrcCards::loadMatches(MTGDeck * deck){
@@ -139,7 +138,6 @@ int WSrcCards::loadMatches(MTGDeck * deck){
} }
} }
validate(); validate();
updateCounts();
return count; return count;
} }
int WSrcCards::loadMatches(WSrcCards* src, bool all){ int WSrcCards::loadMatches(WSrcCards* src, bool all){
@@ -160,7 +158,6 @@ int WSrcCards::loadMatches(WSrcCards* src, bool all){
} }
src->setOffset(oldp); src->setOffset(oldp);
validate(); validate();
updateCounts();
return count; return count;
} }
int WSrcCards::addRandomCards(MTGDeck * i, int howmany){ int WSrcCards::addRandomCards(MTGDeck * i, int howmany){
@@ -276,6 +273,8 @@ void WSrcCards::Shuffle(){
} }
void WSrcCards::validate(){ void WSrcCards::validate(){
validated.clear(); validated.clear();
updateCounts();
if(!filtersRoot) return;
for(size_t t=0;t<cards.size();t++){ for(size_t t=0;t<cards.size();t++){
if(matchesFilters(cards[t])) if(matchesFilters(cards[t]))
validated.push_back(t); validated.push_back(t);
@@ -310,7 +309,6 @@ void WSrcCards::addFilter(WCardFilter * f) {
else else
filtersRoot = NEW WCFilterAND(f,filtersRoot); filtersRoot = NEW WCFilterAND(f,filtersRoot);
validate(); validate();
updateCounts();
currentPos = 0; currentPos = 0;
} }
float WSrcCards::filterFee(){ float WSrcCards::filterFee(){
@@ -385,7 +383,6 @@ int WSrcDeck::loadMatches(MTGDeck * deck){
} }
} }
validate(); validate();
updateCounts();
return count; return count;
} }
void WSrcDeck::updateCounts(){ void WSrcDeck::updateCounts(){
@@ -406,26 +403,28 @@ void WSrcDeck::clearCounts(){
} }
void WSrcDeck::addCount(MTGCard * c, int qty){ void WSrcDeck::addCount(MTGCard * c, int qty){
if(!c || !c->data) return; if(!c || !c->data) return;
map<int,int>::iterator cp = copies.find(c->getMTGId());
if(matchesFilters(c)){ if(matchesFilters(c)){
counts[FILTERED_COPIES]+=qty; 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_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++) for(int i=Constants::MTG_COLOR_ARTIFACT;i<=Constants::MTG_COLOR_LAND;i++)
if (c->data->hasColor(i)) counts[i]+= qty; 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(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; if(qty > counts[UNFILTERED_MAX_COPIES]) counts[UNFILTERED_MAX_COPIES] = qty;
} }
int WSrcDeck::Add(MTGCard * c, int quantity){ int WSrcDeck::Add(MTGCard * c, int quantity){
if(!c) if(!c) return 0;
return 0; if(copies.find(c->getMTGId()) == copies.end()){
if(copies.find(c->getMTGId()) == copies.end()) cards.push_back(c);
cards.push_back(c); //FIXME Make sure these two stay synced. }
copies[c->getMTGId()] += quantity; copies[c->getMTGId()] += quantity;
addCount(c,quantity); addCount(c,quantity);
validate();
return 1; return 1;
} }
@@ -444,7 +443,6 @@ int WSrcDeck::Remove(MTGCard * c, int quantity, bool erase){
if(i != cards.end()) if(i != cards.end())
cards.erase(i); cards.erase(i);
} }
validate();
addCount(c,-quantity); addCount(c,-quantity);
return 1; return 1;
} }