convert AnimationCache to DependencyManager

This commit is contained in:
ZappoMan 2014-12-15 19:48:15 -08:00
parent 02737a4ec4
commit 660bf2720e
8 changed files with 15 additions and 21 deletions

View file

@ -28,7 +28,7 @@ void ScriptableAvatar::startAnimation(const QString& url, float fps, float prior
Q_ARG(float, lastFrame), Q_ARG(const QStringList&, maskedJoints));
return;
}
_animation = _scriptEngine->getAnimationCache()->getAnimation(url);
_animation = DependencyManager::get<AnimationCache>()->getAnimation(url);
_animationDetails = AnimationDetails("", QUrl(url), fps, 0, loop, hold, false, firstFrame, lastFrame, true, firstFrame);
_maskedJoints = maskedJoints;
}

View file

@ -4003,7 +4003,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("AnimationCache", &_animationCache);
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>());
scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance());
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);

View file

@ -249,7 +249,6 @@ public:
ToolWindow* getToolWindow() { return _toolWindow ; }
AnimationCache* getAnimationCache() { return &_animationCache; }
DeferredLightingEffect* getDeferredLightingEffect() { return &_deferredLightingEffect; }
ControllerScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; }
@ -566,8 +565,6 @@ private:
QSet<int> _keysPressed;
AnimationCache _animationCache;
DeferredLightingEffect _deferredLightingEffect;
AmbientOcclusionEffect _ambientOcclusionEffect;

View file

@ -10,11 +10,11 @@
//
#include "AnimationHandle.h"
#include "Application.h"
#include "Model.h"
void AnimationHandle::setURL(const QUrl& url) {
if (_url != url) {
_animation = Application::getInstance()->getAnimationCache()->getAnimation(_url = url);
_animation = DependencyManager::get<AnimationCache>()->getAnimation(_url = url);
_jointMappings.clear();
}
}

View file

@ -15,30 +15,31 @@
#include <QScriptEngine>
#include <QScriptValue>
#include <ResourceCache.h>
#include <DependencyManager.h>
#include <FBXReader.h>
#include <ResourceCache.h>
class Animation;
typedef QSharedPointer<Animation> AnimationPointer;
/// Scriptable interface for FBX animation loading.
class AnimationCache : public ResourceCache {
class AnimationCache : public ResourceCache, public DependencyManager::Dependency {
Q_OBJECT
public:
AnimationCache(QObject* parent = NULL);
Q_INVOKABLE AnimationPointer getAnimation(const QString& url) { return getAnimation(QUrl(url)); }
Q_INVOKABLE AnimationPointer getAnimation(const QUrl& url);
protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra);
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra);
private:
AnimationCache(QObject* parent = NULL);
virtual ~AnimationCache() { }
friend class DependencyManager;
};
Q_DECLARE_METATYPE(AnimationPointer)

View file

@ -285,7 +285,6 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit
QMap<QString, AnimationPointer> ModelEntityItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s)
AnimationCache ModelEntityItem::_animationCache;
// This class/instance will cleanup the animations once unloaded.
class EntityAnimationsBookkeeper {
@ -309,7 +308,7 @@ Animation* ModelEntityItem::getAnimation(const QString& url) {
// if we don't already have this model then create it and initialize it
if (_loadedAnimations.find(url) == _loadedAnimations.end()) {
animation = _animationCache.getAnimation(url);
animation = DependencyManager::get<AnimationCache>()->getAnimation(url);
_loadedAnimations[url] = animation;
} else {
animation = _loadedAnimations[url];

View file

@ -94,7 +94,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam
_quatLibrary(),
_vec3Library(),
_uuidLibrary(),
_animationCache(this),
_isUserLoaded(false),
_arrayBufferClass(new ArrayBufferClass(this))
{
@ -256,7 +255,7 @@ void ScriptEngine::init() {
registerGlobalObject("Quat", &_quatLibrary);
registerGlobalObject("Vec3", &_vec3Library);
registerGlobalObject("Uuid", &_uuidLibrary);
registerGlobalObject("AnimationCache", &_animationCache);
registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>());
registerGlobalObject("Voxels", &_voxelsScriptingInterface);

View file

@ -51,7 +51,6 @@ public:
static EntityScriptingInterface* getEntityScriptingInterface() { return &_entityScriptingInterface; }
ArrayBufferClass* getArrayBufferClass() { return _arrayBufferClass; }
AnimationCache* getAnimationCache() { return &_animationCache; }
/// sets the script contents, will return false if failed, will fail if script is already running
bool setScriptContents(const QString& scriptContents, const QString& fileNameString = QString(""));
@ -149,7 +148,6 @@ private:
Quat _quatLibrary;
Vec3 _vec3Library;
ScriptUUID _uuidLibrary;
AnimationCache _animationCache;
bool _isUserLoaded;
ArrayBufferClass* _arrayBufferClass;