SPIDAR API Library  0x16033101
Space Interface Device for Artificial Reality
Timer.cpp
Go to the documentation of this file.
1 
5 #include "Timer.hpp"
6 
7 namespace Spidar
8 {
9 namespace Win32
10 {
17 void Timer::initialize(double frequency)
18 {
19  deltaTime_ = 0;
20  avgDeltaTime_ = 0;
21  maxDeltaTime_ = 0;
22  minDeltaTime_ = 10;
23 
24  ::QueryPerformanceFrequency(&systemFrequency_);
25 
26  cycle_ = static_cast<LONGLONG>(systemFrequency_.QuadPart / frequency);
27 
28  ::QueryPerformanceCounter(&countPrev_);
29 }
30 
35 void Timer::wait(void)
36 {
37  LONGLONG delta = 0;
38 
39  while (delta < cycle_)
40  {
41  ::QueryPerformanceCounter(&countCurr_);
42 
43  delta = countCurr_.QuadPart - countPrev_.QuadPart;
44  }
45  countPrev_ = countCurr_;
46 
47  deltaTime_ = static_cast<double>(delta) / systemFrequency_.QuadPart;
48 
49  avgDeltaTime_ = avgDeltaTime_ * 0.99 + deltaTime_ * 0.01;
50 
51  if (maxDeltaTime_ < deltaTime_) maxDeltaTime_ = deltaTime_;
52  if (minDeltaTime_ > deltaTime_) minDeltaTime_ = deltaTime_;
53 }
54 
55 } // end of namespace Win32.
56 } // end of namespace Spidar.
57 
58 // end of file.
void initialize(double frequency)
タイマーを初期化します.
Definition: Timer.cpp:17
SPIDARライブラリのルート名前空間です.
void wait(void)
指定時間が経過するまで待機します.
Definition: Timer.cpp:35