void Client::render(ui::Frame &f) { const Clamped &gameFocusFactor = uiState.gameFocusFactor, &pageFocusFactor = uiState.pageFocusFactor; if (uiState.gameFocused() && game) { renderGame(f); } else { if (!game) { f.drawSprite(resources.getTexture(ui::TextureID::MenuBackground), {0, 0}, {0, 0, 1600, 900}); } else { renderGame(f); f.drawRect( {0, 0, 1600, 900}, mixColors(style.menu.gameOverlayColor, sf::Color(255, 255, 255, 0), gameFocusFactor)); } f.withAlpha( linearTween(1, 0, gameFocusFactor) * (game ? linearTween(style.menu.menuInGameFade, 1, pageFocusFactor) : linearTween(style.menu.menuNormalFade, 1, pageFocusFactor)), [&]() { renderUI(f); }); } }
int main(int argc, char* argv[]) { initializeSDL(); // Start Menu titleSurface = TTF_RenderText_Solid(silkscreen, "Simple Pong", white); titleTexture = SDL_CreateTextureFromSurface(renderer, titleSurface); titleRect.w = 512; titleRect.h = 128; titleRect.x = SCREEN_WIDTH / 2 - titleRect.w / 2; titleRect.y = 25; // Start Button startButtonSurface = TTF_RenderText_Solid(silkscreen, "Start", white); startButtonTexture = SDL_CreateTextureFromSurface(renderer, startButtonSurface); startButtonRect.w = 128; startButtonRect.h = 48; startButtonRect.x = SCREEN_WIDTH / 2 - startButtonRect.w / 2; startButtonRect.y = SCREEN_HEIGHT / 2; defineRects(); while(!quit) // Main Loop { while(SDL_PollEvent(&e) != 0) { if(e.type == SDL_QUIT) quit = 1; } getKeystates(); switch(screen) { case 0: // Start Menu clearScreen(); renderStartMenu(); break; case 1: // Game ballPhysics(); clearScreen(); renderGame(); break; case 2: // Pause Menu clearScreen(); SDL_RenderCopy(renderer, startMessageTexture, NULL, &startMessageRect); renderGame(); break; } SDL_Delay(2); // Slow down the loop. } quitSDL(); // Quit all SDL subsystems and free memory. return 0; }
void GameLogic::run() { enable2D(); m_backgroundMusic.play(); m_platform.fetchUser(); while (!m_shutdown) { // platform handle input m_platform.processEvents(); m_backgroundMusic.tick(); switch (m_state) { case FetchUser: renderFetchUser(); break; case GamePlay: update(); renderGame(); break; case LeaderBoard: renderLeadBoard(); break; } } }
void render() { clear(); switch(getState()) { case MAIN_MENU: renderMainMenu(); break; case GAME: renderGame(); break; case BATTLE: renderBattle(); break; case INSTRUCTIONS: renderInstructions(); break; case OPTIONS: renderOptions(); break; case STATUS: renderStatus(); break; default: break; } refresh(); // call curses's refresh funct to update screen }
//============================================================================= // Call repeatedly by the main message loop in WinMain //============================================================================= void Game::run(HWND hwnd) { if(graphics == NULL) // if graphics not initialized return; // calculate elapsed time of last frame, save in frameTime QueryPerformanceCounter(&timeEnd); frameTime = (float)(timeEnd.QuadPart - timeStart.QuadPart ) / (float)timerFreq.QuadPart; // Power saving code, requires winmm.lib // if not enough time has elapsed for desired frame rate if (frameTime < MIN_FRAME_TIME) { sleepTime = (DWORD)((MIN_FRAME_TIME - frameTime)*1000); timeBeginPeriod(1); // Request 1mS resolution for windows timer Sleep(sleepTime); // release cpu for sleepTime timeEndPeriod(1); // End 1mS timer resolution return; } if (frameTime > 0.0) fps = (fps*0.99f) + (0.01f/frameTime); // average fps if (frameTime > MAX_FRAME_TIME) // if frame rate is very slow frameTime = MAX_FRAME_TIME; // limit maximum frameTime timeStart = timeEnd; // update(), ai(), and collisions() are pure virtual functions. // These functions must be provided in the class that inherits from Game. if (!paused) // if not paused { update(); // update all game items ai(); // artificial intelligence collisions(); // handle collisions input->vibrateControllers(frameTime); // handle controller vibration } //for FPS on the title char windowtext[255]; sprintf(windowtext,"frameTime = %f, FPS= %f",frameTime, fps); SetWindowText(hwnd, windowtext); renderGame(); // draw all game items // input->readCoSntrollers(); // read state of controllers // if Alt+Enter toggle fullscreen/window if (input->isKeyDown(ALT_KEY) && input->wasKeyPressed(ENTER_KEY)) setDisplayMode(graphicsNS::TOGGLE); // toggle fullscreen/window // if Esc key, set window mode if (input->isKeyDown(ESC_KEY)) setDisplayMode(graphicsNS::WINDOW); // set window mode // Clear input // Call this after all key checks are done input->clear(inputNS::KEYS_PRESSED); }
void GlWindow::paintGL(float _dt) { updateGame(_dt); /* Draws the scene and its child. */ renderGame(_dt); /* Updates QT window. */ update(); }
// ================================================================== // WinMain内のメインのメッセージループで繰り返し呼び出される // ================================================================== void Game::run(HWND hwnd) { if(graphics == NULL) // グラフィックスが初期化されていない場合 return; // エスケープキーで終了 if(input->isKeyDown(ESC_KEY)) { PostQuitMessage(0); return; } // 最後のフレームからの経過時間を計算、frameTimeに保存 QueryPerformanceCounter(&timeEnd); frameTime = (float)(timeEnd.QuadPart - timeStart.QuadPart) / (float)timeFreq.QuadPart; // 省電力コード(winmm.libが必要) // 希望するフレームレートに対して経過時間が短い場合 if(frameTime < MIN_FRAME_TIME) { sleepTime = (DWORD)((MIN_FRAME_TIME - frameTime) * 1000); timeBeginPeriod(1); // 1ミリ秒の分解能をWindowsタイマーに要求 Sleep(sleepTime); // sleepTimeの間、CPUを解放 timeEndPeriod(1); // 1ミリ秒のタイマー分解能を終了 return; } if(frameTime > 0.0) fps = (fps * 0.99f) + (0.01f / frameTime); // 平均fps if(frameTime > MAX_FRAME_TIME) // フレームレートが非常に遅い場合 frameTime = MAX_FRAME_TIME; // 最大frameTimeを制限 timeStart = timeEnd; input->readControllers(); // コントローラの状態を読み取る // update()、ai()、collisions()は純粋仮想関数です // これらの関数は、Gameを継承しているクラス側で記述する必要があります if(!paused) // 一時停止中でない { update(); // すべてのゲームアイテムを更新 ai(); // 人工知能 collisions(); // 衝突を処理 input->vibrateControllers(frameTime); //コントローラの振動を処理 } renderGame(); // すべてのゲームアイテムを描画 // 入力をクリア // すべてのキーチェックが行われた後これを呼び出す input->clear(inputNS::KEYS_PRESSED); }
//-------------------------------------------------------------- // Purpose : Render function is to update the console screen // At this point, you should know exactly what to draw onto the screen. // Just draw it! // To get an idea of the values for colours, look at console.h and the URL listed there // Input : void // Output : void //-------------------------------------------------------------- void render() { clearScreen(); // clears the current screen and draw from scratch switch (g_eGameState) { case S_SPLASHSCREEN: renderSplashScreen(); break; case S_GAME: renderGame(); break; } renderFramerate(); // renders debug information, frame rate, elapsed time, etc renderToScreen(); // dump the contents of the buffer to the screen, one frame worth of game }
//============================================================================= // Call repeatedly by the main message loop in WinMain //============================================================================= void Game::run(HWND hwnd) { if(graphics == NULL) // if graphics not initialized return; // calculate elapsed time of last frame, save in frameTime QueryPerformanceCounter(&timeEnd); frameTime = (float)(timeEnd.QuadPart - timeStart.QuadPart ) / (float)timerFreq.QuadPart; // Power saving code, requires winmm.lib // if not enough time has elapsed for desired frame rate if (frameTime < MIN_FRAME_TIME) { sleepTime = (DWORD)((MIN_FRAME_TIME - frameTime)*1000); timeBeginPeriod(1); // Request 1mS resolution for windows timer Sleep(sleepTime); // release cpu for sleepTime timeEndPeriod(1); // End 1mS timer resolution return; } if (frameTime > 0.0) fps = (fps*0.99f) + (0.01f/frameTime); // average fps if (frameTime > MAX_FRAME_TIME) // if frame rate is very slow frameTime = MAX_FRAME_TIME; // limit maximum frameTime timeStart = timeEnd; // update(), ai(), and collisions() are pure virtual functions. // These functions must be provided in the class that inherits from Game. if (!paused) // if not paused { update(); // update all game items ai(); // artificial intelligence collisions(); // handle collisions input->vibrateControllers(frameTime); // handle controller vibration } renderGame(); // draw all game items input->readControllers(); // read state of controllers // Clear input // Call this after all key checks are done input->clear(inputNS::KEYS_PRESSED); }
/* * Game execution: Gets input events, processes game logic and draws sprites on the screen */ void Game::gameLoop() { _gameState = GameState::PLAY; while (_gameState != GameState::EXIT) { //Start synchronization between refresh rate and frame rate _fpsLimiter.startSynchronization(); //Process the input information (keyboard and mouse) processInput(); //Execute the player actions (keyboard and mouse) executePlayerCommands(); //Update the game status doPhysics(); //Draw the objects on the screen renderGame(); //Force synchronization _fpsLimiter.forceSynchronization(); } }
void Game::run(HWND hWnd) { if (graphics_ == NULL) // If graphics not initialized { return; } QueryPerformanceCounter(&timeEnd_); frameTime_ = (double)(timeEnd_.QuadPart - timeStart_.QuadPart) / (double)timerFreq_.QuadPart; // if the frame time is less than MIN_FRAME_TIME do idle processing //otherwise run game if (frameTime_ < MIN_FRAME_TIME) { //figure out how long to sleep for sleepTime_ = (DWORD)(MIN_FRAME_TIME - frameTime_) * 1000; timeBeginPeriod(1);// Request 1mS resolution for windows timer Sleep(sleepTime_); // Release CPU for sleepTime timeEndPeriod(1); // End 1mS timer resolution return; } if (frameTime_ > 0.0) { fps_ = (fps_ * .99) + (0.1 / frameTime_); } if (frameTime_ > MAX_FRAME_TIME) { frameTime_ = MAX_FRAME_TIME; } // reset the elapsed time to 0 timeStart_ = timeEnd_; //Pure virtual functions defined by derived Classes update(); // Update all game items renderGame(); //renderGame() draws all items and calls pure virtual function render // Clear input // Call this after all key checks are done input_->clear(InputConstants::KEYS_PRESSED); }
/* * Game execution: Gets input events, processes game logic and draws sprites on the screen */ void Game::gameLoop() { _gameState = GameState::PLAY; while (_gameState != GameState::EXIT) { if (_network.GetNetworkState() == NetworkState::SAYINGHELLO) { _network.SayHello(); } int positionSquare = aSquares[_network.GetIdSquare()].GetPosition(); _network.SendMove(positionSquare,_inputState, _inputStateList); Receiving(); //Update the game physics doPhysics(); //Detect keyboard and/or mouse events _graphic.detectInputEvents(); //Execute the player commands executePlayerCommands(); //Render game renderGame(); } }
/* This is the render loop At this point, you should know exactly what to draw onto the screen. Just draw it! To get an idea of the values for colours, look at console.h and the URL listed there */ void render() { clearScreen(); // clears the current screen and draw from scratch switch (g_eGameState) { case SPLASH: splash(); // splash screen break; case TITLE: titlescreen(); // title screen break; case VICTORY: victory(); // victory screen break; case CREDITS: credits(); // credits & statistics screen break; case PAUSE: pausemenu(); // pause screen break; case CLASSSELECT: classSelect(); // class selection screen break; case GAME: renderGame(); // Game screen break; case GAMEOVER: gameend(); // Retry screen break; } renderToScreen();// dump the contents of the buffer to the screen, one frame worth of game }
void Minesweeper::startGame(){ SDL_Event event; thread timer(&Minesweeper::renderTimerText,this); while (!done){ checkEvents(&event); mtx.lock(); renderGame(); mtx.unlock(); if (isPlayerWinner() || gameOver){ if (isPlayerWinner() && !cheatActived) saveScore(); waitPlayer(&event); } checkCheat(); struct timespec timespec_st = {0,NANOSEC}; nanosleep(×pec_st,NULL); //used to not consume 100% of the cpu 0,1s } timer.join(); SDL_FreeSurface(displayVideo); SDL_FreeSurface(images); SDL_Quit(); TTF_Quit(); }
int main(int argc, char ** argv) { srand(time(NULL)); printf("main: lancement du jeu\n"); init(); // initialisation des ressources communes à toute partie du jeu printf("main: initialisation des ressources graphiques du login\n"); changeStep(login); printf("main: début de la boucle de rendu\n"); while (globalStep!=end) { SDL_RenderClear(renderer); switch(globalStep) { case login: renderLogin();// on dessine le login break; case menu: renderMenu(); break; case mode: renderMode(); break; case stat: renderStat(); break; case game: renderGame(); break; case end: break; default: printf("main: globalState non valide\n"); } SDL_RenderPresent(renderer); //SDL_Delay(5); // provisoire afin de ne pas utiliser tout le cpu switch(globalStep) { case login: eventLogin(); break; case menu: eventMenu(); break; case mode: eventMode(); break; case stat: eventStat(); break; case game: eventGame(); break; case end: break; default: printf("main: globalState non valide\n"); } } //free ressource printf("main: liberation des ressources\n"); quit();// liberation des ressources communes printf("main: fin du jeu\n"); return 0; }
//============================================================================= // Call repeatedly by the main message loop in WinMain //============================================================================= void Game::run(HWND hwnd) { if(graphics == NULL) // if graphics not initialized return; // calculate elapsed time of last frame, save in frameTime QueryPerformanceCounter(&timeEnd); frameTime = (float)(timeEnd.QuadPart - timeStart.QuadPart ) / (float)timerFreq.QuadPart; // Power saving code, requires winmm.lib // if not enough time has elapsed for desired frame rate if (frameTime < MIN_FRAME_TIME) { sleepTime = (DWORD)((MIN_FRAME_TIME - frameTime)*1000); timeBeginPeriod(1); // Request 1mS resolution for windows timer Sleep(sleepTime); // release cpu for sleepTime timeEndPeriod(1); // End 1mS timer resolution return; } if (frameTime > 0.0) fps = (fps*0.99f) + (0.01f/frameTime); // average fps if (frameTime > MAX_FRAME_TIME) // if frame rate is very slow frameTime = MAX_FRAME_TIME; // limit maximum frameTime timeStart = timeEnd; // update(), ai(), and collisions() are pure virtual functions. // These functions must be provided in the class that inherits from Game. if (!paused) // if not paused { update(); // update all game items ai(); // artificial intelligence collisions(); // handle collisions input->vibrateControllers(frameTime); // handle controller vibration } renderGame(); // draw all game items //check for console key if (input->getCharIn() == CONSOLE_KEY) { input->clearCharIn(); // clear last char console->showHide(); paused = console->getVisible(); // pause game when console is visible } consoleCommand(); // process user entered console command input->readControllers(); // read state of controllers messageDialog->update(); inputDialog->update(); audio->run(); // perform periodic sound engine tasks // if Alt+Enter toggle fullscreen/window if (input->isKeyDown(ALT_KEY) && input->wasKeyPressed(ENTER_KEY)) setDisplayMode(graphicsNS::TOGGLE); // toggle fullscreen/window // if Esc key, set window mode if (input->isKeyDown(ESC_KEY)) setDisplayMode(graphicsNS::WINDOW); // set window mode // if Pause key if (input->wasKeyPressed(VK_PAUSE)) paused = !paused; // Clear input keys pressed // Call this after all key checks are done input->clear(inputNS::KEYS_PRESSED); }
//============================================================================= // Call repeatedly by the main message loop in WinMain //============================================================================= void Game::run(HWND hwnd) { if(graphics == NULL) // if graphics not initialized return; // calculate elapsed time of last frame, save in frameTime QueryPerformanceCounter(&timeEnd); frameTime = (float)(timeEnd.QuadPart - timeStart.QuadPart ) / (float)timerFreq.QuadPart; // Power saving code, requires winmm.lib // if not enough time has elapsed for desired frame rate if (frameTime < MIN_FRAME_TIME) { sleepTime = (DWORD)((MIN_FRAME_TIME - frameTime)*1000); timeBeginPeriod(1); // Request 1mS resolution for windows timer Sleep(sleepTime); // release cpu for sleepTime timeEndPeriod(1); // End 1mS timer resolution return; } if (frameTime > 0.0) fps = (fps*0.99f) + (0.01f/frameTime); // average fps if (frameTime > MAX_FRAME_TIME) // if frame rate is very slow frameTime = MAX_FRAME_TIME; // limit maximum frameTime timeStart = timeEnd; //PAUSE and UNPAUSE the game if(input->isStartPressed() && (currentState == OVERWORLD || currentState == BATTLE)) { if(paused) { paused = false; if(currentState == BATTLE) { audio->stopCue(NOSTRINGS); audio->playCue(BATTLELOOP); } else if (currentState == OVERWORLD) { audio->stopCue(BATTLELOOP); audio->playCue(NOSTRINGS); } } else { audio->stopCue(NOSTRINGS); audio->stopCue(BATTLELOOP); paused = true; } } // update(), ai(), and collisions() are pure virtual functions. // These functions must be provided in the class that inherits from Game. if (!paused) // if not paused { update(); // update all game items ai(); // artificial intelligence collisions(); // handle collisions input->vibrateControllers(frameTime); // handle controller vibration } renderGame(); // draw all game items input->readControllers(); // read state of controllers audio->run(); // perform periodic sound engine tasks // if Alt+Enter toggle fullscreen/window if (input->isKeyDown(ALT_KEY) && input->wasKeyPressed(ENTER_KEY)) setDisplayMode(graphicsNS::TOGGLE); // toggle fullscreen/window // if Esc key, set window mode //if (input->isKeyDown(ESC_KEY)) // setDisplayMode(graphicsNS::WINDOW); // set window mode // Clear input // Call this after all key checks are done input->clear(inputNS::KEYS_PRESSED); }