1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 05:15:33 +00:00

Use vector for Animation::mActiveControllers

Container is only used to add elements, iterate over all of them and
clear. Multimap adds overhead for all of these operations without any
benefits. Reduce Animation::resetActiveGroups CPU time usage by 50%.
This commit is contained in:
elsid 2020-05-21 17:23:32 +02:00
parent 61fbc1cd0b
commit 9326111f4c
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
5 changed files with 11 additions and 10 deletions

View file

@ -1064,7 +1064,7 @@ namespace MWRender
void Animation::resetActiveGroups() void Animation::resetActiveGroups()
{ {
// remove all previous external controllers from the scene graph // remove all previous external controllers from the scene graph
for (ControllerMap::iterator it = mActiveControllers.begin(); it != mActiveControllers.end(); ++it) for (auto it = mActiveControllers.begin(); it != mActiveControllers.end(); ++it)
{ {
osg::Node* node = it->first; osg::Node* node = it->first;
node->removeUpdateCallback(it->second); node->removeUpdateCallback(it->second);
@ -1103,7 +1103,7 @@ namespace MWRender
osg::ref_ptr<osg::Node> node = getNodeMap().at(it->first); // this should not throw, we already checked for the node existing in addAnimSource osg::ref_ptr<osg::Node> node = getNodeMap().at(it->first); // this should not throw, we already checked for the node existing in addAnimSource
node->addUpdateCallback(it->second); node->addUpdateCallback(it->second);
mActiveControllers.insert(std::make_pair(node, it->second)); mActiveControllers.emplace_back(node, it->second);
if (blendMask == 0 && node == mAccumRoot) if (blendMask == 0 && node == mAccumRoot)
{ {
@ -1116,7 +1116,7 @@ namespace MWRender
mResetAccumRootCallback->setAccumulate(mAccumulate); mResetAccumRootCallback->setAccumulate(mAccumulate);
} }
mAccumRoot->addUpdateCallback(mResetAccumRootCallback); mAccumRoot->addUpdateCallback(mResetAccumRootCallback);
mActiveControllers.insert(std::make_pair(mAccumRoot, mResetAccumRootCallback)); mActiveControllers.emplace_back(mAccumRoot, mResetAccumRootCallback);
} }
} }
} }
@ -1850,7 +1850,7 @@ namespace MWRender
{ {
mHeadController = new RotateController(mObjectRoot.get()); mHeadController = new RotateController(mObjectRoot.get());
node->addUpdateCallback(mHeadController); node->addUpdateCallback(mHeadController);
mActiveControllers.insert(std::make_pair(node, mHeadController)); mActiveControllers.emplace_back(node, mHeadController);
} }
} }
} }

View file

@ -6,6 +6,8 @@
#include <components/sceneutil/controller.hpp> #include <components/sceneutil/controller.hpp>
#include <components/sceneutil/util.hpp> #include <components/sceneutil/util.hpp>
#include <vector>
namespace ESM namespace ESM
{ {
struct Light; struct Light;
@ -246,8 +248,7 @@ protected:
// Keep track of controllers that we added to our scene graph. // Keep track of controllers that we added to our scene graph.
// We may need to rebuild these controllers when the active animation groups / sources change. // We may need to rebuild these controllers when the active animation groups / sources change.
typedef std::multimap<osg::ref_ptr<osg::Node>, osg::ref_ptr<osg::NodeCallback> > ControllerMap; std::vector<std::pair<osg::ref_ptr<osg::Node>, osg::ref_ptr<osg::NodeCallback>>> mActiveControllers;
ControllerMap mActiveControllers;
std::shared_ptr<AnimationTime> mAnimationTimePtr[sNumBlendMasks]; std::shared_ptr<AnimationTime> mAnimationTimePtr[sNumBlendMasks];

View file

@ -956,7 +956,7 @@ void NpcAnimation::addControllers()
osg::MatrixTransform* node = found->second.get(); osg::MatrixTransform* node = found->second.get();
mFirstPersonNeckController = new NeckController(mObjectRoot.get()); mFirstPersonNeckController = new NeckController(mObjectRoot.get());
node->addUpdateCallback(mFirstPersonNeckController); node->addUpdateCallback(mFirstPersonNeckController);
mActiveControllers.emplace(node, mFirstPersonNeckController); mActiveControllers.emplace_back(node, mFirstPersonNeckController);
} }
} }
else if (mViewMode == VM_Normal) else if (mViewMode == VM_Normal)

View file

@ -168,7 +168,7 @@ void WeaponAnimation::releaseArrow(MWWorld::Ptr actor, float attackStrength)
} }
void WeaponAnimation::addControllers(const std::map<std::string, osg::ref_ptr<osg::MatrixTransform> >& nodes, void WeaponAnimation::addControllers(const std::map<std::string, osg::ref_ptr<osg::MatrixTransform> >& nodes,
std::multimap<osg::ref_ptr<osg::Node>, osg::ref_ptr<osg::NodeCallback> > &map, osg::Node* objectRoot) std::vector<std::pair<osg::ref_ptr<osg::Node>, osg::ref_ptr<osg::NodeCallback>>> &map, osg::Node* objectRoot)
{ {
for (int i=0; i<2; ++i) for (int i=0; i<2; ++i)
{ {
@ -180,7 +180,7 @@ void WeaponAnimation::addControllers(const std::map<std::string, osg::ref_ptr<os
osg::Node* node = found->second; osg::Node* node = found->second;
mSpineControllers[i] = new RotateController(objectRoot); mSpineControllers[i] = new RotateController(objectRoot);
node->addUpdateCallback(mSpineControllers[i]); node->addUpdateCallback(mSpineControllers[i]);
map.insert(std::make_pair(node, mSpineControllers[i])); map.emplace_back(node, mSpineControllers[i]);
} }
} }
} }

View file

@ -41,7 +41,7 @@ namespace MWRender
/// Add WeaponAnimation-related controllers to \a nodes and store the added controllers in \a map. /// Add WeaponAnimation-related controllers to \a nodes and store the added controllers in \a map.
void addControllers(const std::map<std::string, osg::ref_ptr<osg::MatrixTransform> >& nodes, void addControllers(const std::map<std::string, osg::ref_ptr<osg::MatrixTransform> >& nodes,
std::multimap<osg::ref_ptr<osg::Node>, osg::ref_ptr<osg::NodeCallback> >& map, osg::Node* objectRoot); std::vector<std::pair<osg::ref_ptr<osg::Node>, osg::ref_ptr<osg::NodeCallback>>>& map, osg::Node* objectRoot);
void deleteControllers(); void deleteControllers();