Refactored Callback system in osg::Node, osg::Drawable, osg::StateSet and osg::StateAttribute to use a new osg::Callback base class.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14244 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2014-06-05 16:26:13 +00:00
parent 35d6cb812f
commit 977ec20751
64 changed files with 590 additions and 471 deletions

View File

@@ -21,7 +21,7 @@
#include <osg/Matrixf>
#include <osg/Matrixd>
#include <osg/Quat>
#include <osg/NodeCallback>
#include <osg/Callback>
namespace osg {

202
include/osg/Callback Normal file
View File

@@ -0,0 +1,202 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_CALLBACK
#define OSG_CALLBACK 1
#include <osg/Object>
#include <osg/UserDataContainer>
namespace osg {
class Callback : public virtual Object {
public :
Callback(){}
Callback(const Callback& cb,const CopyOp&):
_nestedCallback(cb._nestedCallback) {}
META_Object(osg, Callback);
/** Invoke the callback, first parameter is the Object that the callback is attached to,
* the second parameter, the data, is typically the NodeVisitor that is invoking the callback.
* The run(..) method may be overriden by users directly, or if the user is using one of the old
* style callbacks such as NodeCallback or Drawable::UpdateCallback then you can just override
* the appropriate callback method on those callback subclasses.
* If you are implementing your own callback then one should call traverse() to make sure nested callbacks
* and visitor traversal() is completed. */
virtual bool run(osg::Object* object, osg::Object* data)
{
return traverse(object, data);
}
/** traverse the nested callbacks or call NodeVisitor::traverse() if the object is Node, and data is NodeVisitor.*/
bool traverse(osg::Object* object, osg::Object* data);
void setNestedCallback(osg::Callback* cb) { _nestedCallback = cb; }
osg::Callback* getNestedCallback() { return _nestedCallback.get(); }
const osg::Callback* getNestedCallback() const { return _nestedCallback.get(); }
inline void addNestedCallback(osg::Callback* nc)
{
if (nc)
{
if (_nestedCallback.valid())
{
_nestedCallback->addNestedCallback(nc);
}
else
{
_nestedCallback = nc;
}
}
}
inline void removeNestedCallback(osg::Callback* nc)
{
if (nc)
{
if (_nestedCallback==nc)
{
ref_ptr<osg::Callback> new_nested_callback = _nestedCallback->getNestedCallback();
_nestedCallback->setNestedCallback(0);
_nestedCallback = new_nested_callback;
}
else if (_nestedCallback.valid())
{
_nestedCallback->removeNestedCallback(nc);
}
}
}
protected:
virtual ~Callback() {}
ref_ptr<Callback> _nestedCallback;
};
typedef std::vector< osg::ref_ptr<osg::Object> > Parameters;
/** Callback for attaching a script to a Node's via there UserDataContainer for the purpose of overriding class methods within scripts.*/
class OSG_EXPORT CallbackObject : public virtual osg::Callback
{
public:
CallbackObject() {}
CallbackObject(const std::string& name) { setName(name); }
CallbackObject(const CallbackObject& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):osg::Callback(rhs,copyop) {}
META_Object(osg, CallbackObject);
virtual CallbackObject* asCallbackObject() { return this; }
virtual const CallbackObject* asCallbackObject() const { return this; }
/** override Callback::run() entry point to adapt to CallbackObject::run(..) method.*/
bool run(osg::Object* object, osg::Object* data);
inline bool run(osg::Object* object) const
{
osg::Parameters inputParameters;
osg::Parameters outputParameters;
return run(object, inputParameters, outputParameters);
}
virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
};
/** Convinience function for getting the CallbackObject associated with specificed name from an Object's UserDataContainer.*/
inline CallbackObject* getCallbackObject(osg::Object* object, const std::string& name)
{
osg::UserDataContainer* udc = object->getUserDataContainer();
return udc ? dynamic_cast<osg::CallbackObject*>(udc->getUserObject(name)) : 0;
}
/** Call run(..) on named CallbackObjects attached to specified Object. Return true if at least one CallbackObject has been successfully invoked.*/
inline bool runNamedCallbackObjects(osg::Object* object, const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters)
{
bool result = false;
osg::UserDataContainer* udc = object->getUserDataContainer();
if (udc)
{
for(unsigned int i = 0; i<udc->getNumUserObjects(); ++i)
{
osg::Object* obj = udc->getUserObject(i);
if (obj && obj->getName()==name)
{
osg::CallbackObject* co = dynamic_cast<osg::CallbackObject*>(obj);
if (co) result = co->run(object, inputParameters, outputParameters) | result;
}
}
}
return result;
}
// forward declare
class Node;
class NodeVisitor;
/** Deprecated. */
class OSG_EXPORT NodeCallback : public virtual Callback {
public :
NodeCallback(){}
NodeCallback(const NodeCallback& nc,const CopyOp& copyop):
Callback(nc,copyop) {}
META_Object(osg,NodeCallback);
/** NodeCallback overrides the Callback::run() method to adapt it the old style NodeCallback::operator()(Node* node, NodeVisitor* nv) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** Callback method called by the NodeVisitor when visiting a node.*/
virtual void operator()(Node* node, NodeVisitor* nv);
protected:
virtual ~NodeCallback() {}
};
// forward declare
class StateAttribute;
/** Deprecated. */
class OSG_EXPORT StateAttributeCallback : public virtual osg::Callback
{
public:
StateAttributeCallback() {}
StateAttributeCallback(const StateAttributeCallback&,const CopyOp&) {}
META_Object(osg,StateAttributeCallback);
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** do customized update code.*/
virtual void operator () (StateAttribute*, NodeVisitor*) {}
};
} // namespace
#endif

View File

@@ -15,7 +15,7 @@
#define OSG_CLUSTERCULLINGCALLBACK 1
#include <osg/Drawable>
#include <osg/NodeCallback>
#include <osg/Callback>
namespace osg {

View File

@@ -31,7 +31,7 @@ class Drawable;
class Array;
class PrimitiveSet;
class Shape;
class NodeCallback;
class Callback;
/** Copy Op(erator) used to control whether shallow or deep copy is used
@@ -80,7 +80,7 @@ class OSG_EXPORT CopyOp
virtual PrimitiveSet* operator() (const PrimitiveSet* primitives) const;
virtual Shape* operator() (const Shape* shape) const;
virtual Uniform* operator() (const Uniform* shape) const;
virtual NodeCallback* operator() (const NodeCallback* nodecallback) const;
virtual Callback* operator() (const Callback* nodecallback) const;
virtual StateAttributeCallback* operator() (const StateAttributeCallback* stateattributecallback) const;
protected:

View File

@@ -268,7 +268,7 @@ class OSG_EXPORT Drawable : public Node
* for all graphics contexts. */
virtual void releaseGLObjects(State* state=0) const;
struct UpdateCallback : public virtual osg::Object
struct OSG_EXPORT UpdateCallback : public virtual Callback
{
UpdateCallback() {}
@@ -276,24 +276,15 @@ class OSG_EXPORT Drawable : public Node
META_Object(osg,UpdateCallback);
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** do customized update code.*/
virtual void update(osg::NodeVisitor*, osg::Drawable*) {}
};
/** Set the UpdateCallback which allows users to attach customize the updating of an object during the update traversal. */
virtual void setUpdateCallback(UpdateCallback* ac);
/** Get the non const UpdateCallback.*/
UpdateCallback* getUpdateCallback() { return _drawableUpdateCallback.get(); }
/** Get the const UpdateCallback.*/
const UpdateCallback* getUpdateCallback() const { return _drawableUpdateCallback.get(); }
/** Return whether this Drawable has update callbacks associated with it, and therefore must be traversed.*/
bool requiresUpdateTraversal() const { return _drawableUpdateCallback.valid() || (_stateset.valid() && _stateset->requiresUpdateTraversal()); }
struct EventCallback : public virtual osg::Object
struct OSG_EXPORT EventCallback : public virtual Callback
{
EventCallback() {}
@@ -301,24 +292,14 @@ class OSG_EXPORT Drawable : public Node
META_Object(osg,EventCallback);
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** do customized Event code. */
virtual void event(osg::NodeVisitor*, osg::Drawable*) {}
};
/** Set the EventCallback which allows users to attach customize the updating of an object during the Event traversal.*/
virtual void setEventCallback(EventCallback* ac);
/** Get the non const EventCallback.*/
EventCallback* getEventCallback() { return _drawableEventCallback.get(); }
/** Get the const EventCallback.*/
const EventCallback* getEventCallback() const { return _drawableEventCallback.get(); }
/** Return whether this Drawable has event callbacks associated with it, and therefore must be traversed.*/
bool requiresEventTraversal() const { return _drawableEventCallback.valid() || (_stateset.valid() && _stateset->requiresEventTraversal()); }
struct CullCallback : public virtual osg::Object
struct CullCallback : public virtual Callback
{
CullCallback() {}
@@ -333,17 +314,6 @@ class OSG_EXPORT Drawable : public Node
virtual bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo) const { return cull(nv, drawable, renderInfo? renderInfo->getState():0); }
};
/** Set the CullCallback which allows users to customize the culling of Drawable during the cull traversal.*/
virtual void setCullCallback(CullCallback* cc) { _drawableCullCallback=cc; }
/** Get the non const CullCallback.*/
CullCallback* getCullCallback() { return _drawableCullCallback.get(); }
/** Get the const CullCallback.*/
const CullCallback* getCullCallback() const { return _drawableCullCallback.get(); }
/** Callback attached to an Drawable which allows the users to customize the drawing of an exist Drawable object.
* The draw callback is implement as a replacement to the Drawable's own drawImplementation() method, if the

View File

@@ -19,7 +19,7 @@
#include <osg/StateSet>
#include <osg/BoundingSphere>
#include <osg/BoundingBox>
#include <osg/NodeCallback>
#include <osg/Callback>
#include <string>
#include <vector>
@@ -202,16 +202,16 @@ class OSG_EXPORT Node : public Object
/** Set update node callback, called during update traversal. */
void setUpdateCallback(NodeCallback* nc);
void setUpdateCallback(Callback* nc);
/** Get update node callback, called during update traversal. */
inline NodeCallback* getUpdateCallback() { return _updateCallback.get(); }
inline Callback* getUpdateCallback() { return _updateCallback.get(); }
/** Get const update node callback, called during update traversal. */
inline const NodeCallback* getUpdateCallback() const { return _updateCallback.get(); }
inline const Callback* getUpdateCallback() const { return _updateCallback.get(); }
/** Convenience method that sets the update callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addUpdateCallback(NodeCallback* nc) {
inline void addUpdateCallback(Callback* nc) {
if (nc != NULL) {
if (_updateCallback.valid()) _updateCallback->addNestedCallback(nc);
else setUpdateCallback(nc);
@@ -219,7 +219,7 @@ class OSG_EXPORT Node : public Object
}
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeUpdateCallback(NodeCallback* nc) {
inline void removeUpdateCallback(Callback* nc) {
if (nc != NULL && _updateCallback.valid()) {
if (_updateCallback == nc)
{
@@ -236,16 +236,16 @@ class OSG_EXPORT Node : public Object
/** Set event node callback, called during event traversal. */
void setEventCallback(NodeCallback* nc);
void setEventCallback(Callback* nc);
/** Get event node callback, called during event traversal. */
inline NodeCallback* getEventCallback() { return _eventCallback.get(); }
inline Callback* getEventCallback() { return _eventCallback.get(); }
/** Get const event node callback, called during event traversal. */
inline const NodeCallback* getEventCallback() const { return _eventCallback.get(); }
inline const Callback* getEventCallback() const { return _eventCallback.get(); }
/** Convenience method that sets the event callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addEventCallback(NodeCallback* nc) {
inline void addEventCallback(Callback* nc) {
if (nc != NULL) {
if (_eventCallback.valid()) _eventCallback->addNestedCallback(nc);
else setEventCallback(nc);
@@ -253,7 +253,7 @@ class OSG_EXPORT Node : public Object
}
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeEventCallback(NodeCallback* nc) {
inline void removeEventCallback(Callback* nc) {
if (nc != NULL && _eventCallback.valid()) {
if (_eventCallback == nc)
{
@@ -270,16 +270,16 @@ class OSG_EXPORT Node : public Object
/** Set cull node callback, called during cull traversal. */
void setCullCallback(NodeCallback* nc) { _cullCallback = nc; }
void setCullCallback(Callback* nc) { _cullCallback = nc; }
/** Get cull node callback, called during cull traversal. */
inline NodeCallback* getCullCallback() { return _cullCallback.get(); }
inline Callback* getCullCallback() { return _cullCallback.get(); }
/** Get const cull node callback, called during cull traversal. */
inline const NodeCallback* getCullCallback() const { return _cullCallback.get(); }
inline const Callback* getCullCallback() const { return _cullCallback.get(); }
/** Convenience method that sets the cull callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addCullCallback(NodeCallback* nc) {
inline void addCullCallback(Callback* nc) {
if (nc != NULL) {
if (_cullCallback.valid()) _cullCallback->addNestedCallback(nc);
else setCullCallback(nc);
@@ -287,7 +287,7 @@ class OSG_EXPORT Node : public Object
}
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeCullCallback(NodeCallback* nc) {
inline void removeCullCallback(Callback* nc) {
if (nc != NULL && _cullCallback.valid()) {
if (_cullCallback == nc)
{
@@ -477,15 +477,15 @@ class OSG_EXPORT Node : public Object
friend class osg::Drawable;
friend class osg::StateSet;
ref_ptr<NodeCallback> _updateCallback;
ref_ptr<Callback> _updateCallback;
unsigned int _numChildrenRequiringUpdateTraversal;
void setNumChildrenRequiringUpdateTraversal(unsigned int num);
ref_ptr<NodeCallback> _eventCallback;
ref_ptr<Callback> _eventCallback;
unsigned int _numChildrenRequiringEventTraversal;
void setNumChildrenRequiringEventTraversal(unsigned int num);
ref_ptr<NodeCallback> _cullCallback;
ref_ptr<Callback> _cullCallback;
bool _cullingActive;
unsigned int _numChildrenWithCullingDisabled;

View File

@@ -14,86 +14,7 @@
#ifndef OSG_NODECALLBACK
#define OSG_NODECALLBACK 1
#include <osg/Object>
#include <osg/ref_ptr>
namespace osg {
class Node;
class NodeVisitor;
class OSG_EXPORT NodeCallback : public virtual Object {
public :
NodeCallback(){}
NodeCallback(const NodeCallback& nc,const CopyOp&):
_nestedCallback(nc._nestedCallback) {}
META_Object(osg,NodeCallback);
/** Callback method called by the NodeVisitor when visiting a node.*/
virtual void operator()(Node* node, NodeVisitor* nv)
{
// note, callback is responsible for scenegraph traversal so
// they must call traverse(node,nv) to ensure that the
// scene graph subtree (and associated callbacks) are traversed.
traverse(node,nv);
}
/** Call any nested callbacks and then traverse the scene graph. */
void traverse(Node* node,NodeVisitor* nv);
void setNestedCallback(NodeCallback* nc) { _nestedCallback = nc; }
NodeCallback* getNestedCallback() { return _nestedCallback.get(); }
const NodeCallback* getNestedCallback() const { return _nestedCallback.get(); }
inline void addNestedCallback(NodeCallback* nc)
{
if (nc)
{
if (_nestedCallback.valid())
{
_nestedCallback->addNestedCallback(nc);
}
else
{
_nestedCallback = nc;
}
}
}
inline void removeNestedCallback(NodeCallback* nc)
{
if (nc)
{
if (_nestedCallback==nc)
{
ref_ptr<NodeCallback> new_nested_callback = _nestedCallback->getNestedCallback();
_nestedCallback->setNestedCallback(0);
_nestedCallback = new_nested_callback;
}
else if (_nestedCallback.valid())
{
_nestedCallback->removeNestedCallback(nc);
}
}
}
public:
ref_ptr<NodeCallback> _nestedCallback;
protected:
virtual ~NodeCallback() {}
};
} // namespace
#include <osg/Callback>
#endif

