Tinman  1.0
timer.h
Go to the documentation of this file.
1 // Copyright (C) 2014 ISAAC LACOBA MOLINA
2 // Tinman author: Isaac Lacoba Molina
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef TIMER_H
18 #define TIMER_H
19 #include <chrono>
20 #include <cmath>
21 
22 class Timer {
23  public:
24  typedef std::chrono::steady_clock::duration DeltaTime;
25  typedef std::chrono::steady_clock::time_point Time;
26 
27  Timer();
28  virtual ~Timer();
29  float get_delta_time();
30  void start();
31  void restart();
32  void stop();
33 
34  float get_time_since_start();
35 
36  private:
38  DeltaTime delta_, freeze_time_;
39  float start_;
40 
41  float time_to_float(DeltaTime time);
42  float truncate(float number);
43  Time now();
44 };
45 
46 #endif
float get_delta_time()
Definition: timer.cpp:30
std::chrono::steady_clock::duration DeltaTime
Definition: timer.h:24
virtual ~Timer()
Definition: timer.cpp:27
Time now()
Definition: timer.cpp:68
Timer()
Definition: timer.cpp:21
float truncate(float number)
Definition: timer.cpp:63
DeltaTime freeze_time_
Definition: timer.h:38
float time_to_float(DeltaTime time)
Definition: timer.cpp:73
float get_time_since_start()
Definition: timer.cpp:38
float start_
Definition: timer.h:39
void start()
Definition: timer.cpp:45
void restart()
Definition: timer.cpp:51
Time stop_
Definition: timer.h:37
Definition: timer.h:22
DeltaTime delta_
Definition: timer.h:38
void stop()
Definition: timer.cpp:58
std::chrono::steady_clock::time_point Time
Definition: timer.h:25
Time last_time_
Definition: timer.h:37