?? asl_timer.cpp
字號(hào):
//-----------------------------------------------------------------------------
//
// ____ Azure Star Game Engine 藍(lán)星游戲引擎 ____
//
// Copyright (c) 2006, 藍(lán)星工作室
// All rights reserved.
//
// 文件名稱: asl_timer.cpp
// 摘 要: 高精度計(jì)時(shí)器類實(shí)現(xiàn)
//
// 當(dāng)前版本: 1.0
// 作 者: 湯 祺
// 創(chuàng)建日期: 2006-7-26
//
//-----------------------------------------------------------------------------
#include "asl_timer.h"
namespace ASL
{
// 類靜態(tài)變量定義
__int64 ASLTimer::m_n64Freq = 0;
//-----------------------------------------------------------------------------
// 函數(shù)名: ASLTimer::ASLTimer()
// 功 能: 構(gòu)造函數(shù)
// 參 數(shù): [void] - 無(wú)
// 返回值: [void] - 無(wú)
// 失敗則拋出ASLSimpleException異常
//-----------------------------------------------------------------------------
ASLTimer::ASLTimer(int nPrecision, bool bPlay) throw(ASLSimpleException)
: m_n64TimeBegin(0)
, m_n64TimeEnd(0)
, m_TimerStatus(tsStop)
{
if (m_n64Freq == 0)
{
LARGE_INTEGER tmp;
if (QueryPerformanceFrequency(&tmp) == FALSE)
{
throw ASLSimpleException("本機(jī)無(wú)法使用高精度計(jì)時(shí)器");
}
m_n64Freq = tmp.QuadPart;
}
ASSERT(nPrecision > 0);
m_nPrecision = nPrecision;
if (bPlay)
{
Play();
}
}
//-----------------------------------------------------------------------------
// 函數(shù)名: ASLTimer::~ASLTimer()
// 功 能: 析構(gòu)函數(shù)
// 參 數(shù): [void] - 無(wú)
// 返回值: [void] - 無(wú)
//-----------------------------------------------------------------------------
ASLTimer::~ASLTimer(void)
{
}
//-----------------------------------------------------------------------------
// 函數(shù)名: ASLTimer::GetTime()
// 功 能: 取當(dāng)前計(jì)時(shí)器讀數(shù), 該值除以精度則為秒數(shù)
// 參 數(shù): [void] - 無(wú)
// 返回值: [DWORD] - 若計(jì)時(shí)器處于運(yùn)行狀態(tài), 則返回開(kāi)始到當(dāng)前時(shí)刻的計(jì)數(shù)值
// 若計(jì)時(shí)器已停止, 則返回從開(kāi)始到停止時(shí)刻的計(jì)數(shù)值
//-----------------------------------------------------------------------------
DWORD ASLTimer::GetTime(void)
{
if (m_TimerStatus != tsRun)
{
return DWORD((m_n64TimeEnd - m_n64TimeBegin) * m_nPrecision / m_n64Freq);
}
else
{
return DWORD((GetCurrentCount() - m_n64TimeBegin) * m_nPrecision / m_n64Freq);
}
}
//-----------------------------------------------------------------------------
// 函數(shù)名: ASLTimer::Play()
// 功 能: 開(kāi)始計(jì)時(shí)
// 參 數(shù): [void] - 無(wú)
// 返回值: [void] - 無(wú)
//-----------------------------------------------------------------------------
void ASLTimer::Play(void)
{
if (m_TimerStatus == tsStop)
{
m_n64TimeBegin = GetCurrentCount();
}
m_TimerStatus = tsRun;
}
//-----------------------------------------------------------------------------
// 函數(shù)名: ASLTimer::Stop()
// 功 能: 停止計(jì)時(shí)
// 參 數(shù): [void] - 無(wú)
// 返回值: [void] - 無(wú)
//-----------------------------------------------------------------------------
void ASLTimer::Stop(void)
{
m_n64TimeEnd = GetCurrentCount();
m_TimerStatus = tsStop;
}
//-----------------------------------------------------------------------------
// 函數(shù)名: ASLTimer::Pause()
// 功 能: 暫停計(jì)時(shí)
// 參 數(shù): [void] - 無(wú)
// 返回值: [void] - 無(wú)
//-----------------------------------------------------------------------------
void ASLTimer::Pause(void)
{
m_n64TimeEnd = GetCurrentCount();
m_TimerStatus = tsPause;
}
//-----------------------------------------------------------------------------
// 函數(shù)名: ASLTimer::GetCurrentCount()
// 功 能: 取系統(tǒng)計(jì)時(shí)器的計(jì)數(shù)值
// 參 數(shù): [void] - 無(wú)
// 返回值: [__int64] - 系統(tǒng)計(jì)時(shí)器的計(jì)數(shù)值
//-----------------------------------------------------------------------------
__int64 ASLTimer::GetCurrentCount(void)
{
LARGE_INTEGER tmp;
QueryPerformanceCounter(&tmp);
return tmp.QuadPart;
}
} // namespace ASL
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -