Time recording for fps system - how to?

Started by
17 comments, last by emileej 22 years, 6 months ago
frames per second = 1 / (seconds per frame)

codeka.com - Just click it.
Advertisement
I allready tried that:
(int)((float)1/(float)framerate)
But it gives 0 no matter what...

-------------
E-)mil
http://eej.dk

- Just another crazy dane
Emil Johansen- SMMOG AI designerhttp://smmog.com
#include
#pragma comment(lib,"winmm.lib")

DWORD g_dwFrameRate = 0; // FPS you want
DWORD g_dwLastTickCount = 0;
DWORD g_dwFrameCount = 0;

timeBeginPeriod(1);
g_dwFrameCount++;

if (abs(timeGetTime() - g_dwLastTickCount) >= 1000)
{
g_dwLastTickCount = timeGetTime();
g_dwFrameRate = g_dwFrameCount;
g_dwFrameCount = 0;
}

timeEndPeriod(1);
>>Payne
Shure - shure - why should that be better than the other method, and how do i calculate the fps value here?
Would u comment it please?

-------------
E-)mil
http://eej.dk

- Just another crazy dane
seem my timeGetTime run at 1000 ticks per second,
should it be 1024? i wonder.........

whatever timeGetTime or timeGetTime,
fps = 1000/(currentframetick-lastframetick)
and that is, u have ur fps every frame.
OK

// Global variables
DWORD g_dwFrameRate = 0; // FPS you want
DWORD g_dwLastTickCount = 0;
DWORD g_dwFrameCount = 0;

// Put the following lines after IDirect3DDevice:resent() method
timeBeginPeriod(1);
g_dwFrameCount++;

if (abs(timeGetTime() - g_dwLastTickCount) >= 1000)
{
g_dwLastTickCount = timeGetTime();
g_dwFrameRate = g_dwFrameCount;
g_dwFrameCount = 0;

char szText[22];
wsprintf(szText, "Frame Rate = %d fps", g_dwFrameRate);
SetWindowText(hWnd, szText);
}

timeEndPeriod(1);
Test

http://www.cwinapp.com
Gah! Sorry, emileej... the proper fps conversion *should* be this:

  float framespersecond = (float)(1000)/(float)(framerate);  


This way, if a frame takes approx 17ms, it should give you a result of 60fps

Paradigm Shift 2000
"I am Locutus of Borg. Resistance is Futile." -- Locutus of Borg
Hehe - i also found it kinda wired, when my fps climbed, when i moved the mouse, and fell when i stopped moving it

-------------
E-)mil
http://eej.dk

- Just another crazy dane
Emil Johansen- SMMOG AI designerhttp://smmog.com

This topic is closed to new replies.

Advertisement