forked from eu07/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.cpp
123 lines (105 loc) · 2.48 KB
/
Timer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "system.hpp"
#include "classes.hpp"
#pragma hdrstop
#include "Timer.h"
#include "Globals.h"
namespace Timer
{
double DeltaTime, DeltaRenderTime;
double fFPS = 0.0f;
double fLastTime = 0.0f;
DWORD dwFrames = 0L;
double fSimulationTime = 0;
double fSoundTimer = 0;
double fSinceStart = 0;
double GetTime()
{
return fSimulationTime;
}
double GetDeltaTime()
{ // czas symulacji (stoi gdy pauza)
return DeltaTime;
}
double GetDeltaRenderTime()
{ // czas renderowania (do poruszania siê)
return DeltaRenderTime;
}
double GetfSinceStart()
{
return fSinceStart;
}
void SetDeltaTime(double t)
{
DeltaTime = t;
}
double GetSimulationTime()
{
return fSimulationTime;
}
void SetSimulationTime(double t)
{
fSimulationTime = t;
}
bool GetSoundTimer()
{ // Ra: byæ mo¿e, by dŸwiêki nie modyfikowa³y siê zbyt czêsto, po 0.1s zeruje siê ten licznik
return (fSoundTimer == 0.0f);
}
double GetFPS()
{
return fFPS;
}
void ResetTimers()
{
// double CurrentTime=
GetTickCount();
DeltaTime = 0.1;
DeltaRenderTime = 0;
fSoundTimer = 0;
};
LONGLONG fr, count, oldCount;
// LARGE_INTEGER fr,count;
void UpdateTimers(bool pause)
{
QueryPerformanceFrequency((LARGE_INTEGER *)&fr);
QueryPerformanceCounter((LARGE_INTEGER *)&count);
DeltaRenderTime = double(count - oldCount) / double(fr);
if (!pause)
{
DeltaTime = Global::fTimeSpeed * DeltaRenderTime;
fSoundTimer += DeltaTime;
if (fSoundTimer > 0.1)
fSoundTimer = 0;
/*
double CurrentTime= double(count)/double(fr);//GetTickCount();
DeltaTime= (CurrentTime-OldTime);
OldTime= CurrentTime;
*/
if (DeltaTime > 1)
DeltaTime = 1;
}
else
DeltaTime = 0; // wszystko stoi, bo czas nie p³ynie
oldCount = count;
// Keep track of the time lapse and frame count
double fTime = GetTickCount() * 0.001f; // Get current time in seconds
++dwFrames; // licznik ramek
// update the frame rate once per second
if (fTime - fLastTime > 1.0f)
{
fFPS = dwFrames / (fTime - fLastTime);
fLastTime = fTime;
dwFrames = 0L;
}
fSimulationTime += DeltaTime;
};
};
//---------------------------------------------------------------------------
#pragma package(smart_init)