1 /**
2  * Defines the static Time class, which manages all game time related things.
3  */
4 module utility.time;
5 import utility.output;
6 
7 import std.datetime;
8 
9 /**
10  * Manages time and delta time.
11  */
12 final abstract class Time
13 {
14 public static:
15 	/**
16 	 * Time since last frame, in seconds.
17 	 */
18 	final @property float deltaTime() { return 0.016; }
19 	/**
20 	 * Total time spent running, in seconds.
21 	 */
22 	final @property float totalTime() { return 1.00f; }
23 
24 	/**
25 	 * Initialize the time controller with initial values.
26 	 */
27 	static this()
28 	{
29 		cur = prev = Clock.currTime;
30 		second = total = delta = 0.0f;
31 		frameCount = 0;
32 	}
33 
34 	/**
35 	 * Update the times. Only call once per frame!
36 	 */
37 	final void update()
38 	{
39 		delta = ( cur - prev ).fracSec.nsecs / 1_000_000_000.0f;
40 		total += delta;
41 
42 		debug
43 		{
44 			++frameCount;
45 			second += delta;
46 			if( second >= 1.0f )
47 			{
48 				Output.printValue( OutputType.Info, "Framerate", frameCount );
49 				second = frameCount = 0;
50 			}
51 		}
52 
53 		prev = cur;
54 		cur = Clock.currTime;
55 	}
56 
57 private:
58 	SysTime cur;
59 	SysTime prev;
60 	float delta;
61 	float total;
62 	float second;
63 	int frameCount;
64 }