Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
app_time.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_time.hpp
8 * @brief Provides time tracking for the application runtime.
9 *
10 * @details
11 * AppTime measures and stores total and per-frame elapsed time using
12 * `std::chrono::high_resolution_clock`. It is typically used by the main
13 * game loop to calculate delta times and track total uptime.
14 *
15 * Example:
16 * @code
17 * AppTime time;
18 * time.SetCurrentTime(std::chrono::high_resolution_clock::now());
19 * float delta = time.ElapsedAppTimeMilliseconds();
20 * @endcode
21 */
22#pragma once
23
24#include <chrono>
25
26namespace rendering_engine
27{
28/**
29 * @class AppTime
30 * @brief Manages current, total, and elapsed time for the application.
31 *
32 * Stores high-resolution timestamps and durations for frame updates.
33 * Provides both millisecond and chrono-based accessors.
34 */
36{
37public:
38 /// Constructs a new AppTime instance with zeroed timers.
39 AppTime();
40 /// Returns the current high-resolution time point.
41 const std::chrono::high_resolution_clock::time_point& CurrentTime() const;
42 /// Sets the current high-resolution time point
43 void SetCurrentTime(const std::chrono::high_resolution_clock::time_point& currentTime);
44 /// Returns total accumulated application time since start.
45 const std::chrono::milliseconds& TotalAppTime() const;
46 /// Returns total accumulated time in milliseconds (float).
47 const float TotalAppTimeMilliseconds() const;
48 /// Sets total accumulated application time.
49 void SetTotalAppTime(const std::chrono::milliseconds& totalAppTime);
50 /// Returns elapsed time since the last frame in milliseconds (float).
51 const float ElapsedAppTimeMilliseconds() const;
52 /// Returns elapsed time since the last frame.
53 const std::chrono::milliseconds& ElapsedAppTime() const;
54 /// Sets elapsed time since the last frame.
55 void SetElapsedAppTime(const std::chrono::milliseconds& elapsedAppTime);
56
57private:
58 std::chrono::high_resolution_clock::time_point mCurrentTime;
59 std::chrono::milliseconds mTotalAppTime;
60 std::chrono::milliseconds mElapsedAppTime;
61};
62
63} //rendering_engine
AppTime()
Constructs a new AppTime instance with zeroed timers.
Definition app_time.cpp:6
void SetTotalAppTime(const std::chrono::milliseconds &totalAppTime)
Sets total accumulated application time.
Definition app_time.cpp:33
void SetCurrentTime(const std::chrono::high_resolution_clock::time_point &currentTime)
Sets the current high-resolution time point.
Definition app_time.cpp:18
void SetElapsedAppTime(const std::chrono::milliseconds &elapsedAppTime)
Sets elapsed time since the last frame.
Definition app_time.cpp:48
const float TotalAppTimeMilliseconds() const
Returns total accumulated time in milliseconds (float).
Definition app_time.cpp:28
const std::chrono::milliseconds & ElapsedAppTime() const
Returns elapsed time since the last frame.
Definition app_time.cpp:43
const std::chrono::high_resolution_clock::time_point & CurrentTime() const
Returns the current high-resolution time point.
Definition app_time.cpp:13
const float ElapsedAppTimeMilliseconds() const
Returns elapsed time since the last frame in milliseconds (float).
Definition app_time.cpp:38
const std::chrono::milliseconds & TotalAppTime() const
Returns total accumulated application time since start.
Definition app_time.cpp:23