Revise scriptable resource caches' interfaces

This commit is contained in:
David Rowe 2018-07-26 16:12:16 +12:00
parent 16e06de9cd
commit baf88ab508
15 changed files with 54 additions and 54 deletions

View file

@ -32,8 +32,8 @@
#include <udt/PacketHeaders.h> #include <udt/PacketHeaders.h>
#include <ResourceCache.h> #include <ResourceCache.h>
#include <ScriptCache.h> #include <ScriptCache.h>
#include <SoundCacheScriptingInterface.h>
#include <ScriptEngines.h> #include <ScriptEngines.h>
#include <SoundCacheScriptingInterface.h>
#include <SoundCache.h> #include <SoundCache.h>
#include <UsersScriptingInterface.h> #include <UsersScriptingInterface.h>
#include <UUID.h> #include <UUID.h>
@ -72,6 +72,7 @@ Agent::Agent(ReceivedMessage& message) :
DependencyManager::set<ResourceCacheSharedItems>(); DependencyManager::set<ResourceCacheSharedItems>();
DependencyManager::set<SoundCache>(); DependencyManager::set<SoundCache>();
DependencyManager::set<SoundCacheScriptingInterface>();
DependencyManager::set<AudioScriptingInterface>(); DependencyManager::set<AudioScriptingInterface>();
DependencyManager::set<AudioInjectorManager>(); DependencyManager::set<AudioInjectorManager>();
@ -456,8 +457,8 @@ void Agent::executeScript() {
// register ourselves to the script engine // register ourselves to the script engine
_scriptEngine->registerGlobalObject("Agent", this); _scriptEngine->registerGlobalObject("Agent", this);
_scriptEngine->registerGlobalObject("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data())); _scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
_scriptEngine->registerGlobalObject("AnimationCache", new AnimationCacheScriptingInterface(DependencyManager::get<AnimationCache>().data())); _scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
QScriptValue webSocketServerConstructorValue = _scriptEngine->newFunction(WebSocketServerClass::constructor); QScriptValue webSocketServerConstructorValue = _scriptEngine->newFunction(WebSocketServerClass::constructor);
_scriptEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue); _scriptEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
@ -846,6 +847,7 @@ void Agent::aboutToFinish() {
DependencyManager::destroy<ScriptEngines>(); DependencyManager::destroy<ScriptEngines>();
DependencyManager::destroy<ResourceCacheSharedItems>(); DependencyManager::destroy<ResourceCacheSharedItems>();
DependencyManager::destroy<SoundCacheScriptingInterface>();
DependencyManager::destroy<SoundCache>(); DependencyManager::destroy<SoundCache>();
DependencyManager::destroy<AudioScriptingInterface>(); DependencyManager::destroy<AudioScriptingInterface>();

View file

@ -21,6 +21,7 @@
#include <shared/QtHelpers.h> #include <shared/QtHelpers.h>
#include <AccountManager.h> #include <AccountManager.h>
#include <AddressManager.h> #include <AddressManager.h>
#include <AnimationCacheScriptingInterface.h>
#include <Assignment.h> #include <Assignment.h>
#include <AvatarHashMap.h> #include <AvatarHashMap.h>
#include <EntityScriptingInterface.h> #include <EntityScriptingInterface.h>
@ -63,6 +64,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri
auto nodeList = DependencyManager::set<NodeList>(NodeType::Unassigned, listenPort); auto nodeList = DependencyManager::set<NodeList>(NodeType::Unassigned, listenPort);
auto animationCache = DependencyManager::set<AnimationCache>(); auto animationCache = DependencyManager::set<AnimationCache>();
DependencyManager::set<AnimationCacheScriptingInterface>();
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>(false); auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>(false);
DependencyManager::registerInheritance<EntityDynamicFactoryInterface, AssignmentDynamicFactory>(); DependencyManager::registerInheritance<EntityDynamicFactoryInterface, AssignmentDynamicFactory>();

View file

@ -66,6 +66,7 @@ EntityScriptServer::EntityScriptServer(ReceivedMessage& message) : ThreadedAssig
DependencyManager::set<ResourceCacheSharedItems>(); DependencyManager::set<ResourceCacheSharedItems>();
DependencyManager::set<SoundCache>(); DependencyManager::set<SoundCache>();
DependencyManager::set<SoundCacheScriptingInterface>();
DependencyManager::set<AudioInjectorManager>(); DependencyManager::set<AudioInjectorManager>();
DependencyManager::set<ScriptCache>(); DependencyManager::set<ScriptCache>();
@ -438,7 +439,7 @@ void EntityScriptServer::resetEntitiesScriptEngine() {
auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor); auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor);
newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue); newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
newEngine->registerGlobalObject("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data())); newEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
// connect this script engines printedMessage signal to the global ScriptEngines these various messages // connect this script engines printedMessage signal to the global ScriptEngines these various messages
auto scriptEngines = DependencyManager::get<ScriptEngines>().data(); auto scriptEngines = DependencyManager::get<ScriptEngines>().data();

View file

@ -869,16 +869,20 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
DependencyManager::set<recording::ClipCache>(); DependencyManager::set<recording::ClipCache>();
DependencyManager::set<GeometryCache>(); DependencyManager::set<GeometryCache>();
DependencyManager::set<ModelCache>(); DependencyManager::set<ModelCache>();
DependencyManager::set<ModelCacheScriptingInterface>();
DependencyManager::set<ScriptCache>(); DependencyManager::set<ScriptCache>();
DependencyManager::set<SoundCache>(); DependencyManager::set<SoundCache>();
DependencyManager::set<SoundCacheScriptingInterface>();
DependencyManager::set<DdeFaceTracker>(); DependencyManager::set<DdeFaceTracker>();
DependencyManager::set<EyeTracker>(); DependencyManager::set<EyeTracker>();
DependencyManager::set<AudioClient>(); DependencyManager::set<AudioClient>();
DependencyManager::set<AudioScope>(); DependencyManager::set<AudioScope>();
DependencyManager::set<DeferredLightingEffect>(); DependencyManager::set<DeferredLightingEffect>();
DependencyManager::set<TextureCache>(); DependencyManager::set<TextureCache>();
DependencyManager::set<TextureCacheScriptingInterface>();
DependencyManager::set<FramebufferCache>(); DependencyManager::set<FramebufferCache>();
DependencyManager::set<AnimationCache>(); DependencyManager::set<AnimationCache>();
DependencyManager::set<AnimationCacheScriptingInterface>();
DependencyManager::set<ModelBlender>(); DependencyManager::set<ModelBlender>();
DependencyManager::set<UsersScriptingInterface>(); DependencyManager::set<UsersScriptingInterface>();
DependencyManager::set<AvatarManager>(); DependencyManager::set<AvatarManager>();
@ -2565,12 +2569,18 @@ Application::~Application() {
DependencyManager::destroy<CompositorHelper>(); // must be destroyed before the FramebufferCache DependencyManager::destroy<CompositorHelper>(); // must be destroyed before the FramebufferCache
DependencyManager::destroy<SoundCacheScriptingInterface>();
DependencyManager::destroy<AvatarManager>(); DependencyManager::destroy<AvatarManager>();
DependencyManager::destroy<AnimationCacheScriptingInterface>();
DependencyManager::destroy<AnimationCache>(); DependencyManager::destroy<AnimationCache>();
DependencyManager::destroy<FramebufferCache>(); DependencyManager::destroy<FramebufferCache>();
DependencyManager::destroy<TextureCacheScriptingInterface>();
DependencyManager::destroy<TextureCache>(); DependencyManager::destroy<TextureCache>();
DependencyManager::destroy<ModelCacheScriptingInterface>();
DependencyManager::destroy<ModelCache>(); DependencyManager::destroy<ModelCache>();
DependencyManager::destroy<ScriptCache>(); DependencyManager::destroy<ScriptCache>();
DependencyManager::destroy<SoundCacheScriptingInterface>();
DependencyManager::destroy<SoundCache>(); DependencyManager::destroy<SoundCache>();
DependencyManager::destroy<OctreeStatsProvider>(); DependencyManager::destroy<OctreeStatsProvider>();
DependencyManager::destroy<GeometryCache>(); DependencyManager::destroy<GeometryCache>();
@ -2992,10 +3002,11 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) {
surfaceContext->setContextProperty("LocationBookmarks", DependencyManager::get<LocationBookmarks>().data()); surfaceContext->setContextProperty("LocationBookmarks", DependencyManager::get<LocationBookmarks>().data());
// Caches // Caches
surfaceContext->setContextProperty("AnimationCache", new AnimationCacheScriptingInterface(DependencyManager::get<AnimationCache>().data())); surfaceContext->setContextProperty("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
surfaceContext->setContextProperty("TextureCache", new TextureCacheScriptingInterface(DependencyManager::get<TextureCache>().data())); surfaceContext->setContextProperty("TextureCache", DependencyManager::get<TextureCacheScriptingInterface>().data());
surfaceContext->setContextProperty("ModelCache", new ModelCacheScriptingInterface(DependencyManager::get<ModelCache>().data())); surfaceContext->setContextProperty("ModelCache", DependencyManager::get<ModelCacheScriptingInterface>().data());
surfaceContext->setContextProperty("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data())); surfaceContext->setContextProperty("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data()); surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data());
surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED
@ -6615,10 +6626,10 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
scriptEngine->registerGlobalObject("Pointers", DependencyManager::get<PointerScriptingInterface>().data()); scriptEngine->registerGlobalObject("Pointers", DependencyManager::get<PointerScriptingInterface>().data());
// Caches // Caches
scriptEngine->registerGlobalObject("AnimationCache", new AnimationCacheScriptingInterface(DependencyManager::get<AnimationCache>().data())); scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("TextureCache", new TextureCacheScriptingInterface(DependencyManager::get<TextureCache>().data())); scriptEngine->registerGlobalObject("TextureCache", DependencyManager::get<TextureCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("ModelCache", new ModelCacheScriptingInterface(DependencyManager::get<ModelCache>().data())); scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get<ModelCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data())); scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface); scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface);

