void Game::Update(float deltaTime, float alphaMul) { if (!m_IsActive) return; // Update base scene Scene::Update(deltaTime, alphaMul); // Update falling gems in grid if (gameState == gemsFalling) gemsGrid->gemsFalling(deltaTime); // Update round timer if (gameState != roundOver && gameState != paused) { if ((int)currentRoundTime != (int)(currentRoundTime - deltaTime)) { char str[32]; snprintf(str, 32, "%d", (int)currentRoundTime); timerLabel->m_Text = str; } currentRoundTime -= deltaTime; if (currentRoundTime <= 0) { currentRoundTime = 0; // Allow last played move to finish if (gameState == waitingFirstGem || gameState == waitingSecondGem) endOfRound(); } } // Detect screen tap if (m_IsInputActive && m_Manager->GetCurrent() == this && !g_pInput->m_Touched && g_pInput->m_PrevTouched) { g_pInput->Reset(); if (gameState == roundOver) { if (infoPanel->HitTest(g_pInput->m_X, g_pInput->m_Y)) initRound(); } else { if (g_pInput->m_Y >= gemsGrid->getGridOriginY()) { int grid_x, grid_y; gemsGrid->screenToGrid(g_pInput->m_X, g_pInput->m_Y, grid_x, grid_y); if (gameState == waitingFirstGem) { // In waiting for first gem state we place a selector over the first selected gem gridTouchesX[0] = grid_x; gridTouchesY[0] = grid_y; changeGameState(waitingSecondGem); } else if (gameState == waitingSecondGem) { gridTouchesX[1] = grid_x; gridTouchesY[1] = grid_y; int dx = gridTouchesX[1] - gridTouchesX[0]; int dy = gridTouchesY[1] - gridTouchesY[0]; if ((dx == 0 && (dy == -1 || dy == 1)) || (dy == 0 && (dx == -1 || dx == 1))) { // Second gem is swappable so switch to thinking state changeGameState(thinking); g_pAudio->PlaySound("audio/gem_swap.wav"); } else { // Second gem is too far or the same gem, so reset changeGameState(waitingFirstGem); g_pAudio->PlaySound("audio/gem_wrong.wav"); } } } else { if (pauseSprite->HitTest(g_pInput->m_X, g_pInput->m_Y)) { // Enter pause menu pauseGame(); } } } } }
void NetBench::roundDone(size_t actualOps) { boost::posix_time::ptime end; end = boost::posix_time::microsec_clock::universal_time(); boost::posix_time::time_duration diff = end - m_start; // Do all stat math using double to avoid rounding errors // during divides double active = (double)std::min(m_totalConns, m_maxActive); double elapsed = (double)diff.total_microseconds(); double usAvg = elapsed / (active * m_iters); double numOps = active * m_iters; double opsSec = (numOps / elapsed) * 1000 * 1000; double mb = (m_numBytes * numOps) * 1024 * 1024; double bw = (mb / elapsed) / (1000 * 1000); // This is a sanity check to make sure that our sychronization // logic is correct and that we are really doing the amount // of work that we think we are if (actualOps != numOps) { std::cerr << "actualOps != numOps (" << actualOps << " != " << numOps << ")\n"; abort(); } std::cout << m_totalConns << " " << elapsed / 1000000 << " " << numOps << " " << usAvg << " " << opsSec << " " << bw << "\n"; // Figure out how many new clients to run with next round if (m_powTwo) { m_newConns = std::min(m_totalConns * 2 - m_totalConns, m_maxConns - m_totalConns); } else { m_newConns = 1; } // Figure out how many total conns and active conns for next round m_totalConns += m_newConns; m_newActive = std::min(m_totalConns, m_maxActive) - m_totalActive; m_totalActive = m_totalActive + m_newActive; // Figure out how many iters to run for the next round. // We'll run for 1ms for non power of two based runs and // a full 3s otherwise (really, for full graphs you should // always run pow2) unsigned long long targetUs = m_powTwo ? 3000000 : 1000; m_iters = (size_t) (targetUs / m_totalActive / usAvg); if (m_iters == 0) { m_iters = 1; } if (m_newConns && m_totalConns <= m_maxConns) { initRound(); } else { m_client->stop(); m_server->stop(); } }
// Starts a new game - Called from the main and pause menus void Game::newGame() { currentRound = 1; initRound(); }
//************************************ // Method: newRound - play one round // FullName: Game::newRound // Access: private // Returns: void // Qualifier: //************************************ void Game::newRound() { initRound(); getDecisions(); closeRound(); }