From 2883a36c76913d58205eeb92b96bd507f9383eaa Mon Sep 17 00:00:00 2001 From: mfranz Date: Fri, 15 Feb 2008 17:54:01 +0000 Subject: [PATCH] Csaba HALASZ: implement conditional (e.g. seasonal) texture loading at startup --- simgear/scene/material/matlib.cxx | 18 +++++++++++++++--- simgear/scene/material/matlib.hxx | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/simgear/scene/material/matlib.cxx b/simgear/scene/material/matlib.cxx index ba8ef9ab..b02aac76 100644 --- a/simgear/scene/material/matlib.cxx +++ b/simgear/scene/material/matlib.cxx @@ -63,6 +63,7 @@ #include #include #include +#include #include #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 condition = sgReadCondition(prop_root, conditionNode); + if (!condition->test()) { + SG_LOG(SG_INPUT, SG_DEBUG, "Skipping material entry #" + << i << " (condition false)"); + continue; + } + } + SGSharedPtr m = new SGMaterial(fg_root, node, season); vectornames = node->getChildren("name"); diff --git a/simgear/scene/material/matlib.hxx b/simgear/scene/material/matlib.hxx index 1407e44f..3b1fb318 100644 --- a/simgear/scene/material/matlib.hxx +++ b/simgear/scene/material/matlib.hxx @@ -41,6 +41,7 @@ #include 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 ); -- 2.39.5