Delta Time - Streamlined Time Keeping For Games

jordan4ibanez jordan4ibanez002 at gmail.com
Sat Aug 20 00:32:25 UTC 2022


This library is extremely simple. A time keeping library for game 
development.

You can see/get it here: 
https://code.dlang.org/packages/delta_time

Many things in games are bound to a simple constraint: time. In 
years past, games would commonly link the game's logic to the 
FPS, but if FPS goes too high, or too low. All of a sudden the 
player's experience is greatly skewed. So a very simple fix for 
this was to get a calculation of the time between the last frame 
and the current frame, then multiply all logic by this value.

This library allows you to track it precisely between frames. 
Nanoseconds precise.

Here's a bare bones example on how to use it:

```d
import delta_time;

void main() {
    bool gameRunning = true;
    // The root loop of the entire game
    while(gameRunning) {
       calculateDelta();

      // Now anywhere in the program on the main thread
      // if delta_time is imported, it can access it by running 
this:
      double theDelta = getDelta();
    }
}

```

The first delta will always be 0, as there is no before time to 
calculate. Hopefully this helps you with your game. Thanks for 
reading.


More information about the Digitalmars-d mailing list