Program4() { getWindowContext(); state.currentRes[0] = RESOLUTION; state.currentRes[1] = RESOLUTION; render.init(state); resize(window->getSize().x, window->getSize().y); previousPos = glm::vec2(0); buttonDown[0]=false; buttonDown[1]=false; buttonDown[2]=false; sf::Clock c; float lastFrame = c.restart().asSeconds(); float lastPrint = lastFrame; float targetFrameTime = 1.0f/(float)TARGET_FPS; while (state.isRunning()) { window->setActive(); float currentTime = c.getElapsedTime().asSeconds(); float sinceLastFrame = currentTime - lastFrame; float sleepTime = targetFrameTime - sinceLastFrame; if(sleepTime > 0) sf::sleep(sf::seconds(sleepTime)); currentTime = c.getElapsedTime().asSeconds(); lastFrame = currentTime; float sinceLastPrint = currentTime - lastPrint; handleEvents(state, render); state.timeStep(currentTime); if(sinceLastPrint > PRINT_FPS_INTERVAL) { lastPrint = currentTime; state.printFPS(); } render.display(state); window->display(); if(state.getIncreaseVelocity()) state.toggleIncreaseVelocity(); } }
Program4() { getWindowContext(); WorldState state; render.init(state); previousPos = glm::vec2(0); buttonDown[0]=false; buttonDown[1]=false; buttonDown[2]=false; sf::Clock c; float lastFrame = c.restart().asSeconds(); float lastPrint = lastFrame; float targetFrameTime = 1.0f/(float)TARGET_FPS; while (state.isRunning()) { App->setActive(); float currentTime = c.getElapsedTime().asSeconds(); float sinceLastFrame = currentTime - lastFrame; float sleepTime = targetFrameTime - sinceLastFrame; if(sleepTime > 0) sf::sleep(sf::seconds(sleepTime)); currentTime = c.getElapsedTime().asSeconds(); lastFrame = currentTime; float sinceLastPrint = currentTime - lastPrint; handleEvents(state, render); state.timeStep(currentTime); if(sinceLastPrint > PRINT_FPS_INTERVAL) { lastPrint = currentTime; state.printFPS(); } render.display(state); App->display(); } }