My next goal for the project was to create a level editor. I really wanted to use .NET Windows forms because they're fast and have a lot of functionality. I also have most of my experience in C#.
I started off using C# with the idea that I would just write everything to a file and have my game engine read that in. I started getting frustrated by the amount of code I would have to re-do. I would essentially have to write serialization code for C# and C++ as well as duplicate the rendering code in C# and C++.
I ditched that after a few hours of setting up OpenGL and thinking there had to be a better way. I started looking at Managed C++ and .NET Forms with C++. At first it was not bad at all, the syntax was a little confusing but I got around that. I had OpenGL rendering on my form and things were looking snappy.
.NET Windows Forms has a really sweet control called PropertyGrid. It basically uses reflection to automatically display a list of editable properties for an object.
Example classes:
[TypeConverter(ExpandableObjectConverter::typeid)]
ref class ManagedTransformComponent : public ManagedComponent
{
public:
property ManagedPxVec3^ Position;
property ManagedPxQuat^ Rotation;
}
[TypeConverter(ExpandableObjectConverter::typeid)]
ref class ManagedPxQuat
{
public:
property float X;
property float Y;
property float Z;
property float W;
};
...
PropertyGrid makes it look like this (the right side):
The problem that I am running into again is duplcation of code. My engine is written in regular C++. The level editor is written in Managed C++. To handle the back and forth I've written Managed copies of each of my classes. I've also written static methods on each managed class to convert itself back and forth between managed and unmanaged.
After fine tunning the code a little bit at a time and then having to copy it to every managed and unmanaged class I wrote a little code generator that reads a list of classes and properties and generates my Managed classes with methods to convert between the two sets of classes.
Even with those capabilities I still havent figured out or decided how to take Managed objects and values and update the OpenGL view at the same time.
I have a pretty good feeling that I am going about this all wrong. I want to write my game engine in C++ and I really enjoy .NET Windows Forms, is there a better way to bridge a level editor in between?
Would it make more sense to create some sort of API for my engine that I can call from C#?
Should I be doing something different entirely?
I've gotten to a point where I can't wrap my head around how to integrate all of this into a level editor and its really frustrating me. I literally couldn't fall asleep last night because my brain would not stop thinking about it.
There was a similar post on here but most of the suggestions were to use Qt instead. Is it really worth all the time I'll have to spend tolearn using Qt?
What do professionals do for their editing tools?