Move propertyExpression code from flightgear to simgear

Also add a function (possibly redundant) to access the global property
root.
This commit is contained in:
Tim Moore
2009-11-09 13:28:11 +01:00
parent b905f4b8aa
commit 4e2eb2f24c
3 changed files with 61 additions and 0 deletions

View File

@@ -59,6 +59,7 @@
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <simgear/scene/tgdb/userdata.hxx>
#include <simgear/scene/util/SGSceneFeatures.hxx>
#include <simgear/scene/util/StateAttributeFactory.hxx>
#include <simgear/structure/OSGUtils.hxx>
@@ -762,4 +763,49 @@ osgDB::RegisterDotOsgWrapperProxy effectProxy
&Effect_writeLocalData
);
}
// Property expressions for technique predicates
class PropertyExpression : public SGExpression<bool>
{
public:
PropertyExpression(SGPropertyNode* pnode) : _pnode(pnode) {}
void eval(bool& value, const expression::Binding*) const
{
value = _pnode->getValue<bool>();
}
protected:
SGPropertyNode_ptr _pnode;
};
class EffectPropertyListener : public SGPropertyChangeListener
{
public:
EffectPropertyListener(Technique* tniq) : _tniq(tniq) {}
void valueChanged(SGPropertyNode* node)
{
_tniq->refreshValidity();
}
protected:
osg::ref_ptr<Technique> _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<TechniquePredParser*>(parser);
if (predParser)
pnode->addChangeListener(new EffectPropertyListener(predParser
->getTechnique()));
return pexp;
}
expression::ExpParserRegistrar propertyRegistrar("property",
propertyExpressionParser);
}

View File

@@ -64,3 +64,10 @@ osg::Node* sgGetRandomModel(SGMatModel *obj) {
return obj->get_random_model( root_props );
}
namespace simgear
{
SGPropertyNode* getPropertyRoot()
{
return root_props;
}
}

View File

@@ -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