void GameManager::run(int fr_time) { frame_time = fr_time; long int loop_time; Clock clock; WorldManager &worldmanager = WorldManager::getInstance(); GraphicsManager &graphicsmanager = GraphicsManager::getInstance(); InputManager &inputmanager = InputManager::getInstance(); LogManager &logmanager = LogManager::getInstance(); //MAIN GAME LOOP int i = 0; int sleep_time; logmanager.writeLog("GameManager::run: Game loop begins\n"); while (!game_over) { clock.delta(); inputmanager.getInput(); EventStep s = EventStep(); onEvent(&s); worldmanager.update(); worldmanager.draw(); graphicsmanager.swapBuffers(); loop_time = clock.split(); usleep((frame_time-loop_time)*1000); } logmanager.writeLog("GameManager::run: Game loop ends\n"); shutDown(); }
void GameManager::run(int fr_time) { if (this->isStarted()) { frame_time = fr_time; Clock clock; long int loop_time; long int time_left; int i; LogManager &log_manager = LogManager::getInstance(); InputManager &input_manager = InputManager::getInstance(); GraphicsManager &graphics_manager = GraphicsManager::getInstance(); WorldManager &world_manager = WorldManager::getInstance(); while (game_over != true) { clock.delta(); input_manager.getInput(); EventStep es; Event e = es; onEvent(&e); world_manager.update(); world_manager.draw(); graphics_manager.swapBuffers(); loop_time = clock.split(); time_left = ((frame_time * 1000) - loop_time); if (time_left > 0) { usleep(time_left); } else { log_manager.writeLog( "The game is running too slow by %d microseconds!", -time_left); } } } }