Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Time.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "core/Core.hpp"
4#include <chrono>
5
6namespace Engine::Resource {
9struct Time {
11 float _elapsedTime = 0.0f;
12
14 std::chrono::time_point<std::chrono::high_resolution_clock> _lastTime = std::chrono::high_resolution_clock::now();
15
21 static void Update(Core &core)
22 {
23 auto &time = core.GetResource<Time>();
24 auto now = std::chrono::high_resolution_clock::now();
25 time._elapsedTime = std::chrono::duration<float>(now - time._lastTime).count();
26 time._lastTime = now;
27 }
28};
29} // namespace Engine::Resource
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
TResource & GetResource()
Get a reference of a resource.
Definition Core.inl:14
Definition Time.hpp:6
Resource that stores the elapsed time since the last frame.
Definition Time.hpp:9
static void Update(Core &core)
Update the _elapsedTime since the last frame. It should be called at the beginning of each frame to u...
Definition Time.hpp:21
float _elapsedTime
Elapsed time since the last frame in seconds.
Definition Time.hpp:11
std::chrono::time_point< std::chrono::high_resolution_clock > _lastTime
The time point of the last frame. It is used to calculate the elapsed time since the last frame.
Definition Time.hpp:14