TDME2
1.9.121
src
tdme
engine
Timing.cpp
Go to the documentation of this file.
1
#include <
tdme/engine/Timing.h
>
2
3
#include <array>
4
5
#include <
tdme/tdme.h
>
6
#include <
tdme/utilities/Time.h
>
7
8
using
std::array;
9
10
using
tdme::engine::Timing
;
11
using
tdme::utilities::Time
;
12
13
Timing::Timing()
14
{
15
frame
= 0;
16
startTime
= Time::getCurrentMillis();
17
lastFrameAtTime
=
UNDEFINED
;
18
currentFrameAtTime
=
UNDEFINED
;
19
avarageFPS
= 60.0f;
20
lastFrameAtTime
=
Timing::UNDEFINED
;
21
currentFrameAtTime
=
Timing::UNDEFINED
;
22
fps
=
Timing::UNDEFINED
;
23
avarageFPS
=
Timing::UNDEFINED
;
24
for
(
auto
i = 0; i <
avarageFPSSequence
.size(); i++)
avarageFPSSequence
[i] = 60.0f;
25
}
26
27
constexpr
int64_t
Timing::UNDEFINED
;
28
29
void
Timing::updateTiming
()
30
{
31
lastFrameAtTime
=
currentFrameAtTime
;
32
currentFrameAtTime
= Time::getCurrentMillis();
33
fps
= 0;
34
if
(
lastFrameAtTime
!=
UNDEFINED
) {
35
fps
= 1000.0f / ((
currentFrameAtTime
-
lastFrameAtTime
));
36
}
37
fps
++;
38
39
// avarage fps
40
avarageFPSIndex
= (
avarageFPSIndex
+ 1) %
avarageFPSSequence
.size();
41
avarageFPSSequence
[
avarageFPSIndex
] =
fps
;
42
avarageFPS
= 0.0f;
43
for
(
auto
i = 0; i <
avarageFPSSequence
.size(); i++)
avarageFPS
+=
avarageFPSSequence
[(
avarageFPSIndex
- i) %
avarageFPSSequence
.size()];
44
avarageFPS
/=
avarageFPSSequence
.size();
45
46
}
Time.h
Timing.h
tdme::engine::Timing
Timing class.
Definition:
Timing.h:17
tdme::engine::Timing::updateTiming
void updateTiming()
Updates timing.
Definition:
Timing.cpp:29
tdme::engine::Timing::avarageFPS
float avarageFPS
Definition:
Timing.h:29
tdme::engine::Timing::fps
float fps
Definition:
Timing.h:28
tdme::engine::Timing::avarageFPSSequence
array< float, 60 *3 > avarageFPSSequence
Definition:
Timing.h:30
tdme::engine::Timing::UNDEFINED
static constexpr int64_t UNDEFINED
Definition:
Timing.h:21
tdme::engine::Timing::currentFrameAtTime
int64_t currentFrameAtTime
Definition:
Timing.h:27
tdme::engine::Timing::startTime
int64_t startTime
Definition:
Timing.h:25
tdme::engine::Timing::lastFrameAtTime
int64_t lastFrameAtTime
Definition:
Timing.h:26
tdme::engine::Timing::frame
int64_t frame
Definition:
Timing.h:24
tdme::engine::Timing::avarageFPSIndex
int avarageFPSIndex
Definition:
Timing.h:31
tdme::utilities::Time
Time utility class.
Definition:
Time.h:21
tdme.h
Generated by
1.9.3