On Feb 9, 2008 12:29 PM, Vivian Meazza <[EMAIL PROTECTED]> wrote:
>
> I would be pleasantly surprised if <condition> worked in materials.xml

Here you go :)

As a side effect, we could get rid of the ugly code that makes
"Terrain.<season>" out of "Terrain" at the expense of some more xml.

I attached a patch against Syd's new materials.xml as well.

-- 
Greets,
Csaba/Jester
Index: src/Main/fg_init.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Main/fg_init.cxx,v
retrieving revision 1.192
@@ -1613,7 +1613,7 @@
     SGPath mpath( globals->get_fg_root() );
     mpath.append( "materials.xml" );
     string season = fgGetString("/sim/startup/season", "summer");
-    if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(), 
season.c_str()) ) {
+    if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(), 
season.c_str(), globals->get_props()) ) {
         SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
         exit(-1);
     }
Index: simgear/scene/material/matlib.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/material/matlib.cxx,v
retrieving revision 1.29
diff -u -r1.29 matlib.cxx
--- simgear/scene/material/matlib.cxx   24 Jan 2008 23:05:19 -0000      1.29
+++ simgear/scene/material/matlib.cxx   10 Feb 2008 21:28:06 -0000
@@ -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,7 +78,7 @@
 }
 
 // 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;
 
@@ -94,6 +95,16 @@
     for (int i = 0; i < nMaterials; 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: simgear/scene/material/matlib.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/source/simgear/scene/material/matlib.hxx,v
retrieving revision 1.16
diff -u -r1.16 matlib.hxx
--- simgear/scene/material/matlib.hxx   24 Jan 2008 23:05:19 -0000      1.16
+++ simgear/scene/material/matlib.hxx   10 Feb 2008 21:28:06 -0000
@@ -41,6 +41,7 @@
 #include <osg/StateSet>
 
 class SGMaterial;
+class SGPropertyNode;
 
 SG_USING_STD(string);
 SG_USING_STD(map);
@@ -65,7 +66,7 @@
     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 );
--- materials.xml.test  2008-02-10 00:30:00.000000000 +0100
+++ materials.xml       2008-02-10 22:37:09.000000000 +0100
@@ -657,6 +657,12 @@
 
 <!-- Coniferous Summer-->
 <material>
+ <condition>
+  <not-equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </not-equals>
+ </condition>
  <name>Landmass</name>
  <name>SomeSort</name>
  <name>EvergreenBroadCover</name>
@@ -679,6 +685,12 @@
 </material>
 
 <material>
+ <condition>
+  <not-equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </not-equals>
+ </condition>
  <name>EvergreenNeedleCover</name>
  <name>WoodedTundraCover</name>
  <texture>Terrain/evergreen.rgb</texture>
@@ -696,6 +708,12 @@
 </material>
 
 <material>
+ <condition>
+  <not-equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </not-equals>
+ </condition>
  <name>DeciduousNeedleCover</name>
  <texture>Terrain/dec_evergreen.rgb</texture>
  <xsize>1000</xsize>
@@ -711,14 +729,14 @@
  <bumpiness>1</bumpiness>
 </material>
 
-<!-- Coniferous Winter
+<!-- Coniferous Winter -->
 
 <material>
  <condition>
- <equals>
- <property>sim/startup/season</property>
- <value>winter</value>
- </equals>
+  <equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </equals>
  </condition>
  <name>Landmass</name>
  <name>SomeSort</name>
@@ -741,10 +759,10 @@
 
 <material>
  <condition>
- <equals>
- <property>sim/startup/season</property>
- <value>winter</value>
- </equals>
+  <equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </equals>
  </condition>
  <name>EvergreenNeedleCover</name>
  <name>WoodedTundraCover</name>
@@ -764,10 +782,10 @@
 
 <material>
  <condition>
- <equals>
- <property>sim/startup/season</property>
- <value>winter</value>
- </equals>
+  <equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </equals>
  </condition>
  <name>DeciduousNeedleCover</name>
  <texture>Terrain.winter/forest1.rgb</texture>
