}
}
-void Effect::UpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
-{
- EffectGeode* eg = dynamic_cast<EffectGeode*>(node);
- if (!eg)
- return;
- Effect* effect = eg->getEffect();
- if (!effect)
- return;
-
- for (vector<SGSharedPtr<Updater> >::iterator itr = effect->_extraData.begin(),
- end = effect->_extraData.end();
- itr != end;
- ++itr) {
- PropertyPoller * poller
- = dynamic_cast<PropertyPoller*>(itr->ptr());
- if (poller)
- poller->pollProperties(effect);
- }
-
- traverse(node, nv);
-}
-
bool Effect::Key::EqualTo::operator()(const Effect::Key& lhs,
const Effect::Key& rhs) const
{
bool _initialized;
};
-class PropertyPoller
-{
-public:
- PropertyPoller() {};
- virtual ~PropertyPoller() {};
- virtual void pollProperties(Effect* effect)
- {
- }
-private:
-};
-
class Effect : public osg::Object
{
public:
{
void doUpdate(osg::Node* node, osg::NodeVisitor* nv);
};
- friend struct UpdateCallback;
- struct UpdateCallback : public osg::NodeCallback
- {
- UpdateCallback() {}
- UpdateCallback(const UpdateCallback& nc, const osg::CopyOp& copyop)
- : osg::NodeCallback(nc, copyop)
- {
- }
-
- virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
- };
protected:
std::vector<SGSharedPtr<Updater> > _extraData;
~Effect();
template<typename OSGParamType, typename ObjType, typename F>
class ScalarChangeListener
: public SGPropertyChangeListener, public InitializeWhenAdded,
- public PropertyPoller,
public Effect::Updater
{
public:
ScalarChangeListener(ObjType* obj, const F& setter,
const std::string& propName)
- : _obj(obj), _setter(setter), _propName(propName)
+ : _obj(obj), _setter(setter)
{
+ _propName = new std::string(propName);
}
virtual ~ScalarChangeListener()
{
+ delete _propName;
+ _propName = 0;
}
void valueChanged(SGPropertyNode* node)
{
}
void initOnAddImpl(Effect* effect, SGPropertyNode* propRoot)
{
- _listenProp = makeNode(propRoot, _propName);
-// if ( _listenProp.valid() )
-// _listenProp->addChangeListener(this, true);
- }
- void pollProperties(Effect* effect)
- {
- if( false == _listenProp.valid() ) return;
- valueChanged(_listenProp);
+ SGPropertyNode* listenProp = makeNode(propRoot, *_propName);
+ delete _propName;
+ _propName = 0;
+ if (listenProp)
+ listenProp->addChangeListener(this, true);
}
private:
- SGPropertyNode_ptr _listenProp;
osg::ref_ptr<ObjType> _obj;
F _setter;
- std::string _propName;
+ std::string* _propName;
};
template<typename T, typename Func>