View File

@@ -17,7 +17,6 @@
#include <iterator>
#include <osg/Node>
#include <osg/NodeCallback>
#include <osg/ObserverNodePath>
namespace osg

View File

@@ -15,20 +15,16 @@
#define OSG_SCRIPTENGINE 1
#include <osg/Object>
#include <osg/NodeCallback>
#include <osg/Callback>
#include <osg/NodeVisitor>
#include <osg/UserDataContainer>
namespace osg
{
typedef std::vector< osg::ref_ptr<osg::Object> > Parameters;
// forward declare
class ScriptEngine;
/* Script class for wrapping a script and the language used in the script.*/
class Script : public osg::Object
{
@@ -57,53 +53,6 @@ class Script : public osg::Object
unsigned int _modifiedCount;
};
/** Callback for attaching a script to a Node's via there UserDataContainer for the purpose of overriding class methods within scripts.*/
class OSG_EXPORT CallbackObject : public osg::Object
{
public:
CallbackObject() {}
CallbackObject(const std::string& name) { setName(name); }
CallbackObject(const CallbackObject& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):osg::Object(rhs,copyop) {}
META_Object(osg, CallbackObject);
inline bool run(osg::Object* object) const
{
osg::Parameters inputParameters;
osg::Parameters outputParameters;
return run(object, inputParameters, outputParameters);
}
virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
};
/** Convinience function for getting the CallbackObject associated with specificed name from an Object's UserDataContainer.*/
inline CallbackObject* getCallbackObject(osg::Object* object, const std::string& name)
{
osg::UserDataContainer* udc = object->getUserDataContainer();
return udc ? dynamic_cast<osg::CallbackObject*>(udc->getUserObject(name)) : 0;
}
/** Call run(..) on named CallbackObjects attached to specified Object. Return true if at least one CallbackObject has been successfully invoked.*/
inline bool runNamedCallbackObjects(osg::Object* object, const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters)
{
bool result = false;
osg::UserDataContainer* udc = object->getUserDataContainer();
if (udc)
{
for(unsigned int i = 0; i<udc->getNumUserObjects(); ++i)
{
osg::Object* obj = udc->getUserObject(i);
if (obj && obj->getName()==name)
{
osg::CallbackObject* co = dynamic_cast<osg::CallbackObject*>(obj);
if (co) result = co->run(object, inputParameters, outputParameters) | result;
}
}
}
return result;
}
/** NodeCallback for attaching a script to a NodeCallback so that it can be called as an update or event callback.*/
class OSG_EXPORT ScriptNodeCallback : public osg::NodeCallback

View File

@@ -16,7 +16,7 @@
#include <osg/Export>
#include <osg/Object>
#include <osg/StateAttributeCallback>
#include <osg/Callback>
#include <osg/Shader>
#include <osg/GL>

View File

@@ -13,27 +13,6 @@
#ifndef OSG_STATEATTRIBUTECALLBACK
#define OSG_STATEATTRIBUTECALLBACK 1
#include <osg/Export>
#include <osg/Object>
namespace osg {
class StateAttribute;
class NodeVisitor;
class OSG_EXPORT StateAttributeCallback : public virtual osg::Object
{
public:
StateAttributeCallback() {}
StateAttributeCallback(const StateAttributeCallback&,const CopyOp&) {}
META_Object(osg,StateAttributeCallback);
/** do customized update code.*/
virtual void operator () (StateAttribute*, NodeVisitor*) {}
};
}
#include <osg/Callback>
#endif

View File

@@ -378,7 +378,7 @@ class OSG_EXPORT StateSet : public Object
inline bool getNestRenderBins() const { return _nestRenderBins; }
struct Callback : public virtual osg::Object
struct Callback : public virtual osg::Callback
{
Callback() {}
@@ -386,6 +386,9 @@ class OSG_EXPORT StateSet : public Object
META_Object(osg,Callback);
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** do customized callback code.*/
virtual void operator() (StateSet*, NodeVisitor*) {}
};

View File

@@ -17,6 +17,7 @@
#include <osgAnimation/Export>
#include <osg/MatrixTransform>
#include <osg/Callback>
namespace osgAnimation
{

View File

@@ -16,10 +16,10 @@
#ifndef OSGANIMATION_UPDATE_MATRIX_TRANSFORM
#define OSGANIMATION_UPDATE_MATRIX_TRANSFORM 1
#include <osg/Callback>
#include <osgAnimation/Export>
#include <osgAnimation/AnimationUpdateCallback>
#include <osgAnimation/StackedTransform>
#include <osg/NodeCallback>
namespace osgAnimation
{

View File

@@ -16,7 +16,6 @@
#include <vector>
#include <osg/NodeCallback>
#include <osg/Drawable>
#include <osg/ApplicationUsage>
@@ -37,12 +36,20 @@ public:
EventHandler() {}
EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(eh,copyop),
osg::Callback(eh,copyop),
osg::NodeCallback(eh, copyop),
osg::Drawable::EventCallback(eh, copyop) {}
META_Object(osgGA, EventHandler);
virtual bool run(osg::Object* object, osg::Object* data)
{
osg::Node* node = dynamic_cast<osg::Node*>(object);
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
operator()(node, nv);
return true;
}
/** Event traversal node callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);

View File

@@ -24,6 +24,7 @@
#include <osg/Transform>
#include <osg/Projection>
#include <osg/OccluderNode>
#include <osg/ScriptEngine>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIActionAdapter>
@@ -68,8 +69,27 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
/** During traversal each type of node calls its callbacks and its children traversed. */
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); }
virtual void apply(osg::Drawable& drawable)
{
osg::Callback* callback = drawable.getEventCallback();
if (callback)
{
osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast<osg::Drawable::UpdateCallback*>(callback);
osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
osg::CallbackObject* callback_object = dynamic_cast<osg::CallbackObject*>(callback);
if (drawable_callback) drawable_callback->update(this,&drawable);
if (node_callback) (*node_callback)(&drawable, this);
if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this);
}
handle_callbacks(drawable.getStateSet());
}
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
@@ -98,34 +118,11 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
{
handle_callbacks(node.getStateSet());
osg::NodeCallback* callback = node.getEventCallback();
if (callback) (*callback)(&node,this);
else if (node.getNumChildrenRequiringEventTraversal()>0) traverse(node);
osg::Callback* callback = node.getEventCallback();
if (callback) callback->run(&node,this);
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
}
inline void handle_geode_callbacks(osg::Geode& node)
{
handle_callbacks(node.getStateSet());
osg::NodeCallback* callback = node.getEventCallback();
if (callback) (*callback)(&node,this);
/*else if (node.getNumChildrenRequiringEventTraversal()>0)*/
traverseGeode(node);
}
inline void traverseGeode(osg::Geode& geode)
{
traverse((osg::Node&)geode);
// Call the app callbacks on the drawables.
for(unsigned int i=0;i<geode.getNumDrawables();++i)
{
osg::Drawable::EventCallback* callback = geode.getDrawable(i)->getEventCallback();
if (callback) callback->event(this,geode.getDrawable(i));
handle_callbacks(geode.getDrawable(i)->getStateSet());
}
}
osgGA::GUIActionAdapter* _actionAdapter;

