X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmaterial%2FEffectBuilder.hxx;h=52e2cf1c98614a2e0c4dee3ea65ff3bf679d7584;hb=f33ad357e928b5210c87cb8977d3cc88deba811b;hp=c9b49e3d986956bf2653d6e37a003e33214e3db6;hpb=cc37713a66345ce3e88d66dbc12a4b6b677134ad;p=simgear.git diff --git a/simgear/scene/material/EffectBuilder.hxx b/simgear/scene/material/EffectBuilder.hxx index c9b49e3d..52e2cf1c 100644 --- a/simgear/scene/material/EffectBuilder.hxx +++ b/simgear/scene/material/EffectBuilder.hxx @@ -167,7 +167,7 @@ EffectPropertyMap::EffectPropertyMap(const EffectNameValue (&attrs)[N]) template struct SimplePropertyMap { - typedef std::map map_type; + typedef std::map map_type; map_type _map; template SimplePropertyMap(const EffectNameValue (&attrs)[N]) @@ -195,10 +195,10 @@ void findAttr(const effect::EffectPropertyMap& pMap, { using namespace effect; typename EffectPropertyMap::BMap::iterator itr - = pMap._map.get().find(name); + = pMap._map.template get().find(name); if (itr == pMap._map.end()) { - throw effect::BuilderException(string("findAttr: could not find attribute ") - + string(name)); + throw effect::BuilderException(std::string("findAttr: could not find attribute ") + + std::string(name)); } else { result = itr->second; } @@ -233,7 +233,7 @@ const T* findAttr(const effect::EffectPropertyMap& pMap, { using namespace effect; typename EffectPropertyMap::BMap::iterator itr - = pMap._map.get().find(name); + = pMap._map.template get().find(name); if (itr == pMap._map.end()) return 0; else @@ -267,8 +267,8 @@ std::string findName(const effect::EffectPropertyMap& pMap, T value) using namespace effect; std::string result; typename EffectPropertyMap::BMap::template index_iterator::type itr - = pMap._map.get().find(value); - if (itr != pMap._map.get().end()) + = pMap._map.template get().find(value); + if (itr != pMap._map.template get().end()) result = itr->first; return result; } @@ -295,9 +295,9 @@ const SGPropertyNode* getEffectPropertyChild(Effect* effect, const char* name); /** - * Get the name of a node mentioned in a clause from the global property + * Get the name of a node mentioned in a \ clause from the global property * tree. - * @return empty if prop doesn't contain a clause; otherwise the + * @return empty if prop doesn't contain a \ clause; otherwise the * mentioned node name. */ std::string getGlobalProperty(const SGPropertyNode* prop, @@ -316,7 +316,7 @@ getVectorProperties(const SGPropertyNode* prop, PropertyList useProps = prop->getChildren("use"); if (useProps.size() == 1) { string parentName = useProps[0]->getStringValue(); - if (parentName.size() == 0 || parentName[0] != '/') + if (parentName.empty() || parentName[0] != '/') parentName = options->getPropertyNode()->getPath() + "/" + parentName; if (parentName[parentName.size() - 1] != '/') parentName.append("/"); @@ -331,7 +331,7 @@ getVectorProperties(const SGPropertyNode* prop, itr != end; ++itr) { string childName = (*itr)->getStringValue(); - if (childName.size() == 0 || childName[0] != '/') + if (childName.empty() || childName[0] != '/') result.push_back(parentName + childName); else result.push_back(childName); @@ -373,7 +373,7 @@ public: template struct InstallAttributeBuilder { - InstallAttributeBuilder(const string& name) + InstallAttributeBuilder(const std::string& name) { PassAttributeBuilder::PassAttrMapSingleton::instance() ->passAttrMap.insert(make_pair(name, new T)); @@ -496,19 +496,17 @@ make_OSGFunctor(Obj* obj, void (Obj::*const func)(const OSGParam&)) template class ScalarChangeListener : public SGPropertyChangeListener, public InitializeWhenAdded, + public PropertyPoller, public Effect::Updater { public: ScalarChangeListener(ObjType* obj, const F& setter, const std::string& propName) - : _obj(obj), _setter(setter) + : _obj(obj), _setter(setter), _propName(propName) { - _propName = new std::string(propName); } virtual ~ScalarChangeListener() { - delete _propName; - _propName = 0; } void valueChanged(SGPropertyNode* node) { @@ -516,16 +514,20 @@ public: } void initOnAddImpl(Effect* effect, SGPropertyNode* propRoot) { - SGPropertyNode* listenProp = makeNode(propRoot, *_propName); - delete _propName; - _propName = 0; - if (listenProp) - listenProp->addChangeListener(this, true); + _listenProp = makeNode(propRoot, _propName); +// if ( _listenProp.valid() ) +// _listenProp->addChangeListener(this, true); + } + void pollProperties(Effect* effect) + { + if( false == _listenProp.valid() ) return; + valueChanged(_listenProp); } private: + SGPropertyNode_ptr _listenProp; osg::ref_ptr _obj; F _setter; - std::string* _propName; + std::string _propName; }; template @@ -597,9 +599,9 @@ inline void setDynamicVariance(osg::Object* obj) /** * Initialize the value and the possible updating of an effect * attribute. If the value is specified directly, set it. Otherwise, - * use the tag to look at the parameters. Again, if there is a + * use the \ tag to look at the parameters. Again, if there is a * value there set it directly. Otherwise, the parameter contains its - * own tag referring to a property in the global property tree; + * own \ tag referring to a property in the global property tree; * install a change listener that will set the attribute when the * property changes. * @@ -614,10 +616,10 @@ initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj, const SGPropertyNode* valProp = getEffectPropertyNode(effect, prop); if (!valProp) return; - setDynamicVariance(obj); if (valProp->nChildren() == 0) { setter(obj, valProp->getValue()); } else { + setDynamicVariance(obj); std::string propName = getGlobalProperty(valProp, options); ScalarChangeListener* listener = new ScalarChangeListener(obj, setter, @@ -641,12 +643,12 @@ initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj, * The parameter may be updated at runtime. * * If the value is specified directly, set it. Otherwise, use the - * tag to look at the parameters. Again, if there is a value + * \ tag to look at the parameters. Again, if there is a value * there set it directly. Otherwise, the parameter contains one or several - * tags. If there is one tag, it is a property that is the root + * \ tags. If there is one tag, it is a property that is the root * for the values needed to update the parameter; nameIter holds the * names of the properties relative to the root. If there are several - * tags, they each hold the name of the property holding the + * \ tags, they each hold the name of the property holding the * value for the corresponding vector member. * * Install a change listener that will set the attribute when the @@ -667,10 +669,10 @@ initFromParameters(Effect* effect, const SGPropertyNode* prop, ObjType* obj, const SGPropertyNode* valProp = getEffectPropertyNode(effect, prop); if (!valProp) return; - setDynamicVariance(obj); if (valProp->nChildren() == 0) { // Has ? setter(obj, Bridge::get(valProp->getValue())); } else { + setDynamicVariance(obj); std::vector paramNames = getVectorProperties(valProp, options,numComponents, nameItr); if (paramNames.empty())