reubert
2004.10.01, 04:46 AM
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
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