Using NSTimer in SDL Loop.
As most of you are aware, the NSTimer initialization call goes something like this:
timer = [NSTimer timerWithTimeInterval:<#(NSTimeInterval)ti#> target:<#(id)aTarget#> selector:<#(SEL)aSelector#> userInfo:<#(id)userInfo#> repeats:<#(BOOL)yesOrNo#>];
I am using SDL in a C based implementation in my main file. What information can I feed the NSTimer to call a C function (such as update(), defined in the main file)? I cannot pass "self" as the object since my main file does not have a Obj-C id.
Thanks!
timer = [NSTimer timerWithTimeInterval:<#(NSTimeInterval)ti#> target:<#(id)aTarget#> selector:<#(SEL)aSelector#> userInfo:<#(id)userInfo#> repeats:<#(BOOL)yesOrNo#>];
I am using SDL in a C based implementation in my main file. What information can I feed the NSTimer to call a C function (such as update(), defined in the main file)? I cannot pass "self" as the object since my main file does not have a Obj-C id.
Thanks!
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Skorche Wrote:Why not use a SDL timer if you are using SDL?
http://www.libsdl.org/cgi/docwiki.cgi/SDL_AddTimer
That could work. I don't like the fact that direct action is not encouraged due to separate threading of the timer. It's functional, but not optimal. Thanks nonetheless, that will probably solve my problem for now. If anyone can answer my original question, that would be awesome. Thanks again.
Skorche Wrote:Why not use a SDL timer if you are using SDL?
http://www.libsdl.org/cgi/docwiki.cgi/SDL_AddTimer
That did the trick. I suppose it works well enough, thanks again.
To answer your original question, the simplest solution would be to write a tiny Objective-C class that does nothing but call your C function when its timer fires (via a function pointer passed into the class if there's more than one function you're interested in calling).
I don't think SDL timers are what you want... and I don't see why you need NSTimers. Just check each time round the event loop whether enough time has expired, "manually"...
OneSadCookie Wrote:I don't think SDL timers are what you want... and I don't see why you need NSTimers. Just check each time round the event loop whether enough time has expired, "manually"...
Do what now? What do you mean manually? Like using a counter variable?
use SDL_GetTicks to find out what the time is, check whether that's after the time you want your "timer" to fire, if so, fire it.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| NSTimer / animation framerate question | MonitorFlickers | 5 | 4,515 |
Dec 4, 2005 01:10 PM Last Post: MonitorFlickers |
|
| Cocoa Event Loop/NSTimer revisited | Fenris | 6 | 4,588 |
Oct 29, 2005 11:27 PM Last Post: maaaaark |
|
| NSTimer Running always or somtimes | unknown | 3 | 2,661 |
Jul 27, 2005 12:49 PM Last Post: unknown |
|
| NSTimer/NSAffineTransform | Coin | 6 | 3,536 |
Feb 4, 2005 06:23 PM Last Post: Coin |
|

