where to put my gameloop?
hi,
i'm playing around with the iphone SDK - and to start i'd like to know:
when i create a Open GL ES application in xcode - where is the mainloop happening? usually i got something like this in my games:
but in the xcode project i don't see a main() function where i could start to build up my game code (well there's a main but it just calls UIApplicationMain())
so where to put my gameloop? is EAGLView -drawView: called every frame so i could call there my game logic? (but meh that feels kind of dirty ...)
how are you guys doing this? maybe with a timer in the app delegate's -applicationDidFinishLaunching:? and if so are the NSTimers reliable enough for games?
regards
i'm playing around with the iphone SDK - and to start i'd like to know:
when i create a Open GL ES application in xcode - where is the mainloop happening? usually i got something like this in my games:
Code:
//simplification^2
main()
{
while (running)
{
doInput();
doAI();
doPhysics();
doRender();
}
}but in the xcode project i don't see a main() function where i could start to build up my game code (well there's a main but it just calls UIApplicationMain())
so where to put my gameloop? is EAGLView -drawView: called every frame so i could call there my game logic? (but meh that feels kind of dirty ...)
how are you guys doing this? maybe with a timer in the app delegate's -applicationDidFinishLaunching:? and if so are the NSTimers reliable enough for games?
regards
superhuso Wrote:and if so are the NSTimers reliable enough for games?
Yes. Using a timer is the normal way of doing this in Cocoa. The main loop is part of the framework, called from NS/UIApplicationMain.
ThemsAllTook Wrote:Yes. Using a timer is the normal way of doing this in Cocoa. The main loop is part of the framework, called from NS/UIApplicationMain.
To expand a bit on this: Generally, the NSTimer precision is irrelevant since your game will effectively rely on VBL syncing for synchronization anyways.
Edit: Whoa! this is IPod/IPhone dev (that'll teach me to click from the main page of the forum...) Sorry about this, I don't even know if that SDK supports VBL synching...
- Sohta
thanks for your replies. 
btw. i don't think that there's a need for VBL synching on the iphone

btw. i don't think that there's a need for VBL synching on the iphone
The iPhone is always VBL sync'd. There's no way you can turn it off.
Excuse me, what does "VBL" mean?
Thanks.
Thanks.
Vertical blank. It refers to the period between display refreshes. What it means to be VBL synced is that you'll always draw a complete frame to the screen, whereas without VBL sync, you can end up with parts of two different frames drawn to different parts of the screen (commonly referred to as "tearing").

