bool GameView::MouseDown(const IPoint& mouse_pos) { if (Core::mainInput.GetMouseRightButton()) { if (isLevelComplete() || isLevelFailed()) { if (isLevelComplete()) { Game::instance().GetGameInfo().nextLevel(); } Cleanup(); Init(); } } else { if (m_leftCatchers > 0 && !isLevelComplete() && !isLevelFailed()) { SpawnCatcher(mouse_pos); m_leftCatchers = (m_leftCatchers > 0) ? --m_leftCatchers : 0; } } return false; }
BasicWork::State ApplyBucketsWork::onRun() { // Check if we're at the beginning of the new level if (isLevelComplete()) { startLevel(); } // The structure of these if statements is motivated by the following: // 1. mCurrApplicator should never be advanced if mSnapApplicator is // not false. Otherwise it is possible for curr to modify the // database when the invariants for snap are checked. // 2. There is no reason to advance mSnapApplicator or mCurrApplicator // if there is nothing to be applied. if (mSnapApplicator) { if (*mSnapApplicator) { advance("snap", *mSnapApplicator); return State::WORK_RUNNING; } mApp.getInvariantManager().checkOnBucketApply( mSnapBucket, mApplyState.currentLedger, mLevel, false); mSnapApplicator.reset(); mSnapBucket.reset(); mBucketApplySuccess.Mark(); } if (mCurrApplicator) { if (*mCurrApplicator) { advance("curr", *mCurrApplicator); return State::WORK_RUNNING; } mApp.getInvariantManager().checkOnBucketApply( mCurrBucket, mApplyState.currentLedger, mLevel, true); mCurrApplicator.reset(); mCurrBucket.reset(); mBucketApplySuccess.Mark(); } mApp.getCatchupManager().logAndUpdateCatchupStatus(true); if (mLevel != 0) { --mLevel; CLOG(DEBUG, "History") << "ApplyBuckets : starting next level: " << mLevel; return State::WORK_RUNNING; } CLOG(DEBUG, "History") << "ApplyBuckets : done, restarting merges"; mApp.getBucketManager().assumeState(mApplyState, mMaxProtocolVersion); return State::WORK_SUCCESS; }
void ApplyBucketsWork::startLevel() { assert(isLevelComplete()); CLOG(DEBUG, "History") << "ApplyBuckets : starting level " << mLevel; auto& level = getBucketLevel(mLevel); HistoryStateBucket const& i = mApplyState.currentBuckets.at(mLevel); bool applySnap = (i.snap != binToHex(level.getSnap()->getHash())); bool applyCurr = (i.curr != binToHex(level.getCurr()->getHash())); if (!mApplying && (applySnap || applyCurr)) { uint32_t oldestLedger = applySnap ? BucketList::oldestLedgerInSnap( mApplyState.currentLedger, mLevel) : BucketList::oldestLedgerInCurr( mApplyState.currentLedger, mLevel); auto& lsRoot = mApp.getLedgerTxnRoot(); lsRoot.deleteObjectsModifiedOnOrAfterLedger(oldestLedger); } if (mApplying || applySnap) { mSnapBucket = getBucket(i.snap); mSnapApplicator = std::make_unique<BucketApplicator>( mApp, mMaxProtocolVersion, mSnapBucket); CLOG(DEBUG, "History") << "ApplyBuckets : starting level[" << mLevel << "].snap = " << i.snap; mApplying = true; mBucketApplyStart.Mark(); } if (mApplying || applyCurr) { mCurrBucket = getBucket(i.curr); mCurrApplicator = std::make_unique<BucketApplicator>( mApp, mMaxProtocolVersion, mCurrBucket); CLOG(DEBUG, "History") << "ApplyBuckets : starting level[" << mLevel << "].curr = " << i.curr; mApplying = true; mBucketApplyStart.Mark(); } }
void GameView::Draw() { GUI::Widget::Draw(); m_effects.Draw(); for (std::vector<MonsterPtr>::iterator it = m_monsters.begin(); it != m_monsters.end(); ++it) { if (*it) (*it)->Draw(); } for (std::vector<CatchersPtr>::iterator it = m_catchers.begin(); it != m_catchers.end(); ++it) { if (*it) (*it)->Draw(); } Render::BindFont("Sansation"); if (isLevelFailed()) { Render::PrintString(width * .5f, height * .5f, "LEVEL FAILED\nPress RIGTH MOUSE BUTTON to restart", 1.f, CenterAlign, BaseLineAlign); } else if (isLevelComplete()) { Render::PrintString(width * .5f, height * .5f, "LEVEL COMPLETE\nPress RIGHT MOUSE BUTTON to continue", 1.f, CenterAlign, BaseLineAlign); } Render::PrintString(width - 100, height - 10, "Level: " + std::to_string(Game::instance().GetGameInfo().getCurrentLevel())); Render::PrintString(10, height - 10, "Monsters Catched: " + std::to_string(m_catchedMonsters) + " from " + std::to_string(Game::instance().GetGameInfo().getNumMonstersToCatch())); Render::PrintString(10, height - 40, "Catchers: " + std::to_string(m_leftCatchers)); }
bool GameView::isLevelFailed() const { const GameInfo& gameInfo = Game::instance().GetGameInfo(); return (m_leftCatchers <= 0 && m_catchers.size() == 0 && !isLevelComplete()); }