Delta Timing - what exactly is it?
Kikaru

What exactly is Delta Timing? I know it has something to do with changing how fast something thing goes (in the case of a moving object) based on how long it took to run the logic loop, but I'm not sure how to implement it, or even exactly how it works. I couldn't really understand the articles I found very well.

Thanks in advance!

blargmob

It is the measurement of time between to points in time.
Between 75ms and 100 ms is 25ms. 25ms is the delta time.

SiegeLord

Delta timing is basically variable time logic step timing.

First, you need a very accurate timer to keep the time. I do not think you can make a good delta timing based loop using allegro's timers for example.

Then you do this:

1float old_time = GetTime();
2while(!key[KEY_ESC])
3{
4 float new_time = GetTime();
5 float delta = new_time - old_time;
6 old_time = new_time;
7
8 if(delta > 0.1)//>0.1 sec
9 {
10 delta = 0.1;//you need this to keep your game from becoming numerically unstable
11 }
12
13 player->x += player->vx * delta;
14 player->sprite.time_passed += delta;
15
16 blit(buffer, screen, 0,0,0,0,100,100);
17
18 RestUntilDeltaIsAtLeastSomeInterval(old_time, 1 / 60.0);//60 frames per second max
19}

Basically, you measure the amount of time passed between each logic update, and do then base your logic things on that time interval. In the example above, for example, I move the player by multiplying his speed in units per second by the time passed in seconds. Also, I update some sprite time counter by the same interval. Then I blit to the screen as usual, and then do a frame limiting step. This last step is optional and most games don't do it, but it is nice to have for the laptop users.

You shouldn't use this method though for a couple of reasons: depending on the speed of the computer the results of the game might be dependent on the FPS, because Euler integration is like that. Also, you need a high quality timer, which you may not have.

At the same time this method is nice to have for this one reason: you can do 'bullet-time' effects trivially, just multiply the delta by some factor and automatically everything in the game is slowed down (or even sped up). This can be done in a fixed time step timing (the usual kind suggested on these forums) but it needs planning. With delta timing you get the ability automatically.

blargmob

That's a bit better explanation then mine :)

Kikaru

Thanks. So it's basically what I thought it was.

Thread #597295. Printed from Allegro.cc