Overriding library classes & anonymous methods

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
hokan
Posts: 21
Joined: Sat Dec 15, 2012 8:49 am
Location: Russia

Overriding library classes & anonymous methods

Post by hokan »

Hi,

This is more about common C++-11 programming, is there a way to write child terrain class inherited from those which used in

Code: Select all

pSceneManager->addTerrainSceneNode(...)
method call, which will be almost the same, but with render() method overriden?
I need this stuff for multi-texturing (http://irrlicht.sourceforge.net/forum/v ... =9&t=38676), but no via MultiTexturingManager, cause it runs its drawAll() method, when all nodes were registered, but decal one (http://irrlicht.sourceforge.net/forum/v ... cal+system) should be drawn after terrain, that cause problems.
So I tried several methods to solve problem:
1. inherit from CTerrainSceneNode, using CTerrainSceneNode.h - failed, linker can't find this class in library
2. inherit from ITerrainSceneNode as proxy-pattern - fine, but proxy must override all ISceneNode methods as well, too much for one overrinding
3. inherit from CDefaultSceneNode (which is renamed CTerrainSceneNode) using source code, this also need copy-pasting and renaming CTerrainSelector (which is friend-class, I wonder why, is it so necessary?) and some other little stuff like removing os-dependence code (change to Logger & Timer classes) - works pretty well, but too much source code using

So the question is, can I write something like this using anonymous methods in C++-11: (I use Java-style here)

Code: Select all

 
ITerrainSceneNode* pTerrainSceneNode = pSceneManager->addTerrainSceneNode() {
@Override
void render() {
// my code here
}
}
 
Or is there an easier way?

P.S I was searching through forum, but didn't find solution
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Overriding library classes & anonymous methods

Post by randomMesh »

I'd go for no. 2. It's a bit copy n pasting to implement all the pure virtual methods, but it's the cleanest solution, imho.
"Whoops..."
hokan
Posts: 21
Joined: Sat Dec 15, 2012 8:49 am
Location: Russia

Re: Overriding library classes & anonymous methods

Post by hokan »

Oh, yeah, I forgot one issue, in case of using #2 or #1 (if it worked) I face redundant render() call - proxy-class call its render() so do I, when calling it after textures applying
Post Reply