Help with ResourceGroupListener

srekel2

17-10-2005 23:19:34

I've tried to make a progressbar by using the ResourceGroupListener that comes with OGRE, but I've failed to get it to work. I've tried a lot of tricks and I'm guessing that there's either a really simple solution that I've overlooked, or it's not bound in PyOgre yet.

It seems part of the problem is that ResourceGroupListener is an abstract class (IIRC), so when I do


class VWResourceListener(ogre.ResourceGroupListener):
def resourceLoadStarted(*args):
"""resourceLoadStarted(self, ResourcePtr resource)"""
for x in args:
print x

and then


resListener = VWResourceListener()
ogre.ResourceGroupManager.getSingleton().addResourceGroupListener(resListener)


I get.. well, I don't get any error messages (at least not as often) since I built PyOgre from the SVN, it just crashes now. But it used to crash with the message "Expected ResourceGroupListener, got VWResourceListener", or something along those lines.

And I can't add
ogre.ResourceGroupListener.__init__(self)
because as I said, it's abstract.

I tried changing it to ResourceGroupListenerPtr and ogre.ResourceGroupListenerPointer and even doing

def __init__(self):
self.__class__ = ogre.ResourceGroupListenerPointer


But nothing works. Any ideas?

Clay

18-10-2005 02:20:23

When you create a subclass for a python callback (director) you need to add a call to the constructor of the parent class:
class VWResourceListener(ogre.ResourceGroupListener):
def __init__(self):
ogre.ResourceGroupListener.__init__(self)

def resourceLoadStarted(*args):
"""resourceLoadStarted(self, ResourcePtr resource)"""
for x in args:
print x


I'm not sure if this will fix all of your problems. I have not fully looked over your code, but start here.

fog

18-10-2005 11:22:01

*Cough* Actually no, you don't need that. Python always call __init__ on the new object but resolve it using the normal inheritance rules (remember: everything in Python is virtual) so if __init__ does not exists the one from the parent class is called.

I suppose the problem is that we didn't enabled directors for that class. I have the change made but I can't access berlios SVN right now. I'll commit a little bit later.

srekel2

18-10-2005 12:35:35

Thanks, I'll try it when I get home. :)

Clay

18-10-2005 19:10:43

*Cough* Actually no, you don't need that. Python always call __init__ on the new object but resolve it using the normal inheritance rules (remember: everything in Python is virtual) so if __init__ does not exists the one from the parent class is called.

I suppose the problem is that we didn't enabled directors for that class. I have the change made but I can't access berlios SVN right now. I'll commit a little bit later.

Whoops. Glad fog is around. =)

fog

18-10-2005 22:58:41

I commited the change right now but I didn't have the tine to write some code to check it. @srekel, Please tell us if it worked or I'll try something in Shy in the next few days.

srekel2

18-10-2005 23:47:17

Cool, I'll try to look at it right away. Thanks. :)



EDIT:

It now crashes while doing


ogre.ResourceGroupManager.getSingleton().loadResourceGroup("General")


Here's everything I do (resource initializing is done before this):

resListener = VWResourceListener()
print type(resListener)
print 123
ogre.ResourceGroupManager.getSingleton().addResourceGroupListener(resListener)
print 234

ogre.ResourceGroupManager.getSingleton().loadResourceGroup("General")


This is the listener:




class VWResourceListener(ogre.ResourceGroupListener):
"""
>>> dir(ogre.ResourceGroupListener)
['__class__', '__del__', '__delattr__', '__dict__', '__doc__', '__getattribute__
', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__
', '__repr__', '__setattr__', '__str__', '__weakref__', 'resourceGroupLoadEnded'
, 'resourceGroupLoadStarted', 'resourceGroupScriptingEnded', 'resourceGroupScrip
tingStarted', 'resourceLoadEnded', 'resourceLoadStarted', 'scriptParseEnded', 's
criptParseStarted', 'worldGeometryStageEnded', 'worldGeometryStageStarted']
"""

def resourceGroupScriptingStarted(*args):
print 1
"""resourceGroupScriptingStarted(self, String groupName, size_t scriptCount)"""
return _ogre.ResourceGroupListener_resourceGroupScriptingStarted(*args)

