Add explicit handling of most commonly used nodes to NodeVisitors to avoid excessive virtual function calls

coverity_scan^2
scrawl 8 years ago
parent c95868969b
commit 33e654f94d

@ -179,6 +179,15 @@ namespace
{
}
virtual void apply(osg::Group& node)
{
traverse(node);
}
virtual void apply(osg::MatrixTransform& node)
{
traverse(node);
}
void remove()
{
for (RemoveVec::iterator it = mToRemove.begin(); it != mToRemove.end(); ++it)

@ -3,6 +3,7 @@
#include <limits>
#include <osg/MatrixTransform>
#include <osg/Geometry>
#include <components/nif/controlled.hpp>
#include <components/nif/nifkey.hpp>
@ -315,7 +316,22 @@ FindGroupByRecIndex::FindGroupByRecIndex(int recIndex)
{
}
void FindGroupByRecIndex::apply(osg::Node &searchNode)
void FindGroupByRecIndex::apply(osg::Node &node)
{
applyNode(node);
}
void FindGroupByRecIndex::apply(osg::MatrixTransform &node)
{
applyNode(node);
}
void FindGroupByRecIndex::apply(osg::Geometry &node)
{
applyNode(node);
}
void FindGroupByRecIndex::applyNode(osg::Node &searchNode)
{
if (searchNode.getUserDataContainer() && searchNode.getUserDataContainer()->getNumUserObjects())
{

@ -196,7 +196,14 @@ namespace NifOsg
public:
FindGroupByRecIndex(int recIndex);
virtual void apply(osg::Node &searchNode);
virtual void apply(osg::Node &node);
// Technically not required as the default implementation would trickle down to apply(Node&) anyway,
// but we'll shortcut instead to avoid the chain of virtual function calls
virtual void apply(osg::MatrixTransform& node);
virtual void apply(osg::Geometry& node);
void applyNode(osg::Node& searchNode);
osg::Group* mFound;
osg::NodePath mFoundPath;

@ -5,6 +5,7 @@
#include <osg/NodeVisitor>
#include <osg/Group>
#include <osg/Geometry>
#include <osg/FrontFace>
#include <osg/PositionAttitudeTransform>
#include <osg/MatrixTransform>
@ -29,7 +30,24 @@ namespace SceneUtil
mFilter2 = "tri " + mFilter;
}
virtual void apply(osg::MatrixTransform& node)
{
applyNode(node);
}
virtual void apply(osg::Geometry& node)
{
applyNode(node);
}
virtual void apply(osg::Node& node)
{
applyNode(node);
}
virtual void apply(osg::Group& node)
{
applyNode(node);
}
void applyNode(osg::Node& node)
{
std::string lowerName = Misc::StringUtils::lowerCase(node.getName());
if ((lowerName.size() >= mFilter.size() && lowerName.compare(0, mFilter.size(), mFilter) == 0)

@ -3,6 +3,8 @@
#include "statesetupdater.hpp"
#include <osg/Drawable>
#include <osg/Geometry>
#include <osg/MatrixTransform>
#include <osg/NodeCallback>
namespace SceneUtil
@ -62,6 +64,21 @@ namespace SceneUtil
}
void ControllerVisitor::apply(osg::Node &node)
{
applyNode(node);
}
void ControllerVisitor::apply(osg::MatrixTransform &node)
{
applyNode(node);
}
void ControllerVisitor::apply(osg::Geometry &node)
{
applyNode(node);
}
void ControllerVisitor::applyNode(osg::Node &node)
{
osg::Callback* callback = node.getUpdateCallback();
while (callback)

@ -64,6 +64,13 @@ namespace SceneUtil
virtual void apply(osg::Node& node);
// Technically not required as the default implementation would trickle down to apply(Node&) anyway,
// but we'll shortcut instead to avoid the chain of virtual function calls
virtual void apply(osg::MatrixTransform& node);
virtual void apply(osg::Geometry& node);
void applyNode(osg::Node& node);
virtual void visit(osg::Node& node, Controller& ctrl) = 0;
};

@ -1,5 +1,7 @@
#include "visitor.hpp"
#include <osg/MatrixTransform>
#include <osgParticle/ParticleSystem>
#include <components/misc/stringops.hpp>
@ -7,14 +9,35 @@
namespace SceneUtil
{
void FindByNameVisitor::apply(osg::Group &group)
bool FindByNameVisitor::checkGroup(osg::Group &group)
{
if (Misc::StringUtils::ciEqual(group.getName(), mNameToFind))
{
mFoundNode = &group;
return;
return true;
}
traverse(group);
return false;
}
void FindByNameVisitor::apply(osg::Group &group)
{
if (!checkGroup(group))
traverse(group);
}
void FindByNameVisitor::apply(osg::MatrixTransform &node)
{
if (!checkGroup(node))
traverse(node);
}
void FindByNameVisitor::apply(osg::Geometry&)
{
}
void DisableFreezeOnCullVisitor::apply(osg::MatrixTransform &node)
{
traverse(node);
}
void DisableFreezeOnCullVisitor::apply(osg::Drawable& drw)

@ -21,6 +21,11 @@ namespace SceneUtil
virtual void apply(osg::Group& group);
virtual void apply(osg::MatrixTransform& node);
virtual void apply(osg::Geometry& node);
bool checkGroup(osg::Group& group);
std::string mNameToFind;
osg::Group* mFoundNode;
};
@ -34,6 +39,8 @@ namespace SceneUtil
{
}
virtual void apply(osg::MatrixTransform& node);
virtual void apply(osg::Drawable& drw);
};

Loading…
Cancel
Save