Allegro.cc Forums » Programming Questions » Delta Timing - what exactly is it?

Credits go to blargmob and SiegeLord for helping out!
 This thread is locked; no one can reply to it.
 Delta Timing - what exactly is it?
 Kikaru Member #7,616 August 2006 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 Member #8,356 February 2007 It is the measurement of time between to points in time.Between 75ms and 100 ms is 25ms. 25ms is the delta time. ---"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski
SiegeLord
Member #7,827
October 2006

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:

 1 float old_time = GetTime(); 2 while(!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.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

 blargmob Member #8,356 February 2007 That's a bit better explanation then mine ---"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski
 Kikaru Member #7,616 August 2006 Thanks. So it's basically what I thought it was.
 Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads