GenericObjectCache stored osg::ref_ptr<osg::Object>, so everything cached had to derive from osg::Object whether that meant anything or not: NifFileHolder and BgsmFileHolder existed for no other reason, Resource::BulletShape and ESMTerrain::LandObject carried META_Object and a CopyOp constructor nothing ever called, and every getter paid a static_cast on the way out. The cache and MultiObjectCache now take their value type as a template parameter, ask "is anything else holding this?" through a useCount overload rather than a base class method, and constrain accept and releaseGLObjects so a value type with neither is not an error. Both holders are deleted; BulletShape, BulletShapeInstance and LandObject become plain classes held by std::shared_ptr across physics, pathfinding, navmeshtool and terrain storage; MWPhysics::HeightField's type-erased osg::Object keep-alive becomes the LandObject it was always holding; every remaining manager names the type it actually caches through the NodeResourceManager alias, which removes eight static_casts and stops clang-format wrapping the declarations. The preloader needs two keep-alive sets for now, because the render-owned entries are still osg::Object; they merge once those move behind the render backend.
74 lines
2.4 KiB
C++
74 lines
2.4 KiB
C++
#include "animblendrulesmanager.hpp"
|
|
|
|
#include <array>
|
|
|
|
#include <components/vfs/manager.hpp>
|
|
|
|
#include <osg/Stats>
|
|
#include <osgAnimation/Animation>
|
|
#include <osgAnimation/BasicAnimationManager>
|
|
#include <osgAnimation/Channel>
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
#include <components/misc/pathhelpers.hpp>
|
|
|
|
#include <components/sceneutil/osgacontroller.hpp>
|
|
#include <components/vfs/pathutil.hpp>
|
|
|
|
#include <components/resource/scenemanager.hpp>
|
|
|
|
#include "objectcache.hpp"
|
|
#include "scenemanager.hpp"
|
|
|
|
namespace Resource
|
|
{
|
|
using AnimBlendRules = SceneUtil::AnimBlendRules;
|
|
|
|
AnimBlendRulesManager::AnimBlendRulesManager(const VFS::Manager* vfs, double expiryDelay)
|
|
: ResourceManager(vfs, expiryDelay)
|
|
{
|
|
}
|
|
|
|
osg::ref_ptr<const AnimBlendRules> AnimBlendRulesManager::getRules(
|
|
const VFS::Path::NormalizedView path, const VFS::Path::NormalizedView overridePath)
|
|
{
|
|
// Note: Providing a non-existing path but an existing overridePath is not supported!
|
|
auto tmpl = loadRules(path);
|
|
if (!tmpl)
|
|
return nullptr;
|
|
|
|
// Create an instance based on template and store template reference inside so the template will not be removed
|
|
// from cache
|
|
osg::ref_ptr<SceneUtil::AnimBlendRules> blendRules(new AnimBlendRules(*tmpl, osg::CopyOp::SHALLOW_COPY));
|
|
blendRules->getOrCreateUserDataContainer()->addUserObject(new Resource::TemplateRef(tmpl));
|
|
|
|
if (!overridePath.value().empty())
|
|
{
|
|
auto blendRuleOverrides = loadRules(overridePath);
|
|
if (blendRuleOverrides)
|
|
{
|
|
blendRules->addOverrideRules(*blendRuleOverrides);
|
|
}
|
|
blendRules->getOrCreateUserDataContainer()->addUserObject(new Resource::TemplateRef(blendRuleOverrides));
|
|
}
|
|
|
|
return blendRules;
|
|
}
|
|
|
|
osg::ref_ptr<const AnimBlendRules> AnimBlendRulesManager::loadRules(VFS::Path::NormalizedView path)
|
|
{
|
|
if (std::optional<osg::ref_ptr<const AnimBlendRules>> cached = mCache->getRefFromObjectCacheOrNone(path))
|
|
return *cached;
|
|
|
|
osg::ref_ptr<AnimBlendRules> blendRules = AnimBlendRules::fromFile(mVFS, path);
|
|
mCache->addEntryToObjectCache(path.value(), blendRules);
|
|
return blendRules;
|
|
}
|
|
|
|
void AnimBlendRulesManager::reportStats(unsigned int frameNumber, osg::Stats* stats) const
|
|
{
|
|
Resource::reportStats("Blending Rules", frameNumber, mCache->getStats(), *stats);
|
|
}
|
|
|
|
}
|