Re: Best solution for game loop on OSX?

2013-12-17 Thread Eric Wing
On 12/17/13, Uli Kusterer  wrote:
> On 17 Dec 2013, at 00:15, Dan Treiman  wrote:
>> The two best solutions (and by best I mean least time-wasting) are
>> CVDisplayLink and NSTimer.
>>
>> CVDisplayLink synchronizes with the display refresh rate and gives you
>> callbacks in a background thread.  This somewhat like CADisplayLink on
>> iOS.  Its pretty easy to do but your code must be thread-aware.
>>
>> NSTimer has more than enough resolution for games, and if you are using
>> OpenGL for graphics you should do: (…)
>
>  He’s talking about OpenAL, not OpenGL. Audio, not graphics. So I don’t
> think the display links are a good choice here. They’re intended to avoid
> tearing when doing screen display, and depending on your screen and power
> saver settings may not get called as often as you’d want for sound.

So I'll put in my 2 cents since OpenAL is something I have a lot of
expertise in.
NSTimer generally works pretty well (and I was under the impression
that 10.9 timers are even more accurate now). Even though the firing
rate can be inconsistent, I don't think you need a lot of precision
for spatial audio. I've never been exposed to an audio system and been
in a situation where I could discern the difference between audio
points only a tiny distance away from each other.


The problem I've had with CVDisplayLink in the past is when the
window/view disappears for certain reasons (I can't remember...was it
user minimizing, or what), the display link callbacks automatically
turn off. This is fine for graphics, but sucks if you are trying to
keep track of time elapsed or want to continue playing background
music. (I haven't experienced this problem with CADisplayLink on iOS.)


Thanks,
Eric
-- 
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Best solution for game loop on OSX?

2013-12-17 Thread Uli Kusterer
On 17 Dec 2013, at 00:15, Dan Treiman  wrote:
> The two best solutions (and by best I mean least time-wasting) are 
> CVDisplayLink and NSTimer.
> 
> CVDisplayLink synchronizes with the display refresh rate and gives you 
> callbacks in a background thread.  This somewhat like CADisplayLink on iOS.  
> Its pretty easy to do but your code must be thread-aware.
> 
> NSTimer has more than enough resolution for games, and if you are using 
> OpenGL for graphics you should do: (…)

 He’s talking about OpenAL, not OpenGL. Audio, not graphics. So I don’t think 
the display links are a good choice here. They’re intended to avoid tearing 
when doing screen display, and depending on your screen and power saver 
settings may not get called as often as you’d want for sound.

Cheers,
-- Uli Kusterer
“The Witnesses of TeachText are everywhere...”
http://zathras.de


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Best solution for game loop on OSX?

2013-12-17 Thread Graham Cox

On 13 Dec 2013, at 10:57 pm, Alex Hall  wrote:

> To do so smoothly, though, will require a loop, so I can update the position 
> in small increments many times per second.


You probably know this, but it’s a point worth repeating.

Whatever method you use to make the game loop, don’t fall into the trap of 
assuming that each callback is equivalent to  seconds. Instead, 
measure the elapsed time and derive your position(s) accordingly.

In other words, suppose you want to move an object from position p1 to position 
p2 over a period of, say, 1 second. You might assume a framerate of 30fps and 
therefore divide p2-p1 into thirty equal increments and add that increment at 
each frame. DO NOT DO THAT! If your timer is held up for any reason, your 
animation slows down. Instead, calculate the elapsed time at each frame and 
derive the true position from it. That way, if the timer is held up, your 
framerate drops but the positions of everything remains correct.

Seems obvious but I’ve seen many developers fall into this trap, especially if 
it’s their first game.

—Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Best solution for game loop on OSX?

2013-12-16 Thread Alex Hall

On Dec 16, 2013, at 8:06 PM, Seth Willits  wrote:

> On Dec 16, 2013, at 3:21 PM, Alex Hall  wrote:
> 
>> I went ahead and used timers, just to get things off the ground. Many people 
>> seem to dislike them, but they work for me, for now anyway. It's really 
>> helpful to know about CVDisplayLink, though, if I ever implement graphics or 
>> need a more strict timing solution. 
> 
> 
> This subject line is really misleading.
> 
> Having no graphics at all makes a big difference. You would not implement a 
> solution to your problem as you would "the best way" for a game, and the 
> solution you need depends on your actual requirements. 

For now it is only sound, but I plan on adding graphics (albeit basic ones) 
before the project is done.
> 
> "update the position in small increments many times per second" — 
> What does "many" mean to you? What level of accuracy do you need? How should 
> this interact with the main thread, etc? 

I'm not sure what sort of resolution sounds need compared to graphics to not be 
choppy or jumpy during panning or other adjustments. Since the plan is to 
incorporate graphics in the future, I figured I may as well do something that 
would work for both. For now, my main thread handles everything, though I may 
need to split things up at some point depending on how the project turns out. 
It is modular, though, so I can hook my loop to any mechanism pretty easily.
> 
> 
> --
> Seth Willits
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/mehgcap%40gmail.com
> 
> This email sent to mehg...@gmail.com



Have a great day,
Alex (msg sent from Mac Mini)
mehg...@gmail.com




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Best solution for game loop on OSX?

2013-12-16 Thread Seth Willits
On Dec 16, 2013, at 3:21 PM, Alex Hall  wrote:

> I went ahead and used timers, just to get things off the ground. Many people 
> seem to dislike them, but they work for me, for now anyway. It's really 
> helpful to know about CVDisplayLink, though, if I ever implement graphics or 
> need a more strict timing solution. 


This subject line is really misleading.

Having no graphics at all makes a big difference. You would not implement a 
solution to your problem as you would "the best way" for a game, and the 
solution you need depends on your actual requirements. 

"update the position in small increments many times per second" — 
What does "many" mean to you? What level of accuracy do you need? How should 
this interact with the main thread, etc? 


--
Seth Willits



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Best solution for game loop on OSX?

2013-12-16 Thread Seth Willits
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  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)
> mehg...@gmail.com
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/slists%40araelium.com
> 
> This email sent to sli...@araelium.com



