mirror of
https://github.com/dashr9230/SA-MP.git
synced 2025-01-03 16:13:34 +08:00
[saco] Implement and match CDXUTTimer class member functions
This commit is contained in:
parent
e38f342453
commit
42a6ead0dc
164
saco/d3d9/common/DXUTmisc.cpp
Normal file
164
saco/d3d9/common/DXUTmisc.cpp
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// File: DXUTMisc.cpp
|
||||||
|
//
|
||||||
|
// Shortcut macros and functions for using DX objects
|
||||||
|
//
|
||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
#include "dxstdafx.h"
|
||||||
|
#undef min // use __min instead
|
||||||
|
#undef max // use __max instead
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CDXUTTimer::CDXUTTimer()
|
||||||
|
{
|
||||||
|
m_bUsingQPF = false;
|
||||||
|
m_bTimerStopped = true;
|
||||||
|
m_llQPFTicksPerSec = 0;
|
||||||
|
|
||||||
|
m_llStopTime = 0;
|
||||||
|
m_llLastElapsedTime = 0;
|
||||||
|
m_llBaseTime = 0;
|
||||||
|
|
||||||
|
// Use QueryPerformanceFrequency() to get frequency of timer.
|
||||||
|
LARGE_INTEGER qwTicksPerSec;
|
||||||
|
m_bUsingQPF = (bool) (QueryPerformanceFrequency( &qwTicksPerSec ) != 0);
|
||||||
|
m_llQPFTicksPerSec = qwTicksPerSec.QuadPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
void CDXUTTimer::Reset()
|
||||||
|
{
|
||||||
|
if( !m_bUsingQPF )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Get either the current time or the stop time
|
||||||
|
LARGE_INTEGER qwTime;
|
||||||
|
if( m_llStopTime != 0 )
|
||||||
|
qwTime.QuadPart = m_llStopTime;
|
||||||
|
else
|
||||||
|
QueryPerformanceCounter( &qwTime );
|
||||||
|
|
||||||
|
m_llBaseTime = qwTime.QuadPart;
|
||||||
|
m_llLastElapsedTime = qwTime.QuadPart;
|
||||||
|
m_llStopTime = 0;
|
||||||
|
m_bTimerStopped = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
void CDXUTTimer::Start()
|
||||||
|
{
|
||||||
|
if( !m_bUsingQPF )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Get the current time
|
||||||
|
LARGE_INTEGER qwTime;
|
||||||
|
QueryPerformanceCounter( &qwTime );
|
||||||
|
|
||||||
|
if( m_bTimerStopped )
|
||||||
|
m_llBaseTime += qwTime.QuadPart - m_llStopTime;
|
||||||
|
m_llStopTime = 0;
|
||||||
|
m_llLastElapsedTime = qwTime.QuadPart;
|
||||||
|
m_bTimerStopped = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
void CDXUTTimer::Stop()
|
||||||
|
{
|
||||||
|
if( !m_bUsingQPF )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( !m_bTimerStopped )
|
||||||
|
{
|
||||||
|
// Get either the current time or the stop time
|
||||||
|
LARGE_INTEGER qwTime;
|
||||||
|
if( m_llStopTime != 0 )
|
||||||
|
qwTime.QuadPart = m_llStopTime;
|
||||||
|
else
|
||||||
|
QueryPerformanceCounter( &qwTime );
|
||||||
|
|
||||||
|
m_llStopTime = qwTime.QuadPart;
|
||||||
|
m_llLastElapsedTime = qwTime.QuadPart;
|
||||||
|
m_bTimerStopped = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
void CDXUTTimer::Advance()
|
||||||
|
{
|
||||||
|
if( !m_bUsingQPF )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_llStopTime += m_llQPFTicksPerSec/10;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
double CDXUTTimer::GetAbsoluteTime()
|
||||||
|
{
|
||||||
|
if( !m_bUsingQPF )
|
||||||
|
return -1.0;
|
||||||
|
|
||||||
|
// Get either the current time or the stop time
|
||||||
|
LARGE_INTEGER qwTime;
|
||||||
|
if( m_llStopTime != 0 )
|
||||||
|
qwTime.QuadPart = m_llStopTime;
|
||||||
|
else
|
||||||
|
QueryPerformanceCounter( &qwTime );
|
||||||
|
|
||||||
|
double fTime = qwTime.QuadPart / (double) m_llQPFTicksPerSec;
|
||||||
|
|
||||||
|
return fTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
double CDXUTTimer::GetTime()
|
||||||
|
{
|
||||||
|
if( !m_bUsingQPF )
|
||||||
|
return -1.0;
|
||||||
|
|
||||||
|
// Get either the current time or the stop time
|
||||||
|
LARGE_INTEGER qwTime;
|
||||||
|
if( m_llStopTime != 0 )
|
||||||
|
qwTime.QuadPart = m_llStopTime;
|
||||||
|
else
|
||||||
|
QueryPerformanceCounter( &qwTime );
|
||||||
|
|
||||||
|
double fAppTime = (double) ( qwTime.QuadPart - m_llBaseTime ) / (double) m_llQPFTicksPerSec;
|
||||||
|
|
||||||
|
return fAppTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
double CDXUTTimer::GetElapsedTime()
|
||||||
|
{
|
||||||
|
if( !m_bUsingQPF )
|
||||||
|
return -1.0;
|
||||||
|
|
||||||
|
// Get either the current time or the stop time
|
||||||
|
LARGE_INTEGER qwTime;
|
||||||
|
if( m_llStopTime != 0 )
|
||||||
|
qwTime.QuadPart = m_llStopTime;
|
||||||
|
else
|
||||||
|
QueryPerformanceCounter( &qwTime );
|
||||||
|
|
||||||
|
double fElapsedTime = (double) ( qwTime.QuadPart - m_llLastElapsedTime ) / (double) m_llQPFTicksPerSec;
|
||||||
|
m_llLastElapsedTime = qwTime.QuadPart;
|
||||||
|
|
||||||
|
return fElapsedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
bool CDXUTTimer::IsStopped()
|
||||||
|
{
|
||||||
|
return m_bTimerStopped;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
41
saco/d3d9/common/DXUTmisc.h
Normal file
41
saco/d3d9/common/DXUTmisc.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// File: DXUTMisc.h
|
||||||
|
//
|
||||||
|
// Helper functions for Direct3D programming.
|
||||||
|
//
|
||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
#ifndef DXUT_MISC_H
|
||||||
|
#define DXUT_MISC_H
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// Performs timer operations
|
||||||
|
// Use DXUTGetGlobalTimer() to get the global instance
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
class CDXUTTimer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CDXUTTimer();
|
||||||
|
|
||||||
|
void Reset(); // resets the timer
|
||||||
|
void Start(); // starts the timer
|
||||||
|
void Stop(); // stop (or pause) the timer
|
||||||
|
void Advance(); // advance the timer by 0.1 seconds
|
||||||
|
double GetAbsoluteTime(); // get the absolute system time
|
||||||
|
double GetTime(); // get the current time
|
||||||
|
double GetElapsedTime(); // get the time that elapsed between GetElapsedTime() calls
|
||||||
|
bool IsStopped(); // returns true if timer stopped
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool m_bUsingQPF;
|
||||||
|
bool m_bTimerStopped;
|
||||||
|
LONGLONG m_llQPFTicksPerSec;
|
||||||
|
|
||||||
|
LONGLONG m_llStopTime;
|
||||||
|
LONGLONG m_llLastElapsedTime;
|
||||||
|
LONGLONG m_llBaseTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
BIN
saco/d3d9/common/directx.ico
Normal file
BIN
saco/d3d9/common/directx.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
11
saco/d3d9/common/dxstdafx.cpp
Normal file
11
saco/d3d9/common/dxstdafx.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// File: DxStdAfx.cpp
|
||||||
|
//
|
||||||
|
// Desc: Precompiled headers for DXUT and DirectX SDK samples
|
||||||
|
//
|
||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
#include "dxstdafx.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
26
saco/d3d9/common/dxstdafx.h
Normal file
26
saco/d3d9/common/dxstdafx.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// File: DxStdAfx.h
|
||||||
|
//
|
||||||
|
// Desc: Standard includes and precompiled headers for DXUT
|
||||||
|
//
|
||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
#pragma once
|
||||||
|
#ifndef DXSDK_STDAFX_H
|
||||||
|
#define DXSDK_STDAFX_H
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <mmsystem.h>
|
||||||
|
#include <commctrl.h> // for InitCommonControls()
|
||||||
|
#include <shellapi.h> // for ExtractIcon()
|
||||||
|
#include <new.h> // for placement new
|
||||||
|
#include <math.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <multimon.h>
|
||||||
|
|
||||||
|
#include "DXUTmisc.h"
|
||||||
|
|
||||||
|
#endif // !defined(DXSDK_STDAFX_H)
|
@ -571,6 +571,22 @@
|
|||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="DXUT"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\d3d9\common\dxstdafx.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\d3d9\common\dxstdafx.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\d3d9\common\DXUTmisc.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\d3d9\common\DXUTmisc.h">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="temp"
|
Name="temp"
|
||||||
Filter="">
|
Filter="">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user