Connecting the editor with the engine?

This topic is 2281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello,

I'm struggling to come up with an efficient way to make my editor interact with my engine. I'm working with c++.

This is a common situation I guess: You're writing an editor for your engine and you want to display information about "stuff" and want to be able to modify it through the editor gui. For example you click on an object and want to display its properties and edit them using appropriate gui controls.

Ideally I'd prefer if the editor doesn't "know" anything about the objects. For example if I added a SetColor(Color c) method to an object, I don't want to modify the editor to make it display a corresponding control, it should just do it

To clarify: I know how to connect a gui control with a method. I just want to automate the whole process.

I hope anyone gets what I'm after Are there good solutions for this?

Share on other sites
A common way to accomplish this is to have each modifiable class export a list of 'properties', where the property includes the variable name, a method to update the variable, and the type of edit control that should be used in the GUI. Then the Editor GUI just loops over the properties for the selected item, and displays the corresponding edit controls.

In a (hypothetical) python example, my objects might look like this:
 class SpaceShip: properties = [ Property(name='name', editor=String) Property(name='speed', editor=Slider(min=1, max=100)) Property(name='colour', editor=ColourPicker) ] 

Share on other sites

A common way to accomplish this is to have each modifiable class export a list of 'properties', where the property includes the variable name, a method to update the variable, and the type of edit control that should be used in the GUI. Then the Editor GUI just loops over the properties for the selected item, and displays the corresponding edit controls.

In a (hypothetical) python example, my objects might look like this:
 class SpaceShip: properties = [ Property(name='name', editor=String) Property(name='speed', editor=Slider(min=1, max=100)) Property(name='colour', editor=ColourPicker) ] 

I do something similar to this, but I let the editor choose which control is suitable for modifying a value as I don't like to have any tool-related code in my engine code

Share on other sites

I do something similar to this, but I let the editor choose which control is suitable for modifying a value as I don't like to have any tool-related code in my engine code

Agreed, but in that case you need some way to expose constraints for a given property (min, max for numbers, length for strings, allowable values for enumerated types, etc.).

Share on other sites

I do something similar to this, but I let the editor choose which control is suitable for modifying a value as I don't like to have any tool-related code in my engine code

Agreed, but in that case you need some way to expose constraints for a given property (min, max for numbers, length for strings, allowable values for enumerated types, etc.).
[/quote]

I built a system which allows me to store most of these constraints as part of the property objects themselves. I can't say that the system works completely like I would want it to as it gets pretty tough to build a system which can generically store any property with any type of constraint (C++ doesn't really provide any help here either), but it gets the job done.

I've thought of taking the Qt route by building a generic property system with the use of a pre-processor, but I really don't like the idea of cluttering my build process.

Share on other sites
Nice, I was experimenting with an approach like this. My implementation feels a little fragile because of storing pointers to functions with different signatures on the engine side and casting them back to the correct type in the editor. But I guess it's a managable problem when there aren't too many property types. Still I'd love to see the "correct" way to implement this in c++

Share on other sites

Nice, I was experimenting with an approach like this. My implementation feels a little fragile because of storing pointers to functions with different signatures on the engine side and casting them back to the correct type in the editor. But I guess it's a managable problem when there aren't too many property types. Still I'd love to see the "correct" way to implement this in c++

I don't think there really is a "correct way" to do this in C++, IMO. It's all about what your requirements are.

Storing pointers to do this does sound sketchy to be honest, could cause a lot of problems if a pointer suddenly gets invalidated for some reason.

What my system does basically comes down to this: It serializes the contents of the object it's trying to manipulate into something called an "Attribute Set". An attribute set contains a collection of generic attributes with the serialized value, type data, and as mentioned above some basic constraint data.
Objects which can provide this data also provide a way for building or modifying their content from such a generic attribute set.
This creates some interesting possibilities, you could use an attribute set for writing out the state of your object in any format you want for example. This means you could pass an attribute set to your editor, let it modify the values, and send the set back to the object you were editing so it can change its values internally. This means no messing with pointers, no potentially unsafe operations, and the object still remains in control of its own state, as opposed to messing with pointers.

Share on other sites
I've built an implementation of your description in my head and it definitely seems to be a good concept Going to try an actual implementation now. Thanks for the food for thought

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• Forum Statistics

• Total Topics
633763
• Total Posts
3013728
×