rag
graphic 2d engine
Timer.h
1 #ifndef _TIMER_H_
2 #define _TIMER_H_
3 
4 #include "Ease.h"
5 #include <rag/Platform.h>
6 
7 namespace rag
8 {
10  class Timer
11  {
12 
13  public:
14 
15  Timer();
16 
18  void start(float time, bool loop = false);
19 
21 
22  float getDelta(Ease::EaseType easetype = Ease::linear_01);
23 
25  bool finished();
26 
28  bool running();
29 
31  void reset();
32 
34  static float deltaTime;
35 
37  static float totalTime;
38 
40  static float timeFactor;
41 
42  private:
43 
44  float time;
45  bool loop;
46  float startTime;
47  bool isRunning;
48  rag::Ease ease;
49 
50 
51  };
52 
53  extern void sleep(int ms);
54 
55 
57  class Chrono
58  {
59  public:
60  Chrono();
61 
63  float getElapsedTime();
64 
66  void reset();
67 
68  private:
69  timeval startTime;
70  };
71 }
72 
73 
74 
75 #endif
Provides time-related functionality.
Definition: Timer.h:10
bool running()
True if the timer is running.
Definition: Timer.cpp:145
static float deltaTime
Stores the elapsed time from frame to frame (use at your convenience).
Definition: Timer.h:34
float getElapsedTime()
Get elapsed time from chrono construction.
Definition: Timer.cpp:202
Definition: Bitmap.h:8
Collection of code-generated curves useful to create procedural tween animations. ...
Definition: Ease.h:887
void reset()
Reset time to 0.
Definition: Timer.cpp:211
bool finished()
True if the timer has been running for the time specified at the start or more. Only valid for non-lo...
Definition: Timer.cpp:140
static float totalTime
Stores total time since app starts.
Definition: Timer.h:37
void start(float time, bool loop=false)
Starts the Timer with a fixed amount of time.
Definition: Timer.cpp:150
void reset()
Reset stops the timer and puts it in the same state it was before start running.
Definition: Timer.cpp:158
static float timeFactor
Factor shared by which all Timer instances.
Definition: Timer.h:40
EaseType
The types of curve supported.
Definition: Ease.h:893
float getDelta(Ease::EaseType easetype=Ease::linear_01)
Returns the time elapsed since the start interpolated between 0 and 1.
Definition: Timer.cpp:165
Helper class to count time elapsed from a moment in time.
Definition: Timer.h:57