ScummVM API documentation
time.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 NANCY_TIME_H
23 #define NANCY_TIME_H
24 
25 #include "common/scummsys.h"
26 
27 namespace Nancy {
28 
29 // A small utility struct to measure/accumulate time
30 struct Time {
31 public:
32  Time() { _milliseconds = 0; }
33  Time(const uint32 &t) { _milliseconds = t; }
34  Time(const Time &t) = default;
35  ~Time() = default;
36  explicit operator uint32() const { return _milliseconds; }
37  Time &operator=(const Time &t) { if (this != &t) _milliseconds = t._milliseconds; return *this; }
38  Time &operator=(const uint32 &t) { _milliseconds = t; return *this; }
39  Time &operator+=(const Time &t) { _milliseconds += t._milliseconds; return *this; }
40  Time &operator+=(const uint32 &t) { _milliseconds+=t; return *this; }
41  Time &operator-=(const Time &t) { _milliseconds -= t._milliseconds; return *this; }
42  Time &operator-=(const uint32 &t) { _milliseconds-=t; return *this; }
43 
44  friend Time operator+(Time l, const Time &r) { l += r; return l; }
45  friend Time operator+(Time l, const uint32 &r) { l += r; return l; }
46  friend Time operator+(const uint32 &l, Time r) { r += l; return r; }
47  friend Time operator-(Time l, const Time &r) { l -= r; return l; }
48  friend Time operator-(Time l, const uint32 &r) { l -= r; return l; }
49  friend Time operator-(const uint32 &l, Time r) { r -= l; return r; }
50 
51  friend bool operator== (const Time &l, const Time &r) { return l._milliseconds == r._milliseconds; }
52  friend bool operator== (const Time &l, const uint32 &r) { return l._milliseconds == r; }
53  friend bool operator== (const uint32 &l, const Time &r) { return l == r._milliseconds; }
54  friend bool operator!= (const Time &l, const Time &r) { return l._milliseconds != r._milliseconds; }
55  friend bool operator!= (const Time &l, const uint32 &r) { return l._milliseconds != r; }
56  friend bool operator!= (const uint32 &l, const Time &r) { return l != r._milliseconds; }
57  friend bool operator< (const Time &l, const Time &r) { return l._milliseconds < r._milliseconds; }
58  friend bool operator< (const Time &l, const uint32 &r) { return l._milliseconds < r; }
59  friend bool operator< (const uint32 &l, const Time &r) { return l < r._milliseconds; }
60  friend bool operator> (const Time &l, const Time &r) { return r < l; }
61  friend bool operator> (const Time &l, const uint32 &r) { return r < l; }
62  friend bool operator> (const uint32 &l, const Time &r) { return r < l; }
63  friend bool operator<= (const Time &l, const Time &r) { return !(l > r); }
64  friend bool operator<= (const Time &l, const uint32 &r) { return !(l > r); }
65  friend bool operator<= (const uint32 &l, const Time &r) { return !(l > r); }
66  friend bool operator>= (const Time &l, const Time &r) { return !(l < r); }
67  friend bool operator>= (const Time &l, const uint32 &r) { return !(l < r); }
68  friend bool operator>= (const uint32 &l, const Time &r) { return !(l < r); }
69 
70  uint16 getSeconds() const { return (_milliseconds / 1000) % 60; }
71  uint16 getMinutes() const { return (_milliseconds / 60000) % 60; }
72  uint16 getTotalHours() const { return _milliseconds / 3600000; }
73 
74  uint16 getHours() const { return (_milliseconds / 3600000) % 24; } // Used for player time
75  uint16 getDays() const { return _milliseconds / 86400000; } // up to 49.7 days
76 
77 private:
78  uint32 _milliseconds;
79 };
80 
81 } // End of namespace Nancy
82 
83 #endif // NANCY_TIME_H
Definition: time.h:30
Definition: actionmanager.h:32