Don't duplicate getFileExtension, use OpenMW's namespaces

pull/593/head
Nelsson Huotari 4 years ago
parent 08dcbe30b3
commit 55dcc6582a

@ -14,7 +14,7 @@
#include "objectcache.hpp" #include "objectcache.hpp"
#include "scenemanager.hpp" #include "scenemanager.hpp"
namespace OsgAOpenMW namespace Resource
{ {
RetrieveAnimationsVisitor::RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target, osg::ref_ptr<osgAnimation::BasicAnimationManager> animationManager) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), mTarget(target), mAnimationManager(animationManager) {} RetrieveAnimationsVisitor::RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target, osg::ref_ptr<osgAnimation::BasicAnimationManager> 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")) if (node.libraryName() == std::string("osgAnimation") && node.className() == std::string("Bone") && node.getName() == std::string("root"))
{ {
osg::ref_ptr<OsgaController::KeyframeController> callback = new OsgaController::KeyframeController(); osg::ref_ptr<SceneUtil::OsgAnimationController> callback = new SceneUtil::OsgAnimationController();
std::vector<OsgaController::EmulatedAnimation> emulatedAnimations; std::vector<SceneUtil::EmulatedAnimation> emulatedAnimations;
for (auto animation : mAnimationManager->getAnimationList()) for (auto animation : mAnimationManager->getAnimationList())
{ {
@ -63,7 +63,7 @@ namespace OsgAOpenMW
mTarget.mTextKeys.emplace(startTime, std::move(loopstart)); mTarget.mTextKeys.emplace(startTime, std::move(loopstart));
mTarget.mTextKeys.emplace(stopTime, std::move(loopstop)); mTarget.mTextKeys.emplace(stopTime, std::move(loopstop));
OsgaController::EmulatedAnimation emulatedAnimation; SceneUtil::EmulatedAnimation emulatedAnimation;
emulatedAnimation.mStartTime = startTime; emulatedAnimation.mStartTime = startTime;
emulatedAnimation.mStopTime = stopTime; emulatedAnimation.mStopTime = stopTime;
emulatedAnimation.mName = animationName; emulatedAnimation.mName = animationName;
@ -76,14 +76,6 @@ namespace OsgAOpenMW
traverse(node); 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 namespace Resource
@ -110,7 +102,7 @@ namespace Resource
else else
{ {
osg::ref_ptr<SceneUtil::KeyframeHolder> loaded (new SceneUtil::KeyframeHolder); osg::ref_ptr<SceneUtil::KeyframeHolder> loaded (new SceneUtil::KeyframeHolder);
std::string ext = OsgAOpenMW::getFileExtension(normalized); std::string ext = Resource::getFileExtension(normalized);
if (ext == "kf") if (ext == "kf")
{ {
NifOsg::Loader::loadKf(Nif::NIFFilePtr(new Nif::NIFFile(mVFS->getNormalized(normalized), normalized)), *loaded.get()); NifOsg::Loader::loadKf(Nif::NIFFilePtr(new Nif::NIFFile(mVFS->getNormalized(normalized), normalized)), *loaded.get());
@ -121,7 +113,7 @@ namespace Resource
osg::ref_ptr<osgAnimation::BasicAnimationManager> bam = dynamic_cast<osgAnimation::BasicAnimationManager*> (scene->getUpdateCallback()); osg::ref_ptr<osgAnimation::BasicAnimationManager> bam = dynamic_cast<osgAnimation::BasicAnimationManager*> (scene->getUpdateCallback());
if (bam) if (bam)
{ {
OsgAOpenMW::RetrieveAnimationsVisitor rav(*loaded.get(), bam); Resource::RetrieveAnimationsVisitor rav(*loaded.get(), bam);
scene->accept(rav); scene->accept(rav);
} }
} }

@ -9,7 +9,7 @@
#include "resourcemanager.hpp" #include "resourcemanager.hpp"
namespace OsgAOpenMW namespace Resource
{ {
/// @brief extract animations to OpenMW's animation system /// @brief extract animations to OpenMW's animation system
class RetrieveAnimationsVisitor : public osg::NodeVisitor class RetrieveAnimationsVisitor : public osg::NodeVisitor
@ -24,8 +24,6 @@ namespace OsgAOpenMW
osg::ref_ptr<osgAnimation::BasicAnimationManager> mAnimationManager; osg::ref_ptr<osgAnimation::BasicAnimationManager> mAnimationManager;
}; };
std::string getFileExtension(const std::string& file);
} }
namespace Resource namespace Resource

@ -338,17 +338,9 @@ namespace Resource
Resource::ImageManager* mImageManager; 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<osg::Node> load (Files::IStreamPtr file, const std::string& normalizedFilename, Resource::ImageManager* imageManager, Resource::NifFileManager* nifFileManager) osg::ref_ptr<osg::Node> 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") if (ext == "nif")
return NifOsg::Loader::load(nifFileManager->get(normalizedFilename), imageManager); return NifOsg::Loader::load(nifFileManager->get(normalizedFilename), imageManager);
else else
@ -780,4 +772,11 @@ namespace Resource
return shaderVisitor; 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();
}
} }

@ -181,6 +181,7 @@ namespace Resource
void operator = (const SceneManager&); void operator = (const SceneManager&);
}; };
std::string getFileExtension(const std::string& file);
} }
#endif #endif

