Skip to main content
gamedev.net
🔒 Locked

A Timer Function.

Started by Esap1 3 replies 550+ views
Original Post
Esap1
Esap1
Could You Please Tell me a Timer Function like how many clicks have passed and how to use it. Im going to use it for finding the Frames Per Second, Thanks A LOT! later,
m_grinder
m_grinder
DWORD m_FPSTimer;
DWORD m_FPS;
FILE* Stream;
stream = fopen("fps.txt", "a");
Draw()
{
m_FPS = ( 1000/( timeGetTime() - m_FPSTimer() ) );
m_FPSTimer = timeGetTime();
fprintf(stream,"%d",m_FPS);
}
///////////////////////////////////
//m_grinder - no brains, no clue.//
///////////////////////////////////

DDnewbie
DDnewbie

I hereby give you my fps-class:

class Fps {
int framecount;
DWORD framestarttime;
int fps;
char buffer[50];
public:
Fps(void) : framecount(0) {}
void Start(void) { framestarttime=GetTickCount(); }
void Stop(void) {
fps=(int)(GetTickCount()-framestarttime);
fps=1000/(fps+1); //+1=security flag to make answer >=1, to avoid probable division by zero!
}
void Draw(void) {
sprintf(buffer,"Frames Per Second=%d",fps);
Draw_Text_GDI(buffer,0,SCREEN_HEIGHT-20,RGB(120,220,20),lpddsback);
}
};


Use it like this in your main-loop or whatever:
Fps framespersecond;
while(1)
{
framespersecond.Start();

Game_Main();

framespersecond.Stop();
}

In Game_Main() you can plot the fps like this:
framespersecond.Draw();


Note: I don''t assure you that this class is correct at all, it might be totally wrong.
If someone knows that this is wrong, please tell me.

/DDnewbie


Newbie
/Mankind gave birth to God.
Staffan
Staffan
Why bother with a class for FPS? It''s not like you''re going to create an large amount of Fps objects now is it?

m_grinder: Where in Värmland are you at? Karlstad by any chance?



"I think, therefore I am...I think"
nes8bit
nes8bit
If you use winapi you can call GetTickCount. It is either in the kernel or user32. Try the following when using it.

StartTime = TickCount
Do_What_Ever
EndTime = TickCount
Time_It_Took = EndTime - StartTime

Check the DX samples. They have framerate code.

Sorry I can''t help you with finding the call. My computer just got a virus and I lost everything.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.