View File

@@ -16,7 +16,6 @@
#include <vector>
#include <osg/NodeCallback>
#include <osg/Drawable>
#include <osg/ApplicationUsage>
@@ -54,7 +53,7 @@ public:
#if 1
GUIEventHandler() {}
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(eh, copyop), EventHandler(eh, copyop) {}
osg::Callback(eh, copyop), EventHandler(eh, copyop) {}
#else
GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
@@ -123,7 +122,7 @@ protected:
unsigned int _ignoreHandledEventsMask;
#endif
protected:
protected:
virtual ~GUIEventHandler();
};

View File

@@ -14,7 +14,7 @@
#define OSG_ANIMATIONMATERIAL 1
#include <osg/Material>
#include <osg/NodeCallback>
#include <osg/Callback>
#include <osgPresentation/Export>

View File

@@ -15,7 +15,6 @@
#include <osg/UserDataContainer>
#include <osg/ValueObject>
#include <osg/NodeCallback>
#include <osg/ImageSequence>
#include <osgGA/GUIEventHandler>
@@ -29,13 +28,13 @@ namespace osgPresentation
class PropertyManager : protected osg::Object
{
public:
PropertyManager() {}
PropertyManager(const PropertyManager& pm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(pm,copyop) {}
META_Object(osgPresentation, PropertyManager)
/** Convinience method that casts the named UserObject to osg::TemplateValueObject<T> and gets the value.
* To use this template method you need to include the osg/ValueObject header.*/
template<typename T>
@@ -57,7 +56,7 @@ public:
int ref() const { return osg::Referenced::ref(); }
int unref() const { return osg::Referenced::unref(); }
protected:
mutable OpenThreads::Mutex _mutex;
@@ -125,7 +124,7 @@ struct PropertyReader
bool _errorGenerated;
osg::NodePath _nodePath;
std::istringstream _sstream;
std::istringstream _sstream;
};
@@ -176,7 +175,7 @@ protected:
double _latestTime;
bool _pause;
double _pauseTime;
};