@@ -783,11 +801,22 @@
  <rolling-friction>1</rolling-friction>
  <bumpiness>1</bumpiness>
 </material>
--->
 
 <!-- Deciduous/Mixed  Summer-->
 
 <material>
+ <condition>
+  <or>
+   <equals>
+    <property>sim/startup/season</property>
+    <value>summer</value>
+   </equals>
+   <equals>
+    <property>sim/startup/season</property>
+    <value>spring</value>
+   </equals>
+  </or>
+ </condition>
  <name>DeciduousBroadCover</name>
  <name>Bog</name>
  <texture>Terrain/deciduous1.rgb</texture>
@@ -807,6 +836,18 @@
 </material>
 
 <material>
+ <condition>
+  <or>
+   <equals>
+    <property>sim/startup/season</property>
+    <value>summer</value>
+   </equals>
+   <equals>
+    <property>sim/startup/season</property>
+    <value>spring</value>
+   </equals>
+  </or>
+ </condition>
  <name>MixedForestCover</name>
  <texture>Terrain/mixedforest.rgb</texture>
  <texture>Terrain/mixedforest2.rgb</texture>
@@ -824,14 +865,14 @@
  <bumpiness>0.95</bumpiness>
 </material>
 
-<!-- Deciduous/Mixed  Fall
+<!-- Deciduous/Mixed  Fall -->
 
 <material>
  <condition>
- <equals>
- <property>sim/startup/season</property>
- <value>fall</value>
- </equals>
+  <equals>
+   <property>sim/startup/season</property>
+   <value>fall</value>
+  </equals>
  </condition>
  <name>DeciduousBroadCover</name>
  <name>Bog</name>
@@ -853,10 +894,10 @@
 
 <material>
  <condition>
- <equals>
- <property>sim/startup/season</property>
- <value>fall</value>
- </equals>
+  <equals>
+   <property>sim/startup/season</property>
+   <value>fall</value>
+  </equals>
  </condition>
  <name>MixedForestCover</name>
  <texture>Terrain/mixedforest.rgb</texture>
@@ -874,16 +915,15 @@
  <rolling-friction>1</rolling-friction>
  <bumpiness>0.95</bumpiness>
 </material>
--->
 
-<!-- Deciduous/Mixed  Winter
+<!-- Deciduous/Mixed  Winter -->
 
 <material>
  <condition>
- <equals>
- <property>sim/startup/season</property>
- <value>winter</value>
- </equals>
+  <equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </equals>
  </condition>
  <name>DeciduousBroadCover</name>
  <name>Bog</name>
@@ -903,10 +943,10 @@
 
 <material>
  <condition>
- <equals>
- <property>sim/startup/season</property>
- <value>winter</value>
- </equals>
+  <equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </equals>
  </condition>
  <name>MixedForestCover</name>
  <texture>Terrain.winter/forest1.rgb</texture>
@@ -922,7 +962,6 @@
  <rolling-friction>1</rolling-friction>
  <bumpiness>0.95</bumpiness>
 </material>
--->
 
 <material>
  <name>Sand</name>
@@ -1197,6 +1236,12 @@
 </material>
 
 <material>
+ <condition>
+  <not-equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </not-equals>
+ </condition>
  <name>Lake</name>
  <name>Pond</name>
  <name>Reservoir</name>
@@ -1229,13 +1274,12 @@
  <bumpiness>0.6</bumpiness>
 </material>
 
-<!--
 <material>
  <condition>
- <equals>
- <property>sim/startup/season</property>
- <value>winter</value>
- </equals>
+  <equals>
+   <property>sim/startup/season</property>
+   <value>winter</value>
+  </equals>
  </condition>
  <name>Lake</name>
  <name>Pond</name>
@@ -1268,7 +1312,6 @@
  <rolling-friction>0.5</rolling-friction>
  <bumpiness>0.1</bumpiness>
 </material>
--->
 
 <material>
  <name>IntermittentStream</name>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to