From 55dcc6582a7b5024994368fbdf07a998b1394cbd Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Sat, 28 Nov 2020 15:03:10 +0200 Subject: [PATCH] Don't duplicate getFileExtension, use OpenMW's namespaces --- components/resource/keyframemanager.cpp | 20 ++++++-------------- components/resource/keyframemanager.hpp | 4 +--- components/resource/scenemanager.cpp | 17 ++++++++--------- components/resource/scenemanager.hpp | 1 + components/sceneutil/osgacontroller.cpp | 14 +++++++------- components/sceneutil/osgacontroller.hpp | 10 +++++----- 6 files changed, 28 insertions(+), 38 deletions(-) diff --git a/components/resource/keyframemanager.cpp b/components/resource/keyframemanager.cpp index 421b0ddf7..af0f365ee 100644 --- a/components/resource/keyframemanager.cpp +++ b/components/resource/keyframemanager.cpp @@ -14,7 +14,7 @@ #include "objectcache.hpp" #include "scenemanager.hpp" -namespace OsgAOpenMW +namespace Resource { RetrieveAnimationsVisitor::RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target, osg::ref_ptr animationManager) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), mTarget(target), mAnimationManager(animationManager) {} @@ -23,9 +23,9 @@ namespace OsgAOpenMW { if (node.libraryName() == std::string("osgAnimation") && node.className() == std::string("Bone") && node.getName() == std::string("root")) { - osg::ref_ptr callback = new OsgaController::KeyframeController(); + osg::ref_ptr callback = new SceneUtil::OsgAnimationController(); - std::vector emulatedAnimations; + std::vector emulatedAnimations; for (auto animation : mAnimationManager->getAnimationList()) { @@ -63,7 +63,7 @@ namespace OsgAOpenMW mTarget.mTextKeys.emplace(startTime, std::move(loopstart)); mTarget.mTextKeys.emplace(stopTime, std::move(loopstop)); - OsgaController::EmulatedAnimation emulatedAnimation; + SceneUtil::EmulatedAnimation emulatedAnimation; emulatedAnimation.mStartTime = startTime; emulatedAnimation.mStopTime = stopTime; emulatedAnimation.mName = animationName; @@ -76,14 +76,6 @@ namespace OsgAOpenMW traverse(node); } - - std::string getFileExtension(const std::string& file) - { - size_t extPos = file.find_last_of('.'); - if (extPos != std::string::npos && extPos+1 < file.size()) - return file.substr(extPos+1); - return std::string(); - } } namespace Resource @@ -110,7 +102,7 @@ namespace Resource else { osg::ref_ptr loaded (new SceneUtil::KeyframeHolder); - std::string ext = OsgAOpenMW::getFileExtension(normalized); + std::string ext = Resource::getFileExtension(normalized); if (ext == "kf") { NifOsg::Loader::loadKf(Nif::NIFFilePtr(new Nif::NIFFile(mVFS->getNormalized(normalized), normalized)), *loaded.get()); @@ -121,7 +113,7 @@ namespace Resource osg::ref_ptr bam = dynamic_cast (scene->getUpdateCallback()); if (bam) { - OsgAOpenMW::RetrieveAnimationsVisitor rav(*loaded.get(), bam); + Resource::RetrieveAnimationsVisitor rav(*loaded.get(), bam); scene->accept(rav); } } diff --git a/components/resource/keyframemanager.hpp b/components/resource/keyframemanager.hpp index 778b4bc9a..3e992ac5e 100644 --- a/components/resource/keyframemanager.hpp +++ b/components/resource/keyframemanager.hpp @@ -9,7 +9,7 @@ #include "resourcemanager.hpp" -namespace OsgAOpenMW +namespace Resource { /// @brief extract animations to OpenMW's animation system class RetrieveAnimationsVisitor : public osg::NodeVisitor @@ -24,8 +24,6 @@ namespace OsgAOpenMW osg::ref_ptr mAnimationManager; }; - - std::string getFileExtension(const std::string& file); } namespace Resource diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index e99003b74..2630cd453 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -338,17 +338,9 @@ namespace Resource Resource::ImageManager* mImageManager; }; - std::string getFileExtension(const std::string& file) - { - size_t extPos = file.find_last_of('.'); - if (extPos != std::string::npos && extPos+1 < file.size()) - return file.substr(extPos+1); - return std::string(); - } - osg::ref_ptr load (Files::IStreamPtr file, const std::string& normalizedFilename, Resource::ImageManager* imageManager, Resource::NifFileManager* nifFileManager) { - std::string ext = getFileExtension(normalizedFilename); + std::string ext = Resource::getFileExtension(normalizedFilename); if (ext == "nif") return NifOsg::Loader::load(nifFileManager->get(normalizedFilename), imageManager); else @@ -780,4 +772,11 @@ namespace Resource return shaderVisitor; } + std::string getFileExtension(const std::string& file) + { + size_t extPos = file.find_last_of('.'); + if (extPos != std::string::npos && extPos+1 < file.size()) + return file.substr(extPos+1); + return std::string(); + } } diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index 8df556158..fd75070a1 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -181,6 +181,7 @@ namespace Resource void operator = (const SceneManager&); }; + std::string getFileExtension(const std::string& file); } #endif diff --git a/components/sceneutil/osgacontroller.cpp b/components/sceneutil/osgacontroller.cpp index 503d9cf02..87e6f02fe 100644 --- a/components/sceneutil/osgacontroller.cpp +++ b/components/sceneutil/osgacontroller.cpp @@ -21,7 +21,7 @@ #include #include -namespace OsgaController +namespace SceneUtil { LinkVisitor::LinkVisitor() : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN ) { @@ -101,14 +101,14 @@ namespace OsgaController apply(static_cast(node)); } - KeyframeController::KeyframeController(const KeyframeController ©, const osg::CopyOp ©op) : SceneUtil::KeyframeController(copy, copyop) + OsgAnimationController::OsgAnimationController(const OsgAnimationController ©, const osg::CopyOp ©op) : SceneUtil::KeyframeController(copy, copyop) , mMergedAnimationTracks(copy.mMergedAnimationTracks) , mEmulatedAnimations(copy.mEmulatedAnimations) { mLinker = nullptr; } - osg::Vec3f KeyframeController::getTranslation(float time) const + osg::Vec3f OsgAnimationController::getTranslation(float time) const { osg::Vec3f translationValue; std::string animationName; @@ -148,7 +148,7 @@ namespace OsgaController return osg::Vec3f(); } - void KeyframeController::update(float time, std::string animationName) + void OsgAnimationController::update(float time, std::string animationName) { for (const osg::ref_ptr mergedAnimationTrack : mMergedAnimationTracks) { @@ -156,7 +156,7 @@ namespace OsgaController } } - void KeyframeController::operator() (osg::Node* node, osg::NodeVisitor* nv) + void OsgAnimationController::operator() (osg::Node* node, osg::NodeVisitor* nv) { if (hasInput()) { @@ -185,12 +185,12 @@ namespace OsgaController traverse(node, nv); } - void KeyframeController::setEmulatedAnimations(std::vector emulatedAnimations) + void OsgAnimationController::setEmulatedAnimations(std::vector emulatedAnimations) { mEmulatedAnimations = emulatedAnimations; } - void KeyframeController::addMergedAnimationTrack(osg::ref_ptr animationTrack) + void OsgAnimationController::addMergedAnimationTrack(osg::ref_ptr animationTrack) { mMergedAnimationTracks.emplace_back(animationTrack); } diff --git a/components/sceneutil/osgacontroller.hpp b/components/sceneutil/osgacontroller.hpp index a3072088a..f1c1584c2 100644 --- a/components/sceneutil/osgacontroller.hpp +++ b/components/sceneutil/osgacontroller.hpp @@ -16,7 +16,7 @@ #include #include -namespace OsgaController +namespace SceneUtil { struct EmulatedAnimation { @@ -44,15 +44,15 @@ namespace OsgaController Resource::Animation* mAnimation; }; - class KeyframeController : public SceneUtil::KeyframeController + class OsgAnimationController : public SceneUtil::KeyframeController { public: /// @brief Handles the animation for osgAnimation formats - KeyframeController() {}; + OsgAnimationController() {}; - KeyframeController(const KeyframeController& copy, const osg::CopyOp& copyop); + OsgAnimationController(const OsgAnimationController& copy, const osg::CopyOp& copyop); - META_Object(OsgaController, KeyframeController) + META_Object(SceneUtil, OsgAnimationController) /// @brief Handles the location of the instance osg::Vec3f getTranslation(float time) const override;