(Ogre) Embedding Python in C++ Example

I decided that I want to find a good way to put Python in my C++ Ogre applications. Now, one method of doing this would be to write an interface for import game_namemy application at a high level. Lets say that Python is going to handle scripting in an RPG-type game. I would need it to do things like “move character to this position, do some spell particle effects, say this dialog”. To accomplish this, I’d manually create a Python module which, when used, would look like this:

When the character’s moveTo, cast, dialog, etc functions are called these events are added to a queue in C++ land, and they are performed in sequence. That is, each of the Python functions return instantly (they don’t wait on a result), and everything is kept in a nice clean interface.

I could do this with the Python/C API fairly simply. It would just take alot of work to define a clean interface to the C++ code and properly wrap every script method into a sequence of C++ calls to perform the action.

READ  Running Alfresco 3.3 with embedded database (H2 in PostgreSQL compability mode)

While I would eventually love to write a solid tutorial on how to accomplish this for a game, this is not my current goal. My current goal is to do something like this:

Basically I want to be able to manipulate most parts of Ogre in a C++ program from embedded Python scripts. If I can get this working it will allow me to have a “Python Console” in any C++ Ogre program. You could pull up the console and change properties of anything on the fly without changing C++ code, or even without stopping the program.

There are many hurdles to overcome when doing this, and I’m not even sure that it’s as simple as I think it is (that is, just converting Ogre objects directly into PyOgre objects using Boost.Python). I hope to have something tangible by the end of the month, or at least know that what I’m trying to do is possible. I could always create a raw interface that allowed changing set things in Ogre land, but that’s not as powerful as what I have in mind.

Leave a Reply

Your email address will not be published. Required fields are marked *