| 41 | } |
| 42 | |
| 43 | void FramerateManager::update() |
| 44 | { |
| 45 | const sf::Time timeBuffer = m_deltaClock.restart(); |
| 46 | m_deltaTime = static_cast<double>(timeBuffer.asMicroseconds()) * microseconds; |
| 47 | if (m_limitFramerate) |
| 48 | { |
| 49 | if (epoch() - m_frameLimiterClock > 1) |
| 50 | { |
| 51 | m_frameLimiterClock = epoch(); |
| 52 | m_currentFrame = 0; |
| 53 | } |
| 54 | m_frameProgression |
| 55 | = round((epoch() - m_frameLimiterClock) / (m_reqFramerateInterval)); |
| 56 | m_needToRender = false; |
| 57 | if (m_frameProgression > m_currentFrame) |
| 58 | { |
| 59 | m_currentFrame = m_frameProgression; |
| 60 | m_needToRender = true; |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | std::this_thread::sleep_for( |
| 65 | std::chrono::duration<double>(m_reqFramerateInterval)); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | TimeUnit FramerateManager::getDeltaTime() const |
| 71 | { |