Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
ApplicationTimer.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_CORE_TIME_APPLICATION_TIMER_H_
34#define DVD_CORE_TIME_APPLICATION_TIMER_H_
35
36#include "FrameRateHandler.h"
37
38// Code from http://www.gamedev.net/reference/articles/article1382.asp
39// Copyright: "Frame Rate Independent Movement" by Ben Dilts
40namespace Divide::Time
41{
42
43using TimeValue = std::chrono::time_point<std::chrono::high_resolution_clock>;
44using NSec = std::chrono::nanoseconds;
45using USec = std::chrono::microseconds;
46using MSec = std::chrono::milliseconds;
47using Sec = std::chrono::seconds;
48
50{
51
52
53 public:
54 ApplicationTimer() noexcept;
55
56 void update();
57 void reset() noexcept;
58
59 void resetFPSCounter() noexcept;
60 [[nodiscard]] F32 getFps() const noexcept;
61 [[nodiscard]] F32 getFrameTime() const noexcept;
62 void getFrameRateAndTime(F32& fpsOut, F32& frameTimeOut) const noexcept;
63
64 PROPERTY_R(F32, speedfactor, 1.0f);
66 PROPERTY_R(string, benchmarkReport, "");
67
68 private:
70 // Measure average FPS and output max/min/average fps to console
72};
73
74
75namespace App
76{
78 U64 ElapsedNanoseconds() noexcept;
79 U64 ElapsedMicroseconds() noexcept;
80 D64 ElapsedMilliseconds() noexcept;
81 D64 ElapsedSeconds() noexcept;
82
83} //namespace App
84
85} // namespace Divide::Time
86
87#endif //DVD_CORE_TIME_APPLICATION_TIMER_H_
88
89#include "ApplicationTimer.inl"
F32 getFrameTime() const noexcept
PROPERTY_R(F32, speedfactor, 1.0f)
PROPERTY_R(U32, targetFrameRate, Config::TARGET_FRAME_RATE)
PROPERTY_R(string, benchmarkReport, "")
void getFrameRateAndTime(F32 &fpsOut, F32 &frameTimeOut) const noexcept
constexpr U16 TARGET_FRAME_RATE
Application desired framerate for physics and input simulations.
Definition: config.h:97
D64 ElapsedSeconds() noexcept
U64 ElapsedMicroseconds() noexcept
U64 ElapsedNanoseconds() noexcept
The following functions force a timer update (a call to query performance timer).
D64 ElapsedMilliseconds() noexcept
std::chrono::microseconds USec
std::chrono::nanoseconds NSec
std::chrono::milliseconds MSec
std::chrono::seconds Sec
std::chrono::time_point< std::chrono::high_resolution_clock > TimeValue
double D64
uint32_t U32
uint64_t U64