hx3d  1
2D/3D Simple Game Framework
timer.hpp
1 /*
2  Timer.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_UTILS_TIMER
22 #define HX3D_UTILS_TIMER
23 
24 #include <chrono>
25 
26 namespace hx3d {
27 
31 class Timer {
32 
33 public:
34 
39  Timer();
40 
47  Timer(long delay, bool loop = false);
48 
55  void initialize(long delay, bool loop = false);
56 
60  void reset();
61 
67  long remaining();
68 
74  bool hasEnded();
75 
79  void update(float delta);
80 
86  bool isLooping();
87 
88 private:
89 
91  long _delay;
93  float _elapsed;
95  bool _alreadyEnded;
97  bool _loop;
98 };
99 
100 } /* hx3d */
101 
102 #endif
Simple timer.
Definition: timer.hpp:31
void update(float delta)
Update the timer.
Definition: timer.cpp:76
void reset()
Reset the timer.
Definition: timer.cpp:41
void initialize(long delay, bool loop=false)
Initialize the timer with a delay.
Definition: timer.cpp:34
bool hasEnded()
Test if the timer has ended.
Definition: timer.cpp:58
bool isLooping()
Is the timer looping ?
Definition: timer.cpp:54
hx3d framework namespace
Definition: audio.hpp:26
Timer()
Create an uninitialized timer. See initialize.
Definition: timer.cpp:27
long remaining()
Get the remaining time as milliseconds.
Definition: timer.cpp:46