Inheritance-Support for Mogre (theory + experimental build)

Tubulii

11-05-2012 11:08:54

I played a bit with c++/cli to implement inheritance and override support into Mogre. And I had some success.

Problem: Mogre does not support inheritance, only a few classes can be overriden but the most important classes (e.g. SimpleRenderable) have no public constructor (that's only a small part of he problem ;) ).

Theory: Bind a managed class (with abstract methods) on a native class and the other way around (circualar dependency!). Both inherit their eqivalent (e.g. Mogre::Archive and Ogre::Archive) (more here).

The problem is that autowrapper does not support this. Maybe there is a way to "unlock" this "feature" but I have not found it yet. Therefore I added some custom files (/classes) to Mogre and compiled it.
It seems to run. Here is an extract of my log:
11:32:58: ArchiveFactory for archive type vfs registered.
11:32:59: Added resource location 'C:[...]\Mogre Tests\Overridable\bin\Debug\models' of type 'vfs' to resource group 'General'
(side note: Usually ogre has no "vfs" ArchiveFactory)
I wrapped two classes by hand: "Archive" and "ArchiveFactory" into "ArchiveOR" and "ArchiveFactoryOR" (OR= overrideable; ArchiveOR inherits Mogre::Archive and ArchiveFactoryOR inherits Mogre::Wrapper).

I guess my approach is buggy and I have no idea if there are any memory leaks or invalid pointer. A quick test does not revealed any serious problems. I was able to load a mesh and display it.
Now I will try to improve my wrapper code and to do more testing. I will upload the source and maybe a compiled test project if its small enough (currently >400MB)

Edit: "Sorry, the board attachment quota has been reached." -> I will upload it to dropbox...
Edit2:
  1. Experimental build (54MB) ( resource paths need to be corrected!)
    Wrapper source code (4KB) (needs to be compiled with mogre source, see autobuilder)[/list:u]

zarfius

12-05-2012 00:20:55

Problem: Mogre does not support inheritance, only a few classes can be overriden but the most important classes (e.g. SimpleRenderable) have no public constructor (that's only a small part of he problem ;) ).
Just out of curiosity, because I'm having trouble thinking of good reasons myself. Are there any real world examples when this is really a problem? I've never found the need to override SimpleRenderable and I'm not sure why you would really ever need too?

Tubulii

12-05-2012 08:31:32

Problem: Mogre does not support inheritance, only a few classes can be overriden but the most important classes (e.g. SimpleRenderable) have no public constructor (that's only a small part of he problem ;) ).
Just out of curiosity, because I'm having trouble thinking of good reasons myself. Are there any real world examples when this is really a problem? I've never found the need to override SimpleRenderable and I'm not sure why you would really ever need too?


Yes, in most cases you can use Movableobject instead, but it makes things easier and more straiht forward if you either port ogre stuff or want to extend mogre with classes which integrate into (m)ogre. And you are not forced to use it. It is more like an experiment if it's possible than a future part of mogre. And it's something new for me :-)

Bekas

19-05-2012 17:27:00


Theory: Bind a managed class (with abstract methods) on a native class and the other way around (circualar dependency!). Both inherit their eqivalent (e.g. Mogre::Archive and Ogre::Archive) (more here).

The problem is that autowrapper does not support this. Maybe there is a way to "unlock" this "feature" but I have not found it yet.

It's been a long time but AFAIK autowrapper has some support for this that provides for the minimal number of classes that can be overridden. Check out AutoWrap/Meta/IncOverridableClassProducer.cs & AutoWrap/Meta/CppOverridableClassProducer.cs.

Tubulii

21-05-2012 09:04:16

Thanks, I'll look at it.