Cocoa level editor

Member
Posts: 320
Joined: 2003.06
Post: #1
Hi people

I'm not really sure how to explain my problem, so I'll just launch straight into the specifics.

My game objects (level components) all load their properties from achieved NSDictionaries.

They store these properties as a member variable NSDictionary. They also unpack the properties into member variables for more runtime efficiency. So to access any variable in a levelComponent class I could either implement [[[levelComponent getProperties] objectForKey:@"xPosition"] floatValue] or [levelComponent getXPosition], because they are both stored.

I thought that I could use this to my advantage in the level editor. The variables could be changed, but the NSDictionary not (or vice versa), and then an "OK" or "Apply" would copy the changed to the other.

I'm just not sure which should be changed by the editor, and which should stay the way it was until applied. Is there any convention for this?

It seems kind of cleaner and easier to change the dictionary. The editor controller can just change the NSDictionary directly, so I don't have to make accessors for every single variable. The variables stay part of the game engine, and the editor just manipulates the properties, like it's supposed to.

On the other hand, changing the variables causes the engine to update automatically, so you don't have to keep clicking "Apply" and loose the ability to cancel that change.

Another option perhaps, is to have a copied dictionary for each component. That way apply could be reversed with cancel, but its kind of messy, and there are now 3 copies of every property...

Anyone have any opinions on which way I should go? I have to decide soon, because a hell of a lot more code is just about to go in based on this structure.

Cheers,
David

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #2
You could hide the accesses to the dictionary inside accessor methods

e.g.
Code:
-(float)getXPosition
{
  return [[[levelComponent getProperties] objectForKey:@"xPosition"] floatValue];
}

That way you can save lots of calls to the dictionary directly (and lots of copies of the string literal floating around.

The only advantage that I can see to actually keeping local copies is for performance, as there is presumably some performance overhead using the dictionary.

- Iain
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #3
well that didn't help at all Rasp Probably due to my bad explanation more than anything.

I ended up deciding on changing the variables. Works best in the end I think.

David

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Map Editor in Cocoa - Beginner dev_tallen 9 10,525 Mar 31, 2012 02:19 PM
Last Post: dev_tallen