]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/matlib.cxx
Random buildings - initial commit.
[simgear.git] / simgear / scene / material / matlib.cxx
index f82cb2599d955ba2eb6b902e39ebdfd788710720..822147250f6ec1cb97a3747c0eb265302d11f092 100644 (file)
 #  include <simgear_config.h>
 #endif
 
-#if defined ( __CYGWIN__ )
-#include <ieeefp.h>
-#endif
-
 #include <simgear/compiler.h>
 #include <simgear/constants.h>
 #include <simgear/structure/exception.hxx>
@@ -71,31 +67,21 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath,
                 << ex.getMessage() );
         throw;
     }
-    osg::ref_ptr<osgDB::ReaderWriter::Options> options
-        = new osgDB::ReaderWriter::Options;
-    options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL);
+    osg::ref_ptr<osgDB::Options> options
+        = new osgDB::Options;
+    options->setObjectCacheHint(osgDB::Options::CACHE_ALL);
     options->setDatabasePath(fg_root);
     int nMaterials = materials.nChildren();
     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(options.get(), node);
+            SGSharedPtr<SGMaterial> m = new SGMaterial(options.get(), node, prop_root);
 
             vector<SGPropertyNode_ptr>names = node->getChildren("name");
             for ( unsigned int j = 0; j < names.size(); j++ ) {
                 string name = names[j]->getStringValue();
                 // cerr << "Material " << name << endl;
-                matlib[name] = m;
+                matlib[name].push_back(m);
                 m->add_name(name);
                 SG_LOG( SG_TERRAIN, SG_DEBUG, "  Loading material "
                         << names[j]->getStringValue() );
@@ -113,9 +99,19 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath,
 SGMaterial *SGMaterialLib::find( const string& material ) {
     SGMaterial *result = NULL;
     material_map_iterator it = matlib.find( material );
-    if ( it != end() ) {
-       result = it->second;
-       return result;
+    if ( it != end() ) {            
+        // We now have a list of materials that match this
+        // name. Find the first one that either doesn't have
+        // a condition, or has a condition that evaluates
+        // to true.
+        material_list_iterator iter = it->second.begin();        
+        while (iter != it->second.end()) {            
+            result = *iter;
+            if (result->valid()) {
+                return result;
+            }
+            iter++;
+        }
     }
 
     return NULL;
@@ -126,8 +122,7 @@ SGMaterialLib::~SGMaterialLib ( void ) {
     SG_LOG( SG_GENERAL, SG_INFO, "SGMaterialLib::~SGMaterialLib() size=" << matlib.size());
 }
 
-const SGMaterial*
-SGMaterialLib::findMaterial(const osg::Geode* geode)
+const SGMaterial *SGMaterialLib::findMaterial(const osg::Geode* geode)
 {
     if (!geode)
         return 0;