From b71ec8400474abca731b0dda332d32af13a108c2 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Wed, 30 Oct 2024 16:03:31 +0300 Subject: [PATCH] Sprinkle const-correctness in NifLoader --- components/nifosg/nifloader.cpp | 58 +++++++++++++++++---------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 59fc8a577a..bf63415b63 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -535,7 +535,7 @@ namespace NifOsg return nullptr; } - bool handleEffect(const Nif::NiAVObject* nifNode, osg::StateSet* stateset) + bool handleEffect(const Nif::NiAVObject* nifNode, osg::StateSet* stateset) const { if (nifNode->recType != Nif::RC_NiTextureEffect) { @@ -592,7 +592,7 @@ namespace NifOsg } // Get a default dataVariance for this node to be used as a hint by optimization (post)routines - osg::ref_ptr createNode(const Nif::NiAVObject* nifNode) + static osg::ref_ptr createNode(const Nif::NiAVObject* nifNode) { osg::ref_ptr node; osg::Object::DataVariance dataVariance = osg::Object::UNSPECIFIED; @@ -863,7 +863,7 @@ namespace NifOsg return node; } - void handleMeshControllers(const Nif::NiAVObject* nifNode, osg::Node* node, + static void handleMeshControllers(const Nif::NiAVObject* nifNode, osg::Node* node, SceneUtil::CompositeStateSetUpdater* composite, const std::vector& boundTextures, int animflags) { @@ -891,7 +891,8 @@ namespace NifOsg } } - void handleNodeControllers(const Nif::NiAVObject* nifNode, osg::Node* node, int animflags, bool& isAnimated) + void handleNodeControllers( + const Nif::NiAVObject* nifNode, osg::Node* node, int animflags, bool& isAnimated) const { for (Nif::NiTimeControllerPtr ctrl = nifNode->mController; !ctrl.empty(); ctrl = ctrl->mNext) { @@ -969,7 +970,7 @@ namespace NifOsg } void handleMaterialControllers(const Nif::NiProperty* materialProperty, - SceneUtil::CompositeStateSetUpdater* composite, int animflags, const osg::Material* baseMaterial) + SceneUtil::CompositeStateSetUpdater* composite, int animflags, const osg::Material* baseMaterial) const { for (Nif::NiTimeControllerPtr ctrl = materialProperty->mController; !ctrl.empty(); ctrl = ctrl->mNext) { @@ -1026,8 +1027,9 @@ namespace NifOsg VFS::Path::toNormalized(Misc::ResourceHelpers::correctTexturePath(path, mImageManager->getVFS()))); } - osg::ref_ptr attachTexture(const std::string& name, osg::ref_ptr image, bool wrapS, - bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector& boundTextures) + static osg::ref_ptr attachTexture(const std::string& name, osg::ref_ptr image, + bool wrapS, bool wrapT, unsigned int uvSet, osg::StateSet* stateset, + std::vector& boundTextures) { osg::ref_ptr texture2d = new osg::Texture2D(image); if (image) @@ -1047,14 +1049,14 @@ namespace NifOsg } osg::ref_ptr attachExternalTexture(const std::string& name, const std::string& path, bool wrapS, - bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector& boundTextures) + bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector& boundTextures) const { return attachTexture(name, getTextureImage(path), wrapS, wrapT, uvSet, stateset, boundTextures); } osg::ref_ptr attachNiSourceTexture(const std::string& name, const Nif::NiSourceTexture* st, bool wrapS, bool wrapT, unsigned int uvSet, osg::StateSet* stateset, - std::vector& boundTextures) + std::vector& boundTextures) const { return attachTexture(name, handleSourceTexture(st), wrapS, wrapT, uvSet, stateset, boundTextures); } @@ -1070,7 +1072,7 @@ namespace NifOsg } void handleTextureControllers(const Nif::NiProperty* texProperty, - SceneUtil::CompositeStateSetUpdater* composite, osg::StateSet* stateset, int animflags) + SceneUtil::CompositeStateSetUpdater* composite, osg::StateSet* stateset, int animflags) const { for (Nif::NiTimeControllerPtr ctrl = texProperty->mController; !ctrl.empty(); ctrl = ctrl->mNext) { @@ -1122,7 +1124,7 @@ namespace NifOsg void handleParticlePrograms(Nif::NiParticleModifierPtr modifier, Nif::NiParticleModifierPtr collider, osg::Group* attachTo, osgParticle::ParticleSystem* partsys, - osgParticle::ParticleProcessor::ReferenceFrame rf) + osgParticle::ParticleProcessor::ReferenceFrame rf) const { osgParticle::ModularProgram* program = new osgParticle::ModularProgram; attachTo->addChild(program); @@ -1189,7 +1191,7 @@ namespace NifOsg // Load the initial state of the particle system, i.e. the initial particles and their positions, velocity and // colors. - void handleParticleInitialState( + static void handleParticleInitialState( const Nif::NiAVObject* nifNode, ParticleSystem* partsys, const Nif::NiParticleSystemController* partctrl) { auto particleNode = static_cast(nifNode); @@ -1245,7 +1247,7 @@ namespace NifOsg partsys->setInitialBound(box); } - osg::ref_ptr handleParticleEmitter(const Nif::NiParticleSystemController* partctrl) + static osg::ref_ptr handleParticleEmitter(const Nif::NiParticleSystemController* partctrl) { std::vector targets; if (partctrl->recType == Nif::RC_NiBSPArrayController && !partctrl->emitAtVertex()) @@ -1743,7 +1745,7 @@ namespace NifOsg parentNode->addChild(drawable); } - osg::BlendFunc::BlendFuncMode getBlendMode(int mode) + osg::BlendFunc::BlendFuncMode getBlendMode(int mode) const { switch (mode) { @@ -1775,7 +1777,7 @@ namespace NifOsg } } - osg::AlphaFunc::ComparisonFunction getTestMode(int mode) + osg::AlphaFunc::ComparisonFunction getTestMode(int mode) const { switch (mode) { @@ -1801,7 +1803,7 @@ namespace NifOsg } } - osg::Stencil::Function getStencilFunction(Nif::NiStencilProperty::TestFunc func) + osg::Stencil::Function getStencilFunction(Nif::NiStencilProperty::TestFunc func) const { using TestFunc = Nif::NiStencilProperty::TestFunc; switch (func) @@ -1829,7 +1831,7 @@ namespace NifOsg } } - osg::Stencil::Operation getStencilOperation(Nif::NiStencilProperty::Action op) + osg::Stencil::Operation getStencilOperation(Nif::NiStencilProperty::Action op) const { using Action = Nif::NiStencilProperty::Action; switch (op) @@ -2002,7 +2004,7 @@ namespace NifOsg return texEnv; } - void handleDepthFlags(osg::StateSet* stateset, bool depthTest, bool depthWrite) + static void handleDepthFlags(osg::StateSet* stateset, bool depthTest, bool depthWrite) { if (!depthWrite && !depthTest) { @@ -2019,7 +2021,7 @@ namespace NifOsg void handleTextureProperty(const Nif::NiTexturingProperty* texprop, const std::string& nodeName, osg::StateSet* stateset, SceneUtil::CompositeStateSetUpdater* composite, - std::vector& boundTextures, int animflags) + std::vector& boundTextures, int animflags) const { // overriding a parent NiTexturingProperty, so remove what was previously bound clearBoundTextures(stateset, boundTextures); @@ -2182,7 +2184,7 @@ namespace NifOsg } void handleShaderMaterialNodeProperties( - const Bgsm::MaterialFile* material, osg::StateSet* stateset, std::vector& boundTextures) + const Bgsm::MaterialFile* material, osg::StateSet* stateset, std::vector& boundTextures) const { const unsigned int uvSet = 0; const bool wrapS = material->wrapS(); @@ -2222,7 +2224,7 @@ namespace NifOsg handleDepthFlags(stateset, material->mDepthTest, material->mDepthWrite); } - void handleDecal(bool enabled, bool hasSortAlpha, osg::Node& node) + void handleDecal(bool enabled, bool hasSortAlpha, osg::Node& node) const { if (!enabled) return; @@ -2236,7 +2238,7 @@ namespace NifOsg stateset->setRenderBinDetails(1, "SORT_BACK_TO_FRONT"); } - void handleAlphaTesting( + static void handleAlphaTesting( bool enabled, osg::AlphaFunc::ComparisonFunction function, int threshold, osg::Node& node) { if (enabled) @@ -2253,7 +2255,7 @@ namespace NifOsg } void handleAlphaBlending( - bool enabled, int sourceMode, int destMode, bool sort, bool& hasSortAlpha, osg::Node& node) + bool enabled, int sourceMode, int destMode, bool sort, bool& hasSortAlpha, osg::Node& node) const { if (enabled) { @@ -2288,8 +2290,8 @@ namespace NifOsg } } - void handleShaderMaterialDrawableProperties( - const Bgsm::MaterialFile* shaderMat, osg::ref_ptr mat, osg::Node& node, bool& hasSortAlpha) + void handleShaderMaterialDrawableProperties(const Bgsm::MaterialFile* shaderMat, + osg::ref_ptr mat, osg::Node& node, bool& hasSortAlpha) const { mat->setAlpha(osg::Material::FRONT_AND_BACK, shaderMat->mTransparency); handleAlphaTesting(shaderMat->mAlphaTest, osg::AlphaFunc::GREATER, shaderMat->mAlphaTestThreshold, node); @@ -2312,7 +2314,7 @@ namespace NifOsg } void handleTextureSet(const Nif::BSShaderTextureSet* textureSet, bool wrapS, bool wrapT, - const std::string& nodeName, osg::StateSet* stateset, std::vector& boundTextures) + const std::string& nodeName, osg::StateSet* stateset, std::vector& boundTextures) const { const unsigned int uvSet = 0; @@ -2653,9 +2655,9 @@ namespace NifOsg // global sharing of State Attributes will reduce the number of GL calls as the osg::State will check by pointer // to see if state is the same template - Attribute* shareAttribute(const osg::ref_ptr& attr) + static Attribute* shareAttribute(const osg::ref_ptr& attr) { - typedef std::set, CompareStateAttribute> Cache; + using Cache = std::set, CompareStateAttribute>; static Cache sCache; static std::mutex sMutex; std::lock_guard lock(sMutex);