Re: Best solution for game loop on OSX?
Re: Best solution for game loop on OSX?
- Subject: Re: Best solution for game loop on OSX?
- From: Seth Willits <email@hidden>
- Date: Mon, 16 Dec 2013 16:53:17 -0800
Are you *only* trying to do audio, or are you trying to render GL as well?
--
Seth Willits
On Dec 13, 2013, at 1:57 PM, Alex Hall <email@hidden> wrote:
> Hello list,
> I am attempting to use OpenAL to move a sound source around. To do so smoothly, though, will require a loop, so I can update the position in small increments many times per second. This is essentially a game loop, so I've done much searching on implementing game loops in Objective-C. There seem to be a few schools of thought on the topic:
>
> NSTimer: it works initially, but you can't rely on it to provide smoothness or constant rates. A timer could take up to 0.1 seconds to execute, so don't rely on it. However, other sources suggest that a timer will work just fine, particularly on the more powerful OSX compared to iOS devices, and doing anything else is a waste of effort for lower FPS projects.
>
> Main loop: every NSApplication has an instance of NSRunLoop attached to it when it starts. Hook into that (the mechanics of doing this are still not clear to me) and you are good to go. However, this is more work for no additional benefit, and you need to worry more about memory usage (I have no idea if the samples I've read were using ARC or not).
>
> Separate thread: uses standard-issue while(keep_running) loop in a new thread to process the game logic and refresh the world, and you're set to go as fast as you need to. However, this introduces the usual multi-threading concerns and is far more advanced than many projects actually need.
>
> Additionally, there is concern about how fast to set the refresh rate, which is not a problem in a regular while loop but becomes a bit complex otherwise. Most people seem to agree that you should see how long the last cycle took, and update your interval accordingly.
>
> Again, this is not (yet) for iOS, so I cannot rely on iOS-specific solutions. I am also not currently doing visuals, and I am not sure which framework I will use when and if I need to begin doing so, so I'd rather have my loop not rely on any visual framework. The bottom line seems to be that timers are easiest but not reliable, yet some people insist they will work well enough. So, what are your thoughts on the best way to make a game loop for OSX? While I would like to port this project to iOS in the future, I'd like a solution that will work on both platforms, and the Mac first. Given that my program is mostly based in sound, would timers be okay? Should I look into hooking into the NSRunLoop somehow instead? I'd really rather not go multi-threaded yet, but if I have to, I have to. Thanks for your opinions.
>
>
> Have a great day,
> Alex (msg sent from Mac Mini)
> email@hidden
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
--
Seth Willits
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden