From 6b874e397b030ef042ae0426551fdceca290dc89 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Wed, 29 Apr 2020 12:25:52 +0300 Subject: [PATCH] Make particle system cloning map names more sensible --- components/sceneutil/clone.cpp | 24 ++++++++++++------------ components/sceneutil/clone.hpp | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/components/sceneutil/clone.cpp b/components/sceneutil/clone.cpp index 0423d61171..0df0f4a5b2 100644 --- a/components/sceneutil/clone.cpp +++ b/components/sceneutil/clone.cpp @@ -47,7 +47,7 @@ namespace SceneUtil if (const osgParticle::ParticleSystemUpdater* updater = dynamic_cast(node)) { osgParticle::ParticleSystemUpdater* cloned = new osgParticle::ParticleSystemUpdater(*updater, osg::CopyOp::SHALLOW_COPY); - mMap2[cloned] = updater->getParticleSystem(0); + mUpdaterToOldPs[cloned] = updater->getParticleSystem(0); return cloned; } return osg::CopyOp::operator()(node); @@ -69,16 +69,16 @@ namespace SceneUtil osgParticle::ParticleProcessor* CopyOp::operator() (const osgParticle::ParticleProcessor* processor) const { osgParticle::ParticleProcessor* cloned = osg::clone(processor, osg::CopyOp::DEEP_COPY_CALLBACKS); - for (std::map::const_iterator it = mMap3.begin(); it != mMap3.end(); ++it) + for (const auto& oldPsNewPsPair : mOldPsToNewPs) { - if (processor->getParticleSystem() == it->first) + if (processor->getParticleSystem() == oldPsNewPsPair.first) { - cloned->setParticleSystem(it->second); + cloned->setParticleSystem(oldPsNewPsPair.second); return cloned; } } - mMap[cloned] = processor->getParticleSystem(); + mProcessorToOldPs[cloned] = processor->getParticleSystem(); return cloned; } @@ -86,24 +86,24 @@ namespace SceneUtil { osgParticle::ParticleSystem* cloned = osg::clone(partsys, *this); - for (std::map::const_iterator it = mMap.begin(); it != mMap.end(); ++it) + for (const auto& processorPsPair : mProcessorToOldPs) { - if (it->second == partsys) + if (processorPsPair.second == partsys) { - it->first->setParticleSystem(cloned); + processorPsPair.first->setParticleSystem(cloned); } } - for (std::map::const_iterator it = mMap2.begin(); it != mMap2.end(); ++it) + for (const auto& updaterPsPair : mUpdaterToOldPs) { - if (it->second == partsys) + if (updaterPsPair.second == partsys) { - osgParticle::ParticleSystemUpdater* updater = it->first; + osgParticle::ParticleSystemUpdater* updater = updaterPsPair.first; updater->removeParticleSystem(updater->getParticleSystem(0)); updater->addParticleSystem(cloned); } } // In rare situations a particle processor may be placed after the particle system in the scene graph. - mMap3[partsys] = cloned; + mOldPsToNewPs[partsys] = cloned; return cloned; } diff --git a/components/sceneutil/clone.hpp b/components/sceneutil/clone.hpp index b0a9d56c3e..20788799fa 100644 --- a/components/sceneutil/clone.hpp +++ b/components/sceneutil/clone.hpp @@ -37,9 +37,9 @@ namespace SceneUtil private: // maps new pointers to their old pointers // a little messy, but I think this should be the most efficient way - mutable std::map mMap; - mutable std::map mMap2; - mutable std::map mMap3; + mutable std::map mProcessorToOldPs; + mutable std::map mUpdaterToOldPs; + mutable std::map mOldPsToNewPs; }; }