Jump to content
  • Advertisement

Archived

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

dusik

Fast timer, NOT win32

This topic is 5941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am programming a 3D engine to support multiple OS''s. So, for Win32 I can use timeGetTime(), etc. But what would I use in Linux? clock() is waaaay too slow! Completely stumped. I''d be very greatful for some info on this. Thanks

Share this post


Link to post
Share on other sites
Advertisement
So ASM is the only way? OK I suppose I could handle that. Strange though that there''s not a nice standard C func for that....

Thanks a lot

Share this post


Link to post
Share on other sites
Have you had a look what's in the Linux time.h header? Some of the functions there might be of use to you.

--
Very simple ideas lie within the reach only of complex minds.

Edited by - SabreMan on February 17, 2002 9:22:47 AM

Share this post


Link to post
Share on other sites
Why, is the time.h header different for Linux than for Windows? I thought it was a standard C header.

Share this post


Link to post
Share on other sites
quote:
Original post by dusik
Why, is the time.h header different for Linux than for Windows? I thought it was a standard C header.


Whoops, yes. I was working from memory which often isn''t the most accurate of techniques. Especially when I haven''t used the header in question for over a year!

--
Very simple ideas lie within the reach only of complex minds.

Share this post


Link to post
Share on other sites
i would create a simple function, inline probably. along the lines of this:
  
int checktimer(long timer) {
if (timer <= time()) {
return 1;
}
return 0;
}

then you would use it by first creating a timer variable and then calling the checktimer() to see if the timer had occured:
  
long timer = time() + 1000; // set a timer for in a second

while (checktimer(timer) == 0) { }
printf("Second is over.\n");


(http://www.ironfroggy.com/)
(http://www.ironfroggy.com/pinch)

Share this post


Link to post
Share on other sites
I still don''t see, though, how this would allow me to calculate, say, frames per second. Say, I''ve got 100 FPS. That means, each frame takes 10 milliseconds to render. So I would do something like:

  
void TimerTick()
{
static long prevtime = time();
long currtime = time();

g_FPS = (1.0f / (float)(currtime-prevtime));

prevtime = currtime;
}


That is similar to what I''ve got now (though simplified) but instead of time() I use timeGetTime() using the Win32 API. The reason is, timeGetTime is accurate to 1 millisecon, which is what I need, whereas the functions in (clock(), time()) are way too inaccurate.

Also, if I''m not mistaken, ironfroggy, the code you wrote is a delay, not a measure of time. I need to measure how much time the frame has been rendering, not pause the programme for any amount of time.

But thanks anyway.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!