• Create Account

### #ActualDebunez

Posted 01 November 2012 - 11:46 AM

Okay can i suggest something? I think you should look into the Windows API high performance timer.
Because looking at your code the way you calculate frame rate seems to be all over the place.

Basically using a couple methods namely: QueryPerformanceFrequency(LARGE_INTEGER); and QueryPerformanceCounter(LARGE_INTEGER)

You can find both the DeltaTime and TotalTime of the application instance. Then using those values you can calculate FramePerSecond and everything else over the moon.

An example of this can be found here http://mengine.googl...c/GameTimer.cpp
written by Frank Luna writer of the "Introduction to 3D game programming using DirectX" series.

Look at it closely and see essentially what is being done in each function.

Then look at the following function that uses the GameTimer class:

void D3DApp::CalculateFrameStats()
{
// Code computes the average frames per second, and also the
// average time it takes to render one frame.  These stats
// are appended to the window caption bar.
static int frameCnt = 0;
static float timeElapsed = 0.0f;
frameCnt++;
// Compute averages over one second period.
if( (mTimer.TotalTime() - timeElapsed) >= 1.0f )
{
float fps = (float)frameCnt; // fps = frameCnt / 1
float mspf = 1000.0f / fps;
std::wostringstream outs;
outs.precision(6);
outs << mMainWndCaption << L"	"
<< L"FPS: " << fps << L"	"
<< L"Frame Time: " << mspf << L" (ms)";
SetWindowText(mhMainWnd, outs.str().c_str());

// Reset for next average.
frameCnt = 0;
timeElapsed += 1.0f;
}
}


Again ALL CREDIT TO FRANK LUNA.

This function calculates the frames per second and displays it to the application window title bar.

Now limiting the frame rate to 60 shouldn't be hard once you have a nice object oriented way to calculate the frames per second of your application.

### #1Debunez

Posted 01 November 2012 - 11:43 AM

Okay can i suggest something? I think you should look into the Windows API high performance timer.

Basically using a couple methods namely: QueryPerformanceFrequency(LARGE_INTEGER); and QueryPerformanceCounter(LARGE_INTEGER)

You can find both the DeltaTime and TotalTime of the application instance. Then using those values you can calculate FramePerSecond and everything else over the moon.

An example of this can be found here http://mengine.googlecode.com/svn-history/r2/trunk/DX10playground/src/GameTimer.cpp
written by Frank Luna writer of the "Introduction to 3D game programming using DirectX" series.

Look at it closely and see essentially what is being done in each function.

Then look at the following function that uses the GameTimer class:

void D3DApp::CalculateFrameStats()
{
// Code computes the average frames per second, and also the
// average time it takes to render one frame.  These stats
// are appended to the window caption bar.
static int frameCnt = 0;
static float timeElapsed = 0.0f;
frameCnt++;
// Compute averages over one second period.
if( (mTimer.TotalTime() - timeElapsed) >= 1.0f )
{
float fps = (float)frameCnt; // fps = frameCnt / 1
float mspf = 1000.0f / fps;
std::wostringstream outs;
outs.precision(6);
outs << mMainWndCaption << L"    "
<< L"FPS: " << fps << L"    "
<< L"Frame Time: " << mspf << L" (ms)";
SetWindowText(mhMainWnd, outs.str().c_str());

// Reset for next average.
frameCnt = 0;
timeElapsed += 1.0f;
}
}


Again ALL CREDIT TO FRANK LUNA.

This function calculates the frames per second and displays it to the application window title bar.

PARTNERS