Alternative to NSTimer
warmi Wrote:Not arbitrary but rather relatively predictable ... something NSTimer is not good for.
The iPhone/Mac OS is a preemptive multitasking system. Whatever you do in your little custom loop won't change that fact. A custom loop will not have any measurable advantage over a plain runloop with a single NSTimer on the *same thread* as the custom loop.
I also neglected to mention that if you set your NSTimer to a really small interval, but your buffer swap blocks the thread anyway, it's probably as efficient as it gets, as your timer will fire once per frame, as soon as the scheduler permits.
Anyhow, as for the screen-synced timer, that is also a bit difficult to handle. As threads are preemptive, the OS doesn't guarantee any execution time limits. Thus, even if your callback was called at the exactly right time, you could still miss the next screen refresh, if your thread didn't get enough CPU time. Temporal aliasing is unavoidable to some degree if the CPU load is high, which with a game, it typically is. Even if the amount of computation per game frame is constant, the execution time may still vary wildly. Incidentally, if you only measure time once per frame, you don't know if the culprit is that the timing is off, or that execution is taking too long. **
On a desktop Mac, input processing probably takes an order of magnitude less time to execute, due to the faster processor, etc, than on the iPhone. So if input processing on the phone takes 30% CPU time, it probably takes 3% on the desktop, and so produces much less noticable jitter, all else being constant. Also, with multiple cores, contention is even less of a problem, and even with a high load, the scheduling latency is greatly reduced.
If you had control of the thread scheduler, and a hardware interrupt for screen sync, and bounded execution time, you could probably reduce jitter a bit. However, if the amount of CPU time you use is variable, and sometimes more than what you got per screen refresh, you'll have to accept some amount of temporal aliasing.
(** if your buffer swap is synced, it'll always seem as if NSTimer skips firing some frames, eg you'll have 0.033, 0.033, 0.066, 0.033 as frame time intervals. But that isn't the fault of NSTimer, as your thread could have been blocked for 0.032s of that 0.066, simply because the buffer swap was initiated a fraction too late, and the timer can only fire after it has been completed. A custom game loop will show the exact same symptoms.)
| Messages In This Thread |
|
Alternative to NSTimer - demonpants - Mar 18, 2009, 02:51 PM
Alternative to NSTimer - longjumper - Mar 18, 2009, 04:15 PM
Alternative to NSTimer - demonpants - Mar 18, 2009, 11:48 PM
Alternative to NSTimer - Frank C. - Mar 19, 2009, 01:28 AM
Alternative to NSTimer - godexsoft - Mar 19, 2009, 02:15 AM
Alternative to NSTimer - riruilo - Mar 20, 2009, 02:56 AM
Alternative to NSTimer - demonpants - Mar 20, 2009, 11:29 AM
Alternative to NSTimer - JustinFic - Mar 20, 2009, 12:01 PM
Alternative to NSTimer - demonpants - Mar 20, 2009, 02:07 PM
Alternative to NSTimer - godexsoft - Mar 23, 2009, 09:04 AM
Alternative to NSTimer - godexsoft - Mar 23, 2009, 09:07 AM
Alternative to NSTimer - GregoryM - Mar 24, 2009, 01:15 AM
Alternative to NSTimer - demonpants - Mar 25, 2009, 05:07 PM
Alternative to NSTimer - godexsoft - Mar 26, 2009, 02:25 AM
Alternative to NSTimer - demonpants - Mar 26, 2009, 10:08 AM
Alternative to NSTimer - Ammonium - Apr 6, 2009, 12:44 PM
Alternative to NSTimer - demonpants - Apr 8, 2009, 02:43 PM
Alternative to NSTimer - mterlecki - May 12, 2009, 09:26 AM
Alternative to NSTimer - longjumper - May 12, 2009, 06:08 PM
Alternative to NSTimer - mister_t - May 13, 2009, 12:49 PM
Alternative to NSTimer - green_ghost - May 13, 2009, 11:12 PM
Alternative to NSTimer - bmantzey - May 15, 2009, 09:25 AM
Alternative to NSTimer - warmi - May 15, 2009, 10:49 AM
Alternative to NSTimer - warmi - May 15, 2009, 10:53 AM
Alternative to NSTimer - green_ghost - May 15, 2009, 07:45 PM
Alternative to NSTimer - ShiftZ - May 16, 2009, 02:24 AM
Alternative to NSTimer - mpatric - May 18, 2009, 09:49 AM
Alternative to NSTimer - ShiftZ - May 18, 2009, 11:55 AM
Alternative to NSTimer - warmi - May 18, 2009, 12:03 PM
Alternative to NSTimer - DoG - May 18, 2009, 02:56 PM
Alternative to NSTimer - warmi - May 18, 2009, 07:46 PM
Alternative to NSTimer - mpatric - May 19, 2009, 02:27 AM
Alternative to NSTimer - DoG - May 19, 2009, 04:07 PM
Alternative to NSTimer - warmi - May 19, 2009, 08:38 PM
Alternative to NSTimer - DoG - May 20, 2009, 02:08 AM
Alternative to NSTimer - ShiftZ - May 20, 2009, 04:48 AM
Alternative to NSTimer - iamflimflam1 - May 20, 2009, 07:33 AM
Alternative to NSTimer - DoG - May 20, 2009, 07:42 AM
Alternative to NSTimer - ShiftZ - May 20, 2009, 08:35 AM
Alternative to NSTimer - warmi - May 20, 2009, 09:08 AM
Alternative to NSTimer - mpatric - May 20, 2009, 11:23 AM
Alternative to NSTimer - mpatric - May 20, 2009, 11:26 AM
Alternative to NSTimer - mpatric - May 20, 2009, 11:31 AM
Alternative to NSTimer - ShiftZ - May 20, 2009, 12:12 PM
Alternative to NSTimer - DoG - May 20, 2009, 02:44 PM
Alternative to NSTimer - warmi - May 20, 2009, 08:17 PM
Alternative to NSTimer - arekkusu - May 20, 2009, 09:05 PM
Alternative to NSTimer - AnotherJake - May 20, 2009, 09:43 PM
Alternative to NSTimer - warmi - May 20, 2009, 10:27 PM
Alternative to NSTimer - maximile - May 21, 2009, 05:46 AM
Alternative to NSTimer - arekkusu - May 21, 2009, 05:47 AM
Alternative to NSTimer - warmi - May 21, 2009, 07:32 AM
Alternative to NSTimer - AnotherJake - May 21, 2009, 07:35 AM
Alternative to NSTimer - arekkusu - May 21, 2009, 09:24 AM
Alternative to NSTimer - warmi - May 21, 2009, 09:43 AM
Alternative to NSTimer - arekkusu - May 21, 2009, 09:58 AM
Alternative to NSTimer - warmi - May 21, 2009, 10:19 AM
Alternative to NSTimer - DoG - May 22, 2009 01:39 AM
Alternative to NSTimer - warmi - May 22, 2009, 09:14 AM
Alternative to NSTimer - demonpants - Jun 8, 2009, 02:41 PM
Alternative to NSTimer - reklis - Jul 12, 2009, 01:36 PM
Alternative to NSTimer - maximile - Jul 13, 2009, 06:50 AM
Alternative to NSTimer - mpatric - Jul 13, 2009, 07:10 AM
Alternative to NSTimer - Frank C. - Jul 13, 2009, 11:33 AM
Alternative to NSTimer - longjumper - Jul 13, 2009, 11:44 AM
Alternative to NSTimer - mpatric - Jul 13, 2009, 12:06 PM
Alternative to NSTimer - warmi - Jul 14, 2009, 12:18 AM
Alternative to NSTimer - DoG - Jul 14, 2009, 12:43 AM
Alternative to NSTimer - warmi - Jul 14, 2009, 08:12 AM
Alternative to NSTimer - mpatric - Jul 14, 2009, 08:12 AM
Alternative to NSTimer - AnotherJake - Jul 14, 2009, 08:35 AM
Alternative to NSTimer - warmi - Jul 14, 2009, 09:09 AM
Alternative to NSTimer - longjumper - Jul 14, 2009, 09:18 AM
Alternative to NSTimer - warmi - Jul 14, 2009, 09:38 AM
Alternative to NSTimer - AnotherJake - Jul 14, 2009, 09:45 AM
Alternative to NSTimer - AnotherJake - Jul 14, 2009, 09:47 AM
Alternative to NSTimer - DoG - Jul 14, 2009, 01:21 PM
Alternative to NSTimer - reklis - Jan 8, 2010, 08:34 PM
Alternative to NSTimer - riruilo - Jan 11, 2010, 01:52 PM
|
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| NSTimer fine, CADisplayLink having some issues | monteboyd | 5 | 7,529 |
Aug 31, 2010 07:05 PM Last Post: Skorche |
|
| NSTimer hiccups/choppy/jerky | jeonghyunhan | 2 | 2,415 |
Sep 24, 2009 07:35 PM Last Post: jeonghyunhan |
|
| Using an NSTimer to progressively draw a view | StevenD | 4 | 3,701 |
May 14, 2009 07:57 AM Last Post: StevenD |
|
| OpenGL render loop - NSTimer vs rendering thread | smallstepforman | 27 | 20,545 |
Feb 2, 2009 10:22 AM Last Post: ThemsAllTook |
|
| Alternative Input/Control Ideas | chrisco | 8 | 3,884 |
Aug 6, 2008 03:21 PM Last Post: bruss14 |
|

