Problem creating MovableObjectFactory and overiding getType

dermont

24-02-2009 09:06:35

Does anyone have an example of creating a custom MovableObjectFactory. I appear to be having a problem overriding the getType method.

Example Class:

class TestMovableObjectFactory(ogre.MovableObjectFactory):
FACTORY_TYPE_NAME = None
def __init__(self):
ogre.MovableObjectFactory.__init__(self)
print self.getTypeFlags()
print self.FACTORY_TYPE_NAME

def __del__(self):
pass
def createInstanceImpl( self, name, params ):
return ogre.MovableObject()
def getType(self):
return self.FACTORY_TYPE_NAME

def destroyInstance(self, obj ):
del obj
TestMovableObjectFactory.FACTORY_TYPE_NAME = "TestMovableFactory"


Creating Factory:

...
self.testMovableObjectFactory = TestMovableObjectFactory()
if not self.root.getSingleton().hasMovableObjectFactory("TestMovableFactory"):
self.root.getSingleton().addMovableObjectFactory( self.testMovableObjectFactory )
..


Error:

RuntimeError: warning W1049: This method could not be overriden in Python - method returns reference to local variable!

andy

24-02-2009 14:16:14

This is a case where Py++ doesn't allow the function overridden.. You might want to ask the question on the google list as Roman tends to watch that one..

I'm taking a look now, as either we can override this particular case, or hand wrap the function to make it useful..

Andy...

andy

25-02-2009 05:09:47

This is now hand-wrapped and in the SVN..

If you get a moment take a look and see if it works the way you expect.. Note the the python getType function will only get call once (the first time) -- and the testing has been very simplistic so I may have missed something...

Thanks

Andy

dermont

26-02-2009 14:16:45

Thank's the patch for the MovableObjectFactory getType function appears to work OK. Looking at the code it may be there are other such instances ( I could be wrong), for example:

generate_code.py

funcNames = ['getType', 'getTypeName']
for funcName in funcNames:
for f in main_ns.member_functions(funcName):
if f.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL:
if not f.parent.name.startswith('placeholder'):
main_ns.class_(f.parent.name).member_function(funcName).exclude()
print ' Excluding pure virtual function %s:%s hand wrapped' % ( f.parent.name, f.name)


output:

Excluding pure virtual function FactoryObj<Ogre::ParticleSystemRenderer>:getTyp
e hand wrapped
Excluding pure virtual function FactoryObj<Ogre::Archive>:getType hand wrapped
Excluding pure virtual function MovableObjectFactory:getType hand wrapped
Excluding pure virtual function ParticleSystemRenderer:getType hand wrapped
Excluding pure virtual function OverlayElementFactory:getTypeName hand wrapped
Excluding pure virtual function OverlayElement:getTypeName hand wrapped
Excluding pure virtual function SceneManager:getTypeName hand wrapped


Therefore the handwrapped code may need to be more generic as per the Physx PointerWrapper etc wrappers.

On a side note, and out of interest, with the example code above how would I set a flag\variable with py++ in generate_code.py to indicated the function needs to be handwrapped?