-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
39 lines (31 loc) · 692 Bytes
/
Copy pathtimer.h
File metadata and controls
39 lines (31 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef TIMER_H
#define TIMER_H
#include <functional>
#include <SDL2/SDL.h>
#ifndef SDL_GetTicks64
#define SDL_GetTicks64 SDL_GetTicks
#endif
class Counter {
float time;
public:
Counter(float time = 0.0f);
float get_time() const;
void set_time(float time);
void tick(float seconds);
};
class ActionCounter : Counter {
std::function<void(void)> action;
public:
ActionCounter(float time = 0.0f, std::function<void(void)> action = []( ) -> void { });
void tick(float seconds);
};
class Timer {
Uint64 start = SDL_GetTicks64();
Uint64 end;
float time = 0.0;
public:
void tick_and_delay(float tick_time);
void tick(float tick_time);
void reset();
};
#endif