Commit dd6d5918 by Sebastian Eichelbaum

[CHANGE] - WGEGroupNode::remove is now synchronous.

parent 05c7dd0b
......@@ -33,7 +33,8 @@
WGEGroupNode::WGEGroupNode():
osg::MatrixTransform(),
m_insertionQueueDirty( false ),
m_removalQueueDirty( false )
m_removalQueueDirty( false ),
m_removedCondition( new WCondition() )
{
setDataVariance( osg::Object::DYNAMIC );
......@@ -65,6 +66,12 @@ void WGEGroupNode::remove( osg::ref_ptr< osg::Node > node )
m_childRemovalQueue.insert( node );
m_removalQueueDirty = true;
lock.unlock();
// wait until the job is done
if ( getNumParents() )
{
m_removedCondition->wait();
}
}
void WGEGroupNode::SafeUpdaterCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
......@@ -115,6 +122,10 @@ void WGEGroupNode::SafeUpdaterCallback::operator()( osg::Node* node, osg::NodeVi
// all children added -> clear
rootNode->m_removalQueueDirty = false;
rootNode->m_childRemovalQueue.clear();
// inform all waiting thread that their removal requests have been processed.
rootNode->m_removedCondition->notify();
lock.unlock();
}
......
......@@ -32,6 +32,8 @@
#include <osg/MatrixTransform>
#include <osg/NodeCallback>
#include "../common/WCondition.h"
/**
* Class to wrap around the osg Group node and providing a thread safe add/removal mechanism. Please be sure to use
* addUpdateCallback() to set your own update callbacks instead of setUpdateCallback, as this class already has set a callback,
......@@ -65,7 +67,7 @@ public:
void insert( osg::ref_ptr< osg::Node > node );
/**
* Removes the specified node from this group in a thread safe manner. See insert() for more details.
* Removes the specified node from this group in a thread safe manner. It returns if the node has been removed.
*
* \param node the node to remove
*/
......@@ -127,6 +129,11 @@ protected:
*/
bool m_removalQueueDirty;
/**
* Condition which fires when the node is removed.
*/
boost::shared_ptr< WCondition > m_removedCondition;
private:
};
......
......@@ -433,7 +433,7 @@ void WMMarchingCubes::renderMesh( boost::shared_ptr< WTriangleMesh2 > mesh )
m_moduleNode->insert( m_surfaceGeode );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_moduleNode );
m_moduleNode->addUpdateCallback( new SurfaceNodeCallback( boost::shared_dynamic_cast< WMMarchingCubes >( shared_from_this() ) ) );
m_moduleNode->addUpdateCallback( new SurfaceNodeCallback( this ) );
//osgDB::writeNodeFile( *m_surfaceGeode, "/tmp/saved.osg" ); //for debugging
}
......
......@@ -211,7 +211,7 @@ public:
* Constructor of the callback adapter.
* \param module A function of this module will be called
*/
explicit SurfaceNodeCallback( boost::shared_ptr< WMMarchingCubes > module );
explicit SurfaceNodeCallback( WMMarchingCubes* module );
/**
* Function that is called by the osg and that call the function in the module.
......@@ -221,10 +221,10 @@ public:
virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
private:
boost::shared_ptr< WMMarchingCubes > m_module; //!< Pointer to the module to which the function that is called belongs to.
WMMarchingCubes* m_module; //!< Pointer to the module to which the function that is called belongs to.
};
inline SurfaceNodeCallback::SurfaceNodeCallback( boost::shared_ptr< WMMarchingCubes > module )
inline SurfaceNodeCallback::SurfaceNodeCallback( WMMarchingCubes* module )
: m_module( module )
{
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment