Sign in to follow this  
josiahpeters

Level/Scene Editor Woes

Recommended Posts

josiahpeters    102
I have been working on an EntitySystem engine for the last couple of months in C++ and OpenGL. They are described in a few places: [url="http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1/"]T-Machine post[/url], [url="http://www.tomseysdavies.com/2011/02/03/getting-started-with-ember/"]Ember[/url] (In ActionScript), [url="http://entity-systems.wikidot.com/"]Entity Systems Wiki[/url]. I've gotten to the point where I can run around on a height map, jump up and down, interract with physics.

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:
[code]
[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;
};
...[/code]


PropertyGrid makes it look like this (the right side):

[img]http://i.imgur.com/mPvxC.png[/img]


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?

Share this post


Link to post
Share on other sites
Radikalizm    4807
I had the exact same issue you have right now, my engine is written in C++ and most of my engine-related tools are done in C# with WinForms since creating form-based applications with Visual Studio is very straightforward and easy (not to mention that you can have something up and running in a minimal amount of time), so it felt natural to me to use WinForms for a scene editor too
After doing some research I got to the same conclusion as you did, to get it all running you'd have to write a complete wrapper of your engine to be able to use it in managed code, even if you were to opt for a managed C++ solution, which is just very frustrating and time-consuming work IMO

I went with QT in the end like you mentioned, although the scene editor project got pushed back on my to-do list since I wanted to do some more work on my engine first, so if anyone finds a clean method of using native C++ code in winforms without having to write a wrapper, I'm all ears :)

Share this post


Link to post
Share on other sites
josiahpeters    102
So this is a lot of code still, but it might make things a little more bearable. I'm going to try wrapping my unmanaged class with managed properties and see how this goes. At least it compiles, I haven't tried it with my windows form app to see if it actually works but this makes me feel a little bit better. Since I have already written a small code generator, I can try an implement this on a single class and if it works adjust my generator to spit out code for all my other classes. At the very least that would save most of the typing.

[code]
class PxVec3
{
public:

float X;
float Y;
float Z;
};

ref class ManagedPxVec3
{
PxVec3* vec;

public:
ManagedPxVec3()
{
vec = new PxVec3();
}
ManagedPxVec3(PxVec3* _vec)
{
vec = _vec;
}
property float X
{
float get()
{
return vec->X;
}
void set(float value)
{
vec->X = value;
}
}
property float Y
{
float get()
{
return vec->Y;
}
void set(float value)
{
vec->Y = value;
}
}
property float Z
{
float get()
{
return vec->Z;
}
void set(float value)
{
vec->Z = value;
}
}
};[/code]


Does this seem like a terrible plan?
*EDIT*
I have experimented with a PropertyGrid and it seems to work. The unmanaged data gets manipulated directly! Now on to wrapping my head around this more. At the very least I can call something like this:
[code]
Vec3* vec3 = new Vec3();

propertyGrid1->SelectedObject = gcnew ManagedVec3(vec3);
[/code]
Edited by josiahpeters

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this