File tree 1 file changed +23
-21
lines changed
1 file changed +23
-21
lines changed Original file line number Diff line number Diff line change 2
2
#include < thread>
3
3
4
4
5
- Clock::Clock () {
6
- last = std::chrono::system_clock::now ();
7
- first = true ;
8
- }
9
-
10
- std::chrono::milliseconds Clock::tick () {
11
- const auto current = std::chrono::system_clock::now ();
12
- std::chrono::milliseconds delta = std::chrono::duration_cast<std::chrono::milliseconds>(
13
- current - this ->last
14
- );
15
- this ->last = current;
16
- return delta;
17
- }
5
+ namespace SDL {
6
+ Clock::Clock () {
7
+ last = std::chrono::system_clock::now ();
8
+ first = true ;
9
+ }
18
10
19
- std::chrono::milliseconds Clock::tick (const float fps) {
20
- const auto delta = this ->tick ();
21
- const auto min_delta = std::chrono::duration<double >(1.0 / double (fps));
22
- const auto delta_delta = delta - min_delta;
23
- if (delta_delta > std::chrono::duration<double >(0 .)) {
24
- std::this_thread::sleep_for (delta_delta);
25
- return std::chrono::duration_cast<std::chrono::milliseconds>(min_delta);
26
- } else {
11
+ std::chrono::milliseconds Clock::tick () {
12
+ const auto current = std::chrono::system_clock::now ();
13
+ std::chrono::milliseconds delta = std::chrono::duration_cast<std::chrono::milliseconds>(
14
+ current - this ->last
15
+ );
16
+ this ->last = current;
27
17
return delta;
28
18
}
19
+
20
+ std::chrono::milliseconds Clock::tick (const float fps) {
21
+ const auto delta = this ->tick ();
22
+ const auto min_delta = std::chrono::duration<double >(1.0 / double (fps));
23
+ const auto delta_delta = delta - min_delta;
24
+ if (delta_delta > std::chrono::duration<double >(0 .)) {
25
+ std::this_thread::sleep_for (delta_delta);
26
+ return std::chrono::duration_cast<std::chrono::milliseconds>(min_delta);
27
+ } else {
28
+ return delta;
29
+ }
30
+ }
29
31
}
You can’t perform that action at this time.
0 commit comments