From: Frederic Bouvier Date: Sun, 29 Apr 2012 11:25:15 +0000 (+0200) Subject: Use observer_ptr to cache light effects X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=87c744b88ba583e855366f62b564dd2c72f19b72;p=simgear.git Use observer_ptr to cache light effects --- diff --git a/simgear/scene/model/SGLightAnimation.cxx b/simgear/scene/model/SGLightAnimation.cxx index 6215efd9..2fc90a8d 100644 --- a/simgear/scene/model/SGLightAnimation.cxx +++ b/simgear/scene/model/SGLightAnimation.cxx @@ -34,7 +34,7 @@ #include #include -typedef std::map > EffectMap; +typedef std::map > EffectMap; static EffectMap lightEffectMap; #define GET_COLOR_VALUE(n) \ @@ -60,9 +60,9 @@ public: if (dim != _prev_values[_key]) { _prev_values[_key] = dim; + osg::ref_ptr effect; EffectMap::iterator iter = lightEffectMap.find(_key); - if (iter != lightEffectMap.end()) { - simgear::Effect* effect = iter->second; + if (iter != lightEffectMap.end() && iter->second.lock(effect)) { SGPropertyNode* params = effect->parametersProp; params->getNode("ambient")->setValue(_ambient * dim); params->getNode("diffuse")->setValue(_diffuse * dim); @@ -143,9 +143,9 @@ SGLightAnimation::install(osg::Node& node) if (_light_type == "spot") { - simgear::Effect* effect = 0; + osg::ref_ptr effect; EffectMap::iterator iter = lightEffectMap.find(_key); - if (iter == lightEffectMap.end()) { + if (iter == lightEffectMap.end() || !iter->second.lock(effect)) { SGPropertyNode_ptr effectProp = new SGPropertyNode; makeChild(effectProp, "name")->setStringValue(_key); makeChild(effectProp, "inherits-from")->setStringValue("Effects/light-spot"); @@ -167,7 +167,10 @@ SGLightAnimation::install(osg::Node& node) params->getNode("far",true)->setValue(_far); effect = simgear::makeEffect(effectProp, true); - lightEffectMap.insert(EffectMap::value_type(_key, effect)); + if (iter==lightEffectMap.end()) + lightEffectMap.insert(EffectMap::value_type(_key, effect)); + else + iter->second = effect; } else { effect = iter->second.get(); } @@ -187,9 +190,9 @@ SGLightAnimation::install(osg::Node& node) } else if (_light_type == "point") { - simgear::Effect* effect = 0; + osg::ref_ptr effect; EffectMap::iterator iter = lightEffectMap.find(_key); - if (iter == lightEffectMap.end()) { + if (iter == lightEffectMap.end() || !iter->second.lock(effect)) { SGPropertyNode_ptr effectProp = new SGPropertyNode; makeChild(effectProp, "name")->setStringValue(_key); makeChild(effectProp, "inherits-from")->setStringValue("Effects/light-point"); @@ -207,7 +210,10 @@ SGLightAnimation::install(osg::Node& node) params->getNode("far",true)->setValue(_far); effect = simgear::makeEffect(effectProp, true); - lightEffectMap.insert(EffectMap::value_type(_key, effect)); + if (iter==lightEffectMap.end()) + lightEffectMap.insert(EffectMap::value_type(_key, effect)); + else + iter->second = effect; } else { effect = iter->second.get(); }