R-Type
R-Type project
EClock.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** gameEngine2
4 ** File description:
5 ** EClock
6 */
7 
8 #ifndef ECLOCK_HPP_
9 #define ECLOCK_HPP_
10 
11 #include <chrono>
12 #include "ETime.hpp"
13 
14 namespace KapEngine {
15  namespace Time {
16  class ETime;
17  }
18 }
19 
20 namespace KapEngine {
21  namespace Time {
22  class EClock {
23  public:
24  EClock() {
25  PROFILER_FUNC_START();
26  __setNow();
27  PROFILER_FUNC_END();
28  }
29  EClock(EClock const& _clk) {
30  PROFILER_FUNC_START();
31  *this = _clk;
32  PROFILER_FUNC_END();
33  }
34  ~EClock() {}
35 
42  virtual ETime restart() {
43  PROFILER_FUNC_START();
44  ETime _got = __getElapse();
45  __setNow();
46  PROFILER_FUNC_END();
47  return _got;
48  }
49 
56  virtual ETime getElapseTime() {
57  PROFILER_FUNC_START();
58  PROFILER_FUNC_END();
59  return ETime(__getElapse());
60  }
61 
62  EClock &operator=(EClock const& _clk) {
63  PROFILER_FUNC_START();
64  this->_start = _clk._start;
65  PROFILER_FUNC_END();
66  return *this;
67  }
68 
69  protected:
70  int64_t _start = 0;
71  private:
72  int64_t __getElapse() {
73  PROFILER_FUNC_START();
74  std::chrono::microseconds ms = std::chrono::duration_cast<std::chrono::microseconds >(
75  std::chrono::high_resolution_clock::now().time_since_epoch()
76  );
77  int64_t _nVal = ms.count();
78  PROFILER_FUNC_END();
79  return (_nVal - _start);
80  }
81 
82  void __setNow() {
83  PROFILER_FUNC_START();
84  std::chrono::microseconds ms = std::chrono::duration_cast<std::chrono::microseconds >(
85  std::chrono::high_resolution_clock::now().time_since_epoch()
86  );
87  PROFILER_FUNC_END();
88  _start = ms.count();
89  }
90  };
91  }
92 }
93 
94 #endif /* !ECLOCK_HPP_ */
KapEngine::Time::EClock::getElapseTime
virtual ETime getElapseTime()
avoir le temps
Definition: EClock.hpp:56
KapEngine::Time::ETime
Engine Time is internal time system of engine.
Definition: ETime.hpp:25
KapEngine::Time::EClock
Definition: EClock.hpp:22
KapEngine
main namespace
Definition: Component.hpp:17
KapEngine::Time::EClock::restart
virtual ETime restart()
Redémarer la clock.
Definition: EClock.hpp:42