View File

@@ -98,28 +98,30 @@ class OSGSHADOW_EXPORT MinimalDrawBoundsShadowMap
osg::observer_ptr< ViewData > _vd;
};
struct CameraCullCallback: public osg::NodeCallback {
struct CameraCullCallback: public osg::Callback {
CameraCullCallback(ViewData * vd, osg::NodeCallback * nc): _vd(vd), _nc(nc)
CameraCullCallback(ViewData * vd, osg::Callback * nc): _vd(vd), _nc(nc)
{
}
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
virtual bool run(osg::Object* object, osg::Object* data)
{
osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( nv );
osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( data );
if( _nc.valid() )
_nc->operator()(node,nv);
_nc->run(object, data);
else
traverse(node,nv);
traverse(object, data);
if( cv )
_vd->recordShadowMapParams( );
return true;
}
protected:
osg::observer_ptr< ViewData > _vd;
osg::ref_ptr< osg::NodeCallback > _nc;
osg::ref_ptr< osg::Callback > _nc;
};
};

View File

@@ -309,15 +309,15 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
inline void handle_cull_callbacks_and_traverse(osg::Node& node)
{
osg::NodeCallback* callback = node.getCullCallback();
if (callback) (*callback)(&node,this);
osg::Callback* callback = node.getCullCallback();
if (callback) callback->run(&node,this);
else traverse(node);
}
inline void handle_cull_callbacks_and_accept(osg::Node& node,osg::Node* acceptNode)
{
osg::NodeCallback* callback = node.getCullCallback();
if (callback) (*callback)(&node,this);
osg::Callback* callback = node.getCullCallback();
if (callback) callback->run(&node,this);
else acceptNode->accept(*this);
}

