-
Notifications
You must be signed in to change notification settings - Fork 17
/
MMTimer.cpp
58 lines (46 loc) · 1.15 KB
/
MMTimer.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
//
// Multimedia timer support
//
#include "DebugOut.h"
#include "MMTimer.h"
// コンストラクタ/デストラクタの為のインスタンス
static CMMTimer MMTimer;
BOOL CMMTimer::m_bInitialize = FALSE;
BOOL CMMTimer::m_bHigh = FALSE;
SQWORD CMMTimer::m_hpFrequency = 0;
CMMTimer::CMMTimer()
{
// 1ms単位を保証する為だけに呼ぶ…なんちゅう仕様じゃ
if( !m_bInitialize ) {
if( ::timeBeginPeriod( 1 ) == TIMERR_NOERROR )
m_bInitialize = TRUE;
}
// ハイパフォーマンスカウンタでの時間計測用
if( ::QueryPerformanceFrequency( (LARGE_INTEGER*)&m_hpFrequency ) ) {
DEBUGOUT( "CMMTimer:Use high performance counter.(QueryPerformanceCounter)\n" );
m_bHigh = TRUE;
}
}
CMMTimer::~CMMTimer()
{
if( m_bInitialize ) {
::timeEndPeriod( 1 );
m_bInitialize = FALSE;
}
}
SQWORD CMMTimer::GetMMTimer()
{
if( m_bHigh ) {
SQWORD freq;
::QueryPerformanceCounter( (LARGE_INTEGER*)&freq );
return freq;
}
return (SQWORD)::timeGetTime();
}
FLOAT CMMTimer::CalcTimeDifference( SQWORD t0, SQWORD t1 )
{
if( m_bHigh ) {
return (FLOAT)(1000.0*(double)(t1-t0)/(double)m_hpFrequency);
}
return (FLOAT)(t1-t0)*1000.0f;
}