def scriptParseStarted(*args):
print 1
"""scriptParseStarted(self, String scriptName)"""
return _ogre.ResourceGroupListener_scriptParseStarted(*args)

def scriptParseEnded(*args):
print 1
"""scriptParseEnded(self)"""
return _ogre.ResourceGroupListener_scriptParseEnded(*args)

def resourceGroupScriptingEnded(*args):
print 1
"""resourceGroupScriptingEnded(self, String groupName)"""
return _ogre.ResourceGroupListener_resourceGroupScriptingEnded(*args)

def resourceGroupLoadStarted(*args):
print 1
"""resourceGroupLoadStarted(self, String groupName, size_t resourceCount)"""
return _ogre.ResourceGroupListener_resourceGroupLoadStarted(*args)

def resourceLoadStarted(*args):
print 1
"""resourceLoadStarted(self, ResourcePtr resource)"""
print "RESLOADSTART"
for x in args:
print x
return _ogre.ResourceGroupListener_resourceLoadStarted(*args)

def resourceLoadEnded(*args):
print 1
"""resourceLoadEnded(self)"""
return _ogre.ResourceGroupListener_resourceLoadEnded(*args)

def worldGeometryStageStarted(*args):
print 1
"""worldGeometryStageStarted(self, String description)"""
return _ogre.ResourceGroupListener_worldGeometryStageStarted(*args)

def worldGeometryStageEnded(*args):
print 1
"""worldGeometryStageEnded(self)"""
return _ogre.ResourceGroupListener_worldGeometryStageEnded(*args)

def resourceGroupLoadEnded(*args):
print 1
"""resourceGroupLoadEnded(self, String groupName)"""
return _ogre.ResourceGroupListener_resourceGroupLoadEnded(*args)




That may very well not be how it should be written, but I guess at least one "1" should get printed before the crash, but nope.

Oh, and the "print type(resListener)" prints out this:

<class 'MenuListener.VWResourceListener'>

which looks a bit strange to me. Oh, wait. MenuListener is the class I'm writing the code in, duh! :D

fog

19-10-2005 09:12:11

I'll add a resource loading progress bar to Shy later today and then enter debug mode. If I don't report back in 24h feel free to push me with a bbq fork.

Clay

19-10-2005 09:16:00

Sorry, latecomer here. What's Shy? =)

fog

19-10-2005 14:49:31

Eh eh eh. I have to admit that I was counting the number of times I could drop a reference to it before Clay would ask. :D

Shy is a little "ogre material manager" of mine that I am using to test PyOgre. A video and a couple of screenshots are available from my blog and the code is available from init.org SVN. In short:

  1. http://initd.org/svn/initd/shy/ (SVN repository)
    http://initd.org/blog/fog/static/Shy3.png (image)
    http://initd.org/blog/fog/static/Shy1.png (image)
    http://initd.org/blog/fog/static/Shy-lightning.html (flash, about 8.3Mb)
    [/list:u]
    I sweared I would post something to the main forum only after getting texture units to work but this is not the main forum.. :D And texture units are quite there, anyway.

Clay

19-10-2005 16:25:39

That's great. Nice work. =)

srekel2

20-10-2005 23:09:20

/me prods fog ;)


..and goes to bed. night!

Clay

22-10-2005 16:09:47

He's working on it. I think it might have been more troublesome than he first thought. =)

fog

24-10-2005 10:44:35

I returned yesterday night from the SMAU, the biggest ITC fair here in Italy. I am working on this.

Srekel

06-11-2005 20:34:51

I returned yesterday night from the SMAU, the biggest ITC fair here in Italy. I am working on this.

Any update on this? I've looked in the changelog but didn't find much since the 18th.

mthorn

19-01-2006 19:36:54

I too was having a problem with the ResourceGroupListener. It seems if you make a local reference:


def _createResourceListener(self):
resourceGroupListener = ResourceGroupListener()
ogre.ResourceGroupManager.getSingleton().addResourceGroupListener(resourceGroupListener)


It fails. I suppose the reference goes away quickly. Instead, make it a property:


def _createResourceListener(self):
self.resourceGroupListener = ResourceGroupListener()
ogre.ResourceGroupManager.getSingleton().addResourceGroupListener(self.resourceGroupListener)


And it works.