Archived

This topic is now archived and is closed to further replies.

Squizz

Newbie- Timer Question

Recommended Posts

Squizz    122
What is the quickest and simplest way to get a timer counting in my program NOT USING MFC... just like a very quick and EASY way. All it needs to do is regulate a game loop. Thnkz in Advance

Share this post


Link to post
Share on other sites
Julio    116
check out my timer class on my page. it should have everything you need.



How many Microsoft employees does it take to screw in a light bulb?
None, they just declare drakness as a new standard.

Share this post


Link to post
Share on other sites
Midnight Coder    122
You can make your own timer system. Just get the amount of time it takes to render a frame, and then you can use that to tell how much time is passed. Like this:

  
int frametime;
int lasttime;
int timer;

void Init(void)
{
//Do initalization...

lasttime = timeGetTime();
frametime = 0;
timer = 0;
//More initialization...

}

void GameMain(void)
{
timer += frametime;
while(timer >= MAX_TIME) //MAX_TIME can be anything

{
timer -= MAX_TIME;
DoWhatever();
}

DoPhysics();
RenderFrame();
//Etc.


frametime = timeGetTime() - lasttime;
lasttime = timeGetTime();
}


This method works very well. The while loop is to ensure it doesn''t fall behind when the framerate drops.

Share this post


Link to post
Share on other sites