1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-04 00:36:41 +00:00

Merge branch 'rm_ref_ptr' into 'master'

Avoid using osg::ref_ptr when reference is enough

See merge request OpenMW/openmw!3690
This commit is contained in:
jvoisin 2023-12-27 08:03:16 +00:00
commit 291d19af48
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 // Notify that this animation has attached magic effects
mHasMagicEffects = true; mHasMagicEffects = true;
overrideFirstRootTexture(texture, mResourceSystem, node); overrideFirstRootTexture(texture, mResourceSystem, *node);
} }
void Animation::removeEffect(int effectId) void Animation::removeEffect(int effectId)

View file

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

View file

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

View file

@ -2,9 +2,8 @@
#define OPENMW_MWRENDER_UTIL_H #define OPENMW_MWRENDER_UTIL_H
#include <osg/NodeCallback> #include <osg/NodeCallback>
#include <osg/ref_ptr>
#include <string> #include <string_view>
namespace osg 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 // 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 // of the .NIF file's root node, if it had a NiTexturingProperty. Used for applying "particle textures" to magic
// effects. // effects.
void overrideFirstRootTexture( void overrideFirstRootTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::Node& node);
std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Node> node);
void overrideTexture( void overrideTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::Node& node);
std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Node> node);
// Node callback to entirely skip the traversal. // Node callback to entirely skip the traversal.
class NoTraverseCallback : public osg::NodeCallback class NoTraverseCallback : public osg::NodeCallback

View file

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