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

Core Data: IN with ordered set of keys?

2013-04-17 Thread Dan Treiman
I have a situation where I want to fetch an ordered array of managed objects 
which contain an ordered set of keys, and return the result in the same order 
as the input set:

NSOrderedSet * orderedIDs = ...;
NSFetchRequest * fetchRequest = [NSFetchRequest 
fetchRequestWithEntityName:@"MyEntityName"];
NSPredicate * predicate = [NSPredicate predicateWithFormat: @"uuid IN %@", 
orderedIDs];
NSArray * orderedObjects = [self.database.managedObjectContext 
executeFetchRequest:fetchRequest error:error];

By 'in the same order', I mean that I would like [[orderedIDs objectAtIndex:i] 
isEqual:[[orderedObjects objectAtIndex:i] uuid]] == YES for all valid indexes 
i.  I implemented a solution that orders the result after the fetch by 
iterating through orderedIDs and building a new array, but I feel like there 
should be a more elegant answer.  Any ideas?

    Thanks!
- Dan Treiman
___

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: Cocoa witch's broom

2011-04-14 Thread Dan Treiman
This sounds like a very interesting project.

For inspiration/an example of something similar, I'd recommend taking a look at 
Philippe Mougin's F-Script. ( http://www.fscript.org/ )

Its a scripting system that lets you explore and manipulate cocoa objects 
interactively.  It also is a very good learning tool for newcomers to cocoa. 


On Apr 14, 2011, at 12:11 PM, Rodrigo Zanatta Silva wrote:

