sculpto
timer.cpp
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file timer.h
3 * \brief Timer, calculating interframe deltatime and fps
4 * class implementation module.
5 *
6 * \author Sabitov Kirill
7 * \date 28 June 2022
8 *********************************************************************/
9
10#include "sclpch.h"
11#include "timer.h"
12
13scl::shared<scl::timer> scl::timer::GlobalTimerInstance = scl::CreateShared<timer>();
14const float scl::timer::UpdateDelay = 0.2f;
15
17{
18 LastFpsCalcutionTime = OldTime = StartTime = high_resolution_clock::now();
19}
20
22{
23 time_point current_time = high_resolution_clock::now();
24 Time = duration<float>(current_time - StartTime).count();
25
26 LastFpsCalcutionFramesCount++;
27 float fps_calculation_delta_time = duration<float>(current_time - LastFpsCalcutionTime).count();
28 if (fps_calculation_delta_time >= UpdateDelay)
29 {
30 Fps = LastFpsCalcutionFramesCount / fps_calculation_delta_time;
31 LastFpsCalcutionTime = high_resolution_clock::now();
32 LastFpsCalcutionFramesCount = 0;
33 }
34
35 DeltaTime = duration<float>(current_time - OldTime).count();
36 OldTime = current_time;
37}
static const float UpdateDelay
Definition: timer.h:35
void Response()
Definition: timer.cpp:21
std::shared_ptr< T > shared
Definition: smart_ptr.h:15
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.
Timer, calculating interframe deltatime and fps class implementation module.