From f68c106e7e4b29c3129066f09ea8f7dfe923e54a Mon Sep 17 00:00:00 2001 From: Xawotihs Date: Sun, 13 Nov 2011 22:36:34 +0000 Subject: [PATCH] - Modified gameObserver and related classes to be able to work with a precise JGE instance given at construction and not the static global one. That allows to run gameObserver without JGE instance (for example in a worker thread). - Added an "ACTION_LOGGING_TESTING" mode in the gameObserver. When this is defined, the game reloads itself in every update. I want to use that to track undo problems. Be aware that it kills performances and crashes with the testsuite if you want to activate it. - Various cleanup/refactor of the game observer. - Added a gameObserver == operator to compare two games - Added player mode to the player serialization - Added a multi-threaded mode to AI_CHANGE_TESTING. For the moment it's only useable with Qt. If you want to use it without, just defined a thread_count higher than 1. - Refactored random generator class to use list intead of queue - Defined a specific type for interrupt decision instead of int --- projects/mtg/include/ActionStack.h | 21 +-- projects/mtg/include/GameObserver.h | 16 ++- projects/mtg/include/GameStateDuel.h | 14 ++ projects/mtg/include/IconButton.h | 2 +- projects/mtg/include/Player.h | 4 +- projects/mtg/include/SimpleMenu.h | 2 +- projects/mtg/include/utils.h | 4 +- projects/mtg/src/AIPlayer.cpp | 6 +- projects/mtg/src/AIPlayerBaka.cpp | 11 +- projects/mtg/src/ActionLayer.cpp | 4 +- projects/mtg/src/ActionStack.cpp | 22 ++-- projects/mtg/src/AllAbilities.cpp | 25 ++-- projects/mtg/src/CardDisplay.cpp | 5 +- projects/mtg/src/CardSelector.cpp | 6 +- projects/mtg/src/DeckMenu.cpp | 2 +- projects/mtg/src/DuelLayers.cpp | 21 +-- projects/mtg/src/GameObserver.cpp | 161 +++++++++++++++++++---- projects/mtg/src/GameStateAwards.cpp | 2 +- projects/mtg/src/GameStateDeckViewer.cpp | 2 +- projects/mtg/src/GameStateDuel.cpp | 50 ++++++- projects/mtg/src/GameStateMenu.cpp | 8 +- projects/mtg/src/GameStateOptions.cpp | 2 +- projects/mtg/src/GameStateShop.cpp | 10 +- projects/mtg/src/GameStateStory.cpp | 4 +- projects/mtg/src/GuiCombat.cpp | 2 +- projects/mtg/src/IconButton.cpp | 2 +- projects/mtg/src/OptionItem.cpp | 2 +- projects/mtg/src/Player.cpp | 1 + projects/mtg/src/SimpleMenu.cpp | 4 +- projects/mtg/src/SimplePopup.cpp | 2 +- projects/mtg/src/StoryFlow.cpp | 4 +- projects/mtg/src/WGui.cpp | 10 +- projects/mtg/src/utils.cpp | 30 ++--- 33 files changed, 320 insertions(+), 141 deletions(-) diff --git a/projects/mtg/include/ActionStack.h b/projects/mtg/include/ActionStack.h index 03c9ec1a2..ee9b81328 100644 --- a/projects/mtg/include/ActionStack.h +++ b/projects/mtg/include/ActionStack.h @@ -190,9 +190,18 @@ public: class ActionStack :public GuiLayer { +public: + typedef enum + { + NOT_DECIDED = 0, + INTERRUPT = -1, + DONT_INTERRUPT = 1, + DONT_INTERRUPT_ALL = 2 + } InterruptDecision; + protected: JQuadPtr pspIcons[8]; - int interruptDecision[2]; + InterruptDecision interruptDecision[2]; float timer; int currentState; int mode; @@ -201,13 +210,6 @@ protected: public: - enum - { - NOT_DECIDED = 0, - INTERRUPT = -1, - DONT_INTERRUPT = 1, - DONT_INTERRUPT_ALL = 2, - }; Player * lastActionController; int setIsInterrupting(Player * player, bool log = true); int count( int type = 0 , int state = 0 , int display = -1); @@ -218,7 +220,7 @@ public: int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1); void Fizzle(Interruptible * action); Interruptible * getAt(int id); - void cancelInterruptOffer(int cancelMode = 1, bool log = true); + void cancelInterruptOffer(InterruptDecision cancelMode = DONT_INTERRUPT, bool log = true); void endOfInterruption(bool log = true); Interruptible * getLatest(int state); Player * askIfWishesToInterrupt; @@ -245,6 +247,7 @@ public: #endif void setCurrentTutorial(ATutorialMessage* message) {currentTutorial = message;}; ATutorialMessage* getCurrentTutorial() {return currentTutorial;}; + bool isCalm() {return interruptDecision[0] == NOT_DECIDED && interruptDecision[1] == NOT_DECIDED;}; }; #endif diff --git a/projects/mtg/include/GameObserver.h b/projects/mtg/include/GameObserver.h index 91d421fcd..3dfff8efe 100644 --- a/projects/mtg/include/GameObserver.h +++ b/projects/mtg/include/GameObserver.h @@ -34,10 +34,16 @@ class GameObserver{ // used when we're loading to know what to load list loadingList; list::iterator loadingite; + RandomGenerator randomGenerator; + WResourceManager* mResourceManager; + JGE* mJGE; + size_t updateCtr; +#ifdef ACTION_LOGGING_TESTING + GameObserver* oldGame; +#endif //ACTION_LOGGING_TESTING int untap(MTGCardInstance * card); bool WaitForExtraPayment(MTGCardInstance* card); - void initialize(); void cleanup(); string startupGameSerialized; bool parseLine(const string& s); @@ -47,8 +53,7 @@ class GameObserver{ bool mLoading; void nextGamePhase(); void shuffleLibrary(Player* p); - RandomGenerator randomGenerator; - WResourceManager* mResourceManager; + void createPlayer(const string& playerMode); public: int currentPlayerId; @@ -97,7 +102,7 @@ class GameObserver{ Player * isInterrupting; Player * opponent(); Player * currentlyActing(); - GameObserver(WResourceManager* resourceManager = NULL); + GameObserver(WResourceManager* output = 0, JGE* input = 0); ~GameObserver(); void gameStateBasedEffects(); void enchantmentStatus(); @@ -132,6 +137,9 @@ class GameObserver{ RandomGenerator* getRandomGenerator() { return &randomGenerator; }; WResourceManager* getResourceManager() { if(this) return mResourceManager;else return 0;}; CardSelectorBase* getCardSelector() { return mLayers->mCardSelector;}; + bool operator==(const GameObserver& aGame); + JGE* getInput(){return mJGE;}; + }; #endif diff --git a/projects/mtg/include/GameStateDuel.h b/projects/mtg/include/GameStateDuel.h index 32130f22f..2796d7937 100644 --- a/projects/mtg/include/GameStateDuel.h +++ b/projects/mtg/include/GameStateDuel.h @@ -7,6 +7,10 @@ #include "DeckMenu.h" #include "MTGDeck.h" #include "GameObserver.h" +#ifdef AI_CHANGE_TESTING +#include "Threading.h" +#endif //AI_CHANGE_TESTING + #define CHOOSE_OPPONENT 7 @@ -56,6 +60,16 @@ public: int totalTestGames; int testPlayer2Victories; int totalAIDecks; + static boost::mutex mMutex; + vector mWorkerThread; + static void ThreadProc(void* inParam); + void handleResults(GameObserver* aGame){ + mMutex.lock(); + totalTestGames++; + if (aGame->gameOver == aGame->players[0]) + testPlayer2Victories++; + mMutex.unlock(); + }; #endif virtual void ButtonPressed(int ControllerId, int ControlId); diff --git a/projects/mtg/include/IconButton.h b/projects/mtg/include/IconButton.h index 643fae687..8a406c411 100644 --- a/projects/mtg/include/IconButton.h +++ b/projects/mtg/include/IconButton.h @@ -11,7 +11,7 @@ class IconButtonsController: public JGuiController, public JGuiListener public: float mX; float mY; - IconButtonsController(float x, float y); + IconButtonsController(JGE* jge, float x, float y); void SetColor(PIXEL_TYPE color); }; diff --git a/projects/mtg/include/Player.h b/projects/mtg/include/Player.h index 8835cd7fe..28ba1d754 100644 --- a/projects/mtg/include/Player.h +++ b/projects/mtg/include/Player.h @@ -21,7 +21,7 @@ protected: bool premade; public: - enum ENUM_PLAY_MODE + enum Mode { MODE_TEST_SUITE, MODE_HUMAN, @@ -29,7 +29,7 @@ public: }; string mAvatarName; - int playMode; + Mode playMode; bool nomaxhandsize; MTGPlayerCards * game; MTGDeck * mDeck; diff --git a/projects/mtg/include/SimpleMenu.h b/projects/mtg/include/SimpleMenu.h index c9e1786f7..7dab22464 100644 --- a/projects/mtg/include/SimpleMenu.h +++ b/projects/mtg/include/SimpleMenu.h @@ -37,7 +37,7 @@ private: public: bool autoTranslate; bool isMultipleChoice; - SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title = "", int _maxItems = 7, bool centerHorizontal = true, bool centerVertical = true); + SimpleMenu(JGE*, int id, JGuiListener* listener, int fontId, float x, float y, const char * _title = "", int _maxItems = 7, bool centerHorizontal = true, bool centerVertical = true); virtual ~SimpleMenu(); void Render(); void Update(float dt); diff --git a/projects/mtg/include/utils.h b/projects/mtg/include/utils.h index 2fd71cc47..9e77467bf 100644 --- a/projects/mtg/include/utils.h +++ b/projects/mtg/include/utils.h @@ -69,8 +69,8 @@ unsigned long hash_djb2(const char *str); class RandomGenerator { protected: - queue loadedRandomValues; - queue usedRandomValues; + list loadedRandomValues; + list usedRandomValues; bool log; public: RandomGenerator(bool doLog = false) : log(doLog) {}; diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 86f185793..d45cc6a90 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -29,12 +29,14 @@ AIAction::AIAction(AIPlayer * owner, MTGCardInstance * c, MTGCardInstance * t) if (owner->getObserver()->getCardSelector()->GetDrawMode() != DrawMode::kText) { //DebugTrace("Prefetching AI card going into play: " << c->getImageName()); - owner->getObserver()->getResourceManager()->RetrieveCard(c, RETRIEVE_THUMB); + if(owner->getObserver()->getResourceManager()) + owner->getObserver()->getResourceManager()->RetrieveCard(c, RETRIEVE_THUMB); // also cache the large image if we're using kNormal mode if (owner->getObserver()->getCardSelector()->GetDrawMode() == DrawMode::kNormal) { - owner->getObserver()->getResourceManager()->RetrieveCard(c); + if(owner->getObserver()->getResourceManager()) + owner->getObserver()->getResourceManager()->RetrieveCard(c); } } } diff --git a/projects/mtg/src/AIPlayerBaka.cpp b/projects/mtg/src/AIPlayerBaka.cpp index a7bcfe81b..8a124db6e 100644 --- a/projects/mtg/src/AIPlayerBaka.cpp +++ b/projects/mtg/src/AIPlayerBaka.cpp @@ -1223,7 +1223,7 @@ int AIPlayerBaka::createAbilityTargets(MTGAbility * a, MTGCardInstance * c, Rank if(!realTargets.size() || (int(realTargets.size()) < a->getActionTc()->maxtargets && a->getActionTc()->targetMin)) return 0; OrderedAIAction aiAction(this, a, c,realTargets); - aiAction.target = (MTGCardInstance*)realTargets[0]; + aiAction.target = dynamic_cast(realTargets[0]); ranking[aiAction] = 1; } return 1; @@ -1770,6 +1770,7 @@ int AIPlayerBaka::computeActions() return 1; } +#ifndef AI_CHANGE_TESTING static bool findingCard = false; //this guard is put in place to prevent Ai from //ever running computeActions() function WHILE its already doing so. @@ -1779,6 +1780,8 @@ int AIPlayerBaka::computeActions() {//is already looking kick me out of this function! return 0; } +#endif //AI_CHANGE_TESTING + Interruptible * action = observer->mLayers->stackLayer()->getAt(-1); Spell * spell = dynamic_cast(action); Player * lastStackActionController = spell ? spell->source->controller() : NULL; @@ -1791,7 +1794,9 @@ int AIPlayerBaka::computeActions() bool ipotential = false; if(p->game->hand->hasType("instant") || p->game->hand->hasAbility(Constants::FLASH)) { +#ifndef AI_CHANGE_TESTING findingCard = true; +#endif //AI_CHANGE_TESTING ManaCost * icurrentMana = getPotentialMana(); icurrentMana->add(this->getManaPool()); if (icurrentMana->getConvertedCost()) @@ -1822,12 +1827,16 @@ int AIPlayerBaka::computeActions() gotPayments.clear(); } } +#ifndef AI_CHANGE_TESTING findingCard = false; +#endif //AI_CHANGE_TESTING nextCardToPlay = NULL; return 1; } nextCardToPlay = NULL; +#ifndef AI_CHANGE_TESTING findingCard = false; +#endif //AI_CHANGE_TESTING return 1; } else if(observer->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) diff --git a/projects/mtg/src/ActionLayer.cpp b/projects/mtg/src/ActionLayer.cpp index d778bfbc9..e9db9ef8f 100644 --- a/projects/mtg/src/ActionLayer.cpp +++ b/projects/mtg/src/ActionLayer.cpp @@ -349,7 +349,7 @@ void ActionLayer::setMenuObject(Targetable * object, bool must) SAFE_DELETE(abilitiesMenu); - abilitiesMenu = NEW SimpleMenu(10, this, Fonts::MAIN_FONT, 100, 100, object->getDisplayName().c_str()); + abilitiesMenu = NEW SimpleMenu(observer->getInput(), 10, this, Fonts::MAIN_FONT, 100, 100, object->getDisplayName().c_str()); currentActionCard = NULL; for (size_t i = 0; i < mObjects.size(); i++) { @@ -375,7 +375,7 @@ void ActionLayer::setCustomMenuObject(Targetable * object, bool must,vectorgetDisplayName().c_str()); + abilitiesMenu = NEW SimpleMenu(observer->getInput(), 10, this, Fonts::MAIN_FONT, 100, 100, object->getDisplayName().c_str()); currentActionCard = NULL; abilitiesMenu->isMultipleChoice = false; if(abilities.size()) diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index 798889141..020103499 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -553,7 +553,7 @@ int ActionStack::AddNextGamePhase() NextGamePhase * next = NEW NextGamePhase(observer, mObjects.size()); addAction(next); int playerId = (observer->currentActionPlayer == observer->players[1]) ? 1 : 0; - interruptDecision[playerId] = 1; + interruptDecision[playerId] = DONT_INTERRUPT; return 1; } @@ -573,7 +573,7 @@ int ActionStack::setIsInterrupting(Player * player, bool log) if (!gModRules.game.canInterrupt()) { - cancelInterruptOffer(1, log); + cancelInterruptOffer(DONT_INTERRUPT, log); return 0; } @@ -586,7 +586,7 @@ int ActionStack::setIsInterrupting(Player * player, bool log) } int playerId = (player == observer->players[1]) ? 1 : 0; - interruptDecision[playerId] = -1; + interruptDecision[playerId] = INTERRUPT; observer->isInterrupting = player; if(log) observer->logAction(player, "yes"); @@ -597,7 +597,7 @@ int ActionStack::addAction(Interruptible * action) { for (int i = 0; i < 2; i++) { - interruptDecision[i] = 0; + interruptDecision[i] = NOT_DECIDED; } Add(action); lastActionController = observer->currentlyActing(); @@ -634,7 +634,7 @@ ActionStack::ActionStack(GameObserver* game) : GuiLayer(game), currentTutorial(0) { for (int i = 0; i < 2; i++) - interruptDecision[i] = 0; + interruptDecision[i] = NOT_DECIDED; askIfWishesToInterrupt = NULL; timer = -1; currentState = -1; @@ -698,15 +698,15 @@ int ActionStack::resolve() for (int i = 0; i < 2; i++) { if (interruptDecision[i] != 2) - interruptDecision[i] = 0; + interruptDecision[i] = NOT_DECIDED; } } else { for (int i = 0; i < 2; i++) { - if (interruptDecision[i] != 2) - interruptDecision[i] = 0; + if (interruptDecision[i] != DONT_INTERRUPT_ALL) + interruptDecision[i] = NOT_DECIDED; } } lastActionController = NULL; @@ -955,7 +955,7 @@ void ActionStack::Update(float dt) } } -void ActionStack::cancelInterruptOffer(int cancelMode, bool log) +void ActionStack::cancelInterruptOffer(InterruptDecision cancelMode, bool log) { int playerId = (observer->isInterrupting == observer->players[1]) ? 1 : 0; interruptDecision[playerId] = cancelMode; @@ -969,7 +969,7 @@ void ActionStack::cancelInterruptOffer(int cancelMode, bool log) void ActionStack::endOfInterruption(bool log) { int playerId = (observer->isInterrupting == observer->players[1]) ? 1 : 0; - interruptDecision[playerId] = 0; + interruptDecision[playerId] = NOT_DECIDED; observer->isInterrupting = NULL; if(log) observer->logAction(playerId, "endinterruption"); @@ -994,7 +994,7 @@ bool ActionStack::CheckUserInput(JButton key) } else if ((JGE_BTN_PRI == key)) { - cancelInterruptOffer(2); + cancelInterruptOffer(DONT_INTERRUPT_ALL); return true; } return true; diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 5f67f7a90..8fada24ef 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -2359,7 +2359,7 @@ int MenuAbility::reactToChoiceClick(Targetable * object,int choice,int control) mClone->resolve(); SAFE_DELETE(mClone); if (source->controller() == game->isInterrupting) - game->mLayers->stackLayer()->cancelInterruptOffer(1, false); + game->mLayers->stackLayer()->cancelInterruptOffer(ActionStack::DONT_INTERRUPT, false); this->forceDestroy = 1; removeMenu = true; return reactToTargetClick(object); @@ -3913,7 +3913,7 @@ AAConnect * AAConnect::clone() const //Tutorial Messaging ATutorialMessage::ATutorialMessage(GameObserver* observer, MTGCardInstance * source, string message, int limit) - : MTGAbility(observer, 0, source), IconButtonsController(0, 0), mLimit(limit) + : MTGAbility(observer, 0, source), IconButtonsController(observer->getInput(), 0, 0), mLimit(limit) { mBgTex = NULL; @@ -3923,16 +3923,19 @@ ATutorialMessage::ATutorialMessage(GameObserver* observer, MTGCardInstance * sou for (int i = 0; i < 9; i++) mBg[i] = NULL; - string gfx = game->getResourceManager()->graphicsFile(message); - if (fileExists(gfx.c_str())) + if(game->getResourceManager()) { - mIsImage = true; - mMessage = message; - } - else - { - mMessage = _(message); //translate directly here, remove this and translate at rendering time if it bites us - boost::replace_all(mMessage, "\\n", "\n"); + string gfx = game->getResourceManager()->graphicsFile(message); + if (fileExists(gfx.c_str())) + { + mIsImage = true; + mMessage = message; + } + else + { + mMessage = _(message); //translate directly here, remove this and translate at rendering time if it bites us + boost::replace_all(mMessage, "\\n", "\n"); + } } if (mIsImage) diff --git a/projects/mtg/src/CardDisplay.cpp b/projects/mtg/src/CardDisplay.cpp index e9b9c3159..cef314bba 100644 --- a/projects/mtg/src/CardDisplay.cpp +++ b/projects/mtg/src/CardDisplay.cpp @@ -178,7 +178,8 @@ bool CardDisplay::CheckUserInput(JButton key) int n = mCurr; int x1,y1; JButton key; - if (JGE::GetInstance()->GetLeftClickCoordinates(x1, y1)) + JGE* jge = observer->getInput(); + if (jge && jge->GetLeftClickCoordinates(x1, y1)) { for (size_t i = 0; i < mObjects.size(); i++) { @@ -218,7 +219,7 @@ bool CardDisplay::CheckUserInput(JButton key) mObjects[mCurr]->Entering(); result = true; } - JGE::GetInstance()->LeftClickedProcessed(); + jge->LeftClickedProcessed(); } return result; } diff --git a/projects/mtg/src/CardSelector.cpp b/projects/mtg/src/CardSelector.cpp index cefde2f3d..2b8587ee2 100644 --- a/projects/mtg/src/CardSelector.cpp +++ b/projects/mtg/src/CardSelector.cpp @@ -187,7 +187,9 @@ bool CardSelector::CheckUserInput(JButton key) Target* oldactive = active; int x,y; - if(JGE::GetInstance()->GetLeftClickCoordinates(x, y)) + JGE* jge = observer->getInput(); + if(!jge) return false; + if(jge->GetLeftClickCoordinates(x, y)) { active = closest (cards, limitor, static_cast (x), static_cast (y)); } @@ -223,7 +225,7 @@ bool CardSelector::CheckUserInput(JButton key) return true; default: { - if(!JGE::GetInstance()->GetLeftClickCoordinates(x, y)) + if(!jge->GetLeftClickCoordinates(x, y)) { return false; } diff --git a/projects/mtg/src/DeckMenu.cpp b/projects/mtg/src/DeckMenu.cpp index 181b0870c..37145a799 100644 --- a/projects/mtg/src/DeckMenu.cpp +++ b/projects/mtg/src/DeckMenu.cpp @@ -34,7 +34,7 @@ hgeParticleSystem* DeckMenu::stars = NULL; // *** Need to make this configurable in a file somewhere to allow for class reuse DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _title, const int& startIndex, bool showDetailsOverride) : -JGuiController(id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOverride ) +JGuiController(JGE::GetInstance(), id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOverride ) { backgroundName = "DeckMenuBackdrop"; diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index 89333bc5c..9b8412df5 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -43,36 +43,39 @@ void DuelLayers::CheckUserInput(int isAI) { JButton key; int x, y; - while ((key = JGE::GetInstance()->ReadButton()) || JGE::GetInstance()->GetLeftClickCoordinates(x, y)) + JGE* jge = observer->getInput(); + if(!jge) return; + + while ((key = jge->ReadButton()) || jge->GetLeftClickCoordinates(x, y)) { - if ((!isAI) && ((0 != key) || JGE::GetInstance()->GetLeftClickCoordinates(x, y))) + if ((!isAI) && ((0 != key) || jge->GetLeftClickCoordinates(x, y))) { if (stack->CheckUserInput(key)) { - JGE::GetInstance()->LeftClickedProcessed(); + jge->LeftClickedProcessed(); break; } if (combat->CheckUserInput(key)) { - JGE::GetInstance()->LeftClickedProcessed(); + jge->LeftClickedProcessed(); break; } if (avatars->CheckUserInput(key)) { - JGE::GetInstance()->LeftClickedProcessed(); + jge->LeftClickedProcessed(); break; //avatars need to check their input before action (CTRL_CROSS) } if (action->CheckUserInput(key)) { - JGE::GetInstance()->LeftClickedProcessed(); + jge->LeftClickedProcessed(); break; } if (hand->CheckUserInput(key)) { - JGE::GetInstance()->LeftClickedProcessed(); + jge->LeftClickedProcessed(); break; } if (mCardSelector->CheckUserInput(key)) { - JGE::GetInstance()->LeftClickedProcessed(); + jge->LeftClickedProcessed(); break; } } - JGE::GetInstance()->LeftClickedProcessed(); + jge->LeftClickedProcessed(); } } diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 10c98362c..8d5aff325 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -17,28 +17,6 @@ #include "TestSuiteAI.h" #endif -void GameObserver::initialize() -{ - mGameType = GAME_TYPE_CLASSIC; - currentPlayer = NULL; - currentActionPlayer = NULL; - isInterrupting = NULL; - currentPlayerId = 0; - currentGamePhase = -1; - targetChooser = NULL; - cardWaitingForTargets = NULL; - mExtraPayment = NULL; - gameOver = NULL; - phaseRing = NULL; - replacementEffects = NEW ReplacementEffects(); - combatStep = BLOCKERS; - mRules = NULL; - connectRule = false; - mLoading = false; - mLayers = NULL; - mTrash = new Trash(); -} - void GameObserver::cleanup() { SAFE_DELETE(targetChooser); @@ -69,6 +47,10 @@ void GameObserver::cleanup() GameObserver::~GameObserver() { +#ifdef ACTION_LOGGING_TESTING + if(oldGame) SAFE_DELETE(oldGame); +#endif //ACTION_LOGGING_TESTING + LOG("==Destroying GameObserver=="); for (size_t i = 0; i < players.size(); ++i) { @@ -89,13 +71,34 @@ GameObserver::~GameObserver() SAFE_DELETE(mTrash); } -GameObserver::GameObserver(WResourceManager *resourceManager) - : randomGenerator(true), mResourceManager(resourceManager) +GameObserver::GameObserver(WResourceManager *output, JGE* input) + : randomGenerator(true), mResourceManager(output), mJGE(input) { + updateCtr = 0; +#ifdef ACTION_LOGGING_TESTING + oldGame = 0; +#endif //ACTION_LOGGING_TESTING ExtraRules = new MTGCardInstance[2](); - initialize(); + mGameType = GAME_TYPE_CLASSIC; + currentPlayer = NULL; + currentActionPlayer = NULL; + isInterrupting = NULL; + currentPlayerId = 0; + currentGamePhase = -1; + targetChooser = NULL; + cardWaitingForTargets = NULL; + mExtraPayment = NULL; + gameOver = NULL; + phaseRing = NULL; + replacementEffects = NEW ReplacementEffects(); + combatStep = BLOCKERS; + mRules = NULL; + connectRule = false; + mLoading = false; + mLayers = NULL; + mTrash = new Trash(); } int GameObserver::getCurrentGamePhase() @@ -417,9 +420,80 @@ bool GameObserver::removeObserver(ActionElement * observer) } +bool GameObserver::operator==(const GameObserver& aGame) +{ + int error = 0; + + if (aGame.currentGamePhase != currentGamePhase) + { + error++; + } + for (int i = 0; i < 2; i++) + { + TestSuiteAI * p = (TestSuiteAI *) (aGame.players[i]); + + if (p->life != players[i]->life) + { + error++; + } + if (p->poisonCount != players[i]->poisonCount) + { + error++; + } + if (!p->getManaPool()->canAfford(players[i]->getManaPool())) + { + error++; + } + if (!players[i]->getManaPool()->canAfford(p->getManaPool())) + { + error++; + } + MTGGameZone * aZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay }; + MTGGameZone * thisZones[] = { players[i]->game->graveyard, + players[i]->game->library, + players[i]->game->hand, + players[i]->game->inPlay }; + for (int j = 0; j < 4; j++) + { + MTGGameZone * zone = aZones[j]; + if (zone->nb_cards != thisZones[j]->nb_cards) + { + error++; + } + for (size_t k = 0; k < (size_t)thisZones[j]->nb_cards; k++) + { + MTGCardInstance* cardToCheck = (kcards.size())?thisZones[j]->cards[k]:0; + MTGCardInstance* card = (kcards.size())?aZones[j]->cards[k]:0; + if(!card || !cardToCheck || cardToCheck->getId() != card->getId()) + { + error++; + } + } + } + } + + return (error == 0); +} + void GameObserver::Update(float dt) { + /*******************/ + updateCtr++; +#ifdef ACTION_LOGGING_TESTING + if(!oldGame || (!(*oldGame == *this) && + !mLoading && mLayers->stackLayer()->isCalm())) + { // constant game check + stringstream stream; + stream << *this; + if(oldGame) SAFE_DELETE(oldGame); + oldGame = new GameObserver(); + oldGame->mRules = mRules; + oldGame->load(stream.str()); + assert(*this == *oldGame); + } +#endif // ACTION_LOGGING_TESTING + /*******************/ Player * player = currentPlayer; if (Constants::MTG_PHASE_COMBATBLOCKERS == currentGamePhase && BLOCKERS == combatStep) { @@ -1368,7 +1442,12 @@ bool GameObserver::load(const string& ss, bool undo) else { if(players.size() == 0 || !players[0]) - players.push_back(new HumanPlayer(this, deckFile, deckFileSmall)); + { + if (s.find("mode=") == 0) + { + createPlayer(s.substr(5)); + } + } players[0]->parseLine(s); } break; @@ -1379,9 +1458,12 @@ bool GameObserver::load(const string& ss, bool undo) } else { - if(players.size() == 1 || !players[1]) { - AIPlayerFactory playerCreator; - players.push_back(playerCreator.createAIPlayer(this, MTGCollection(), players[0])); + if(players.size() == 1 || !players[1]) + { + if (s.find("mode=") == 0) + { + createPlayer(s.substr(5)); + } } players[1]->parseLine(s); } @@ -1556,6 +1638,27 @@ void GameObserver::Mulligan(Player* player) player->takeMulligan(); } +void GameObserver::createPlayer(const string& playerMode) +{ + Player::Mode aMode = (Player::Mode)atoi(playerMode.c_str()); + switch(aMode) + { + case Player::MODE_AI: + AIPlayerFactory playerCreator; + // FIXME: gonna break in AI vs AI mode + players.push_back(playerCreator.createAIPlayer(this, MTGCollection(), players[0])); + break; + case Player::MODE_HUMAN: + players.push_back(new HumanPlayer(this, "", "")); + break; + case Player::MODE_TEST_SUITE: + // FIXME, not real TestPlayer, but we don't care here. + players.push_back(new Player(this, "", "")); + players.back()->playMode = Player::MODE_TEST_SUITE; + break; + } +} + #ifdef TESTSUITE void GameObserver::loadTestSuitePlayer(int playerId, TestSuiteGame* testSuite) { diff --git a/projects/mtg/src/GameStateAwards.cpp b/projects/mtg/src/GameStateAwards.cpp index 104a690cd..b10f70a25 100644 --- a/projects/mtg/src/GameStateAwards.cpp +++ b/projects/mtg/src/GameStateAwards.cpp @@ -184,7 +184,7 @@ void GameStateAwards::Update(float dt) case JGE_BTN_MENU: showMenu = true; SAFE_DELETE(menu); - menu = NEW SimpleMenu(EXIT_AWARDS_MENU, this, Fonts::MENU_FONT, 50, 170); + menu = NEW SimpleMenu(JGE::GetInstance(), EXIT_AWARDS_MENU, this, Fonts::MENU_FONT, 50, 170); if (mState == STATE_DETAILS) menu->Add(kBackToTrophiesID, "Back to Trophies"); menu->Add(kBackToMainMenuID, "Back to Main Menu"); diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 2e3c9bec5..2f277782b 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -454,7 +454,7 @@ void GameStateDeckViewer::Update(float dt) sprintf(buffer, "%s : %i %s", _(card->data->getName()).c_str(), price, _("credits").c_str()); const float menuXOffset = SCREEN_WIDTH_F - 300; const float menuYOffset = SCREEN_HEIGHT_F / 2; - subMenu = NEW SimpleMenu(MENU_CARD_PURCHASE, this, Fonts::MAIN_FONT, menuXOffset, menuYOffset, buffer); + subMenu = NEW SimpleMenu(JGE::GetInstance(), MENU_CARD_PURCHASE, this, Fonts::MAIN_FONT, menuXOffset, menuYOffset, buffer); subMenu->Add(MENU_ITEM_YES, "Yes"); subMenu->Add(MENU_ITEM_NO, "No", "", true); } diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index eb3e853c5..d8e99eaa9 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -119,7 +119,7 @@ void GameStateDuel::Start() renderer->EnableVSync(true); OpponentsDeckid = 0; - game = NEW GameObserver(WResourceManager::Instance()); + game = NEW GameObserver(WResourceManager::Instance(), JGE::GetInstance()); #ifdef TESTSUITE SAFE_DELETE(testSuite); @@ -200,7 +200,7 @@ void GameStateDuel::loadTestSuitePlayers() if (!testSuite) return; initRand(testSuite->seed); SAFE_DELETE(game); - game = new GameObserver(WResourceManager::Instance()); + game = new GameObserver(WResourceManager::Instance(), JGE::GetInstance()); testSuite->setObserver(game); for (int i = 0; i < 2; i++) { @@ -274,6 +274,28 @@ void GameStateDuel::setGamePhase(int newGamePhase) { JGE::GetInstance()->SendCommand("enterduelphase:" + string(stateStrings[mGamePhase])); } +#ifdef AI_CHANGE_TESTING +boost::mutex GameStateDuel::mMutex; + +void GameStateDuel::ThreadProc(void* inParam) +{ + GameStateDuel* instance = reinterpret_cast(inParam); + float counter = 1.0f; + while(instance->mGamePhase != DUEL_STATE_BACK_TO_MAIN_MENU) + { + GameObserver observer; + observer.loadPlayer(0, PLAYER_TYPE_TESTSUITE); + observer.loadPlayer(1, PLAYER_TYPE_TESTSUITE); + observer.startGame(instance->mParent->gameType, instance->mParent->rules); + + while(!observer.gameOver) + observer.Update(counter++); + + instance->handleResults(&observer); + } +} +#endif //AI_CHANGE_TESTING + void GameStateDuel::Update(float dt) { switch (mGamePhase) @@ -421,12 +443,20 @@ void GameStateDuel::Update(float dt) #ifdef AI_CHANGE_TESTING if (mParent->players[0] == PLAYER_TYPE_CPU_TEST && mParent->players[1] == PLAYER_TYPE_CPU_TEST) { - totalTestGames++; - if (game->gameOver == game->players[0]) - testPlayer2Victories++; + handleResults(game); End(); Start(); } + if(mWorkerThread.empty()) + { // "I don't like to wait" mode + size_t thread_count = 1; + #ifdef QT_CONFIG + thread_count = QThread::idealThreadCount(); + #endif + for(size_t i = 0; i < (thread_count-1); i++) + mWorkerThread.push_back(boost::thread(ThreadProc, this)); + } + #endif if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU) { @@ -438,7 +468,7 @@ void GameStateDuel::Update(float dt) { if (!menu) { - menu = NEW SimpleMenu(DUEL_MENU_GAME_MENU, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25, + menu = NEW SimpleMenu(JGE::GetInstance(), DUEL_MENU_GAME_MENU, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25, game->players[1]->deckName.c_str()); int cardsinhand = game->currentPlayer->game->hand->nb_cards; @@ -498,6 +528,14 @@ void GameStateDuel::Update(float dt) case DUEL_STATE_BACK_TO_MAIN_MENU: if (menu) { +#ifdef AI_CHANGE_TESTING + while(mWorkerThread.size()) + { + mWorkerThread.back().join(); + mWorkerThread.pop_back(); + } +#endif //AI_CHANGE_TESTING + menu->Update(dt); if (menu->isClosed()) { diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index 351ecac0b..0cc36d62f 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -353,7 +353,7 @@ void GameStateMenu::setLang(int id) void GameStateMenu::loadLangMenu() { LOG("GameStateMenu::loadLangMenu"); - subMenuController = NEW SimpleMenu(MENU_LANGUAGE_SELECTION, this, Fonts::MENU_FONT, 150, 60); + subMenuController = NEW SimpleMenu(JGE::GetInstance(), MENU_LANGUAGE_SELECTION, this, Fonts::MENU_FONT, 150, 60); if (!subMenuController) return; @@ -418,7 +418,7 @@ void GameStateMenu::ensureMGuiController() { if (!mGuiController) { - mGuiController = NEW JGuiController(100, this); + mGuiController = NEW JGuiController(JGE::GetInstance(), 100, this); if (mGuiController) { WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MENU_FONT); @@ -617,7 +617,7 @@ void GameStateMenu::Update(float dt) if (!hasChosenGameType) { currentState = MENU_STATE_MAJOR_SUBMENU; - subMenuController = NEW SimpleMenu(MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60); + subMenuController = NEW SimpleMenu(JGE::GetInstance(), MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60); if (subMenuController) { for (size_t i = 0; i < Rules::RulesList.size(); ++i) @@ -791,7 +791,7 @@ void GameStateMenu::ButtonPressed(int controllerId, int controlId) switch (controlId) { case MENUITEM_PLAY: - subMenuController = NEW SimpleMenu(MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60); + subMenuController = NEW SimpleMenu(JGE::GetInstance(), MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60); if (subMenuController) { subMenuController->Add(SUBMENUITEM_1PLAYER, "1 Player"); diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index bdd22af12..e816b7397 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -117,7 +117,7 @@ void GameStateOptions::Start() optionsList->failMsg = ""; optionsTabs->Add(optionsList); - optionsMenu = NEW SimpleMenu(-102, this, Fonts::MENU_FONT, 50, 170); + optionsMenu = NEW SimpleMenu(JGE::GetInstance(), -102, this, Fonts::MENU_FONT, 50, 170); optionsMenu->Add(kBackToMainMenuID, "Back to Main Menu"); optionsMenu->Add(kSaveAndBackToMainMenuID, "Save & Back to Main Menu"); optionsMenu->Add(kCancelMenuID, "Cancel"); diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index a67a3885b..0357a8105 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -214,12 +214,12 @@ void GameStateShop::beginPurchase(int controlId) SAFE_DELETE(menu); if (mInventory[controlId] <= 0) { - menu = NEW SimpleMenu(-145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, _("Sold Out").c_str()); + menu = NEW SimpleMenu(JGE::GetInstance(), -145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, _("Sold Out").c_str()); menu->Add(-1, "Ok"); } else if (playerdata->credits - mPrices[controlId] < 0) { - menu = NEW SimpleMenu(-145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, _("Not enough credits").c_str()); + menu = NEW SimpleMenu(JGE::GetInstance(), -145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, _("Not enough credits").c_str()); menu->Add(-1, "Ok"); if (options[Options::CHEATMODE].number) { @@ -233,7 +233,7 @@ void GameStateShop::beginPurchase(int controlId) sprintf(buf, _("Purchase Booster: %i credits").c_str(), mPrices[controlId]); else sprintf(buf, _("Purchase Card: %i credits").c_str(), mPrices[controlId]); - menu = NEW SimpleMenu(-145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, buf); + menu = NEW SimpleMenu(JGE::GetInstance(), -145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, buf); menu->Add(controlId, "Yes"); menu->Add(-1, "No"); @@ -495,7 +495,7 @@ void GameStateShop::Update(float dt) menu->Update(dt); else { - menu = NEW SimpleMenu(11, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 20); + menu = NEW SimpleMenu(JGE::GetInstance(), 11, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 20); menu->Add(22, "Ask about..."); menu->Add(14, "Check task board"); if (options[Options::CHEATMODE].number) @@ -525,7 +525,7 @@ void GameStateShop::Update(float dt) { if (!menu) { - menu = NEW SimpleMenu(11, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 20); + menu = NEW SimpleMenu(JGE::GetInstance(), 11, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 20); menu->Add(15, "Return to shop"); menu->Add(12, "Save & Back to Main Menu"); menu->Add(kCancelMenuID, "Cancel"); diff --git a/projects/mtg/src/GameStateStory.cpp b/projects/mtg/src/GameStateStory.cpp index d79b287a2..1d1a14de6 100644 --- a/projects/mtg/src/GameStateStory.cpp +++ b/projects/mtg/src/GameStateStory.cpp @@ -44,7 +44,7 @@ void GameStateStory::loadStoriesMenu(const char * root) flow = NEW StoryFlow(stories[0]); break; default: - menu = NEW SimpleMenu(103, this, Fonts::MENU_FONT, 150, 60); + menu = NEW SimpleMenu(JGE::GetInstance(), 103, this, Fonts::MENU_FONT, 150, 60); for (size_t i = 0; i < stories.size(); ++i) { menu->Add(i, stories[i].c_str()); @@ -64,7 +64,7 @@ void GameStateStory::Update(float dt) { if (!menu && mEngine->GetButtonClick(JGE_BTN_MENU)) { - menu = NEW SimpleMenu(100, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25); + menu = NEW SimpleMenu(JGE::GetInstance(), 100, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25); menu->Add(0, "Back to main menu"); menu->Add(kCancelMenuID, "Cancel"); } diff --git a/projects/mtg/src/GuiCombat.cpp b/projects/mtg/src/GuiCombat.cpp index 1550253b9..84a8e16e8 100644 --- a/projects/mtg/src/GuiCombat.cpp +++ b/projects/mtg/src/GuiCombat.cpp @@ -201,7 +201,7 @@ bool GuiCombat::CheckUserInput(JButton key) DamagerDamaged* oldActive = active; /* int x,y; - if(JGE::GetInstance()->GetLeftClickCoordinates(x, y)) + if(observer->getInput()->GetLeftClickCoordinates(x, y)) { DamagerDamaged* old = active; active = closest (activeAtk->blockers, NULL, static_cast (x), static_cast (y)); diff --git a/projects/mtg/src/IconButton.cpp b/projects/mtg/src/IconButton.cpp index 944f1e148..0f5a5c06a 100644 --- a/projects/mtg/src/IconButton.cpp +++ b/projects/mtg/src/IconButton.cpp @@ -7,7 +7,7 @@ #define SCALE_SELECTED 1.2f #define SCALE_NORMAL 1.0f - IconButtonsController::IconButtonsController(float x, float y): JGuiController(0, NULL), mX(x), mY(y) + IconButtonsController::IconButtonsController(JGE* jge, float x, float y): JGuiController(jge, 0, NULL), mX(x), mY(y) { mListener = this; diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index 1a1cec685..ca9673b64 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -614,7 +614,7 @@ void OptionKey::KeyPressed(LocalKeySym key) g->UngrabKeyboard(this); grabbed = false; - btnMenu = NEW SimpleMenu(0, this, Fonts::MENU_FONT, 80, 10); + btnMenu = NEW SimpleMenu(JGE::GetInstance(), 0, this, Fonts::MENU_FONT, 80, 10); for (int i = sizeof(btnList) / sizeof(btnList[0]) - 1; i >= 0; --i) { const KeyRep& rep = translateKey(btnList[i]); diff --git a/projects/mtg/src/Player.cpp b/projects/mtg/src/Player.cpp index 53edd2ada..da704af20 100644 --- a/projects/mtg/src/Player.cpp +++ b/projects/mtg/src/Player.cpp @@ -292,6 +292,7 @@ bool Player::parseLine(const string& s) ostream& operator<<(ostream& out, const Player& p) { + out << "mode=" << p.playMode << endl; out << *(Damageable*)&p; string manapoolstring = p.manaPool->toString(); if(manapoolstring != "") diff --git a/projects/mtg/src/SimpleMenu.cpp b/projects/mtg/src/SimpleMenu.cpp index 3d9cddb77..5e39b702c 100644 --- a/projects/mtg/src/SimpleMenu.cpp +++ b/projects/mtg/src/SimpleMenu.cpp @@ -28,8 +28,8 @@ JTexture* SimpleMenu::spadeLTex = NULL; JTexture* SimpleMenu::jewelTex = NULL; JTexture* SimpleMenu::sideTex = NULL; -SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems, bool centerHorizontal, bool centerVertical) - : JGuiController(id, listener), fontId(fontId), mCenterHorizontal(centerHorizontal), mCenterVertical(centerVertical) +SimpleMenu::SimpleMenu(JGE* jge, int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems, bool centerHorizontal, bool centerVertical) + : JGuiController(jge, id, listener), fontId(fontId), mCenterHorizontal(centerHorizontal), mCenterVertical(centerVertical) { autoTranslate = true; isMultipleChoice = false; diff --git a/projects/mtg/src/SimplePopup.cpp b/projects/mtg/src/SimplePopup.cpp index 2a9756315..d7434fb95 100644 --- a/projects/mtg/src/SimplePopup.cpp +++ b/projects/mtg/src/SimplePopup.cpp @@ -14,7 +14,7 @@ #include SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection) : - JGuiController(id, listener), mFontId(fontId), mCollection(collection) + JGuiController(JGE::GetInstance(), id, listener), mFontId(fontId), mCollection(collection) { mX = 19; mY = 66; diff --git a/projects/mtg/src/StoryFlow.cpp b/projects/mtg/src/StoryFlow.cpp index 3194a7c74..71a3af06f 100644 --- a/projects/mtg/src/StoryFlow.cpp +++ b/projects/mtg/src/StoryFlow.cpp @@ -303,7 +303,7 @@ StoryChoice::StoryChoice(string pageId, string text, int JGOid, float mX, float //Actually loads a duel void StoryDuel::init() { - game = new GameObserver(); + game = new GameObserver(WResourceManager::Instance(), JGE::GetInstance()); char folder[255], deckFile[255], deckFileSmall[255]; sprintf(folder, CAMPAIGNS_FOLDER"%s/%s", mParent->folder.c_str(), pageId.c_str()); @@ -410,7 +410,7 @@ int StoryPage::loadElement(TiXmlElement* element) } StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent) : - StoryPage(mParent), JGuiListener(), JGuiController(1, NULL) + StoryPage(mParent), JGuiListener(), JGuiController(JGE::GetInstance(), 1, NULL) { currentY = 0; diff --git a/projects/mtg/src/WGui.cpp b/projects/mtg/src/WGui.cpp index d608fe266..5d992fc02 100644 --- a/projects/mtg/src/WGui.cpp +++ b/projects/mtg/src/WGui.cpp @@ -542,7 +542,7 @@ void WDecoConfirm::Entering(JButton key) SAFE_DELETE(confirmMenu); mState = OP_CONFIRMED; - confirmMenu = NEW SimpleMenu(444, listener, Fonts::MENU_FONT, 50, 170); + confirmMenu = NEW SimpleMenu(JGE::GetInstance(), 444, listener, Fonts::MENU_FONT, 50, 170); confirmMenu->Add(1, confirm.c_str()); confirmMenu->Add(2, cancel.c_str()); } @@ -1965,7 +1965,7 @@ void WGuiFilterItem::updateValue() SAFE_DELETE(mParent->subMenu); mState = STATE_CHOOSE_TYPE; SAFE_DELETE(mParent->subMenu); - mParent->subMenu = NEW SimpleMenu(-1234, this, Fonts::MENU_FONT, 20, 20, "Filter By...", 10); + mParent->subMenu = NEW SimpleMenu(JGE::GetInstance(), -1234, this, Fonts::MENU_FONT, 20, 20, "Filter By...", 10); if (mParent->isAvailable(FILTER_SET)) { mParent->subMenu->Add(FILTER_SET, "Set"); @@ -2033,7 +2033,7 @@ void WGuiFilterItem::updateValue() SAFE_DELETE(mParent->subMenu); mParent->clearArgs(); mState = STATE_CHOOSE_VAL; - mParent->subMenu = NEW SimpleMenu(-1234, this, Fonts::MENU_FONT, 20, 20, "Filter:"); + mParent->subMenu = NEW SimpleMenu(JGE::GetInstance(), -1234, this, Fonts::MENU_FONT, 20, 20, "Filter:"); if (filterType == FILTER_TYPE) { mParent->addArg("Artifact", "t:Artifact;"); @@ -2341,7 +2341,7 @@ WGuiBase::CONFIRM_TYPE WGuiKeyBinder::needsConfirm() confirmationString = ss.str(); // Then create the menu. - confirmMenu = NEW SimpleMenu(0, this, Fonts::MENU_FONT, 40, 130, "Conflict"); + confirmMenu = NEW SimpleMenu(JGE::GetInstance(), 0, this, Fonts::MENU_FONT, 40, 130, "Conflict"); confirmMenu->Add(1, _("Cancel and return to the options menu").c_str()); confirmMenu->Add(2, _("This is okay, validate and save").c_str()); return CONFIRM_NEED; @@ -2369,7 +2369,7 @@ WGuiBase::CONFIRM_TYPE WGuiKeyBinder::needsConfirm() confirmationString = s; confirmingButton = btnToCheck[i]; - confirmMenu = NEW SimpleMenu(1, this, Fonts::MENU_FONT, 40, 130, "Binding missing"); + confirmMenu = NEW SimpleMenu(JGE::GetInstance(), 1, this, Fonts::MENU_FONT, 40, 130, "Binding missing"); confirmMenu->Add(1, _("Cancel and return to the options menu").c_str()); confirmMenu->Add(2, _("This is okay, validate and save").c_str()); return CONFIRM_NEED; diff --git a/projects/mtg/src/utils.cpp b/projects/mtg/src/utils.cpp index cb347a2cb..6bb96961c 100644 --- a/projects/mtg/src/utils.cpp +++ b/projects/mtg/src/utils.cpp @@ -31,22 +31,19 @@ int RandomGenerator::random() else { result = loadedRandomValues.front(); - loadedRandomValues.pop(); + loadedRandomValues.pop_front(); } if(log) - usedRandomValues.push(result); + usedRandomValues.push_back(result); return result; } ostream& RandomGenerator::saveUsedRandValues(ostream& out) { - while(usedRandomValues.size()) + list::iterator ite; + for(ite=usedRandomValues.begin(); ite != usedRandomValues.end(); ite++) { - out << usedRandomValues.front(); - if(usedRandomValues.size() >= 1) - out << ","; - - usedRandomValues.pop(); + out << *ite << ","; } return out; @@ -54,13 +51,10 @@ ostream& RandomGenerator::saveUsedRandValues(ostream& out) ostream& RandomGenerator::saveLoadedRandValues(ostream& out) { - while(loadedRandomValues.size()) + list::iterator ite; + for(ite=loadedRandomValues.begin(); ite != loadedRandomValues.end(); ite++) { - out << loadedRandomValues.front(); - if(loadedRandomValues.size() >= 1) - out << ","; - - loadedRandomValues.pop(); + out << *ite << ","; } return out; @@ -68,10 +62,8 @@ ostream& RandomGenerator::saveLoadedRandValues(ostream& out) void RandomGenerator::loadRandValues(string s) { - while(loadedRandomValues.size()) - loadedRandomValues.pop(); - while(usedRandomValues.size()) - usedRandomValues.pop(); + loadedRandomValues.clear(); + usedRandomValues.clear(); while (s.size()) { @@ -87,7 +79,7 @@ void RandomGenerator::loadRandValues(string s) value = atoi(s.c_str()); s = ""; } - if (value) loadedRandomValues.push(value); + if (value) loadedRandomValues.push_back(value); } }