From 14f65c55b5c627374c3ba19f567670ff7c3b08ef Mon Sep 17 00:00:00 2001 From: zethfoxster Date: Sat, 9 Jul 2016 00:48:08 -0400 Subject: [PATCH] going to try only updating affinity() when cards move from anywhere to anywhere to help minimize the calls to this function. this atleast allows me to debug albeit slowly the follow issue ive been working to fix. not sure when this was introduced but it was not happening when i first coded this function. manacost->copy() did not slow the game to a crawl. anyways, trinisphere and any card containing other={H(land[basic]|mybattlefield)}{1} name(Pay /1/ and Return a Basic Land to Hand) cost such as this with a CD tc. --- projects/mtg/include/GameObserver.h | 1 + projects/mtg/src/GameObserver.cpp | 33 +++++++++++++++++------------ projects/mtg/src/MTGGameZones.cpp | 1 + 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/projects/mtg/include/GameObserver.h b/projects/mtg/include/GameObserver.h index 0e1a096eb..6b5fddb79 100644 --- a/projects/mtg/include/GameObserver.h +++ b/projects/mtg/include/GameObserver.h @@ -124,6 +124,7 @@ class GameObserver{ void gameStateBasedEffects(); void enchantmentStatus(); void Affinity(); + bool AffinityNeedsUpdate; void addObserver(MTGAbility * observer); bool removeObserver(ActionElement * observer); void startGame(GameType, Rules * rules); diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 28801ae3c..9db6fbdb9 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -53,6 +53,7 @@ void GameObserver::cleanup() actionsList.clear(); gameTurn.clear(); OpenedDisplay = NULL; + AffinityNeedsUpdate = false; } GameObserver::~GameObserver() @@ -1092,20 +1093,22 @@ void GameObserver::Affinity() NewAffinityFound = true; } } - bool DoReduceIncrease = false; - if (card->has(Constants::AFFINITYARTIFACTS) || - card->has(Constants::AFFINITYFOREST) || - card->has(Constants::AFFINITYGREENCREATURES) || - card->has(Constants::AFFINITYISLAND) || - card->has(Constants::AFFINITYMOUNTAIN) || - card->has(Constants::AFFINITYPLAINS) || - card->has(Constants::AFFINITYSWAMP) || - card->has(Constants::TRINISPHERE) || - card->getIncreasedManaCost()->getConvertedCost() || - card->getReducedManaCost()->getConvertedCost() || - NewAffinityFound) - DoReduceIncrease = true; - if (!DoReduceIncrease) + //bool DoReduceIncrease = false; + //if (card->has(Constants::AFFINITYARTIFACTS) || + // card->has(Constants::AFFINITYFOREST) || + // card->has(Constants::AFFINITYGREENCREATURES) || + // card->has(Constants::AFFINITYISLAND) || + // card->has(Constants::AFFINITYMOUNTAIN) || + // card->has(Constants::AFFINITYPLAINS) || + // card->has(Constants::AFFINITYSWAMP) || + // card->has(Constants::TRINISPHERE) || + // card->getIncreasedManaCost()->getConvertedCost() || + // card->getReducedManaCost()->getConvertedCost() || + // NewAffinityFound) + // DoReduceIncrease = true; + //if (!DoReduceIncrease) + // continue; + if(!AffinityNeedsUpdate)//we only adjust cost when cards move from anywhere to anywhere. continue; //above we check if there are even any cards that effect cards manacost //if there are none, leave this function. manacost->copy( is a very expensive funtion @@ -1117,6 +1120,7 @@ void GameObserver::Affinity() card->getManaCost()->resetCosts(); ManaCost *newCost = NEW ManaCost(); newCost->copy(card->computeNewCost(card, card->getManaCost(), card->model->data->getManaCost())); + card->getManaCost()->copy(newCost); SAFE_DELETE(newCost); if (card->getManaCost()->getAlternative()) @@ -1171,6 +1175,7 @@ void GameObserver::Affinity() }//end } } + AffinityNeedsUpdate = false; } void GameObserver::Render() diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 8e995dd69..18e697aba 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -328,6 +328,7 @@ MTGCardInstance * MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone bool shufflelibrary = card->basicAbilities[(int)Constants::SHUFFLELIBRARYDEATH]; bool inplaytoinplay = false; bool ripToken = false; + g->AffinityNeedsUpdate = true;//we refresh affinity whenever a card is moved from anywhere to anywhere. if (g->players[0]->game->battlefield->hasName("Rest in Peace")||g->players[1]->game->battlefield->hasName("Rest in Peace")) ripToken = true; //Madness or Put in Play...