Fast timer, NOT win32
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
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
Thanks a lot
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
--
Very simple ideas lie within the reach only of complex minds.
Edited by - SabreMan on February 17, 2002 9:22:47 AM
Why, is the time.h header different for Linux than for Windows? I thought it was a standard C header.
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.
i would create a simple function, inline probably. along the lines of this:
then you would use it by first creating a timer variable and then calling the checktimer() to see if the timer had occured:
(http://www.ironfroggy.com/)
(http://www.ironfroggy.com/pinch)
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 secondwhile (checktimer(timer) == 0) { }printf("Second is over.\n");
(http://www.ironfroggy.com/)
(http://www.ironfroggy.com/pinch)
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:
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement