🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Timer

Started by
1 comment, last by GameDev.net 24 years, 10 months ago
In the main game loop, have something like:


int prev_time;

struct timeval tv;

while( 1 )
{
gettimeofday( &tv, NULL );
if( ((tv.tv_usec) - prev_time) < MIN_DELAY )
{
prev_time = (tv.tv_usec);
MainGameLoop();
}
}

(MIN_DELAY is the minimum microseconds between each game cycle)

I'm not sure if the tv.u_sec is microseconds from current second, or total microseconds seconds since Jan 1st 1970...

do a man gettimeofday...

------------------
Mark Collnis
- EHB Software

[This message has been edited by Godfree^ (edited August 24, 1999).]

After careful deliberation, I have come to the conclusion that Nazrix is not cool. I am sorry for any inconvienience my previous mistake may have caused. We now return you to the original programming

Advertisement
Hi, I have reasonable experience with writing Win32 games. I'm now considering writing games for Linux. One thing I find that is sorely missing is a good reference book or two for Linux game programming. There are tons of books out there for Win32 game programming though... Anyway, I need to know how to control game speed under Linux? I use Win32 functions like SetTimer(...), QueryPerformanceCounter(...), and timeGetTime(...). But I have no clue what to use for Linux? How do you guys do it? Thanks in advance!
Hi.
gettimeofday() is one possibility.
you can also use an event driven callback timer, which you set with setitimer().
after you've set the frequency(max 100 Hz, because of system timer, same in windows I think) you have to set the SIGALRM signal handler to an own function through signal().
note that sleep() and usleep() do not work anymore, because a SIGALRM signal forces the program to go on.

cu,
Sengir


--
Sengir

This topic is closed to new replies.

Advertisement