> Lol, this will be a open source project. I will not do this alone and not do
> in one day. Like I say, there are function in same objects that you will
> only understand what it do if you use it and you will lose a lot of time in
> this trial and error.
> 
> Exist even difficult function to implement. I started using NSString, a
> trivial object and I saw how difficult is implement the function
> *initWithFormat:locale:arguments:*
> *
> *
> You will see a lot of people in this forum saying to see code in my program
> in the future :P*
> *
> 
> 2011/4/14 Allyn Bauer 
> 
>> I'm not sure creating a program to use every method in Cocoa is such a
>> great idea. What you should probably do instead is pick a small simple idea
>> and implement it. Perhaps you can make an app that lists the native trees of
>> Brazil and their diseases. :)
>> 
>> Allyn
>> 
>> On Apr 14, 2011, at 9:28 AM, Rodrigo Zanatta Silva wrote:
>> 
>>> Hi. I am starting a project that will be a program to learn. My idea is
>> use
>>> every single function of Cocoa framework to show any behavior. For newbie
>>> like me, same time is difficult read the Apple docs and know what the
>>> function exact do, and what object I have to use in same cases.
>>> 
>>> Ok, but firstly I have to chose a name. First I thought use "Cocoa with
>>> hate", a joke because exist the site "Cocoa with love" (I am not hate
>> Cocoa,
>>> not all the time :P ). But I thought this a bit bad.
>>> 
>>> My new idea was use the disease of cocoa, namely "witch's broom". Here in
>>> Brazil, this is a pest and isn't a easy to prevent. There are two
>> meanings
>>> in this name. First is the joke because we have to "fight" with cocoa to
>>> learn. The disease itself is a (don't know the correct english name for
>>> this) huddle, congeries... of wood and leaves that look like a witch's
>>> broom. 
>> And
>>> this will be the program, a lot of thing in a small place.
>>> 
>>> Witch's broom isn't disease only for cocoa. So "Witch's broom" itself
>> isn't
>>> a good name for a program. My ideas was:
>>> 
>>>  - Cocoa Witch's Broom (Do this the most correct?)
>>>  - Cocoa Witches Broom  (Isn't it the correct?)
>>>  - Cocoa's With Broom (With Broom of cocoa)
>>>  - Cocoa's Witch's Broom
>>>  - Witch's Broom of Cocoa
>>>  - Witches Broom of Cocoa
>>> 
>>> For you, English speaker, what is the most correct, The first is not the
>>> correct? Witches is the plural? Give-me a idea for this.
>>> ___
>>> 
>>> 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:
>>> http://lists.apple.com/mailman/options/cocoa-dev/allyn.bauer%40gmail.com
>>> 
>>> This email sent to allyn.ba...@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:
> http://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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: On NSClassFromString method

2011-02-24 Thread Dan Treiman
You can fix this by adding the -ObjC linker flag.  See related issue:
http://developer.apple.com/library/mac/#qa/qa2006/qa1490.html
This will force the linker to load classes from the static library


Another way is to reference the class directly somewhere in the code such that 
it has no effect, i.e.
[ClassINeed class];


-Dan Treiman

On Feb 24, 2011, at 9:19 PM, Leon Qiao wrote:

> Dear all,
> 
> I got a problem when using the NSClassFromString method to get a class.
> The code is used in the google docs library. It failed to get the Class
> object, the return value is 0x0.
> But I already linked the library, and it works fine when using the class
> itself directly.
> Anyone who met the same problem, please help me. Thanks!
> 
> -- 
> Best regards
> Leon
> ___
> 
> 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:
> http://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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


NSTokenField memory management issue

2010-05-22 Thread Dan Treiman
I have a cocoa app which changes the content of a window as you navigate, 
similar to a web browser.  This app is compiled using gc required.  Everything 
is fine unless my NSTokenField subclass is displayed, in which case the entire 
view hierarchy remains rooted and does not get garbage collected.

I'm using NSRoundedTokenStyle, and my best guess is that the tokens are 
registered somewhere to track the mouse?  Why else would they be rooted?  
Anyway, does anybody have any insight or any suggestions on how to work around 
this?

thanks!
    - Dan Treiman


(gdb) info gc-roots 0x20073ff80
Number of roots: 3
Root:
   0 Kind: bytes   rc:   1  Address: 0x0002011a6960
   1 Kind: bytes   rc:   0  Address: 0x0002011a6ee0  Offset: 
0x0050
   2 Kind: object  rc:   0  Address: 0x00020086bc60  Offset: 
0x0020  Class: NSTokenAttachment
   3 Kind: object  rc:   0  Address: 0x00020070e220  Class: 
NSTokenFieldCell  ivar: NSTextFieldCell.NSActionCell._controlView
   4 Kind: object  rc:   0  Address: 0x000200726c40  Class: 
GSAttributeTokenField  ivar: 
NSTokenField.NSTextField.NSControl.NSView.NSResponder._nextResponder
   5 Kind: object  rc:   0  Address: 0x00020073bcc0  Class: NSView  ivar: 
NSResponder._nextResponder
   6 Kind: object  rc:   0  Address: 0x0002007eb000  Class: NSTabView  
ivar: _delegate

___

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

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


Crash using IKImageBrowserView

2009-12-28 Thread Dan Treiman
I'm seeing a recurring but intermittent crash in my GC-enabled app, which uses 
multiple IKImageBrowserViews.

Has anybody seen anything like this?  Have any insight as to why its crashing 
here?

Stack:

Thread 0 Crashed:
0   GLEngine0x00011b051940 glGetError_Exec + 16
1   com.apple.imageKit  0x000100cc81b4 -[IKTexturePacker 
releaseTexturePackerAtIndex:] + 309
2   com.apple.imageKit  0x000100cd71e3 -[IKVRamManager 
_unbind:notifyDelegate:] + 471
3   com.apple.imageKit  0x000100cd7d10 -[IKVRamManager 
removeEntriedOlderThanSessionID:] + 404
4   com.apple.imageKit  0x000100cd23b5 -[IKCacheManager 
removeEntriedOlderThanSessionID:] + 47
5   com.apple.imageKit  0x000100cd2ba1 -[IKCacheManager 
IKCleanTimedOutCache] + 174
6   com.apple.Foundation0x7fff84081ca3 
__NSFireDelayedPerform + 307
7   com.apple.CoreFoundation0x7fff83f33245 CFRunLoopRunSpecific 
+ 3797
8   com.apple.HIToolbox 0x7fff83b8bd0e 
RunCurrentEventLoopInMode + 278
9   com.apple.HIToolbox 0x7fff83b8bb44 
ReceiveNextEventCommon + 322
10  com.apple.HIToolbox 0x7fff83b8b9ef 
BlockUntilNextEventMatchingListInMode + 79
11  com.apple.AppKit0x7fff82ff2e70 _DPSNextEvent + 603
12  com.apple.AppKit0x7fff82ff27b1 -[NSApplication 
nextEventMatchingMask:untilDate:inMode:dequeue:] + 136
13  com.apple.AppKit0x7fff82fec523 -[NSApplication run] 
+ 434
14  com.apple.AppKit0x7fff82fb92f0 NSApplicationMain + 
373
15  com.gendaigames.GameSalad   0x00012290 start + 52
___

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

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


IKImageBrowserView scrolling with core animation

2008-11-06 Thread Dan Treiman
I'm having some trouble with an IKImageBrowserView in a layer-backed  
NSScrollView.  Everything works fine when the scrollers are hidden,  
but as soon as I have too many images to fit in the view, it gets  
confused.  Specifically, when I scroll all the way to the bottom, I  
see my last row of images just fine.  But as I scroll upwards, more  
and more of the view gets clipped, when I get to the top, the view is  
empty.


I've tried turning off layer-backing, and it works perfectly - I only  
have the problem when layer-backing is on
(I'm calling [view setWantsLayer:YES] on an ancestor of the scroll  
view).  Is there anything I can do to fix this?


thanks,
    -Dan Treiman
___

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

This email sent to [EMAIL PROTECTED]