@ -21,7 +21,7 @@
#include <components/sceneutil/controller.hpp> #include <components/sceneutil/controller.hpp>
#include <components/sceneutil/keyframe.hpp> #include <components/sceneutil/keyframe.hpp>
namespace OsgaController namespace SceneUtil
{ {
LinkVisitor::LinkVisitor() : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN ) LinkVisitor::LinkVisitor() : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN )
{ {
@ -101,14 +101,14 @@ namespace OsgaController
apply(static_cast<osg::Node&>(node)); apply(static_cast<osg::Node&>(node));
} }
KeyframeController::KeyframeController(const KeyframeController &copy, const osg::CopyOp &copyop) : SceneUtil::KeyframeController(copy, copyop) OsgAnimationController::OsgAnimationController(const OsgAnimationController &copy, const osg::CopyOp &copyop) : SceneUtil::KeyframeController(copy, copyop)
, mMergedAnimationTracks(copy.mMergedAnimationTracks) , mMergedAnimationTracks(copy.mMergedAnimationTracks)
, mEmulatedAnimations(copy.mEmulatedAnimations) , mEmulatedAnimations(copy.mEmulatedAnimations)
{ {
mLinker = nullptr; mLinker = nullptr;
} }
osg::Vec3f KeyframeController::getTranslation(float time) const osg::Vec3f OsgAnimationController::getTranslation(float time) const
{ {
osg::Vec3f translationValue; osg::Vec3f translationValue;
std::string animationName; std::string animationName;
@ -148,7 +148,7 @@ namespace OsgaController
return osg::Vec3f(); return osg::Vec3f();
} }
void KeyframeController::update(float time, std::string animationName) void OsgAnimationController::update(float time, std::string animationName)
{ {
for (const osg::ref_ptr<Resource::Animation> mergedAnimationTrack : mMergedAnimationTracks) for (const osg::ref_ptr<Resource::Animation> 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()) if (hasInput())
{ {
@ -185,12 +185,12 @@ namespace OsgaController
traverse(node, nv); traverse(node, nv);
} }
void KeyframeController::setEmulatedAnimations(std::vector<EmulatedAnimation> emulatedAnimations) void OsgAnimationController::setEmulatedAnimations(std::vector<EmulatedAnimation> emulatedAnimations)
{ {
mEmulatedAnimations = emulatedAnimations; mEmulatedAnimations = emulatedAnimations;
} }
void KeyframeController::addMergedAnimationTrack(osg::ref_ptr<Resource::Animation> animationTrack) void OsgAnimationController::addMergedAnimationTrack(osg::ref_ptr<Resource::Animation> animationTrack)
{ {
mMergedAnimationTracks.emplace_back(animationTrack); mMergedAnimationTracks.emplace_back(animationTrack);
} }

@ -16,7 +16,7 @@
#include <components/sceneutil/keyframe.hpp> #include <components/sceneutil/keyframe.hpp>
#include <components/resource/animation.hpp> #include <components/resource/animation.hpp>
namespace OsgaController namespace SceneUtil
{ {
struct EmulatedAnimation struct EmulatedAnimation
{ {
@ -44,15 +44,15 @@ namespace OsgaController
Resource::Animation* mAnimation; Resource::Animation* mAnimation;
}; };
class KeyframeController : public SceneUtil::KeyframeController class OsgAnimationController : public SceneUtil::KeyframeController
{ {
public: public:
/// @brief Handles the animation for osgAnimation formats /// @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 /// @brief Handles the location of the instance
osg::Vec3f getTranslation(float time) const override; osg::Vec3f getTranslation(float time) const override;

Loading…
Cancel
Save