From: Tim Moore Date: Mon, 9 Nov 2009 12:28:11 +0000 (+0100) Subject: Move propertyExpression code from flightgear to simgear X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4e2eb2f24c3d7c77a0aec85213755c03e1483097;p=simgear.git Move propertyExpression code from flightgear to simgear Also add a function (possibly redundant) to access the global property root. --- diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index b36702ad..14ad2022 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -59,6 +59,7 @@ #include #include +#include #include #include #include @@ -762,4 +763,49 @@ osgDB::RegisterDotOsgWrapperProxy effectProxy &Effect_writeLocalData ); } + +// Property expressions for technique predicates +class PropertyExpression : public SGExpression +{ +public: + PropertyExpression(SGPropertyNode* pnode) : _pnode(pnode) {} + + void eval(bool& value, const expression::Binding*) const + { + value = _pnode->getValue(); + } +protected: + SGPropertyNode_ptr _pnode; +}; + +class EffectPropertyListener : public SGPropertyChangeListener +{ +public: + EffectPropertyListener(Technique* tniq) : _tniq(tniq) {} + + void valueChanged(SGPropertyNode* node) + { + _tniq->refreshValidity(); + } +protected: + osg::ref_ptr _tniq; +}; + +Expression* propertyExpressionParser(const SGPropertyNode* exp, + expression::Parser* parser) +{ + SGPropertyNode_ptr pnode = getPropertyRoot()->getNode(exp->getStringValue(), + true); + PropertyExpression* pexp = new PropertyExpression(pnode); + TechniquePredParser* predParser + = dynamic_cast(parser); + if (predParser) + pnode->addChangeListener(new EffectPropertyListener(predParser + ->getTechnique())); + return pexp; +} + +expression::ExpParserRegistrar propertyRegistrar("property", + propertyExpressionParser); + } diff --git a/simgear/scene/tgdb/userdata.cxx b/simgear/scene/tgdb/userdata.cxx index fab67b2f..11d69e12 100644 --- a/simgear/scene/tgdb/userdata.cxx +++ b/simgear/scene/tgdb/userdata.cxx @@ -64,3 +64,10 @@ osg::Node* sgGetRandomModel(SGMatModel *obj) { return obj->get_random_model( root_props ); } +namespace simgear +{ +SGPropertyNode* getPropertyRoot() +{ + return root_props; +} +} diff --git a/simgear/scene/tgdb/userdata.hxx b/simgear/scene/tgdb/userdata.hxx index e5a870e3..ab0a6a55 100644 --- a/simgear/scene/tgdb/userdata.hxx +++ b/simgear/scene/tgdb/userdata.hxx @@ -44,4 +44,12 @@ void sgUserDataInit(SGPropertyNode *p); */ osg::Node* sgGetRandomModel(SGMatModel *obj); +namespace simgear +{ +/** + * Get the property root for the simulation + */ +SGPropertyNode* getPropertyRoot(); +} + #endif // _SG_USERDATA_HXX