]> git.mxchange.org Git - simgear.git/commitdiff
Csaba HALASZ: implement conditional (e.g. seasonal) texture loading at startup
authormfranz <mfranz>
Fri, 15 Feb 2008 17:54:01 +0000 (17:54 +0000)
committermfranz <mfranz>
Fri, 15 Feb 2008 17:54:01 +0000 (17:54 +0000)
simgear/scene/material/matlib.cxx
simgear/scene/material/matlib.hxx

index ba8ef9abb0df6faee2accfb84d565d2cda964ffa..b02aac76dd51dce5af0c3ddd3a57faea667a16cb 100644 (file)
@@ -63,6 +63,7 @@
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/props/condition.hxx>
 #include <simgear/scene/tgdb/userdata.hxx>
 
 #include "mat.hxx"
@@ -77,8 +78,9 @@ SGMaterialLib::SGMaterialLib ( void ) {
 }
 
 // Load a library of material properties
-bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char *season ) {
-
+bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char *season,
+        SGPropertyNode *prop_root )
+{
     SGPropertyNode materials;
 
     SG_LOG( SG_INPUT, SG_INFO, "Reading materials from " << mpath );
@@ -92,8 +94,18 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
 
     int nMaterials = materials.nChildren();
     for (int i = 0; i < nMaterials; i++) {
-        const SGPropertyNode * node = materials.getChild(i);
+        const SGPropertyNode *node = materials.getChild(i);
         if (!strcmp(node->getName(), "material")) {
+            const SGPropertyNode *conditionNode = node->getChild("condition");
+            if (conditionNode) {
+                SGSharedPtr<const SGCondition> condition = sgReadCondition(prop_root, conditionNode);
+                if (!condition->test()) {
+                    SG_LOG(SG_INPUT, SG_DEBUG, "Skipping material entry #"
+                        << i << " (condition false)");
+                    continue;
+                }
+            }
+
             SGSharedPtr<SGMaterial> m = new SGMaterial(fg_root, node, season);
 
             vector<SGPropertyNode_ptr>names = node->getChildren("name");
index 1407e44f5b3680a6745564b9cdc39435c0ea3dec..3b1fb3189ec513f9d27a199be5b97e639d2e0956 100644 (file)
@@ -41,6 +41,7 @@
 #include <osg/StateSet>
 
 class SGMaterial;
+class SGPropertyNode;
 
 SG_USING_STD(string);
 SG_USING_STD(map);
@@ -65,7 +66,8 @@ public:
     SGMaterialLib ( void );
 
     // Load a library of material properties
-    bool load( const string &fg_root, const string& mpath, const char *season );
+    bool load( const string &fg_root, const string& mpath, const char *season,
+            SGPropertyNode *prop_root );
 
     // Add the named texture with default properties
     bool add_item( const string &tex_path );