Re: [GD-General] Multiple Inheritance and RTTI
Brought to you by:
vexxed72
From: Noel L. <ll...@co...> - 2003-02-05 21:38:05
|
On Wed, 05 Feb 2003 23:24:54 +0200 Peter Dimov <pd...@mm...> wrote: > > Every frame we quickly cull out any scene nodes that are not visible > > from a camera, and then for each scene node we query to see if they > > implement the IRenderable interface. If they do, they get a render > > call. > > Yes, I envisioned something like that. > > What are the advantages of this approach over just providing a (possibly > empty) render() in every node type? A virtual call can never lose to a QI + > test + potential call. Clearly, it's not there for performance reasons. The main thing it buys us is some clarity (and maintainability) by keeping the interface of each type of scene node to a minimum size. Especially if you use many potentially different interfaces, things could get pretty cluttered. It also makes it easier to create new types of objects. If I create a new scene node I might not be sure exactly what functions I need to override so it renders correctly. As soon as I inherit from IRenderable things are very clear (and if they aren't, the compiler will remind me to implement all those pure virtual functions). In our case we ended up not having as many different types of scene nodes or as many different interfaes as I initially anticipated, so we could very well have folded the few functions in IRenderable back into the SceneNode class. I think that another potential advantage is that the QueryInterface method might work better in a very heterogeneous environment, where you are manipulating objects of all sorts of types, without a common base class. Requiring that they all implement all the possible common functions would be a total pain. But I haven't seen that in practice. --Noel ll...@co... |