View file

@ -253,7 +253,7 @@ void Web3DOverlay::setupQmlSurface() {
_webSurface->getSurfaceContext()->setContextProperty("AvatarList", DependencyManager::get<AvatarManager>().data()); _webSurface->getSurfaceContext()->setContextProperty("AvatarList", DependencyManager::get<AvatarManager>().data());
_webSurface->getSurfaceContext()->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance());
_webSurface->getSurfaceContext()->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data()); _webSurface->getSurfaceContext()->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data());
_webSurface->getSurfaceContext()->setContextProperty("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data())); _webSurface->getSurfaceContext()->setContextProperty("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
_webSurface->getSurfaceContext()->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance());
_webSurface->getSurfaceContext()->setContextProperty("Settings", SettingsScriptingInterface::getInstance()); _webSurface->getSurfaceContext()->setContextProperty("Settings", SettingsScriptingInterface::getInstance());
_webSurface->getSurfaceContext()->setContextProperty("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data()); _webSurface->getSurfaceContext()->setContextProperty("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data());

View file

@ -11,11 +11,10 @@
#include "AnimationCacheScriptingInterface.h" #include "AnimationCacheScriptingInterface.h"
AnimationCacheScriptingInterface::AnimationCacheScriptingInterface(AnimationCache* animationCache) : AnimationCacheScriptingInterface::AnimationCacheScriptingInterface() :
_animationCache(animationCache), ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get<AnimationCache>())
ScriptableResourceCache::ScriptableResourceCache(animationCache)
{ } { }
AnimationPointer AnimationCacheScriptingInterface::getAnimation(const QUrl& url) { AnimationPointer AnimationCacheScriptingInterface::getAnimation(const QUrl& url) {
return _animationCache->getAnimation(url); return DependencyManager::get<AnimationCache>()->getAnimation(url);
} }