--
Seth Willits




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Best solution for game loop on OSX?

2013-12-16 Thread Richard Heard
Perhaps CVDisplayLink is what you are looking for.
-R

On 13 Dec 2013, at 1:57:15 PM, Alex Hall  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)
> mehg...@gmail.com
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/heardrwt%40gmail.com
> 
> This email sent to heard...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Best solution for game loop on OSX?

2013-12-16 Thread Marcelo Alves

You can use CVDisplayLink (Foundation, OS X) / CADisplayLink (iOS) with pretty 
good accuracy or a time dispatch timer. The dispatch timer approach is more 
portable (no changes in your code), a bit cleaner (block based, instead of 
function pointers in the case of CVDisplayLink), but it is up to you. 


> 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:
> 

:: marcelo.alves


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Best solution for game loop on OSX?

2013-12-16 Thread ChanMaxthon
My personal preference is GCD dispatching from your graphics rendering loop. 

Sent from my iPhone

> On 2013年12月14日, at 5:57, Alex Hall  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)
> mehg...@gmail.com
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/xcvista%40me.com
> 
> This email sent to xcvi...@me.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Best solution for game loop on OSX?

2013-12-16 Thread Alex Hall
I went ahead and used timers, just to get things off the ground. Many people 
seem to dislike them, but they work for me, for now anyway. It's really helpful 
to know about CVDisplayLink, though, if I ever implement graphics or need a 
more strict timing solution. Thanks for the response.
On Dec 16, 2013, at 6:15 PM, Dan Treiman  wrote:

> Alex,
> 
>   Ah, this has been a continuous discussion ever since OSX launched… :-). 
>  Heres my 2¢:
> 
> The two best solutions (and by best I mean least time-wasting) are 
> CVDisplayLink and NSTimer.
> 
> CVDisplayLink synchronizes with the display refresh rate and gives you 
> callbacks in a background thread.  This somewhat like CADisplayLink on iOS.  
> Its pretty easy to do but your code must be thread-aware.
> 
> NSTimer has more than enough resolution for games, and if you are using 
> OpenGL for graphics you should do:
> GLint swapInt = 1;
> [[self openGLContext] setValues:&swapInt 
> forParameter:NSOpenGLCPSwapInterval];
> to ensure your updates are synced with screen refresh.
> 
> Since your game does not sound especially graphically intensive, I would 
> recommend the solution that requires the least code written (NSTimer), and 
> avoid multithreading.  If you run into performance problems you can always 
> implement a more advanced solution later.
> 
>   cheers,
>   - Dan
> 
> 
> On Dec 13, 2013, at 3:57 PM, Alex Hall  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)
>> mehg...@gmail.com
>> 
>> 
>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> https://lists.apple.com/mailman/options/cocoa-dev/dtreiman%40mac.com
>> 
>> This email sent to dtrei...@mac.com
> 



Have a great day,
Alex (msg sent from Mac Mini)
mehg...@gmail.com



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@ma

Re: Best solution for game loop on OSX?

2013-12-16 Thread Dan Treiman
Alex,

Ah, this has been a continuous discussion ever since OSX launched… :-). 
 Heres my 2¢:

The two best solutions (and by best I mean least time-wasting) are 
CVDisplayLink and NSTimer.

CVDisplayLink synchronizes with the display refresh rate and gives you 
callbacks in a background thread.  This somewhat like CADisplayLink on iOS.  
Its pretty easy to do but your code must be thread-aware.

NSTimer has more than enough resolution for games, and if you are using OpenGL 
for graphics you should do:
GLint swapInt = 1;
[[self openGLContext] setValues:&swapInt 
forParameter:NSOpenGLCPSwapInterval];
to ensure your updates are synced with screen refresh.

Since your game does not sound especially graphically intensive, I would 
recommend the solution that requires the least code written (NSTimer), and 
avoid multithreading.  If you run into performance problems you can always 
implement a more advanced solution later.

cheers,
- Dan


On Dec 13, 2013, at 3:57 PM, Alex Hall  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)
> mehg...@gmail.com
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/dtreiman%40mac.com
> 
> This email sent to dtrei...@mac.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Best solution for game loop on OSX?

2013-12-16 Thread Alex Hall
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)
mehg...@gmail.com




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com