Commit d1c81ed0 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - replaced sets by stacks in WGEGroupNode

parent a15f64dc
......@@ -32,10 +32,8 @@
WGEGroupNode::WGEGroupNode():
osg::MatrixTransform(),
m_insertionQueueDirty( false ),
m_removalQueueDirty( false ),
m_removeAll( false ),
m_removedCondition( new WCondition() )
m_childOperationQueueDirty( false ),
m_removeAll( false )
{
setDataVariance( osg::Object::DYNAMIC );
......@@ -55,30 +53,24 @@ WGEGroupNode::~WGEGroupNode()
void WGEGroupNode::insert( osg::ref_ptr< osg::Node > node )
{
boost::unique_lock<boost::shared_mutex> lock = boost::unique_lock<boost::shared_mutex>( m_childInsertionQueueLock );
m_childInsertionQueue.insert( node );
m_insertionQueueDirty = true;
boost::unique_lock<boost::shared_mutex> lock = boost::unique_lock<boost::shared_mutex>( m_childOperationQueueLock );
m_childOperationQueue.push( ChildOperation( true, node ) );
m_childOperationQueueDirty = true;
lock.unlock();
}
void WGEGroupNode::remove( osg::ref_ptr< osg::Node > node )
{
boost::unique_lock<boost::shared_mutex> lock = boost::unique_lock<boost::shared_mutex>( m_childRemovalQueueLock );
m_childRemovalQueue.insert( node );
m_removalQueueDirty = true;
boost::unique_lock<boost::shared_mutex> lock = boost::unique_lock<boost::shared_mutex>( m_childOperationQueueLock );
m_childOperationQueue.push( ChildOperation( false, node ) );
m_childOperationQueueDirty = true;
lock.unlock();
// wait until the job is done
if ( getNumParents() )
{
m_removedCondition->wait();
}
}
void WGEGroupNode::clear()
{
m_removeAll = true;
m_removalQueueDirty = true;
m_childOperationQueueDirty = true;
}
void WGEGroupNode::SafeUpdaterCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
......@@ -90,9 +82,9 @@ void WGEGroupNode::SafeUpdaterCallback::operator()( osg::Node* node, osg::NodeVi
boost::unique_lock<boost::shared_mutex> lock;
// write lock the removal list
if ( rootNode->m_removalQueueDirty )
if ( rootNode->m_childOperationQueueDirty )
{
lock = boost::unique_lock<boost::shared_mutex>( rootNode->m_childRemovalQueueLock );
lock = boost::unique_lock<boost::shared_mutex>( rootNode->m_childOperationQueueLock );
if ( rootNode->m_removeAll )
{
rootNode->removeChild( 0, rootNode->getNumChildren() );
......@@ -100,44 +92,20 @@ void WGEGroupNode::SafeUpdaterCallback::operator()( osg::Node* node, osg::NodeVi
else
{
// insert all children which requested it
for ( std::set< osg::ref_ptr< osg::Node > >::iterator iter = rootNode->m_childRemovalQueue.begin();
/*for ( std::set< osg::ref_ptr< osg::Node > >::iterator iter = rootNode->m_childRemovalQueue.begin();
iter != rootNode->m_childRemovalQueue.end();
++iter )
{
rootNode->removeChild( ( *iter ) );
}
}*/
}
rootNode->dirtyBound();
// all children added -> clear
rootNode->m_removalQueueDirty = false;
// all children added/removed -> clear
rootNode->m_childOperationQueueDirty = false;
rootNode->m_removeAll = false;
rootNode->m_childRemovalQueue.clear();
// inform all waiting thread that their removal requests have been processed.
rootNode->m_removedCondition->notify();
lock.unlock();
}
// same game for insertion request list
if ( rootNode->m_insertionQueueDirty )
{
lock = boost::unique_lock<boost::shared_mutex>( rootNode->m_childInsertionQueueLock );
// insert all children which requested it
for ( std::set< osg::ref_ptr< osg::Node > >::iterator iter = rootNode->m_childInsertionQueue.begin();
iter != rootNode->m_childInsertionQueue.end();
++iter )
{
rootNode->addChild( ( *iter ) );
}
rootNode->dirtyBound();
//rootNode->m_childOperationQueue.clear();
// all children added -> clear
rootNode->m_insertionQueueDirty = false;
rootNode->m_childInsertionQueue.clear();
lock.unlock();
}
......
......@@ -25,7 +25,7 @@
#ifndef WGEGROUPNODE_H
#define WGEGROUPNODE_H
#include <set>
#include <stack>
#include <boost/thread.hpp>
......@@ -105,45 +105,31 @@ protected:
osg::ref_ptr< SafeUpdaterCallback > m_nodeUpdater;
/**
* Queue of childs that need to be added during the next update cycle.
* A pair denoting an operation on this group. The boolean denotes deletion (false) or insertion (true).
*/
std::set< osg::ref_ptr< osg::Node > > m_childInsertionQueue;
typedef std::pair< bool, osg::ref_ptr< osg::Node > > ChildOperation;
/**
* Queue of childs that need to be removed during the next update cycle.
* Queue of childs that need to be added/removed during the next update cycle. It is a pair per operation, where the bool is denoting removal
* or insertion.
*/
std::set< osg::ref_ptr< osg::Node > > m_childRemovalQueue;
std::stack< ChildOperation > m_childOperationQueue;
/**
* Lock used for inserting childs into the child insertion queue.
* Lock used for inserting and removing childs into the child insertion/removal queue.
*/
boost::shared_mutex m_childInsertionQueueLock;
boost::shared_mutex m_childOperationQueueLock;
/**
* Lock used for inserting childs into the child removal queue.
* Flag denoting whether the m_childOperationQueue should be considered during the next update of the node.
*/
boost::shared_mutex m_childRemovalQueueLock;
/**
* Flag denoting whether the m_childInsertionQueue should be considered during the next update of the node.
*/
bool m_insertionQueueDirty;
/**
* Flag denoting whether the m_childRemovalQueue should be considered during the next update of the node.
*/
bool m_removalQueueDirty;
bool m_childOperationQueueDirty;
/**
* True whenever all child nodes should be removed.
*/
bool m_removeAll;
/**
* Condition which fires when the node is removed.
*/
boost::shared_ptr< WCondition > m_removedCondition;
private:
};
......
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