Speed up ControllerVisitor by skipping sub graphs that have no ChildrenRequiringUpdateTraversal()

This commit is contained in:
scrawl 2017-02-03 23:10:14 +01:00
parent c58fc6d276
commit a76d693627
2 changed files with 35 additions and 31 deletions

View file

@ -770,43 +770,46 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
} }
} }
boost::shared_ptr<SceneUtil::ControllerSource> src; osg::Node* node = mObjectParts[type]->getNode();
if (type == ESM::PRT_Head) if (node->getNumChildrenRequiringUpdateTraversal() > 0)
{ {
src = mHeadAnimationTime; boost::shared_ptr<SceneUtil::ControllerSource> src;
if (type == ESM::PRT_Head)
osg::Node* node = mObjectParts[type]->getNode();
if (node->getUserDataContainer())
{ {
for (unsigned int i=0; i<node->getUserDataContainer()->getNumUserObjects(); ++i) src = mHeadAnimationTime;
{
osg::Object* obj = node->getUserDataContainer()->getUserObject(i);
if (NifOsg::TextKeyMapHolder* keys = dynamic_cast<NifOsg::TextKeyMapHolder*>(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; if (node->getUserDataContainer())
{
for (unsigned int i=0; i<node->getUserDataContainer()->getNumUserObjects(); ++i)
{
osg::Object* obj = node->getUserDataContainer()->getUserObject(i);
if (NifOsg::TextKeyMapHolder* keys = dynamic_cast<NifOsg::TextKeyMapHolder*>(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)
else if (type == ESM::PRT_Weapon) src = mWeaponAnimationTime;
src = mWeaponAnimationTime; else
else src.reset(new NullAnimationTime);
src.reset(new NullAnimationTime);
SceneUtil::AssignControllerSourcesVisitor assignVisitor(src); SceneUtil::AssignControllerSourcesVisitor assignVisitor(src);
mObjectParts[type]->getNode()->accept(assignVisitor); node->accept(assignVisitor);
}
return true; return true;
} }

View file

@ -81,7 +81,8 @@ namespace SceneUtil
callback = callback->getNestedCallback(); callback = callback->getNestedCallback();
} }
traverse(node); if (node.getNumChildrenRequiringUpdateTraversal() > 0)
traverse(node);
} }
AssignControllerSourcesVisitor::AssignControllerSourcesVisitor() AssignControllerSourcesVisitor::AssignControllerSourcesVisitor()