discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSRunLoop and timers


From: Alexander Malmberg
Subject: Re: NSRunLoop and timers
Date: Fri, 08 Aug 2003 21:30:28 +0200

Cyrille Gautard wrote:
> Hello,
> 
> I use a NSRunLoop to perform screen updates in an openGL program. I use
> the performSelector method to call my display method on each loop. But
> the NSRunLoop doesn't loop until an event is sent. So I use an NSTimer
> to send an event but it limits the frame per second to the timer
> interval.
> 
> How can I use the NSRunLoop class without being limited by the timer and
> display the most possible frames per second ?

NSRunLoop is meant to be used when you want to block while waiting for
input and use as little cpu time as possible, which is very different
from wanting to suck up as much cpu time as possible. Thus, you'll
probably have to run the loop yourself, something similar to:

while (1)
{
   do_opengl_stuff();
   [theRunLoop runMode: NSDefaultRunLoopMode  beforeDate: [NSDate
dateWithTimeIntervalSinceNow: 0.00001]];
}

(but with extra code for eg. autorelease pools.) The constant (0.00001
here) should be small enough that it doesn't affect the frame rate, but
large enough that NSRunLoop thinks it's in the future (otherwise, it
won't actually poll for new input). (If you have access to vertical
refresh timing information, you might want to try to increase this to
fill the gaps between rendering and flipping buffers.)

Another possible solution would be to create a separate thread that uses
NSRunLoop to handle input instead of trying to both draw and handle
input in one thread.

- Alexander Malmberg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]