Windows: Simplify QueryPerformanceCounter usage
(cherry picked from commit 5ba38fb208
)
This commit is contained in:
parent
57cceb47d1
commit
e1429dd80f
@ -174,12 +174,8 @@ void OS_Windows::initialize_core() {
|
|||||||
NetSocketPosix::make_default();
|
NetSocketPosix::make_default();
|
||||||
|
|
||||||
// We need to know how often the clock is updated
|
// We need to know how often the clock is updated
|
||||||
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second))
|
QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second);
|
||||||
ticks_per_second = 1000;
|
QueryPerformanceCounter((LARGE_INTEGER *)&ticks_start);
|
||||||
// If timeAtGameStart is 0 then we get the time since
|
|
||||||
// the start of the computer when we call GetGameTime()
|
|
||||||
ticks_start = 0;
|
|
||||||
ticks_start = get_ticks_usec();
|
|
||||||
|
|
||||||
// set minimum resolution for periodic timers, otherwise Sleep(n) may wait at least as
|
// set minimum resolution for periodic timers, otherwise Sleep(n) may wait at least as
|
||||||
// long as the windows scheduler resolution (~16-30ms) even for calls like Sleep(1)
|
// long as the windows scheduler resolution (~16-30ms) even for calls like Sleep(1)
|
||||||
@ -2460,8 +2456,10 @@ uint64_t OS_Windows::get_ticks_usec() const {
|
|||||||
uint64_t ticks;
|
uint64_t ticks;
|
||||||
|
|
||||||
// This is the number of clock ticks since start
|
// This is the number of clock ticks since start
|
||||||
if (!QueryPerformanceCounter((LARGE_INTEGER *)&ticks))
|
QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
|
||||||
ticks = (UINT64)timeGetTime();
|
// Subtract the ticks at game start to get
|
||||||
|
// the ticks since the game started
|
||||||
|
ticks -= ticks_start;
|
||||||
|
|
||||||
// Divide by frequency to get the time in seconds
|
// Divide by frequency to get the time in seconds
|
||||||
// original calculation shown below is subject to overflow
|
// original calculation shown below is subject to overflow
|
||||||
@ -2481,9 +2479,6 @@ uint64_t OS_Windows::get_ticks_usec() const {
|
|||||||
// seconds
|
// seconds
|
||||||
time += seconds * 1000000L;
|
time += seconds * 1000000L;
|
||||||
|
|
||||||
// Subtract the time at game start to get
|
|
||||||
// the time since the game started
|
|
||||||
time -= ticks_start;
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user