View file

@ -19,7 +19,7 @@
#include "AnimationCache.h" #include "AnimationCache.h"
class AnimationCacheScriptingInterface : public ScriptableResourceCache { class AnimationCacheScriptingInterface : public ScriptableResourceCache, public Dependency {
Q_OBJECT Q_OBJECT
// Properties are copied over from ResourceCache (see ResourceCache.h for reason). // Properties are copied over from ResourceCache (see ResourceCache.h for reason).
@ -44,7 +44,7 @@ class AnimationCacheScriptingInterface : public ScriptableResourceCache {
*/ */
public: public:
AnimationCacheScriptingInterface(AnimationCache* animationCache); AnimationCacheScriptingInterface();
/**jsdoc /**jsdoc
* Returns animation resource for particular animation. * 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 QString& url) { return getAnimation(QUrl(url)); }
Q_INVOKABLE AnimationPointer getAnimation(const QUrl& url); Q_INVOKABLE AnimationPointer getAnimation(const QUrl& url);
private:
AnimationCache* _animationCache;
}; };
#endif // hifi_AnimationCacheScriptingInterface_h #endif // hifi_AnimationCacheScriptingInterface_h

View file

@ -11,11 +11,10 @@
#include "SoundCacheScriptingInterface.h" #include "SoundCacheScriptingInterface.h"
SoundCacheScriptingInterface::SoundCacheScriptingInterface(SoundCache* soundCache) : SoundCacheScriptingInterface::SoundCacheScriptingInterface() :
_soundCache(soundCache), ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get<SoundCache>())
ScriptableResourceCache::ScriptableResourceCache(soundCache)
{ } { }
SharedSoundPointer SoundCacheScriptingInterface::getSound(const QUrl& url) { SharedSoundPointer SoundCacheScriptingInterface::getSound(const QUrl& url) {
return _soundCache->getSound(url); return DependencyManager::get<SoundCache>()->getSound(url);
} }

View file

@ -19,7 +19,7 @@
#include "SoundCache.h" #include "SoundCache.h"
class SoundCacheScriptingInterface : public ScriptableResourceCache { class SoundCacheScriptingInterface : public ScriptableResourceCache, public Dependency {
Q_OBJECT Q_OBJECT
// Properties are copied over from ResourceCache (see ResourceCache.h for reason). // Properties are copied over from ResourceCache (see ResourceCache.h for reason).
@ -45,7 +45,7 @@ class SoundCacheScriptingInterface : public ScriptableResourceCache {
*/ */
public: public:
SoundCacheScriptingInterface(SoundCache* soundCache); SoundCacheScriptingInterface();
/**jsdoc /**jsdoc
* @function SoundCache.getSound * @function SoundCache.getSound
@ -53,9 +53,6 @@ public:
* @returns {SoundObject} * @returns {SoundObject}
*/ */
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url); Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
private:
SoundCache* _soundCache;
}; };
#endif // hifi_SoundCacheScriptingInterface_h #endif // hifi_SoundCacheScriptingInterface_h

