This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Arcade | ||
** File description: | ||
** Clock.hpp | ||
*/ | ||
|
||
#ifndef ARCADE_CLOCK_HPP | ||
#define ARCADE_CLOCK_HPP | ||
|
||
#include <chrono> | ||
|
||
#include "RayTracer/Clock/Time.hpp" | ||
|
||
namespace Arcade | ||
{ | ||
class Clock | ||
{ | ||
public: | ||
/** | ||
* @brief Construct a new Clock object | ||
*/ | ||
Clock() { restart(); }; | ||
|
||
~Clock() = default; | ||
|
||
/** | ||
* @brief Restart the clock | ||
*/ | ||
void restart() { m_start = std::chrono::high_resolution_clock::now(); }; | ||
|
||
/** | ||
* @brief Pause the clock | ||
*/ | ||
void pause(); | ||
|
||
/** | ||
* @brief Resume the clock | ||
*/ | ||
void resume(); | ||
|
||
/** | ||
* @brief Get the elapsed time since the last restart | ||
* | ||
* @return Time The elapsed time | ||
*/ | ||
[[nodiscard]] Time getElapsedTime() const; | ||
|
||
/** | ||
* @brief TimePoint is a type alias for a time point which is a very long and complicated type in the standard library | ||
*/ | ||
using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>; | ||
|
||
private: | ||
TimePoint m_start{}; | ||
TimePoint m_pause{}; | ||
bool m_paused{false}; | ||
|
||
}; // Clock | ||
|
||
} // namespace Arcade | ||
|
||
#endif // ARCADE_CLOCK_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Arcade | ||
** File description: | ||
** time.hpp | ||
*/ | ||
|
||
#ifndef ARCADE_TIME_HPP | ||
#define ARCADE_TIME_HPP | ||
|
||
namespace Arcade | ||
{ | ||
class Time | ||
{ | ||
public: | ||
/** | ||
* @brief Construct a new Time object | ||
*/ | ||
explicit Time(double seconds) : m_seconds(seconds) {}; | ||
|
||
/** | ||
* @brief Transform the time to seconds | ||
*/ | ||
[[nodiscard]] int asSeconds() const { return static_cast<int>(m_seconds); }; | ||
|
||
/** | ||
* @brief Transform the time to milliseconds | ||
*/ | ||
[[nodiscard]] int asMilliseconds() const { return static_cast<int>(m_seconds * 1000); } | ||
|
||
/** | ||
* @brief Transform the time to microseconds | ||
*/ | ||
[[nodiscard]] int asMicroseconds() const { return static_cast<int>(m_seconds * 1000000); }; | ||
|
||
private: | ||
double m_seconds{0.0F}; | ||
|
||
}; // Time | ||
|
||
} // namespace Arcade | ||
|
||
#endif // ARCADE_TIME_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Arcade | ||
** File description: | ||
** Clock.cpp | ||
*/ | ||
|
||
#include "RayTracer/Clock/Clock.hpp" | ||
|
||
void Arcade::Clock::pause() | ||
{ | ||
if (!m_paused) { | ||
m_pause = std::chrono::high_resolution_clock::now(); | ||
m_paused = true; | ||
} | ||
} | ||
|
||
void Arcade::Clock::resume() | ||
{ | ||
if (m_paused) { | ||
m_start += std::chrono::high_resolution_clock::now() - m_pause; | ||
m_paused = false; | ||
} | ||
} | ||
|
||
Arcade::Time Arcade::Clock::getElapsedTime() const | ||
{ | ||
TimePoint now = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<float> elapsed_time{}; | ||
if (m_paused) { | ||
elapsed_time = m_pause - m_start; | ||
} else { | ||
elapsed_time = now - m_start; | ||
} | ||
return Time(elapsed_time.count()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.