Re: [Tuxnes-devel] usleep() and gettimeofday() aren't portable
Brought to you by:
tmmm
|
From: Mike M. <che...@ya...> - 2004-05-11 09:29:32
|
NTSC is 29.97 times a second or 59.94 / 2. I don't see how waiting for a
second after drawing 30 frames will be any good to the average nintendo
buff. Sleeping should be done with idle loops, thought we will need a
high percision clock to time them corectly.
--- Jason Dorje Short <jd...@us...> wrote:
> The usleep() function is not portable. It's not available on win32; we
> should use Sleep() instead.
>
> Freeciv has code like
>
> /***************************************************************
> Suspend execution for the specified number of microseconds.
> ***************************************************************/
> void myusleep(unsigned long usec)
> {
> #ifdef HAVE_USLEEP
> usleep(usec);
> #else
> #ifdef HAVE_SNOOZE /* BeOS */
> snooze(usec);
> #else
> #ifdef GENERATING_MAC
> EventRecord the_event; /* dummy - always be a null event */
> usec /= 16666; /* microseconds to 1/60th seconds */
> if (usec < 1) usec = 1;
> /* suposed to give other application processor time for the mac */
> WaitNextEvent(0, &the_event, usec, 0L);
> #else
> #ifdef WIN32_NATIVE
> Sleep(usec / 1000);
> #else
> struct timeval tv;
> tv.tv_sec=0;
> tv.tv_usec=usec;
> select(0, NULL, NULL, NULL, &tv);
> #endif
> #endif
> #endif
> #endif
> }
>
> where HAVE_USLEEP, HAVE_SNOOZE, GENERATING_MAC, and WIN32_NATIVE are all
>
> checked at configure time.
>
> There's a similar problem with gettimeofday. ftime is more portable and
>
> is reported to have 10ms resolution on win32 (barely adequate for tuxnes
>
> purposes). So there is code like
>
> #ifdef HAVE_GETTIMEOFDAY
> int ret = gettimeofday(&t->start.tv, NULL);
> if (ret == -1) {
> report_gettimeofday_failed(t);
> return;
> }
> #elif defined HAVE_FTIME
> ftime(&t->start.tp);
> #else
> t->start.t = time(NULL);
> if (t->start.t == (time_t) -1) {
> report_time_failed(t);
> return;
> }
> #endif
>
> I think it would be convenient to have wrappers that take times in
> seconds, as float or double values. Internally these can convert to
> whatever integer form is needed by the backend.
>
> Incidentally there is no good way to check for Sleep and other win32-api
>
> functions because linking is done differently. I have no idea why this
> is but it does seem to be the case. The solution is to check for the
> win32 api in one go and define WIN32_NATIVE or WIN32_API or some such.
> Then this value can be used to cover all win32-specific function calls
> (which will be consistent across all windows platforms).
>
> jason
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by Sleepycat Software
> Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to
> deliver
> higher performing products faster, at low TCO.
> http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3
> _______________________________________________
> Tuxnes-devel mailing list
> Tux...@li...
> https://lists.sourceforge.net/lists/listinfo/tuxnes-devel
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover
|