Refactored Observer/ObserverNodePath and DatabasePager to improve their robustness.
This commit is contained in:
@@ -27,11 +27,6 @@ class OSG_EXPORT Observer
|
||||
Observer();
|
||||
virtual ~Observer();
|
||||
|
||||
/** Get the optional global observer mutex, this can be shared between all osg::Observer.*/
|
||||
static OpenThreads::Mutex* getGlobalObserverMutex();
|
||||
|
||||
inline OpenThreads::Mutex* getObserverMutex() const { return osg::Observer::getGlobalObserverMutex(); }
|
||||
|
||||
/** objectUnreferenced(void*) is called when the observed object's referenced count goes to zero, indicating that
|
||||
* the object will be deleted unless a new reference is made to it. If you wish to prevent deletion of the object
|
||||
* then it's reference count should be incremented such as via taking a ref_ptr<> to it, if no refernce is taken
|
||||
@@ -54,12 +49,13 @@ class OSG_EXPORT ObserverSet
|
||||
ObserverSet();
|
||||
~ObserverSet();
|
||||
|
||||
inline OpenThreads::Mutex* getObserverSetMutex() const { return osg::Observer::getGlobalObserverMutex(); }
|
||||
inline OpenThreads::Mutex* getObserverSetMutex() const { return &_mutex; }
|
||||
|
||||
void addObserver(Observer* observer);
|
||||
void removeObserver(Observer* observer);
|
||||
|
||||
void signalObjectUnreferenced(void* ptr);
|
||||
|
||||
void signalObjectDeleted(void* ptr);
|
||||
|
||||
typedef std::set<Observer*> Observers;
|
||||
@@ -68,7 +64,8 @@ class OSG_EXPORT ObserverSet
|
||||
|
||||
protected:
|
||||
|
||||
Observers _observers;
|
||||
mutable OpenThreads::Mutex _mutex;
|
||||
Observers _observers;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -15,17 +15,16 @@
|
||||
#define OSG_OBSERVERNODEPATH 1
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osg/Observer>
|
||||
#include <osg/ref_ptr>
|
||||
#include <list>
|
||||
#include <osg/observer_ptr>
|
||||
#include <vector>
|
||||
|
||||
namespace osg {
|
||||
|
||||
typedef std::list< osg::ref_ptr<osg::Node> > RefNodePath;
|
||||
typedef std::vector< osg::ref_ptr<osg::Node> > RefNodePath;
|
||||
|
||||
/** ObserverNodePath is an observer class for tracking changes to a NodePath,
|
||||
* that automatically invalidates it when nodes are deleted.*/
|
||||
class OSG_EXPORT ObserverNodePath : public osg::Observer
|
||||
class OSG_EXPORT ObserverNodePath
|
||||
{
|
||||
public:
|
||||
ObserverNodePath();
|
||||
@@ -38,9 +37,6 @@ class OSG_EXPORT ObserverNodePath : public osg::Observer
|
||||
|
||||
ObserverNodePath& operator = (const ObserverNodePath& rhs);
|
||||
|
||||
bool valid() const { return _valid; }
|
||||
|
||||
|
||||
/** get the NodePath from the first parental chain back to root, plus the specified node.*/
|
||||
void setNodePathTo(osg::Node* node);
|
||||
|
||||
@@ -61,21 +57,18 @@ class OSG_EXPORT ObserverNodePath : public osg::Observer
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
if (!_valid) return true;
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(*getObserverMutex());
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
return _nodePath.empty();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void _setNodePath(const osg::NodePath& nodePath);
|
||||
|
||||
void _clearNodePath();
|
||||
|
||||
virtual bool objectUnreferenced(void* ptr);
|
||||
|
||||
osg::NodePath _nodePath;
|
||||
bool _valid;
|
||||
typedef std::vector< osg::observer_ptr<osg::Node> > ObsNodePath;
|
||||
mutable OpenThreads::Mutex _mutex;
|
||||
ObsNodePath _nodePath;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -345,28 +345,9 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
|
||||
|
||||
struct RequestQueue;
|
||||
|
||||
struct PagedLODObserver : public osg::observer_ptr<osg::PagedLOD>
|
||||
{
|
||||
typedef osg::observer_ptr<osg::PagedLOD> BaseClass;
|
||||
|
||||
PagedLODObserver(osg::PagedLOD* plod):BaseClass(plod) {}
|
||||
PagedLODObserver(const PagedLODObserver& plodObserver):BaseClass(plodObserver) {}
|
||||
|
||||
PagedLODObserver& operator = (const PagedLODObserver& rhs)
|
||||
{
|
||||
(*static_cast<BaseClass*>(this)) = rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual void objectDeleted(void* ptr)
|
||||
{
|
||||
BaseClass::objectDeleted(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
typedef osg::observer_ptr<osg::PagedLOD> PagedLODObserver;
|
||||
typedef std::list< PagedLODObserver > PagedLODList;
|
||||
|
||||
|
||||
struct DatabaseRequest : public osg::Referenced
|
||||
{
|
||||
DatabaseRequest():
|
||||
|
||||
Reference in New Issue
Block a user