R-Type
R-Type project
ETime.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** gameEngine2
4 ** File description:
5 ** Time
6 */
7 
8 #ifndef TIME_HPP_
9 #define TIME_HPP_
10 
11 #include <cstdint>
12 
13 namespace KapEngine {
19  namespace Time {
20 
25  class ETime {
26  public:
27  ETime() {
28  PROFILER_FUNC_START();
29  _micro_s = 0;
30  PROFILER_FUNC_END();
31  }
32  ETime(int64_t _val) {
33  PROFILER_FUNC_START();
34  _micro_s = _val;
35  PROFILER_FUNC_END();
36  }
37  ETime(ETime const& _val) {
38  PROFILER_FUNC_START();
39  *this = _val;
40  PROFILER_FUNC_END();
41  }
42  ~ETime() {
43  PROFILER_FUNC_START();
44  PROFILER_FUNC_END();
45  }
46 
52  virtual double asSecond() const {
53  PROFILER_FUNC_START();
54  PROFILER_FUNC_END();
55  return ((double)asMilliSecond() / 1000.0);
56  }
62  virtual int32_t asMilliSecond() const {
63  PROFILER_FUNC_START();
64  PROFILER_FUNC_END();
65  return (_micro_s / 100);
66  }
72  virtual int64_t asMicroSecond() const {
73  PROFILER_FUNC_START();
74  PROFILER_FUNC_END();
75  return _micro_s;
76  }
77 
78  virtual ETime &operator=(ETime const& _time) {
79  PROFILER_FUNC_START();
80  this->_micro_s = _time._micro_s;
81  PROFILER_FUNC_END();
82  return *this;
83  }
84  virtual ETime &operator=(ETime const* _time) {
85  PROFILER_FUNC_START();
86  *this = *_time;
87  PROFILER_FUNC_END();
88  return *this;
89  }
90  virtual ETime &operator=(int64_t const& _val) {
91  PROFILER_FUNC_START();
92  this->_micro_s = _val;
93  PROFILER_FUNC_END();
94  return *this;
95  }
96 
97  virtual bool operator<(ETime const& _time) {
98  PROFILER_FUNC_START();
99  PROFILER_FUNC_END();
100  return (this->_micro_s < _time._micro_s);
101  }
102  virtual bool operator<(int64_t const& _time) {
103  PROFILER_FUNC_START();
104  PROFILER_FUNC_END();
105  return (this->_micro_s < _time);
106  }
107 
108  virtual bool operator<=(ETime const& _time) {
109  PROFILER_FUNC_START();
110  PROFILER_FUNC_END();
111  return (this->_micro_s <= _time._micro_s);
112  }
113  virtual bool operator<=(int64_t const& _time) {
114  PROFILER_FUNC_START();
115  PROFILER_FUNC_END();
116  return (this->_micro_s <= _time);
117  }
118 
119  virtual bool operator>(ETime const& _time) {
120  PROFILER_FUNC_START();
121  PROFILER_FUNC_END();
122  return (this->_micro_s > _time._micro_s);
123  }
124  virtual bool operator>(int64_t const& _time) {
125  PROFILER_FUNC_START();
126  PROFILER_FUNC_END();
127  return (this->_micro_s > _time);
128  }
129 
130  virtual bool operator>=(ETime const& _time) {
131  PROFILER_FUNC_START();
132  PROFILER_FUNC_END();
133  return (this->_micro_s >= _time._micro_s);
134  }
135  virtual bool operator>=(int64_t const& _time) {
136  PROFILER_FUNC_START();
137  PROFILER_FUNC_END();
138  return (this->_micro_s >= _time);
139  }
140 
141  virtual ETime &operator+=(ETime const& _time) {
142  PROFILER_FUNC_START();
143  this->_micro_s += _time._micro_s;
144  PROFILER_FUNC_END();
145  return *this;
146  }
147 
152  void setSeconds(float s) {
153  PROFILER_FUNC_START();
154  _micro_s = (int64_t)(s * 1000000.0f);
155  PROFILER_FUNC_END();
156  }
157 
162  void setMilliseconds(int64_t ms) {
163  PROFILER_FUNC_START();
164  _micro_s = ms * 100;
165  PROFILER_FUNC_END();
166  }
167 
173  void setMicroseconds(int64_t mc) {
174  PROFILER_FUNC_START();
175  _micro_s = mc;
176  PROFILER_FUNC_END();
177  }
178 
179  protected:
180  int64_t _micro_s;
181 
182  private:
183  };
184 
185  }
186 }
187 
188 #endif /* !TIME_HPP_ */
KapEngine::Time::ETime
Engine Time is internal time system of engine.
Definition: ETime.hpp:25
KapEngine::Time::ETime::asMicroSecond
virtual int64_t asMicroSecond() const
avoir le temps en microsecondes
Definition: ETime.hpp:72
KapEngine::Time::ETime::setMicroseconds
void setMicroseconds(int64_t mc)
Set the Microseconds of time.
Definition: ETime.hpp:173
KapEngine::Time::ETime::asSecond
virtual double asSecond() const
avoir le temps en secondes
Definition: ETime.hpp:52
KapEngine::Time::ETime::setMilliseconds
void setMilliseconds(int64_t ms)
Set the Milliseconds of time.
Definition: ETime.hpp:162
KapEngine::Time::ETime::asMilliSecond
virtual int32_t asMilliSecond() const
avoir le temps en millisecondes
Definition: ETime.hpp:62
KapEngine::Time::ETime::setSeconds
void setSeconds(float s)
Set the Seconds of time.
Definition: ETime.hpp:152
KapEngine
main namespace
Definition: Component.hpp:17