View file

@ -11,7 +11,6 @@
#include "ModelCacheScriptingInterface.h" #include "ModelCacheScriptingInterface.h"
ModelCacheScriptingInterface::ModelCacheScriptingInterface(ModelCache* modelCache) : ModelCacheScriptingInterface::ModelCacheScriptingInterface() :
_ModelCache(modelCache), ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get<ModelCache>())
ScriptableResourceCache::ScriptableResourceCache(modelCache)
{ } { }

View file

@ -19,7 +19,7 @@
#include "ModelCache.h" #include "ModelCache.h"
class ModelCacheScriptingInterface : public ScriptableResourceCache { class ModelCacheScriptingInterface : public ScriptableResourceCache, public Dependency {
Q_OBJECT Q_OBJECT
// Properties are copied over from ResourceCache (see ResourceCache.h for reason). // Properties are copied over from ResourceCache (see ResourceCache.h for reason).
@ -43,10 +43,7 @@ class ModelCacheScriptingInterface : public ScriptableResourceCache {
*/ */
public: public:
ModelCacheScriptingInterface(ModelCache* modelCache); ModelCacheScriptingInterface();
private:
ModelCache* _ModelCache;
}; };
#endif // hifi_ModelCacheScriptingInterface_h #endif // hifi_ModelCacheScriptingInterface_h

View file

@ -11,14 +11,13 @@
#include "TextureCacheScriptingInterface.h" #include "TextureCacheScriptingInterface.h"
TextureCacheScriptingInterface::TextureCacheScriptingInterface(TextureCache* textureCache) : TextureCacheScriptingInterface::TextureCacheScriptingInterface() :
_textureCache(textureCache), ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get<TextureCache>())
ScriptableResourceCache::ScriptableResourceCache(textureCache)
{ {
connect(_textureCache, &TextureCache::spectatorCameraFramebufferReset, connect(DependencyManager::get<TextureCache>().data(), &TextureCache::spectatorCameraFramebufferReset,
this, &TextureCacheScriptingInterface::spectatorCameraFramebufferReset); this, &TextureCacheScriptingInterface::spectatorCameraFramebufferReset);
} }
ScriptableResource* TextureCacheScriptingInterface::prefetch(const QUrl& url, int type, int maxNumPixels) { ScriptableResource* TextureCacheScriptingInterface::prefetch(const QUrl& url, int type, int maxNumPixels) {
return _textureCache->prefetch(url, type, maxNumPixels); return DependencyManager::get<TextureCache>()->prefetch(url, type, maxNumPixels);
} }

