1 /**
2  * Copyright:       Copyright (C) 2018 Gabriel Gheorghe, All Rights Reserved
3  * Authors:         $(Gabriel Gheorghe)
4  * License:         $(LINK2 https://www.gnu.org/licenses/gpl-3.0.txt, GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007)
5  * Source:          $(LINK2 https://github.com/GabyForceQ/LibertyEngine/blob/master/source/liberty/time.d)
6  * Documentation:
7  * Coverage:
8 **/
9 module liberty.time;
10 
11 import bindbc.glfw;
12 
13 import std.conv : to;
14 
15 /**
16  * Basic time manager class.
17 **/
18 final abstract class Time {
19   private {
20     static float delta = 0.0f;
21     static float lastFrame = 0.0f;
22     static float elapsed = 0.0f;
23   }
24 
25   /**
26    * Returns current time ticks in milliseconds.
27   **/
28   static float getTime()  {
29     return glfwGetTime();
30   }
31 
32   /**
33    * Returns delta time.
34   **/
35   static float getDelta()  {
36     return delta;
37   }
38 
39   /**
40    * Returns delta time as string.
41   **/
42   static string getDeltaStr() {
43     return delta.to!string;
44   }
45 
46   /**
47    * Returns last frame time.
48   **/
49   static float getLastFrame()  {
50     return lastFrame;
51   }
52 
53   /**
54    * Returns last frame time as string.
55   **/
56   static string getLastFrame() {
57     return lastFrame.to!string;
58   }
59 
60   /**
61    * Returns elapsed time.
62   **/
63   static float getElapsed()  {
64     return elapsed;
65   }
66 
67   /**
68    * Returns elapsed time as string.
69   **/
70   static string getElapsed() {
71     return elapsed.to!string;
72   }
73 
74   package static void processTime()  {
75     // Time should be porcessed every single frame
76     elapsed = getTime();
77     delta = elapsed - lastFrame;
78     lastFrame = elapsed;
79   }
80 }