Porting to python-ogre, framelisteners and eventprocessor?


25-03-2007 06:16:46

I'm in the middle of porting an existing pyogre application over to python-ogre. I'd greatly appreciate any advice regarding python-ogre best practices for reimplementing the following code.

#import pyogre.ogre as ogre
import Ogre as ogre

#class FrameListener(ogre.CombinedListener, object):
class FrameListener(ogre.FrameListener, object):

def __init__(self):
self._keeprendering = True
self._framenumber = 0

def setWindow(self, window):
self._window = window
self._eventprocessor = ogre.EventProcessor()

def getWindow(self):
return self._window

window = property(getWindow, setWindow)

def frameStarted(self, frameEvent):
"""Simplest of frame callbacks allows for quitting"""
self._framenumber += 1
return self._keeprendering

def keyPressed(self, event):
if event.key == ogre.KC_ESCAPE:
self._keeprendering = False

def frameEnded(self, frameEvent):
return True

def mousePressed(self, event):
if event.buttonID & ogre.MouseEvent.BUTTON0_MASK:

It's been awhile but I take it that EventProcessor is a pyogre construct? Also, looking through the python-ogre ogre demos there is reliance on a SampleFramework. Is it suggested that we use this for real projects, or as with Ogre, should we be "rolling our own"?


25-03-2007 06:23:24

I would suggest rolling your own framework for real projects. Driving rendering from Python (via renderFrame()) gives you a lot more control over the game loop. The framelistener approach means your updates are dependent upon framerate, but that's not usually what you want.

My $.02.


25-03-2007 06:48:17

The code you want to look at is in your python site-packages directory and is sf_OIS.py (c:\python25\Lib\site-packages\Ogre\sf_OIS.py)

It's basically a port of the original PyOgre application framework and shows how to handle the examples you've given. ie.
class FrameListener(ogre.FrameListener, ogre.WindowEventListener):
You actually have a 3 way conversion happening as you are converting:
  1. * From PyOgre to Python-Ogre
    * From Ogre 1.2 to Ogre 1.4
    * To OIS (for input handling)
    [/list:u]However have a look at the demos and the sample framework (sf_OIS) and it should be fairly clear :)

    Now we did start a FAQ topic on this which I'd very much appreciate people updating as they find issues etc in their conversions from PyOgre to Python-Ogre.. It can be found [b]here[/b]

    Let me know if there are specific items causing issues..