View File

@@ -15,7 +15,7 @@
#ifndef OSGUTIL_TRANSFORMCALLBACK
#define OSGUTIL_TRANSFORMCALLBACK 1
#include <osg/Node>
#include <osg/Callback>
#include <osgUtil/Export>
namespace osgUtil

View File

@@ -15,7 +15,6 @@
#define OSGUTIL_UPDATEVISITOR 1
#include <osg/NodeVisitor>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Billboard>
#include <osg/LOD>
@@ -24,6 +23,7 @@
#include <osg/Transform>
#include <osg/Projection>
#include <osg/OccluderNode>
#include <osg/ScriptEngine>
#include <osgUtil/Export>
@@ -50,17 +50,24 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
virtual void apply(osg::Drawable& drawable)
{
osg::Drawable::UpdateCallback* callback = drawable.getUpdateCallback();
if (callback) callback->update(this,&drawable);
osg::Callback* callback = drawable.getUpdateCallback();
if (callback)
{
osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast<osg::Drawable::UpdateCallback*>(callback);
osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
osg::CallbackObject* callback_object = dynamic_cast<osg::CallbackObject*>(callback);
osg::NodeCallback* node_callback = drawable.osg::Node::getUpdateCallback();
if (node_callback) (*node_callback)(&drawable, this);
if (drawable_callback) drawable_callback->update(this,&drawable);
if (node_callback) (*node_callback)(&drawable, this);
if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this);
}
handle_callbacks(drawable.getStateSet());
}
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); }
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
@@ -92,31 +99,10 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
{
handle_callbacks(node.getStateSet());
osg::NodeCallback* callback = node.getUpdateCallback();
if (callback) (*callback)(&node,this);
osg::Callback* callback = node.getUpdateCallback();
if (callback) callback->run(&node,this);
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
}
inline void handle_geode_callbacks(osg::Geode& geode)
{
handle_callbacks(geode.getStateSet());
osg::NodeCallback* callback = geode.getUpdateCallback();
if (callback) (*callback)(&geode,this);
// Call the app callbacks on the drawables.
for(unsigned int i=0;i<geode.getNumDrawables();++i)
{
osg::Drawable::UpdateCallback* callback = geode.getDrawable(i)->getUpdateCallback();
if (callback) callback->update(this,geode.getDrawable(i));
handle_callbacks(geode.getDrawable(i)->getStateSet());
}
// should we traverse just in case a subclass of Geode adds children?? Won't for now as
// Geode's arn't designed to have children.
// traverse(geode);
}
};
}

