ScummVM API documentation
chrono.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef AGS_STD_CHRONO_H
23 #define AGS_STD_CHRONO_H
24 
25 #include "common/system.h"
26 
27 namespace AGS3 {
28 namespace std {
29 
30 namespace chrono {
31 
32 class duration {
33 private:
34  uint32 _value;
35 public:
36  duration() : _value(0) {
37  }
38  duration(uint32 value) : _value(value) {
39  }
40 
41  size_t count() const {
42  // durations for ScummVM are hardcoded to be in milliseconds
43  return 1000;
44  }
45 
46  operator uint32() const {
47  return _value;
48  }
49 
50  inline bool operator>=(const duration &rhs) const {
51  return _value >= rhs._value;
52  }
53 };
54 
55 class milliseconds : public duration {
56 public:
57  milliseconds() : duration(0) {}
58  milliseconds(uint32 val) : duration(val) {}
59 
60  static milliseconds zero() {
61  return milliseconds();
62  }
63 };
64 
65 class microseconds : public duration {
66 public:
67  microseconds() : duration(0) {}
68  microseconds(long val) : duration(val / 1000) {}
69 };
70 
71 
72 struct system_clock {
73 };
74 
75 
76 struct steady_clock { // wraps QueryPerformanceCounter
77  using rep = uint32;
78  using period = milliseconds;
79  using duration = milliseconds;
80  using time_point = uint32;
81  static constexpr bool is_steady = true;
82 
83  static time_point now() { // get current time
84  return g_system->getMillis();
85  }
86 };
87 
89 
90 template<class T>
91 duration duration_cast(T param);
92 
93 template<class T>
94 duration duration_cast(T param) {
95  return duration(param);
96 }
97 
98 } // namespace chrono
99 
100 } // namespace std
101 } // namespace AGS3
102 
103 #endif
Definition: chrono.h:76
virtual uint32 getMillis(bool skipRecord=false)=0
Definition: chrono.h:32
OSystem * g_system
Definition: chrono.h:65
Definition: ags.h:40
Definition: chrono.h:72
Definition: chrono.h:55