1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

Avoid using osg::ref_ptr when reference is enough

This commit is contained in:
elsid 2023-12-26 11:35:03 +01:00
parent 851bad4262
commit 145f7b5672
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625
5 changed files with 37 additions and 41 deletions

View File

@ -1575,7 +1575,7 @@ namespace MWRender
// Notify that this animation has attached magic effects
mHasMagicEffects = true;
overrideFirstRootTexture(texture, mResourceSystem, node);
overrideFirstRootTexture(texture, mResourceSystem, *node);
}
void Animation::removeEffect(int effectId)

View File

@ -52,9 +52,9 @@ namespace MWRender
node->accept(assignVisitor);
if (isMagicVFX)
overrideFirstRootTexture(textureOverride, mResourceSystem, node);
overrideFirstRootTexture(textureOverride, mResourceSystem, *node);
else
overrideTexture(textureOverride, mResourceSystem, node);
overrideTexture(textureOverride, mResourceSystem, *node);
mParentNode->addChild(trans);

View File

@ -11,41 +11,40 @@
namespace MWRender
{
class TextureOverrideVisitor : public osg::NodeVisitor
namespace
{
public:
TextureOverrideVisitor(std::string_view texture, Resource::ResourceSystem* resourcesystem)
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
, mTexture(texture)
, mResourcesystem(resourcesystem)
class TextureOverrideVisitor : public osg::NodeVisitor
{
}
void apply(osg::Node& node) override
{
int index = 0;
osg::ref_ptr<osg::Node> nodePtr(&node);
if (node.getUserValue("overrideFx", index))
public:
TextureOverrideVisitor(std::string_view texture, Resource::ResourceSystem* resourcesystem)
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
, mTexture(texture)
, mResourcesystem(resourcesystem)
{
if (index == 1)
overrideTexture(mTexture, mResourcesystem, std::move(nodePtr));
}
traverse(node);
}
std::string_view mTexture;
Resource::ResourceSystem* mResourcesystem;
};
void overrideFirstRootTexture(
std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Node> node)
{
TextureOverrideVisitor overrideVisitor(texture, resourceSystem);
node->accept(overrideVisitor);
void apply(osg::Node& node) override
{
int index = 0;
if (node.getUserValue("overrideFx", index))
{
if (index == 1)
overrideTexture(mTexture, mResourcesystem, node);
}
traverse(node);
}
std::string_view mTexture;
Resource::ResourceSystem* mResourcesystem;
};
}
void overrideTexture(
std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Node> node)
void overrideFirstRootTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::Node& node)
{
TextureOverrideVisitor overrideVisitor(texture, resourceSystem);
node.accept(overrideVisitor);
}
void overrideTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::Node& node)
{
if (texture.empty())
return;
@ -58,14 +57,14 @@ namespace MWRender
tex->setName("diffuseMap");
osg::ref_ptr<osg::StateSet> stateset;
if (node->getStateSet())
stateset = new osg::StateSet(*node->getStateSet(), osg::CopyOp::SHALLOW_COPY);
if (const osg::StateSet* const src = node.getStateSet())
stateset = new osg::StateSet(*src, osg::CopyOp::SHALLOW_COPY);
else
stateset = new osg::StateSet;
stateset->setTextureAttribute(0, tex, osg::StateAttribute::OVERRIDE);
node->setStateSet(stateset);
node.setStateSet(stateset);
}
bool shouldAddMSAAIntermediateTarget()

View File

@ -2,9 +2,8 @@
#define OPENMW_MWRENDER_UTIL_H
#include <osg/NodeCallback>
#include <osg/ref_ptr>
#include <string>
#include <string_view>
namespace osg
{
@ -21,11 +20,9 @@ namespace MWRender
// Overrides the texture of nodes in the mesh that had the same NiTexturingProperty as the first NiTexturingProperty
// of the .NIF file's root node, if it had a NiTexturingProperty. Used for applying "particle textures" to magic
// effects.
void overrideFirstRootTexture(
std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Node> node);
void overrideFirstRootTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::Node& node);
void overrideTexture(
std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Node> node);
void overrideTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::Node& node);
// Node callback to entirely skip the traversal.
class NoTraverseCallback : public osg::NodeCallback

View File

@ -255,7 +255,7 @@ namespace MWWorld
SceneUtil::AssignControllerSourcesVisitor assignVisitor(state.mEffectAnimationTime);
state.mNode->accept(assignVisitor);
MWRender::overrideFirstRootTexture(texture, mResourceSystem, std::move(projectile));
MWRender::overrideFirstRootTexture(texture, mResourceSystem, *projectile);
}
void ProjectileManager::update(State& state, float duration)