Files
Bret Curtis e8f6c25d1a Cache animation data as std::shared_ptr, dropping their osg::Object base
SceneUtil::KeyframeHolder and SceneUtil::AnimBlendRules are pure data — a
map of keyframe controllers and a vector of blend rules. Nothing attaches
them to a scene graph; both classes existed as osg::Object only because
the cache stored them via osg::ref_ptr. With the value-type seam from the
previous MR in place, they can be plain classes cached as
std::shared_ptr<const T>, and the TemplateRef pins in AnimBlendRulesManager
become an aliasing shared_ptr that keeps the cached base and override rules
alive while merged rules are in use.
2026-10-05 17:36:58 +02:00

72 lines
2.1 KiB
C++

#ifndef OPENMW_COMPONENTS_KEYFRAMEMANAGER_H
#define OPENMW_COMPONENTS_KEYFRAMEMANAGER_H
#include <memory>
#include <string>
#include <osg/ref_ptr>
#include <osgAnimation/BasicAnimationManager>
#include <components/sceneutil/keyframe.hpp>
#include "resourcemanager.hpp"
namespace ToUTF8
{
class StatelessUtf8Encoder;
}
namespace Resource
{
/// @brief extract animations from OSG formats to OpenMW's animation system
class RetrieveAnimationsVisitor : public osg::NodeVisitor
{
public:
explicit RetrieveAnimationsVisitor(SceneUtil::KeyframeHolder& target,
osg::ref_ptr<osgAnimation::BasicAnimationManager> animationManager, VFS::Path::NormalizedView path,
const VFS::Manager& vfs);
bool belongsToLeftUpperExtremity(const std::string& name);
bool belongsToRightUpperExtremity(const std::string& name);
bool belongsToTorso(const std::string& name);
void addKeyframeController(const std::string& name, const osg::Node& node);
virtual void apply(osg::Node& node) override;
private:
SceneUtil::KeyframeHolder& mTarget;
osg::ref_ptr<osgAnimation::BasicAnimationManager> mAnimationManager;
VFS::Path::Normalized mPath;
const VFS::Manager* mVFS;
};
}
namespace Resource
{
class SceneManager;
/// @brief Managing of keyframe resources
/// @note May be used from any thread.
class KeyframeManager : public ResourceManager<std::shared_ptr<const SceneUtil::KeyframeHolder>>
{
public:
explicit KeyframeManager(const VFS::Manager* vfs, SceneManager* sceneManager, double expiryDelay,
const ToUTF8::StatelessUtf8Encoder* encoder);
~KeyframeManager() = default;
/// Retrieve a read-only keyframe resource by name (case-insensitive).
/// @note Throws an exception if the resource is not found.
std::shared_ptr<const SceneUtil::KeyframeHolder> get(VFS::Path::NormalizedView name);
void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;
private:
SceneManager* mSceneManager;
const ToUTF8::StatelessUtf8Encoder* mEncoder;
};
}
#endif