[OpenWalnut-Dev] Callbacks made simple
Sebastian Eichelbaum
eichelbaum at informatik.uni-leipzig.de
Thu Sep 30 16:18:55 CEST 2010
Hi List
We have a new class WGEFunctorCallback in graphicsEngine/callbacks. As the name says, you can use functors as callbacks. He? What? Here is an example:
// a callback function doing something to node
void MyLocalCallback( osg::Node* node )
{
...
}
// a callback function doing something to node and using some WMMyModule members
void WMMyModule::MyCallback( osg::Node* node )
{
...
accessMemberOfWMMyModule( m_something );
...
}
void WMMYModule::setupOSG()
{
...
// if the callback is a member of WMMyModule:
m_node->addUpdateCallback( new WGEFunctorCallback( boost::bind( &WMMyModule::MyCallback, this, _1 ) );
// if the callback only is a local function it is even simpler
m_node->addUpdateCallback( new WGEFunctorCallback( &MyLocalCallback ) );
...
}
The nice thing is: the need to write nested classes as callbacks is over. Write your callback as simple member function of your module and use WGEFunctorCallback to have it called every update cycle. This prevents you from adding many many ref pointer and shared_ptr to the nested class to have access to something.
Sebastian
--
Dipl.-Inf. Sebastian Eichelbaum
Universität Leipzig
Institut für Informatik
Abteilung Bild- und Signalverarbeitung
PF 100920
D-04009 Leipzig
More information about the OpenWalnut-Dev
mailing list