hx3d  1
2D/3D Simple Game Framework
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
timer_manager.hpp
1 /*
2  Timer manager.
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_MANAGER
22 #define HX3D_UTILS_TIMER_MANAGER
23 
24 #include "hx3d/utils/callback_timer.hpp"
25 #include <map>
26 #include <string>
27 #include <vector>
28 
29 namespace hx3d {
30 
34 class TimerManager {
35  public:
36  TimerManager();
37 
44  void addNamedTimer(std::string name, CallbackTimer& timer);
45 
54  void createNamedTimer(std::string name, float delay, std::function<void()> callback, bool loop = false);
55 
61  void resetNamedTimer(std::string name);
62 
68  void removeNamedTimer(std::string name);
69 
75  void addTemporaryTimer(CallbackTimer& timer);
76 
84  void createTemporaryTimer(float delay, std::function<void()> callback, bool loop = false);
85 
91  void update(float delta);
92 
96  void clear();
97 
98  private:
99  std::map<std::string, CallbackTimer> _registered;
100  std::vector<CallbackTimer> _temporaries;
101 };
102 
103 } /* hx3d */
104 
105 #endif /* HX3D_UTILS_TIMER_MANAGER */
void addTemporaryTimer(CallbackTimer &timer)
Add an existing temporary timer.
void clear()
Clear all the timers.
hx3d framework namespace
Definition: audio.hpp:26
void resetNamedTimer(std::string name)
Reset a named timer.
Improved timer with callback execution.
void removeNamedTimer(std::string name)
Remove a named timer.
Manages multiple callback timers.
void createTemporaryTimer(float delay, std::function< void()> callback, bool loop=false)
Create a new temporary timer.
void update(float delta)
Update the timers.
void createNamedTimer(std::string name, float delay, std::function< void()> callback, bool loop=false)
Create a new named timer.
void addNamedTimer(std::string name, CallbackTimer &timer)
Add an existing named timer.