where to put my gameloop?

Nibbie
Posts: 2
Joined: 2008.11
Post: #1
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:

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
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #2
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.
Quote this message in a reply
Member
Posts: 72
Joined: 2006.10
Post: #3
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
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2008.11
Post: #4
thanks for your replies. Smile

btw. i don't think that there's a need for VBL synching on the iphone Smile
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #5
The iPhone is always VBL sync'd. There's no way you can turn it off.
Quote this message in a reply
Member
Posts: 249
Joined: 2008.10
Post: #6
Excuse me, what does "VBL" mean?

Thanks.
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #7
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").
Quote this message in a reply
Post Reply