From a76d6936274042d92638a6bb96dc5ccd4ce91035 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 3 Feb 2017 23:10:14 +0100 Subject: [PATCH] Speed up ControllerVisitor by skipping sub graphs that have no ChildrenRequiringUpdateTraversal() --- apps/openmw/mwrender/npcanimation.cpp | 63 ++++++++++++++------------- components/sceneutil/controller.cpp | 3 +- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 53eaf0996d..e850086793 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -770,43 +770,46 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g } } - boost::shared_ptr src; - if (type == ESM::PRT_Head) + osg::Node* node = mObjectParts[type]->getNode(); + if (node->getNumChildrenRequiringUpdateTraversal() > 0) { - src = mHeadAnimationTime; - - osg::Node* node = mObjectParts[type]->getNode(); - if (node->getUserDataContainer()) + boost::shared_ptr src; + if (type == ESM::PRT_Head) { - for (unsigned int i=0; igetUserDataContainer()->getNumUserObjects(); ++i) - { - osg::Object* obj = node->getUserDataContainer()->getUserObject(i); - if (NifOsg::TextKeyMapHolder* keys = dynamic_cast(obj)) - { - for (NifOsg::TextKeyMap::const_iterator it = keys->mTextKeys.begin(); it != keys->mTextKeys.end(); ++it) - { - if (Misc::StringUtils::ciEqual(it->second, "talk: start")) - mHeadAnimationTime->setTalkStart(it->first); - if (Misc::StringUtils::ciEqual(it->second, "talk: stop")) - mHeadAnimationTime->setTalkStop(it->first); - if (Misc::StringUtils::ciEqual(it->second, "blink: start")) - mHeadAnimationTime->setBlinkStart(it->first); - if (Misc::StringUtils::ciEqual(it->second, "blink: stop")) - mHeadAnimationTime->setBlinkStop(it->first); - } + src = mHeadAnimationTime; - break; + if (node->getUserDataContainer()) + { + for (unsigned int i=0; igetUserDataContainer()->getNumUserObjects(); ++i) + { + osg::Object* obj = node->getUserDataContainer()->getUserObject(i); + if (NifOsg::TextKeyMapHolder* keys = dynamic_cast(obj)) + { + for (NifOsg::TextKeyMap::const_iterator it = keys->mTextKeys.begin(); it != keys->mTextKeys.end(); ++it) + { + if (Misc::StringUtils::ciEqual(it->second, "talk: start")) + mHeadAnimationTime->setTalkStart(it->first); + if (Misc::StringUtils::ciEqual(it->second, "talk: stop")) + mHeadAnimationTime->setTalkStop(it->first); + if (Misc::StringUtils::ciEqual(it->second, "blink: start")) + mHeadAnimationTime->setBlinkStart(it->first); + if (Misc::StringUtils::ciEqual(it->second, "blink: stop")) + mHeadAnimationTime->setBlinkStop(it->first); + } + + break; + } } } } - } - else if (type == ESM::PRT_Weapon) - src = mWeaponAnimationTime; - else - src.reset(new NullAnimationTime); + else if (type == ESM::PRT_Weapon) + src = mWeaponAnimationTime; + else + src.reset(new NullAnimationTime); - SceneUtil::AssignControllerSourcesVisitor assignVisitor(src); - mObjectParts[type]->getNode()->accept(assignVisitor); + SceneUtil::AssignControllerSourcesVisitor assignVisitor(src); + node->accept(assignVisitor); + } return true; } diff --git a/components/sceneutil/controller.cpp b/components/sceneutil/controller.cpp index 12c89c87d0..15a614880b 100644 --- a/components/sceneutil/controller.cpp +++ b/components/sceneutil/controller.cpp @@ -81,7 +81,8 @@ namespace SceneUtil callback = callback->getNestedCallback(); } - traverse(node); + if (node.getNumChildrenRequiringUpdateTraversal() > 0) + traverse(node); } AssignControllerSourcesVisitor::AssignControllerSourcesVisitor()