From baf88ab508399e1eb0c282464a112f5faaf490af Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 26 Jul 2018 16:12:16 +1200 Subject: [PATCH] Revise scriptable resource caches' interfaces --- assignment-client/src/Agent.cpp | 8 +++--- assignment-client/src/AssignmentClient.cpp | 2 ++ .../src/scripts/EntityScriptServer.cpp | 3 ++- interface/src/Application.cpp | 27 +++++++++++++------ interface/src/ui/overlays/Web3DOverlay.cpp | 2 +- .../src/AnimationCacheScriptingInterface.cpp | 9 +++---- .../src/AnimationCacheScriptingInterface.h | 7 ++--- .../src/SoundCacheScriptingInterface.cpp | 7 +++-- .../audio/src/SoundCacheScriptingInterface.h | 7 ++--- .../ModelCacheScriptingInterface.cpp | 5 ++-- .../ModelCacheScriptingInterface.h | 7 ++--- .../TextureCacheScriptingInterface.cpp | 9 +++---- .../TextureCacheScriptingInterface.h | 7 ++--- libraries/networking/src/ResourceCache.cpp | 2 +- libraries/networking/src/ResourceCache.h | 6 ++--- 15 files changed, 54 insertions(+), 54 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 304f24d51c..15844b90cf 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -32,8 +32,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -72,6 +72,7 @@ Agent::Agent(ReceivedMessage& message) : DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -456,8 +457,8 @@ void Agent::executeScript() { // register ourselves to the script engine _scriptEngine->registerGlobalObject("Agent", this); - _scriptEngine->registerGlobalObject("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get().data())); - _scriptEngine->registerGlobalObject("AnimationCache", new AnimationCacheScriptingInterface(DependencyManager::get().data())); + _scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get().data()); + _scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get().data()); QScriptValue webSocketServerConstructorValue = _scriptEngine->newFunction(WebSocketServerClass::constructor); _scriptEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue); @@ -846,6 +847,7 @@ void Agent::aboutToFinish() { DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 41e42aa0a1..d761699285 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri auto nodeList = DependencyManager::set(NodeType::Unassigned, listenPort); auto animationCache = DependencyManager::set(); + DependencyManager::set(); auto entityScriptingInterface = DependencyManager::set(false); DependencyManager::registerInheritance(); diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index afb6d3588b..0e1126cebe 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -66,6 +66,7 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -438,7 +439,7 @@ void EntityScriptServer::resetEntitiesScriptEngine() { auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor); newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue); - newEngine->registerGlobalObject("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get().data())); + newEngine->registerGlobalObject("SoundCache", DependencyManager::get().data()); // connect this script engines printedMessage signal to the global ScriptEngines these various messages auto scriptEngines = DependencyManager::get().data(); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a613704afe..025290ce30 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -869,16 +869,20 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -2565,12 +2569,18 @@ Application::~Application() { DependencyManager::destroy(); // must be destroyed before the FramebufferCache + DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); @@ -2992,10 +3002,11 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { surfaceContext->setContextProperty("LocationBookmarks", DependencyManager::get().data()); // Caches - surfaceContext->setContextProperty("AnimationCache", new AnimationCacheScriptingInterface(DependencyManager::get().data())); - surfaceContext->setContextProperty("TextureCache", new TextureCacheScriptingInterface(DependencyManager::get().data())); - surfaceContext->setContextProperty("ModelCache", new ModelCacheScriptingInterface(DependencyManager::get().data())); - surfaceContext->setContextProperty("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get().data())); + surfaceContext->setContextProperty("AnimationCache", DependencyManager::get().data()); + surfaceContext->setContextProperty("TextureCache", DependencyManager::get().data()); + surfaceContext->setContextProperty("ModelCache", DependencyManager::get().data()); + surfaceContext->setContextProperty("SoundCache", DependencyManager::get().data()); + surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get().data()); surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED @@ -6615,10 +6626,10 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerGlobalObject("Pointers", DependencyManager::get().data()); // Caches - scriptEngine->registerGlobalObject("AnimationCache", new AnimationCacheScriptingInterface(DependencyManager::get().data())); - scriptEngine->registerGlobalObject("TextureCache", new TextureCacheScriptingInterface(DependencyManager::get().data())); - scriptEngine->registerGlobalObject("ModelCache", new ModelCacheScriptingInterface(DependencyManager::get().data())); - scriptEngine->registerGlobalObject("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get().data())); + scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get().data()); + scriptEngine->registerGlobalObject("TextureCache", DependencyManager::get().data()); + scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get().data()); + scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get().data()); scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface); diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index b65fb93707..798b3d3cba 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -253,7 +253,7 @@ void Web3DOverlay::setupQmlSurface() { _webSurface->getSurfaceContext()->setContextProperty("AvatarList", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("InputConfiguration", DependencyManager::get().data()); - _webSurface->getSurfaceContext()->setContextProperty("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get().data())); + _webSurface->getSurfaceContext()->setContextProperty("SoundCache", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("Settings", SettingsScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("AvatarBookmarks", DependencyManager::get().data()); diff --git a/libraries/animation/src/AnimationCacheScriptingInterface.cpp b/libraries/animation/src/AnimationCacheScriptingInterface.cpp index a648a06228..450187a084 100644 --- a/libraries/animation/src/AnimationCacheScriptingInterface.cpp +++ b/libraries/animation/src/AnimationCacheScriptingInterface.cpp @@ -11,11 +11,10 @@ #include "AnimationCacheScriptingInterface.h" -AnimationCacheScriptingInterface::AnimationCacheScriptingInterface(AnimationCache* animationCache) : - _animationCache(animationCache), - ScriptableResourceCache::ScriptableResourceCache(animationCache) +AnimationCacheScriptingInterface::AnimationCacheScriptingInterface() : + ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get()) { } AnimationPointer AnimationCacheScriptingInterface::getAnimation(const QUrl& url) { - return _animationCache->getAnimation(url); -} \ No newline at end of file + return DependencyManager::get()->getAnimation(url); +} diff --git a/libraries/animation/src/AnimationCacheScriptingInterface.h b/libraries/animation/src/AnimationCacheScriptingInterface.h index ff7137040c..032ca169b8 100644 --- a/libraries/animation/src/AnimationCacheScriptingInterface.h +++ b/libraries/animation/src/AnimationCacheScriptingInterface.h @@ -19,7 +19,7 @@ #include "AnimationCache.h" -class AnimationCacheScriptingInterface : public ScriptableResourceCache { +class AnimationCacheScriptingInterface : public ScriptableResourceCache, public Dependency { Q_OBJECT // Properties are copied over from ResourceCache (see ResourceCache.h for reason). @@ -44,7 +44,7 @@ class AnimationCacheScriptingInterface : public ScriptableResourceCache { */ public: - AnimationCacheScriptingInterface(AnimationCache* animationCache); + AnimationCacheScriptingInterface(); /**jsdoc * Returns animation resource for particular animation. @@ -54,9 +54,6 @@ public: */ Q_INVOKABLE AnimationPointer getAnimation(const QString& url) { return getAnimation(QUrl(url)); } Q_INVOKABLE AnimationPointer getAnimation(const QUrl& url); - -private: - AnimationCache* _animationCache; }; #endif // hifi_AnimationCacheScriptingInterface_h diff --git a/libraries/audio/src/SoundCacheScriptingInterface.cpp b/libraries/audio/src/SoundCacheScriptingInterface.cpp index d9c65ddd29..94bb12be8c 100644 --- a/libraries/audio/src/SoundCacheScriptingInterface.cpp +++ b/libraries/audio/src/SoundCacheScriptingInterface.cpp @@ -11,11 +11,10 @@ #include "SoundCacheScriptingInterface.h" -SoundCacheScriptingInterface::SoundCacheScriptingInterface(SoundCache* soundCache) : - _soundCache(soundCache), - ScriptableResourceCache::ScriptableResourceCache(soundCache) +SoundCacheScriptingInterface::SoundCacheScriptingInterface() : + ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get()) { } SharedSoundPointer SoundCacheScriptingInterface::getSound(const QUrl& url) { - return _soundCache->getSound(url); + return DependencyManager::get()->getSound(url); } diff --git a/libraries/audio/src/SoundCacheScriptingInterface.h b/libraries/audio/src/SoundCacheScriptingInterface.h index 01b5753965..1995cef026 100644 --- a/libraries/audio/src/SoundCacheScriptingInterface.h +++ b/libraries/audio/src/SoundCacheScriptingInterface.h @@ -19,7 +19,7 @@ #include "SoundCache.h" -class SoundCacheScriptingInterface : public ScriptableResourceCache { +class SoundCacheScriptingInterface : public ScriptableResourceCache, public Dependency { Q_OBJECT // Properties are copied over from ResourceCache (see ResourceCache.h for reason). @@ -45,7 +45,7 @@ class SoundCacheScriptingInterface : public ScriptableResourceCache { */ public: - SoundCacheScriptingInterface(SoundCache* soundCache); + SoundCacheScriptingInterface(); /**jsdoc * @function SoundCache.getSound @@ -53,9 +53,6 @@ public: * @returns {SoundObject} */ Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url); - -private: - SoundCache* _soundCache; }; #endif // hifi_SoundCacheScriptingInterface_h diff --git a/libraries/model-networking/src/model-networking/ModelCacheScriptingInterface.cpp b/libraries/model-networking/src/model-networking/ModelCacheScriptingInterface.cpp index 88330cf319..cdf75be9ca 100644 --- a/libraries/model-networking/src/model-networking/ModelCacheScriptingInterface.cpp +++ b/libraries/model-networking/src/model-networking/ModelCacheScriptingInterface.cpp @@ -11,7 +11,6 @@ #include "ModelCacheScriptingInterface.h" -ModelCacheScriptingInterface::ModelCacheScriptingInterface(ModelCache* modelCache) : - _ModelCache(modelCache), - ScriptableResourceCache::ScriptableResourceCache(modelCache) +ModelCacheScriptingInterface::ModelCacheScriptingInterface() : + ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get()) { } diff --git a/libraries/model-networking/src/model-networking/ModelCacheScriptingInterface.h b/libraries/model-networking/src/model-networking/ModelCacheScriptingInterface.h index 5ac8271e7a..5ac7ac1e50 100644 --- a/libraries/model-networking/src/model-networking/ModelCacheScriptingInterface.h +++ b/libraries/model-networking/src/model-networking/ModelCacheScriptingInterface.h @@ -19,7 +19,7 @@ #include "ModelCache.h" -class ModelCacheScriptingInterface : public ScriptableResourceCache { +class ModelCacheScriptingInterface : public ScriptableResourceCache, public Dependency { Q_OBJECT // Properties are copied over from ResourceCache (see ResourceCache.h for reason). @@ -43,10 +43,7 @@ class ModelCacheScriptingInterface : public ScriptableResourceCache { */ public: - ModelCacheScriptingInterface(ModelCache* modelCache); - -private: - ModelCache* _ModelCache; + ModelCacheScriptingInterface(); }; #endif // hifi_ModelCacheScriptingInterface_h diff --git a/libraries/model-networking/src/model-networking/TextureCacheScriptingInterface.cpp b/libraries/model-networking/src/model-networking/TextureCacheScriptingInterface.cpp index 10f4591053..ff5c7ca298 100644 --- a/libraries/model-networking/src/model-networking/TextureCacheScriptingInterface.cpp +++ b/libraries/model-networking/src/model-networking/TextureCacheScriptingInterface.cpp @@ -11,14 +11,13 @@ #include "TextureCacheScriptingInterface.h" -TextureCacheScriptingInterface::TextureCacheScriptingInterface(TextureCache* textureCache) : - _textureCache(textureCache), - ScriptableResourceCache::ScriptableResourceCache(textureCache) +TextureCacheScriptingInterface::TextureCacheScriptingInterface() : + ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get()) { - connect(_textureCache, &TextureCache::spectatorCameraFramebufferReset, + connect(DependencyManager::get().data(), &TextureCache::spectatorCameraFramebufferReset, this, &TextureCacheScriptingInterface::spectatorCameraFramebufferReset); } ScriptableResource* TextureCacheScriptingInterface::prefetch(const QUrl& url, int type, int maxNumPixels) { - return _textureCache->prefetch(url, type, maxNumPixels); + return DependencyManager::get()->prefetch(url, type, maxNumPixels); } diff --git a/libraries/model-networking/src/model-networking/TextureCacheScriptingInterface.h b/libraries/model-networking/src/model-networking/TextureCacheScriptingInterface.h index 7246dcf64e..4120840759 100644 --- a/libraries/model-networking/src/model-networking/TextureCacheScriptingInterface.h +++ b/libraries/model-networking/src/model-networking/TextureCacheScriptingInterface.h @@ -19,7 +19,7 @@ #include "TextureCache.h" -class TextureCacheScriptingInterface : public ScriptableResourceCache { +class TextureCacheScriptingInterface : public ScriptableResourceCache, public Dependency { Q_OBJECT // Properties are copied over from ResourceCache (see ResourceCache.h for reason). @@ -43,7 +43,7 @@ class TextureCacheScriptingInterface : public ScriptableResourceCache { */ public: - TextureCacheScriptingInterface(TextureCache* textureCache); + TextureCacheScriptingInterface(); /**jsdoc * @function TextureCache.prefetch @@ -60,9 +60,6 @@ signals: * @returns {Signal} */ void spectatorCameraFramebufferReset(); - -private: - TextureCache* _textureCache; }; #endif // hifi_TextureCacheScriptingInterface_h diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 7cc04cb3cb..aed9f3b0e5 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -132,7 +132,7 @@ QSharedPointer ResourceCacheSharedItems::getHighestPendingRequest() { } -ScriptableResourceCache::ScriptableResourceCache(ResourceCache* resourceCache) { +ScriptableResourceCache::ScriptableResourceCache(QSharedPointer resourceCache) { _resourceCache = resourceCache; } diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 072c5cc5c2..2c0baad3f7 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -303,7 +303,7 @@ private: class ScriptableResourceCache : public QObject { Q_OBJECT - // JSDoc 3.5.5 doesn't augment namespaces with @property definitions so the following properties JSDoc is copied to the + // JSDoc 3.5.5 doesn't augment name spaces with @property definitions so the following properties JSDoc is copied to the // different exposed cache classes. /**jsdoc @@ -318,7 +318,7 @@ class ScriptableResourceCache : public QObject { Q_PROPERTY(size_t sizeCached READ getSizeCachedResources NOTIFY dirty) public: - ScriptableResourceCache(ResourceCache* resourceCache); + ScriptableResourceCache(QSharedPointer resourceCache); /**jsdoc * Get the list of all resource URLs. @@ -351,7 +351,7 @@ signals: void dirty(); private: - ResourceCache * _resourceCache; + QSharedPointer _resourceCache; size_t getNumTotalResources() const { return _resourceCache->getNumTotalResources(); } size_t getSizeTotalResources() const { return _resourceCache->getSizeTotalResources(); }