Hi folks,
I'm having the old jitter-bug problem trying to sync my game frame-rate with the physics step(s).
I have read these posts:
viewtopic.php?f=4&t=3973
viewtopic.php?f=4&t=3027
And read Glenn Fiedler's article (http://gafferongames.com/game-physics/f ... -timestep/) but I'm obviously missing something because I'm not understanding how this solves the problem.
I am developing for Android, and as such I have VERY limited [hardware] resources. Rendering is done in hardware (opengl) and hence I kind of NEED to process physics steps in a separate thread (hence CPU for phys, GPU for render.. more or less).
So this creates the problem with a variable frame-rate. I am synchronizing the step(s) of box2d with the render so I have a stable physics state while rendering, but the variable frame-rate means one of two things:
1. I fix a set number of steps in physics land, and the game runs at wildly different speeds depending on the framerate... no good.
2. I bind the number of fixed-time steps to the time taken for the previous render. This gives a constant-time game, but also gives a very jittery experience as one render frame will involve a variable number of physics steps.
What I can't get my head around is how this is solvable. Glenn Fiedler states:
Excuse my noobness, but I have absolutely no idea what this means in a box2d context. I assume it means stepping with a constant time for a given number of steps, then stepping with a smaller time for the "remainder" which together with the cumulative time taken for the fixed steps matches with the previous frame render time.
Reading the above-mentioned posts, the assumption seems to be that rendering and physics are done in the same thread. This just won't work for me because an average render is usually closer to 32ms anyway so adding the time taken to process box2d would destroy the framerate.
The second (viewtopic.php?f=4&t=3027) post also seems to indicate the solution is:
But this is the same solution I currently have, and means that every render frame is not guaranteed to have the same number of physics steps. Which means bodies will appear to "jump" forward every so often as the accumulated time reaches one "step-worth".
I'm hoping (assuming) there is someone out there considerably less nooby than I clearly am to help shed some light on this.
Thanks!
I'm having the old jitter-bug problem trying to sync my game frame-rate with the physics step(s).
I have read these posts:
viewtopic.php?f=4&t=3973
viewtopic.php?f=4&t=3027
And read Glenn Fiedler's article (http://gafferongames.com/game-physics/f ... -timestep/) but I'm obviously missing something because I'm not understanding how this solves the problem.
I am developing for Android, and as such I have VERY limited [hardware] resources. Rendering is done in hardware (opengl) and hence I kind of NEED to process physics steps in a separate thread (hence CPU for phys, GPU for render.. more or less).
So this creates the problem with a variable frame-rate. I am synchronizing the step(s) of box2d with the render so I have a stable physics state while rendering, but the variable frame-rate means one of two things:
1. I fix a set number of steps in physics land, and the game runs at wildly different speeds depending on the framerate... no good.
2. I bind the number of fixed-time steps to the time taken for the previous render. This gives a constant-time game, but also gives a very jittery experience as one render frame will involve a variable number of physics steps.
What I can't get my head around is how this is solvable. Glenn Fiedler states:
Quote:
The solution is to interpolate between the previous physics state and the current state based on how much time is left in the accumulator.
Excuse my noobness, but I have absolutely no idea what this means in a box2d context. I assume it means stepping with a constant time for a given number of steps, then stepping with a smaller time for the "remainder" which together with the cumulative time taken for the fixed steps matches with the previous frame render time.
Reading the above-mentioned posts, the assumption seems to be that rendering and physics are done in the same thread. This just won't work for me because an average render is usually closer to 32ms anyway so adding the time taken to process box2d would destroy the framerate.
The second (viewtopic.php?f=4&t=3027) post also seems to indicate the solution is:
Code:
double max = _dt*2.0;
while (deltasec>=max && !_quit)
{
m_world->Step((float)_dt, _iters);
deltasec -= _dt;
}
m_world->Step((float)deltasec, _iters); //This syncs up the physics engine to the current frame
while (deltasec>=max && !_quit)
{
m_world->Step((float)_dt, _iters);
deltasec -= _dt;
}
m_world->Step((float)deltasec, _iters); //This syncs up the physics engine to the current frame
But this is the same solution I currently have, and means that every render frame is not guaranteed to have the same number of physics steps. Which means bodies will appear to "jump" forward every so often as the accumulated time reaches one "step-worth".
I'm hoping (assuming) there is someone out there considerably less nooby than I clearly am to help shed some light on this.
Thanks!