Fixing time step
#1 Members - Reputation: 391
Posted 01 December 2012 - 01:30 PM
The reason I ask is because if you are calculating times for animation tracks, you can just get the current time and use that as a reference point for local animations. I've done this and it seems to work pretty much spot on for animation timings, no matter how long your frame time is.
#2 Members - Reputation: 347
Posted 01 December 2012 - 01:53 PM
It really depends on the requirements of your game.
#3 Crossbones+ - Reputation: 5172
Posted 01 December 2012 - 02:16 PM
The basic way to think of it is that anything with a foundation in logic should be fixed, while anything that is purely graphical can be variable. Basic animations are generally purely graphics, but more complex ones may tie into simulation logic. You will have to decide for yourself which way to go.
L. Spiro
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#4 Members - Reputation: 239
Posted 01 December 2012 - 04:48 PM
The reason I ask is because if you are calculating times for animation tracks, you can just get the current time and use that as a reference point for local animations. I've done this and it seems to work pretty much spot on for animation timings, no matter how long your frame time is.
What happens if your game freezes for an entire second? Whether or not the animation is correct, the world will have advanced a whole second and the user will be confused about what happened in that time. For simple problems, maybe one doesn't need a fixed time step, but there should at least be a maximum allowable amount of time to pass in one frame.
#5 Members - Reputation: 391
Posted 02 December 2012 - 02:08 AM
What happens if your game freezes for an entire second?
I'm not sure if this would matter too much..? If you're mapping animation to actual time, when the frame finally appears, it will use the appropriate animation frame (interpolated between key frames,, etc) based on the local timeline of the animation. No matter when the frame is drawn, you'll sill know the absolute time so if you have two or three complex animation blends, it should still know where in the set to draw.
With regard to network play, I think if each client synchronises their clock at the start, wouldn't this negate the need for fixed time step?
I need to do some more reading on this but I was also wondering what happens with 3rd party physics libraries, how do they match up to your frame timing? Does it have all that built in itself or would you need to pass it delta times?
#6 Members - Reputation: 391
Posted 02 December 2012 - 02:48 AM
What happens if your game freezes for an entire second?
I'm not sure if this would matter too much..? If you're mapping animation to actual time, when the frame finally appears, it will use the appropriate animation frame (interpolated between key frames,, etc) based on the local timeline of the animation. No matter when the frame is drawn, you'll sill know the absolute time so if you have two or three complex animation blends, it should still know where in the set to draw.
With regard to network play, I think if each client synchronises their clock at the start, wouldn't this negate the need for fixed time step?
I need to do some more reading on this but I was also wondering what happens with 3rd party physics libraries, how do they match up to your frame timing? Does it have all that built in itself or would you need to pass it delta times?
#7 Crossbones+ - Reputation: 5172
Posted 02 December 2012 - 03:18 AM
That is just the animation of your character. What about the simulation of the game world?I'm not sure if this would matter too much..? If you're mapping animation to actual time, when the frame finally appears, it will use the appropriate animation frame (interpolated between key frames,, etc) based on the local timeline of the animation. No matter when the frame is drawn, you'll sill know the absolute time so if you have two or three complex animation blends, it should still know where in the set to draw.
If the game stops for 1 second, then starts again, and if you then pass a 1-second time-stamp to the physics engine, suddenly everything slams into the ground due to a second’s worth of accumulated gravity and suddenly bounces up into the air.
This is called a physics simulation explosion. It is well understood and a common artifact of variable-length time-steps.
As I said before, anything that needs to simulate the physical world or game logic should be on a fixed time-step.
Not at all. Firstly, synchronization is on-going, not just a once-at-the-start thing.With regard to network play, I think if each client synchronises their clock at the start, wouldn't this negate the need for fixed time step?
Secondly, you aren’t understanding the implications of different time-steps when running a physics simulation.
Two computers are playing a networked game. One is twice as fast as the other so it runs updates twice as fast.
When an object smacks into a wall, the computer with the slower time-step allows the object to interpenetrate the wall deeper than the faster computer would, thus changing the location of contact and possibly the angle of reflection, thus sending the object bouncing in a different direction than the faster would have.
With fixed time-steps the object interpenetrates by the same amount on each client and thus gets bounced off exactly the same for each client, baring differences floating-point modes. These tiny differences accumulate much less severely and are part of the cause for on-going synchronization.
L. Spiro
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#8 Members - Reputation: 391
Posted 02 December 2012 - 11:39 AM
One thing though - in the GoG article, he puts in his code that if the frame time is greater than 0.25 then clamp it at 0.25 - what happens here if there is a one second delay in the logic? It will only move on by 0.25 won't it?
#9 Crossbones+ - Reputation: 5172
Posted 02 December 2012 - 11:45 AM
This is not used for online games, however, and it is at your discretion to use it.
L. Spiro
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#11 Members - Reputation: 147
Posted 02 December 2012 - 09:49 PM
In fact, with varying time steps, the same computer running with the same inputs can (most likely will) produce different results, which can be problematic when hunting bugs etc.
And yes, L. Spiro's has some great resources
#12 Members - Reputation: 391
Posted 07 December 2012 - 05:31 PM
I'm sure it does work somehow but I can't get my head around it. You've got a while loop which is doing timesteps for your chosen increment and once you've reached the max ticks for the frame, you do a render. How can the amount of renders ever be more than the number of physics updates? I can't see how it can work...
I'm using the gafferongames example - I read that we 'trick' us into thinking we're using more render frames by interpolating at the end between physics updates, but I still can't see how that can look smooth, if you have 60 updates to do in a frame, you do them all and then render so how can you render more times than you do physics updates.
I'm probably missing something really simple... Could someone please explain?
Thanks
#13 Members - Reputation: 147
Posted 08 December 2012 - 12:36 AM
Example, you want to do 20 physics ticks per second, render as fast as possible:
20 ticks per second means you want the time between ticks to be 1 sec / 20 ticks/sec = 0.05 seconds or 50 ms
- keep track of when the last time you did a physics update. (Time A)
- the next physics tick should then happen at (Time A + Time between ticks)
So you'd have a while loop that does something like
[source lang="cpp"]while (play_game){ current_time = getthesystemtime(); while (last_physics_tick + time_between_physics_ticks > current_time) { do_physics_tick(current_time); last_physics_tick += time_between_physics_ticks; } // Here you want to draw a frame based on the current physics state // but the frame would only look accurate if past_physics_tick == current_time, // so what you want to do is interpolate movement of objects here by: extra_time = current_time - last_physics_tick. // aka you want to show things as they currently look, which is // last_physics_tick + extra_time (= current_time) // So, this call should draw the frame given the current physics state // and interpolate the position (or whatever) of the objects based on say // the latest velocity of the last tick. draw_frame(extra_time);}[/source]
Hope that helps!
#15 Members - Reputation: 391
Posted 08 December 2012 - 05:22 AM
Thanks for the write up Rethan, so if your physics step is one 30th of a second, lets say, and your physics step takes one 30th of a second to complete, you can only do 30 renders per second right? If your physics step is one 30th of a second and the physics step takes one 60th of a second, you can do 60 renders per second - so in essence, the rendering isn't really decoupled from the physics as such. Is that about right?
#17 Members - Reputation: 147
Posted 08 December 2012 - 12:09 PM
- if you want to do 30 physics ticks per second, your physics tick function should take (much) less than 1/30 seconds to complete, otherwise you'll start to stutter because you are doing physics all the time and you'll fall behind when rendering frames.
- If you want to do 30 physics ticks per second and your physics tick function takes 1/60 seconds, then you can draw as many frames that can fit in the other 1/60 seconds. So if your draw function is slow, you'll stutter, but if it's fast that will help smooth out the fast moving objects that get interpolated via "extra_time".
If during play there is a hickup (some other process hogs the cpu, some single frame took way long to render than usual etc) and you need to catch up on some physics ticks, you'd end up doing a number of catchup physics ticks before rendering again (which will cause things to jump to the user). This is a case you may want to plan for by limiting the number of catchup physics ticks to run, and/or by limiting the wall clock time that the physics is allowed to take to catch up etc.
So worst cases:
- if your physics takes a long time, your game will become sluggish/slow (the FPS becomes choppy, the game looks like it's in slow-mo).
- if your graphics takes a long time, your game will become unresponsive (things happen that the user can't react to properly).
#18 Members - Reputation: 391
Posted 09 December 2012 - 03:02 PM
I'm not really sure where to start looking for this 0.2 seconds or whether it's worth it.
Edited by RobMaddison, 09 December 2012 - 03:03 PM.
#19 Crossbones+ - Reputation: 5172
Posted 09 December 2012 - 08:33 PM
You are likely accumulating small errors over many iterations/frames. This can and will happen if you accumulate time using floating-point values etc.
You will need to show how you accumulate time, including the types of all variables involved.
L. Spiro
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#20 GDNet+ - Reputation: 1731
Posted 10 December 2012 - 01:42 AM
As a side note. We using computers can go great lengths how this is inaccurate. But, in generic science, to produce an accurate measurement you need instruments guaranteed to be as accurate and a methodology guaranteed to be compatible with instrument accuracy.my keyframes are between 0.0 and 1.0) and after around 10 minutes, it looks like my animation is edging ahead of time by around 0.2 seconds. I know over 10 minutes this isn't much, but is this generally acceptable? Over 50 minutes we're talking a second out - probably not a big deal but worth checking.
Both your tests are visual and manual as long as I understand. The methodology does not appear adeguate to guarantee this level of accuracy, much less to drive serious decisions.
By generic scientific method.
As a fact, being off by .2s after 10 minutes looks compatible with reaction time.
I'd investigate the issue for further confirmation (nobody really wants to accumulate errors too much) but I wouldn't jump in to fix this.