View File

@@ -525,7 +525,7 @@ protected:
InteractiveImageHandler() {}
InteractiveImageHandler(const InteractiveImageHandler&,const osg::CopyOp& = osg::CopyOp::SHALLOW_COPY):
osg::Object(), osgGA::GUIEventHandler(), osg::Drawable::CullCallback(), _fullscreen(false) {}
osg::Callback(), osgGA::GUIEventHandler(), osg::Drawable::CullCallback(), _fullscreen(false) {}
bool mousePosition(osgViewer::View* view, osg::NodeVisitor* nv, const osgGA::GUIEventAdapter& ea, int& x, int &y) const;

View File

@@ -447,7 +447,9 @@ class OSGVOLUME_EXPORT PropertyAdjustmentCallback : public osgGA::GUIEventHandle
PropertyAdjustmentCallback(const PropertyAdjustmentCallback&,const osg::CopyOp&);
META_Object(osgVolume,PropertyAdjustmentCallback);
META_Object(osgVolume, PropertyAdjustmentCallback);
virtual bool run(osg::Object* object, osg::Object* data) { return osgGA::GUIEventHandler::run(object, data); }
void setKeyEventCycleForward(int key) { _cyleForwardKey = key; }
int getKeyEventCycleForward() const { return _cyleForwardKey; }