Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
app_clock.hpp
Go to the documentation of this file.
1// This file is part of the Rendering Engine project.
2// Author: Alexander Obzherin <alexanderobzherin@gmail.com>
3// Copyright (c) 2025 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5
6/**
7 * @file app_clock.hpp
8 * @brief High-resolution clock for updating application time.
9 *
10 * @details
11 * AppClock measures precise frame timing using `std::chrono::high_resolution_clock`
12 * and updates an associated AppTime instance each frame. It tracks the start,
13 * last, and current timestamps, enabling the engine to compute total and
14 * delta time values.
15 *
16 * @see rendering_engine::AppTime
17 */
18#pragma once
19
20#include <chrono>
21namespace rendering_engine
22{
23
24class AppTime;
25/**
26 * @class AppClock
27 * @brief Provides high-resolution timing for frame updates.
28 *
29 * AppClock tracks time since the application started and between frames.
30 * Each call to UpdateAppTime() updates an AppTime instance with new total
31 * and elapsed durations.
32 *
33 * Typical usage:
34 * @code
35 * AppClock clock;
36 * AppTime time;
37 * clock.Reset();
38 *
39 * while (running)
40 * {
41 * clock.UpdateAppTime(time);
42 * float delta = time.ElapsedAppTimeMilliseconds();
43 * // Update logic...
44 * }
45 * @endcode
46 *
47 * @see rendering_engine::AppTime
48 */
50{
51public:
52 /// Constructs a new clock initialized with the current time.
53 AppClock();
54 AppClock(AppClock const&) = default;
55 AppClock& operator=(AppClock const&) = default;
56 AppClock(AppClock &&) = default;
57 AppClock& operator=(AppClock &&) = default;
58 ~AppClock() = default;
59 /// Returns the timestamp when the clock was started.
60 const std::chrono::high_resolution_clock::time_point& StartTime() const;
61 /// Returns the most recent recorded time (current frame).
62 const std::chrono::high_resolution_clock::time_point& CurrentTime() const;
63 /// Returns the time recorded at the previous frame.
64 const std::chrono::high_resolution_clock::time_point& LastTime() const;
65 /// Resets the clock to the current system time.
66 void Reset();
67 /**
68 * @brief Updates the given AppTime instance with elapsed and total durations.
69 *
70 * Calculates the time difference between the last and current frame,
71 * updates internal state, and synchronizes AppTime accordingly.
72 *
73 * @param appTime Reference to the AppTime instance to update.
74 */
75 void UpdateAppTime(AppTime& appTime);
76
77private:
78 std::chrono::high_resolution_clock::time_point mStartTime;
79 std::chrono::high_resolution_clock::time_point mCurrentTime;
80 std::chrono::high_resolution_clock::time_point mLastTime;
81};
82
83} //rendering_engine
void Reset()
Resets the clock to the current system time.
Definition app_clock.cpp:31
void UpdateAppTime(AppTime &appTime)
Updates the given AppTime instance with elapsed and total durations.
Definition app_clock.cpp:38
AppClock()
Constructs a new clock initialized with the current time.
Definition app_clock.cpp:7
AppClock & operator=(AppClock &&)=default
const std::chrono::high_resolution_clock::time_point & CurrentTime() const
Returns the most recent recorded time (current frame).
Definition app_clock.cpp:21
AppClock & operator=(AppClock const &)=default
AppClock(AppClock &&)=default
AppClock(AppClock const &)=default
const std::chrono::high_resolution_clock::time_point & LastTime() const
Returns the time recorded at the previous frame.
Definition app_clock.cpp:26
const std::chrono::high_resolution_clock::time_point & StartTime() const
Returns the timestamp when the clock was started.
Definition app_clock.cpp:16
Manages current, total, and elapsed time for the application.
Definition app_time.hpp:36