2
\$\begingroup\$

I am making a C++ program with Opengl and GLFW for window and input handling.
The program is updated with the main loop by delta time which is calculated by subtracting new frame start time with old frame start time.
My problem is that when title bar is hold the whole program stops, but when it is released the delta time is as big as hold time.
I am also using chrono library for calculating passed time.

My code:

unsigned long second = std::chrono::seconds( 1 ) / precision;
frameStartTime = std::chrono::system_clock::now().time_since_epoch() / precision;
while ( running && !glfwWindowShouldClose( glfwWindow ) && !input::keyboard::isDown( GLFW_KEY_ESCAPE ) ) {
    lastFrameTime = frameStartTime;
    frameStartTime = std::chrono::system_clock::now().time_since_epoch() / precision;
    deltaTime = float( frameStartTime - lastFrameTime ) / second;

glfwPollEvents(); mainScene->update( deltaTime ); input::clear(); mainScene->draw(); glfwSwapBuffers( glfwWindow ); countFps( deltaTime ); }

What am I doing wrong and how can I fix this issue?
Thanks.

\$\endgroup\$
  • 2
    \$\begingroup\$ That's a normal behavior and is currently unfixable. You can put your render code and update loop in different threads to at least keep the updating going. \$\endgroup\$ – Bálint Feb 22 '17 at 6:51
0
\$\begingroup\$

Balint said pretty much all there is.

This is Windows behavior, and there's not much you can do to fix it on the surface.

You could move your main logic to a background thread, though that is sometimes easier said than done. It won't be able to fix the visible pause, though - you'll be able to keep rendering and updating but you won't be able to see the results (hearing them will be fine, and networking will keep functioning as expected, though).

Most games just ignore it, and treat it as they would any other long frame pause that can happen from unexpected system strain. To deal with the big frame times, just cap the maximum amount of elapsed time; that avoids some of the problems that can happen with big frame times.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.