#include "animblendrulesmanager.hpp" #include #include #include #include #include #include #include #include #include #include #include #include "objectcache.hpp" #include "scenemanager.hpp" namespace Resource { using AnimBlendRules = SceneUtil::AnimBlendRules; AnimBlendRulesManager::AnimBlendRulesManager(const VFS::Manager* vfs, double expiryDelay) : ResourceManager(vfs, expiryDelay) { } std::shared_ptr 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; // Cached rules are immutable, so callers without overrides can share them. Only a ruleset with overrides // applied needs its own copy. if (overridePath.value().empty()) return tmpl; auto blendRuleOverrides = loadRules(overridePath); if (!blendRuleOverrides) return tmpl; // Keep the cached sources referenced for as long as the merged rules live, so the cache doesn't expire and // reparse them while actors still use the result. struct MergedRules { std::shared_ptr mBase; std::shared_ptr mOverrides; AnimBlendRules mRules; }; auto merged = std::make_shared(MergedRules{ tmpl, blendRuleOverrides, *tmpl }); merged->mRules.addOverrideRules(*blendRuleOverrides); return std::shared_ptr(merged, &merged->mRules); } std::shared_ptr AnimBlendRulesManager::loadRules(VFS::Path::NormalizedView path) { if (std::optional> cached = mCache->getRefFromObjectCacheOrNone(path)) return *cached; std::shared_ptr 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); } }