stellarlib 0.1.0
Loading...
Searching...
No Matches
clock.hpp
1/* clang-format off */
2
3/*
4 stellarlib
5 Copyright (C) 2025-2026 Domán Zana
6
7 This software is provided 'as-is', without any express or implied
8 warranty. In no event will the authors be held liable for any damages
9 arising from the use of this software.
10
11 Permission is granted to anyone to use this software for any purpose,
12 including commercial applications, and to alter it and redistribute it
13 freely, subject to the following restrictions:
14
15 1. The origin of this software must not be misrepresented; you must not
16 claim that you wrote the original software. If you use this software
17 in a product, an acknowledgment in the product documentation would be
18 appreciated but is not required.
19 2. Altered source versions must be plainly marked as such, and must not be
20 misrepresented as being the original software.
21 3. This notice may not be removed or altered from any source distribution.
22*/
23
24#ifndef STELLARLIB_APP_CLOCK_HPP
25#define STELLARLIB_APP_CLOCK_HPP
26
27#include <stellarlib/app/lifecycle.hpp>
28
29/**
30 * @brief Application runtime
31 */
33{
34/**
35 * @brief Clock subsystem
36 */
37class clock final
38{
39friend internal::lifecycle<class context>;
40
41public:
42 /**
43 * @brief Clock initialization descriptor
44 */
45 struct info final
46 {
47 /**
48 * @brief Target scene update frequency in hertz [0.0F, +INF) (0.0F means as fast as possible)
49 */
51
52 /**
53 * @brief Maximum allowed delta time in seconds [0.0F, +INF)
54 */
55 float max_delta;
56 };
57
58 /**
59 * @brief Deleted copy constructor
60 */
61 [[nodiscard]]
62 constexpr clock(const clock &) noexcept = delete;
63
64 /**
65 * @brief Deleted move constructor
66 */
67 [[nodiscard]]
68 constexpr clock(clock &&) noexcept = delete;
69
70 /**
71 * @brief Deleted copy assignment operator
72 */
73 constexpr auto operator=(const clock &) noexcept
74 -> clock & = delete;
75
76 /**
77 * @brief Deleted move assignment operator
78 */
79 constexpr auto operator=(clock &&) noexcept
80 -> clock & = delete;
81
82 /**
83 * @brief Destructor
84 */
86
87 /**
88 * @brief Returns the elapsed time in seconds since context initialization
89 * @return Elapsed time in seconds since context initialization
90 */
91 [[nodiscard]]
92 auto now() const
93 -> float;
94
95 /**
96 * @brief Returns the target scene update frequency in hertz [0.0F, +INF) (0.0F means as fast as possible)
97 * @return Target scene update frequency in hertz [0.0F, +INF) (0.0F means as fast as possible)
98 */
99 [[nodiscard]]
100 auto target_frequency() const
101 -> float;
102
103 /**
104 * @brief Sets the target scene update frequency in hertz [0.0F, +INF) (0.0F means as fast as possible)
105 * @param target_frequency Target scene update frequency in hertz [0.0F, +INF) (0.0F means as fast as possible)
106 */
108
109 /**
110 * @brief Returns the elapsed time in seconds between context initialization and the last scene update
111 * @return Elapsed time in seconds between context initialization and the last scene update
112 */
113 [[nodiscard]]
114 auto frame() const
115 -> float;
116
117 /**
118 * @brief Returns the maximum allowed delta time in seconds [0.0F, +INF)
119 * @return Maximum allowed delta time in seconds [0.0F, +INF)
120 */
121 [[nodiscard]]
122 auto max_delta() const
123 -> float;
124
125 /**
126 * @brief Sets the maximum allowed delta time in seconds [0.0F, +INF)
127 * @param max_delta Maximum allowed delta time in seconds [0.0F, +INF)
128 */
130
131 /**
132 * @brief Returns the elapsed time in seconds between the previous and current scene updates
133 * @return Elapsed time in seconds between the previous and current scene updates
134 */
135 [[nodiscard]]
136 auto delta() const
137 -> float;
138
139private:
140 float _delta{};
141 float _frame{now()};
142 float _max_delta{};
143
144 [[nodiscard]]
145 explicit clock(const info &info);
146
147 void iterate();
148};
149}
150
151#endif
auto delta() const -> float
Returns the elapsed time in seconds between the previous and current scene updates.
constexpr clock(const clock &) noexcept=delete
Deleted copy constructor.
auto frame() const -> float
Returns the elapsed time in seconds between context initialization and the last scene update.
constexpr clock(clock &&) noexcept=delete
Deleted move constructor.
void set_max_delta(float max_delta)
Sets the maximum allowed delta time in seconds [0.0F, +INF).
auto target_frequency() const -> float
Returns the target scene update frequency in hertz [0.0F, +INF) (0.0F means as fast as possible).
auto max_delta() const -> float
Returns the maximum allowed delta time in seconds [0.0F, +INF).
void set_target_frequency(float target_frequency)
Sets the target scene update frequency in hertz [0.0F, +INF) (0.0F means as fast as possible).
auto now() const -> float
Returns the elapsed time in seconds since context initialization.
Application runtime.
Definition clock.hpp:33
context::info info
Main initialization descriptor.
Definition init.hpp:41
Clock initialization descriptor.
Definition clock.hpp:46
float target_frequency
Target scene update frequency in hertz [0.0F, +INF) (0.0F means as fast as possible).
Definition clock.hpp:50
float max_delta
Maximum allowed delta time in seconds [0.0F, +INF).
Definition clock.hpp:55