]> git.mxchange.org Git - simgear.git/commitdiff
Move propertyExpression code from flightgear to simgear
authorTim Moore <timoore@redhat.com>
Mon, 9 Nov 2009 12:28:11 +0000 (13:28 +0100)
committerTim Moore <timoore@redhat.com>
Mon, 9 Nov 2009 14:53:10 +0000 (15:53 +0100)
Also add a function (possibly redundant) to access the global property
root.

simgear/scene/material/Effect.cxx
simgear/scene/tgdb/userdata.cxx
simgear/scene/tgdb/userdata.hxx

index b36702adaaebdc95e0d299d5c720bd2c25c5f19b..14ad2022c059465423136695ec363c1ab6e50bc6 100644 (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);
+
 }
index fab67b2fcedd11bb4f67b625ed1de7d2a975ac24..11d69e12f7fafa64f66a66cf1aaa816843cc6bff 100644 (file)
@@ -64,3 +64,10 @@ osg::Node* sgGetRandomModel(SGMatModel *obj) {
    return obj->get_random_model( root_props );
  }
 
+namespace simgear
+{
+SGPropertyNode* getPropertyRoot()
+{
+    return root_props;
+}
+}
index e5a870e3ae4bc03604c2c80d72efa818b3e8ecea..ab0a6a559c2e64e41d6a4716f23d35efb267263c 100644 (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