Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
timestep.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace helios {
4
5/**
6 * @brief Represents a time step in seconds.
7 * @details Provides utility functions to convert to milliseconds and framerate.
8 */
9class Timestep {
10public:
11 /**
12 * @brief Default constructor, initializes time step to 0.
13 */
14 constexpr Timestep() noexcept = default;
15
16 /**
17 * @brief Constructs a Timestep with the given time in seconds.
18 * @param time Time in seconds.
19 */
20 explicit constexpr Timestep(float time) noexcept : time_(time) {}
21 constexpr Timestep(const Timestep&) noexcept = default;
22 constexpr Timestep(Timestep&&) noexcept = default;
23 constexpr ~Timestep() noexcept = default;
24
25 constexpr Timestep& operator=(const Timestep&) noexcept = default;
26 constexpr Timestep& operator=(Timestep&&) noexcept = default;
27
28 explicit constexpr operator float() const noexcept { return time_; }
29
30 /**
31 * @brief Gets the time step in seconds.
32 * @return Time step in seconds.
33 */
34 [[nodiscard]] constexpr float Sec() const noexcept { return time_; }
35
36 /**
37 * @brief Gets the time step in milliseconds.
38 * @return Time step in milliseconds.
39 */
40 [[nodiscard]] constexpr float MilliSec() const noexcept { return time_ * 1000.0F; }
41
42 /**
43 * @brief Gets the framerate corresponding to the time step.
44 * @return Framerate (frames per second).
45 */
46 [[nodiscard]] constexpr float Framerate() const noexcept { return 1.0F / time_; }
47
48private:
49 float time_ = 0.0F;
50};
51
52} // namespace helios
Represents a time step in seconds.
Definition timestep.hpp:9
constexpr Timestep(Timestep &&) noexcept=default
constexpr float Framerate() const noexcept
Gets the framerate corresponding to the time step.
Definition timestep.hpp:46
constexpr Timestep(const Timestep &) noexcept=default
constexpr float MilliSec() const noexcept
Gets the time step in milliseconds.
Definition timestep.hpp:40
constexpr Timestep() noexcept=default
Default constructor, initializes time step to 0.
constexpr float Sec() const noexcept
Gets the time step in seconds.
Definition timestep.hpp:34