Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: dealing with massive frame time  (Read 1922 times)

0 Members and 1 Guest are viewing this topic.

Naofu

  • Newbie
  • *
  • Posts: 6
    • View Profile
dealing with massive frame time
« on: September 21, 2019, 01:14:07 pm »
When I move/resize window without pausing game, game messes up like Goomba instakills Mario beyond obstacles, because Clock is still progressing while window is completely frozen.
First I fixed it by this:
if(frameTime > 1 / 60.f) frameTime = 1 / 60.f;
But this looks unsmart. This may cause lags when fps drops below 60.
Is there any good way? thx.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: dealing with massive frame time
« Reply #1 on: September 21, 2019, 05:29:52 pm »
One way is to break down the amount of time passed into regular chunks of time and process those separately.
That would be achieved with a "while (more time than the timestep is left to process)" rather than an "if (time is more than timestep)". Then just process each chunk as if only that chunk of time has passed. This leads to multiple updates in a single frame before drawing.

Of course, one other thing to consider is that that amount of time could be considerable and processing all of the chunks in that time still processes all of the time so setting a maximum time value to process is a good start (say, max of 1 second, for example)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Naofu

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: dealing with massive frame time
« Reply #2 on: September 22, 2019, 03:39:27 am »
So...do I have to separate all updatings and drawings like this?

// ......

if(frameTime > 1.f) frameTime = 1.f;
while(frameTime > 1 / 60.f)
{
        gameContent.Update(1 / 60.f);
        frameTime -= 1 / 60.f;
}
gameContent.Update(frameTime);
gameContent.Draw(window);       // or window.draw(gameContent);
window.display();
 

I've not tested it yet. Applying this to my current code needs a lot of changes, because of my badness which I combined some draw calls and updating sprites/vertices together. :'(

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: dealing with massive frame time
« Reply #3 on: September 22, 2019, 09:48:19 pm »
I would say leave the remaining frametime and store it and add it to the time next time around. That way, you're only ever processing a chunk of exactly the usual timestep. This allows it to be treated as a fixed timestep, which simplifies a number of things.

But, yes, do multiple updates of logic and then a single, final draw per frame.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Naofu

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: dealing with massive frame time
« Reply #4 on: September 23, 2019, 01:03:53 pm »
I'm surprised there are such several ways to solve this.

Ok, Thank you Hapax!  :D

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: dealing with massive frame time
« Reply #5 on: September 23, 2019, 09:00:30 pm »
You're welcome. Hope it helps! :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*