Clay
22-10-2005 02:29:57
Bad news. It seems that swig directors (C++ callbacks) cannot handle multiple inheritance. Normally we could inherit from multiple Listeners in Ogre:
But this fails in PyOgre:
Because the FrameListener's __init__ was called last, SWIG thinks that this is ONLY a FrameListener object. This is a problem with SWIG, and there is not much I can do about it. I have opened a bug on their tracker, but I'm not expecting it to get fixed anytime soon.
A current solution is to simply use different classes for each director you use, but for the Key/Mouse/Frame Listeners this would be a hassle. So I have created a CombinedListener class that can be used as a FrameListener, KeyListener, MouseListener, and/or MouseMotionListener. Until swig fixes the problem, this is going to be the best I can do, sorry.
class Whatever : public Ogre::FrameListener, public Ogre::KeyListener, ...
But this fails in PyOgre:
class TutorialFrameListener(SampleFramework.FrameListener, ogre.MouseListener,
ogre.MouseMotionListener, ogre.KeyListener):
def __init__(self, renderWindow, camera, sceneManager):
ogre.MouseListener.__init__(self)
ogre.MouseMotionListener.__init__(self)
ogre.KeyListener.__init__(self)
SampleFramework.FrameListener.__init__(self, renderWindow, camera)
self.eventProcessor.addKeyListener(self) #fails
TypeError: argument number 2: a 'Ogre::KeyListener *' is expected, 'PySwigObject(_p_Ogre__FrameListener)' is received
Because the FrameListener's __init__ was called last, SWIG thinks that this is ONLY a FrameListener object. This is a problem with SWIG, and there is not much I can do about it. I have opened a bug on their tracker, but I'm not expecting it to get fixed anytime soon.
A current solution is to simply use different classes for each director you use, but for the Key/Mouse/Frame Listeners this would be a hassle. So I have created a CombinedListener class that can be used as a FrameListener, KeyListener, MouseListener, and/or MouseMotionListener. Until swig fixes the problem, this is going to be the best I can do, sorry.