-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitTimer.cpp
99 lines (83 loc) · 3.99 KB
/
UnitTimer.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
// ---------------------------------------------------------------------------
#pragma hdrstop
// ---------------------------------------------------------------------------
// Include
// ---------------------------------------------------------------------------
#include "UnitTimer.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
// ---------------------------------------------------------------------------
namespace NSApplication {
// ---------------------------------------------------------------------------
// Global Variables
// ---------------------------------------------------------------------------
extern CTimer GlobalTimer;
CTimer GlobalTimer;
// ---------------------------------------------------------------------------
// Definitions of CTimer
// ---------------------------------------------------------------------------
CTimer::CTimer() {
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&startingTime);
}
// ---------------------------------------------------------------------------
microseconds CTimer::getTime() const {
LARGE_INTEGER currentTime;
QueryPerformanceCounter(¤tTime);
currentTime.QuadPart -= startingTime.QuadPart;
currentTime.QuadPart *= microsecondsInOneSecond;
currentTime.QuadPart /= frequency.QuadPart;
return currentTime.QuadPart;
}
// ---------------------------------------------------------------------------
milliseconds CTimer::MicroSecondsToMilliSeconds(microseconds Time) {
return static_cast<double>(Time) /
static_cast<double>(microsecondsInOneMillisecond);
}
// ---------------------------------------------------------------------------
seconds CTimer::MicroSecondsToSeconds(microseconds Time) {
return static_cast<double>(Time) /
static_cast<double>(microsecondsInOneSecond);
}
// ---------------------------------------------------------------------------
minutes CTimer::MicroSecondsToMinutes(microseconds Time) {
return static_cast<double>(Time) /
static_cast<double>(microsecondsInOneMinute);
}
// ---------------------------------------------------------------------------
hours CTimer::MicroSecondsToHours(microseconds Time) {
return static_cast<double>(Time) /
static_cast<double>(microsecondsInOneHour);
}
// ---------------------------------------------------------------------------
roundminutes CTimer::MicroSecondsToRoundMinutes(microseconds Time) {
return Time / microsecondsInOneMinute;
}
// ---------------------------------------------------------------------------
roundhours CTimer::MicroSecondsToRoundHours(microseconds Time) {
return Time / microsecondsInOneHour;
}
// ---------------------------------------------------------------------------
microseconds CTimer::MillisecondsToMicroseconds(milliseconds Time) {
return static_cast<microseconds>(Time * microsecondsInOneMillisecond);
}
// ---------------------------------------------------------------------------
microseconds CTimer::SecondsToMicroseconds(milliseconds Time) {
return static_cast<microseconds>(Time * microsecondsInOneSecond);
}
// ---------------------------------------------------------------------------
microseconds CTimer::MinutesToMicroseconds(roundminutes Time) {
return static_cast<microseconds>(Time) * microsecondsInOneMinute;
}
// ---------------------------------------------------------------------------
microseconds CTimer::HoursToMicroseconds(roundhours Time) {
return static_cast<microseconds>(Time) * microsecondsInOneHour;
}
// ---------------------------------------------------------------------------
symbolsPerMinute CTimer::convertTimeToSpeed(microseconds Time) {
return static_cast<double>(microsecondsInOneMinute) /
static_cast<double>(Time);
}
// ---------------------------------------------------------------------------
} // NSApplication
// ---------------------------------------------------------------------------