Re: [AD] rest and yield_timeslice

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Angelo Mottola wrote:
True, the rescheduling will make it loose some milliseconds. But we stated nowhere rest() is meant to be used for accurate timing. When you need accurate timing, you'd better stick with Allegro timers.

Allegro's timers are just as accurate as a system's sleep function, if not less so. In fact, IIRC the timer thread system sleeps when there's nothing immediately waiting to run, so you end up getting a resolution of about 10ms per timer function call (which can be called multiple times to catch up, if needs be).

And true, the docs don't say that rest should be used for accurate timing, however I don't think that should automatically give us the liberties to make it more innacurate than it has to be.

Again, rest() is not meant to be used in an inner game loop. Timers are meant for this.

The timers are, at most, just as accurate as system sleep functions. The only way to time more accurately than this is to busy loop with a high accuracy timer, for which Allegro doesn't provide a cross-platform way to do so. As well, this has the obvious disadvantage of not lowering CPU usage.

And we could do this:

I personally would prefer:
void rest(long time)
{
  if(time <= 0 || !timer_driver)
    return;

  timer_driver->rest(x);
}

And the driver's rest method wouldn't have to worry about platform dependant rest 0 behavior, or add an extra check for <= 0, since the rest function itself does it.

But then you'd be fool to call rest(0) since it does nothing.

You might not necessarilly know ahead of time. Like in my example, if you do 'rest(expected_time - actual_time);' you won't immediately know. It could even come out negative. You'd have to add an extra check, which would, IMO, be pointless since Allegro would do its own check as well.


I was suggesting to merge the functions because rest(0) has no real meaning currently, and because I wanted to reduce slightly API clutter...

rest(0) does have a perfectly valid meaning. It means to rest for 0ms, or as close as possible. And as well, yield_timeslice has been a part of the API since pre 4.0, so I don't think it can go anywhere for a while. You'd end up having two ways to do the same thing, which is a bit worse than a little clutter for a couple things that behave slightly different.

Remember.. rest gives up the CPU as a side effect, not as standard behavior. AFAICR, the docs have never said anything about rest giving up the CPU as normal behavior.

- Kitty Cat




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/