View file

@ -19,7 +19,7 @@
#include "TextureCache.h" #include "TextureCache.h"
class TextureCacheScriptingInterface : public ScriptableResourceCache { class TextureCacheScriptingInterface : public ScriptableResourceCache, public Dependency {
Q_OBJECT Q_OBJECT
// Properties are copied over from ResourceCache (see ResourceCache.h for reason). // Properties are copied over from ResourceCache (see ResourceCache.h for reason).
@ -43,7 +43,7 @@ class TextureCacheScriptingInterface : public ScriptableResourceCache {
*/ */
public: public:
TextureCacheScriptingInterface(TextureCache* textureCache); TextureCacheScriptingInterface();
/**jsdoc /**jsdoc
* @function TextureCache.prefetch * @function TextureCache.prefetch
@ -60,9 +60,6 @@ signals:
* @returns {Signal} * @returns {Signal}
*/ */
void spectatorCameraFramebufferReset(); void spectatorCameraFramebufferReset();
private:
TextureCache* _textureCache;
}; };
#endif // hifi_TextureCacheScriptingInterface_h #endif // hifi_TextureCacheScriptingInterface_h

View file

@ -132,7 +132,7 @@ QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
} }
ScriptableResourceCache::ScriptableResourceCache(ResourceCache* resourceCache) { ScriptableResourceCache::ScriptableResourceCache(QSharedPointer<ResourceCache> resourceCache) {
_resourceCache = resourceCache; _resourceCache = resourceCache;
} }

View file

@ -303,7 +303,7 @@ private:
class ScriptableResourceCache : public QObject { class ScriptableResourceCache : public QObject {
Q_OBJECT 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. // different exposed cache classes.
/**jsdoc /**jsdoc
@ -318,7 +318,7 @@ class ScriptableResourceCache : public QObject {
Q_PROPERTY(size_t sizeCached READ getSizeCachedResources NOTIFY dirty) Q_PROPERTY(size_t sizeCached READ getSizeCachedResources NOTIFY dirty)
public: public:
ScriptableResourceCache(ResourceCache* resourceCache); ScriptableResourceCache(QSharedPointer<ResourceCache> resourceCache);
/**jsdoc /**jsdoc
* Get the list of all resource URLs. * Get the list of all resource URLs.
@ -351,7 +351,7 @@ signals:
void dirty(); void dirty();
private: private:
ResourceCache * _resourceCache; QSharedPointer<ResourceCache> _resourceCache;
size_t getNumTotalResources() const { return _resourceCache->getNumTotalResources(); } size_t getNumTotalResources() const { return _resourceCache->getNumTotalResources(); }
size_t getSizeTotalResources() const { return _resourceCache->getSizeTotalResources(); } size_t getSizeTotalResources() const { return _resourceCache->getSizeTotalResources(); }