[C++-sig] Problems getting to grips with Boost v2.0

Oliver Malham oliver.malham at savageparsnip.com
Tue Nov 5 00:09:33 CET 2002


Hiya,

	First off, let me congratulate everyone who has contributed to
Boost.Python on producing such an excellent library. (And I'm sorry if
this question is a bit long winded ;-)

	I'm currently working on a game engine that will use Python as the
ingame scripting language that controls everything. A key part of this
functionality is building the scenegraph for the current level. This
takes the form of a tree of objects which are created by a factory
object, and passed about as object pointers (the factory class manages
the object's lifetime). Building a basic scenegraph in C++ works fine;
however building the same scenegraph through the python interface
doesn't seem to setup the scenegraph properly (the scenegraph object
complains about being empty). I'm not sure where I've gone wrong, and
would appreciate it if you could point me in the right direction.

Here's the code involved:

BOOST_PYTHON_MODULE(KeiPy)
{

// Scene object manages scenegraph, user IO, AI, etc.
class_<Scene>("Scene")
  .def("activate", &Scene::activate)
  .def("sleep", &Scene::sleep)
  .def("cleanup", &Scene::cleanup)
  .def_readonly("scenegraph", &Scene::scenegraph) // Member class
;

// Scenegraph handles all drawable objects
class_<SceneGraph>("SceneGraph")
  .def("setStart", &SceneGraph::setStart) //Takes SceneGraphNode pointer
;

// Base scenegraph node object
class_<SceneGraphNode>("SceneGraphNode")
  .def("type", &SceneGraphNode::type)
;

// Very simple object just clears the screen to blue
class_<BlueScreen, bases<SceneGraphNode> >("BlueScreen")
  .def("type", &BlueScreen::type)
;

// Factory creates and owns all dynamically built objects
class_<Factory>("Factory")
  .def("newScene", &Factory::newScene, return_internal_reference<>())
  .def("newBlueScreen", &Factory::newBlueScreen,
return_internal_reference<>())
;

};

And the Python code that builds the scenegraph:

from KeiPy import *

factory = Factory()

scene = factory.newScene()
bluescreen = factory.newBlueScreen()
scene.scenegraph.setStart(bluescreen)

When this enters the game's main loop, I get messages from the
constructors for the scene, scenegraph and bluescreen objects. From my
debug messages it looks like the bluescreen object is being assigned to
a different scenegraph object than the one constructed, which has me
just a bit confused.

Thanks for any advice you can give me, and I hope I'm not being stupid
and wasting your time ;-)

Cheers,

Oliver Malham

Software Engineer
Savage Parsnip Games
http://savageparsnip.com





More information about the Cplusplus-sig mailing list