I’m currently looking at integrating scripting support into Ogre. Although there are plenty of other ‘core’ features I’d like to be adding to the engine right now, the lack of an interpreted interface to the engine is becoming more and more limiting, especially for testing out new features. So I’ve decided to take the hit now and work in scripting support so I can control the engine on the fly rather than having to recompile a test application all the time. There are actually 2 ways that I would like to add scripting to Ogre:

  1. initialise and run Ogre entirely from an interpreted script
  2. call back an interpreted script from Ogre compiled code during frame updates, collision events etc
  3. combine the two, i.e. the main application is compiled by an embedded scripting engine can run scripts on the fly when required

Right now Ogre can only be initialised from, and callback to compiled code. Whilst interpreted code (the script) is slower, the tasks it is doing are generally far less processor-intensive, and in any case the methods in Ogre that it calls still compiled & optimised so are fast anyway.

I’ve provisionally chosen Python as my scripting language of choice. My reasons for this are that Python is well-structured and has Object-Oriented features which fit nicely with Ogre’s internal structure, and that it’s performance is good.

I also found an extremely useful tool called SWIG (Simple Wrapper and Interface Generator). This will generate interface wrappers for C/C++ code to many popular scripting languages like Perl, TCL and Python. Of particular note is it’s ability to generate Python ‘shadow’ objects i.e. Python objects that look like the C++ objects they are communicating with. The only downside is that support for many C++ features which I use (like namespaces, overloading) is weak, but I may be able to overcome this by simplifying things through interface objects.

So I’ll be working on this for little while! I have managed to get SWIG and Python working with simple objects, but getting the full Ogre objects available will take longer. I also have to recompile all my Ogre libraries so they use the multithreaded runtime library so I can put them in a DLL rather than a static .lib file. It’s interesting stuff, though!

Exit mobile version