R-Type  2
Doom but in better
Loading...
Searching...
No Matches
Clock.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** rtype (Workspace)
4** File description:
5** Clock.cpp
6*/
7
15
16GUI::ECS::Systems::Clock::Clock(const std::uint32_t entityId)
17 : EntityNode(entityId)
18{
19 _clock.restart();
20 _isRunning = true;
21}
22
24
26{
27 std::int64_t node = 0;
28 if (_isRunning) {
29 node = _clock.restart().asMicroseconds();
30 } else {
31 node = _clock.reset().asMicroseconds();
32 }
33 return node;
34}
35
37{
38 return _clock.getElapsedTime().asMicroseconds();
39}
40
42{
43 _clock.start();
44 _isRunning = true;
45}
46
48{
49 _clock.stop();
50 _isRunning = false;
51}
52
54{
55 return _isRunning;
56}
57
58
59const std::string GUI::ECS::Systems::Clock::getInfo(const unsigned int indent) const
60{
61
62 std::string indentation = "";
63 for (unsigned int i = 0; i < indent; ++i) {
64 indentation += "\t";
65 }
66 std::string result = indentation + "Clock:\n";
67 result += indentation + "- Entity Id: " + Recoded::myToString(getEntityNodeId()) + "\n";
68 result += indentation + "- Is Running: " + Recoded::myToString(isRunning()) + "\n";
69 result += indentation + "- Elapsed Time: " + Recoded::myToString(getElapsedTime()) + "\n";
70 return result;
71}
72
73std::ostream &GUI::ECS::Systems::operator<<(std::ostream &os, const GUI::ECS::Systems::Clock &item)
74{
75 os << item.getInfo();
76 return os;
77}
This is the file that contains the Clock class.
A class for managing time tracking within the ECS system.
Definition Clock.hpp:36
const std::int64_t getElapsedTime() const
Gets the elapsed time since the clock was last reset.
Definition Clock.cpp:36
void stop()
Stops the clock.
Definition Clock.cpp:47
const std::string getInfo(const unsigned int indent=0) const
This is a function meant for debugging purposes It will dump the current state of the variables upon ...
Definition Clock.cpp:59
const bool isRunning() const
Checks if the clock is currently running.
Definition Clock.cpp:53
Clock(const std::uint32_t entityId=0)
Construct a new Clock object.
Definition Clock.cpp:16
const std::int64_t reset()
Resets the clock and returns the elapsed time since the last reset.
Definition Clock.cpp:25
~Clock()
Destroy the Clock object.
Definition Clock.cpp:23
void start()
Starts the clock.
Definition Clock.cpp:41
std::ostream & operator<<(std::ostream &os, const Clock &item)
Outputs the clock's info to a stream.
Definition Clock.cpp:73
const std::string myToString(const Rect< RectType > &rectangle)
Converts a Rect<T> object to its string representation.
Definition Rect.hpp:223