Is it possible to have a "mainloop" in your iPhone application, such as what would be used in a game or other application requiring constant activity? If so, where is the best place to put such a loop?
I think most iPhone apps are designed to respond to events, do some processing, then return from the event handler. A game, on the other hand, obviously needs to be running the game code at all times. The old-school approach would have been to do something like this:
This is what I'd like to be able to do, but I'm sure where code like this can go without risking locking up the device or OS by "hanging" in a loop like this.
In the GLSprite demo, Apple chose to use an NSTimer to get updates at a regular interval, but I'd prefer to run the game code as quickly as possible and not be limited by a timer interval that is not optimally in sync with the game code.
I think most iPhone apps are designed to respond to events, do some processing, then return from the event handler. A game, on the other hand, obviously needs to be running the game code at all times. The old-school approach would have been to do something like this:
Code:
int main()
{
init_the_game();
bool running = 1;
while (running)
{
running = run_the_game_loop(); // returns 0 if user quits game
}
cleanup();
exit(0);
}
This is what I'd like to be able to do, but I'm sure where code like this can go without risking locking up the device or OS by "hanging" in a loop like this.
In the GLSprite demo, Apple chose to use an NSTimer to get updates at a regular interval, but I'd prefer to run the game code as quickly as possible and not be limited by a timer interval that is not optimally in sync with the game code.