PDA

View Full Version : Technical design: Best way to implement object properties system


Backov
06-13-2007, 05:29 PM
This is pretty esoteric, but I figured someone might have some good insights here.

I'm (re)implementing my track editor in my Ogre engine. One of the features of that editor is that objects on the track have "properties", which are as simple as position, width, height and then additional properties like "speed boosted %", "refuel per second", etc..

Essentially they're all int or float properties at this point.

Anyway, in my old system I had a properties system that wasn't the greatest I don't think, but it worked pretty well. When you'd click on an item, the game would ask the selected object for its properties.. The object would return its base objects properties as well as its own in a dictionary of properties, all object instances inherited from AbstractProperty, like FloatProperty, IntProperty, etc.. Once it got the whole dictionary, it would create a list of editor GUI controls, like a text box, increment/decrement boxes, etc, and hook their methods up to each of the properties.. When the properties were changed, they'd alert the actual track objects, so you could instantly see the change on the track display. It worked pretty well.

Anyway, something about it seems kludgey. It worked, but I think there's probably a nicer way to do it. Anyone know of a good pattern for this? Something to do with templates?

mot
06-13-2007, 05:38 PM
Looks fine to me.. allowing objects to publish their properties gives you great flexibility.

I would focus more on figuring out how to let the user edit multiple objects' properties at once. If there are more objects selected, show only the properties they have in common (and either show the value too if it's the same for all or gray colored if it differs) and change it for all the objects at once. Stuff like that...

And sorry about the cat! We don't have such dangerous animals around here (coyotes).

Backov
06-13-2007, 05:46 PM
Looks fine to me.. allowing objects to publish their properties gives you great flexibility.

I would focus more on figuring out how to let the user edit multiple objects' properties at once. If there are more objects selected, show only the properties they have in common (and either show the value too if it's the same for all or gray colored if it differs) and change it for all the objects at once. Stuff like that...

Ya that's a nice feature I hadn't thought of. I can see a few cases where that would be useful. I'm guessing I could either compare the properties by name, or if there was some name collisions, I could use some sort of unique identifier. Thanks Mot, I'll integrate that one for sure.


And sorry about the cat! We don't have such dangerous animals around here (coyotes).

Ya, you're lucky. I hadn't thought they were a serious threat where we are - it's not like we live in the country. And as a violent, desensitized gamer, the local coyotes are lucky I'm too lazy to enact my vengeance. Thanks for the sympathy though, we miss our old man.

James C. Smith
06-14-2007, 06:10 AM
This is pretty esoteric, but I figured someone might have some good insights here.
....properties...... Anyone know of a good pattern for this? Something to do with templates?

I love this kind of stuff. You should read the topic a posted a while ago about Reflexive's Property System. It doesn't use any templates but there is a "magic macro" that is used to generate the meta data to make things automated and error free.

Backov
06-14-2007, 11:26 AM
Thanks James, that was a really interesting read. It also got me (through google) to a whole bunch of papers on reflection in C++. They all basically do it like you're doing it there, except with a bunch of templated helper classes to make things smoother.

A lot of it made my head hurt. :)

That said, I think I'm going to go with a somewhat hybrid approach, due to me not wanting to spend the time learning/debugging a full reflection system. I'll probably template my property class and make it nicer that way. Not sure what else yet. :)