Merge pull request #13689 from ctrlaltdavid/M15244

Move scriptable caches' APIs into scripting interfaces
This commit is contained in:
John Conklin II 2018-08-01 11:50:13 -07:00 committed by GitHub
commit fd1a431729
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 429 additions and 290 deletions

View file

@ -19,6 +19,7 @@
#include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkReply>
#include <QThread> #include <QThread>
#include <AnimationCacheScriptingInterface.h>
#include <AssetClient.h> #include <AssetClient.h>
#include <AvatarHashMap.h> #include <AvatarHashMap.h>
#include <AudioInjectorManager.h> #include <AudioInjectorManager.h>
@ -32,6 +33,7 @@
#include <ResourceCache.h> #include <ResourceCache.h>
#include <ScriptCache.h> #include <ScriptCache.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>
@ -71,6 +73,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>();
@ -453,8 +456,8 @@ void Agent::executeScript() {
// register ourselves to the script engine // register ourselves to the script engine
_scriptEngine->registerGlobalObject("Agent", new AgentScriptingInterface(this)); _scriptEngine->registerGlobalObject("Agent", new AgentScriptingInterface(this));
_scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data()); _scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
_scriptEngine->registerGlobalObject("AnimationCache", 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);
@ -843,6 +846,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

@ -26,7 +26,7 @@
#include <ResourceManager.h> #include <ResourceManager.h>
#include <ScriptCache.h> #include <ScriptCache.h>
#include <ScriptEngines.h> #include <ScriptEngines.h>
#include <SoundCache.h> #include <SoundCacheScriptingInterface.h>
#include <UUID.h> #include <UUID.h>
#include <WebSocketServerClass.h> #include <WebSocketServerClass.h>
@ -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", 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

@ -63,6 +63,7 @@
#include <AddressManager.h> #include <AddressManager.h>
#include <AnimDebugDraw.h> #include <AnimDebugDraw.h>
#include <BuildInfo.h> #include <BuildInfo.h>
#include <AnimationCacheScriptingInterface.h>
#include <AssetClient.h> #include <AssetClient.h>
#include <AssetUpload.h> #include <AssetUpload.h>
#include <AutoUpdater.h> #include <AutoUpdater.h>
@ -98,6 +99,8 @@
#include <MainWindow.h> #include <MainWindow.h>
#include <MappingRequest.h> #include <MappingRequest.h>
#include <MessagesClient.h> #include <MessagesClient.h>
#include <model-networking/ModelCacheScriptingInterface.h>
#include <model-networking/TextureCacheScriptingInterface.h>
#include <ModelEntityItem.h> #include <ModelEntityItem.h>
#include <NetworkAccessManager.h> #include <NetworkAccessManager.h>
#include <NetworkingConstants.h> #include <NetworkingConstants.h>
@ -127,7 +130,7 @@
#include <ScriptEngines.h> #include <ScriptEngines.h>
#include <ScriptCache.h> #include <ScriptCache.h>
#include <ShapeEntityItem.h> #include <ShapeEntityItem.h>
#include <SoundCache.h> #include <SoundCacheScriptingInterface.h>
#include <ui/TabletScriptingInterface.h> #include <ui/TabletScriptingInterface.h>
#include <ui/ToolbarScriptingInterface.h> #include <ui/ToolbarScriptingInterface.h>
#include <InteractiveWindow.h> #include <InteractiveWindow.h>
@ -867,16 +870,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>();
@ -2563,12 +2570,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>();
@ -2994,10 +3007,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", DependencyManager::get<AnimationCache>().data()); surfaceContext->setContextProperty("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
surfaceContext->setContextProperty("TextureCache", DependencyManager::get<TextureCache>().data()); surfaceContext->setContextProperty("TextureCache", DependencyManager::get<TextureCacheScriptingInterface>().data());
surfaceContext->setContextProperty("ModelCache", DependencyManager::get<ModelCache>().data()); surfaceContext->setContextProperty("ModelCache", DependencyManager::get<ModelCacheScriptingInterface>().data());
surfaceContext->setContextProperty("SoundCache", 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
@ -6611,10 +6625,10 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
scriptEngine->registerGlobalObject("Pointers", DependencyManager::get<PointerScriptingInterface>().data()); scriptEngine->registerGlobalObject("Pointers", DependencyManager::get<PointerScriptingInterface>().data());
// Caches // Caches
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data()); scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("TextureCache", DependencyManager::get<TextureCache>().data()); scriptEngine->registerGlobalObject("TextureCache", DependencyManager::get<TextureCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get<ModelCache>().data()); scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get<ModelCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data()); scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface); scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface);

View file

@ -55,7 +55,7 @@
#include "scripting/AccountServicesScriptingInterface.h" #include "scripting/AccountServicesScriptingInterface.h"
#include <plugins/InputConfiguration.h> #include <plugins/InputConfiguration.h>
#include "ui/Snapshot.h" #include "ui/Snapshot.h"
#include "SoundCache.h" #include "SoundCacheScriptingInterface.h"
#include "raypick/PointerScriptingInterface.h" #include "raypick/PointerScriptingInterface.h"
#include <display-plugins/CompositorHelper.h> #include <display-plugins/CompositorHelper.h>
#include "AboutUtil.h" #include "AboutUtil.h"
@ -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", 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

@ -24,71 +24,12 @@ class Animation;
typedef QSharedPointer<Animation> AnimationPointer; typedef QSharedPointer<Animation> AnimationPointer;
/// Scriptable interface for FBX animation loading.
class AnimationCache : public ResourceCache, public Dependency { class AnimationCache : public ResourceCache, public Dependency {
Q_OBJECT Q_OBJECT
SINGLETON_DEPENDENCY SINGLETON_DEPENDENCY
public: public:
// Properties are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* API to manage animation cache resources.
* @namespace AnimationCache
*
* @hifi-interface
* @hifi-client-entity
* @hifi-assignment-client
*
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*/
// Functions are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* Get the list of all resource URLs.
* @function AnimationCache.getResourceList
* @returns {string[]}
*/
/**jsdoc
* @function AnimationCache.dirty
* @returns {Signal}
*/
/**jsdoc
* @function AnimationCache.updateTotalSize
* @param {number} deltaSize
*/
/**jsdoc
* Prefetches a resource.
* @function AnimationCache.prefetch
* @param {string} url - URL of the resource to prefetch.
* @param {object} [extra=null]
* @returns {ResourceObject}
*/
/**jsdoc
* Asynchronously loads a resource from the specified URL and returns it.
* @function AnimationCache.getResource
* @param {string} url - URL of the resource to load.
* @param {string} [fallback=""] - Fallback URL if load of the desired URL fails.
* @param {} [extra=null]
* @returns {object}
*/
/**jsdoc
* Returns animation resource for particular animation.
* @function AnimationCache.getAnimation
* @param {string} url - URL to load.
* @returns {AnimationObject} animation
*/
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);

View file

@ -0,0 +1,20 @@
//
// AnimationCacheScriptingInterface.cpp
// libraries/animation/src
//
// Created by David Rowe on 25 Jul 2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "AnimationCacheScriptingInterface.h"
AnimationCacheScriptingInterface::AnimationCacheScriptingInterface() :
ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get<AnimationCache>())
{ }
AnimationPointer AnimationCacheScriptingInterface::getAnimation(const QString& url) {
return DependencyManager::get<AnimationCache>()->getAnimation(QUrl(url));
}

View file

@ -0,0 +1,58 @@
//
// AnimationCacheScriptingInterface.h
// libraries/animation/src
//
// Created by David Rowe on 25 Jul 2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#pragma once
#ifndef hifi_AnimationCacheScriptingInterface_h
#define hifi_AnimationCacheScriptingInterface_h
#include <QObject>
#include <ResourceCache.h>
#include "AnimationCache.h"
class AnimationCacheScriptingInterface : public ScriptableResourceCache, public Dependency {
Q_OBJECT
// Properties are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* API to manage animation cache resources.
* @namespace AnimationCache
*
* @hifi-interface
* @hifi-client-entity
* @hifi-assignment-client
*
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*
* @borrows ResourceCache.getResourceList as getResourceList
* @borrows ResourceCache.updateTotalSize as updateTotalSize
* @borrows ResourceCache.prefetch as prefetch
* @borrows ResourceCache.dirty as dirty
*/
public:
AnimationCacheScriptingInterface();
/**jsdoc
* Returns animation resource for particular animation.
* @function AnimationCache.getAnimation
* @param {string} url - URL to load.
* @returns {AnimationObject} animation
*/
Q_INVOKABLE AnimationPointer getAnimation(const QString& url);
};
#endif // hifi_AnimationCacheScriptingInterface_h

View file

@ -16,73 +16,13 @@
#include "Sound.h" #include "Sound.h"
/// Scriptable interface for sound loading.
class SoundCache : public ResourceCache, public Dependency { class SoundCache : public ResourceCache, public Dependency {
Q_OBJECT Q_OBJECT
SINGLETON_DEPENDENCY SINGLETON_DEPENDENCY
public: public:
// Properties are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* API to manage sound cache resources.
* @namespace SoundCache
*
* @hifi-interface
* @hifi-client-entity
* @hifi-server-entity
* @hifi-assignment-client
*
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*/
// Functions are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* Get the list of all resource URLs.
* @function SoundCache.getResourceList
* @returns {string[]}
*/
/**jsdoc
* @function SoundCache.dirty
* @returns {Signal}
*/
/**jsdoc
* @function SoundCache.updateTotalSize
* @param {number} deltaSize
*/
/**jsdoc
* Prefetches a resource.
* @function SoundCache.prefetch
* @param {string} url - URL of the resource to prefetch.
* @param {object} [extra=null]
* @returns {ResourceObject}
*/
/**jsdoc
* Asynchronously loads a resource from the specified URL and returns it.
* @function SoundCache.getResource
* @param {string} url - URL of the resource to load.
* @param {string} [fallback=""] - Fallback URL if load of the desired URL fails.
* @param {} [extra=null]
* @returns {object}
*/
/**jsdoc
* @function SoundCache.getSound
* @param {string} url
* @returns {SoundObject}
*/
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url); Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
protected: protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
const void* extra) override; const void* extra) override;

View file

@ -0,0 +1,20 @@
//
// SoundCacheScriptingInterface.cpp
// libraries/audio/src
//
// Created by David Rowe on 25 Jul 2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "SoundCacheScriptingInterface.h"
SoundCacheScriptingInterface::SoundCacheScriptingInterface() :
ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get<SoundCache>())
{ }
SharedSoundPointer SoundCacheScriptingInterface::getSound(const QUrl& url) {
return DependencyManager::get<SoundCache>()->getSound(url);
}

View file

@ -0,0 +1,58 @@
//
// SoundCacheScriptingInterface.h
// libraries/audio/src
//
// Created by David Rowe on 25 Jul 2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#pragma once
#ifndef hifi_SoundCacheScriptingInterface_h
#define hifi_SoundCacheScriptingInterface_h
#include <QObject>
#include <ResourceCache.h>
#include "SoundCache.h"
class SoundCacheScriptingInterface : public ScriptableResourceCache, public Dependency {
Q_OBJECT
// Properties are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* API to manage sound cache resources.
* @namespace SoundCache
*
* @hifi-interface
* @hifi-client-entity
* @hifi-server-entity
* @hifi-assignment-client
*
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*
* @borrows ResourceCache.getResourceList as getResourceList
* @borrows ResourceCache.updateTotalSize as updateTotalSize
* @borrows ResourceCache.prefetch as prefetch
* @borrows ResourceCache.dirty as dirty
*/
public:
SoundCacheScriptingInterface();
/**jsdoc
* @function SoundCache.getSound
* @param {string} url
* @returns {SoundObject}
*/
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
};
#endif // hifi_SoundCacheScriptingInterface_h

View file

@ -140,58 +140,6 @@ class ModelCache : public ResourceCache, public Dependency {
public: public:
// Properties are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* API to manage model cache resources.
* @namespace ModelCache
*
* @hifi-interface
* @hifi-client-entity
*
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*/
// Functions are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* Get the list of all resource URLs.
* @function ModelCache.getResourceList
* @returns {string[]}
*/
/**jsdoc
* @function ModelCache.dirty
* @returns {Signal}
*/
/**jsdoc
* @function ModelCache.updateTotalSize
* @param {number} deltaSize
*/
/**jsdoc
* Prefetches a resource.
* @function ModelCache.prefetch
* @param {string} url - URL of the resource to prefetch.
* @param {object} [extra=null]
* @returns {ResourceObject}
*/
/**jsdoc
* Asynchronously loads a resource from the specified URL and returns it.
* @function ModelCache.getResource
* @param {string} url - URL of the resource to load.
* @param {string} [fallback=""] - Fallback URL if load of the desired URL fails.
* @param {} [extra=null]
* @returns {object}
*/
GeometryResource::Pointer getGeometryResource(const QUrl& url, GeometryResource::Pointer getGeometryResource(const QUrl& url,
const QVariantHash& mapping = QVariantHash(), const QVariantHash& mapping = QVariantHash(),
const QUrl& textureBaseUrl = QUrl()); const QUrl& textureBaseUrl = QUrl());

View file

@ -0,0 +1,16 @@
//
// ModelCacheScriptingInterface.cpp
// libraries/mmodel-networking/src/model-networking
//
// Created by David Rowe on 25 Jul 2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "ModelCacheScriptingInterface.h"
ModelCacheScriptingInterface::ModelCacheScriptingInterface() :
ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get<ModelCache>())
{ }

View file

@ -0,0 +1,49 @@
//
// ModelCacheScriptingInterface.h
// libraries/mmodel-networking/src/model-networking
//
// Created by David Rowe on 25 Jul 2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#pragma once
#ifndef hifi_ModelCacheScriptingInterface_h
#define hifi_ModelCacheScriptingInterface_h
#include <QObject>
#include <ResourceCache.h>
#include "ModelCache.h"
class ModelCacheScriptingInterface : public ScriptableResourceCache, public Dependency {
Q_OBJECT
// Properties are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* API to manage model cache resources.
* @namespace ModelCache
*
* @hifi-interface
* @hifi-client-entity
*
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*
* @borrows ResourceCache.getResourceList as getResourceList
* @borrows ResourceCache.updateTotalSize as updateTotalSize
* @borrows ResourceCache.prefetch as prefetch
* @borrows ResourceCache.dirty as dirty
*/
public:
ModelCacheScriptingInterface();
};
#endif // hifi_ModelCacheScriptingInterface_h

View file

@ -156,58 +156,6 @@ class TextureCache : public ResourceCache, public Dependency {
public: public:
// Properties are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* API to manage texture cache resources.
* @namespace TextureCache
*
* @hifi-interface
* @hifi-client-entity
*
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*/
// Functions are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* Get the list of all resource URLs.
* @function TextureCache.getResourceList
* @returns {string[]}
*/
/**jsdoc
* @function TextureCache.dirty
* @returns {Signal}
*/
/**jsdoc
* @function TextureCache.updateTotalSize
* @param {number} deltaSize
*/
/**jsdoc
* Prefetches a resource.
* @function TextureCache.prefetch
* @param {string} url - URL of the resource to prefetch.
* @param {object} [extra=null]
* @returns {ResourceObject}
*/
/**jsdoc
* Asynchronously loads a resource from the specified URL and returns it.
* @function TextureCache.getResource
* @param {string} url - URL of the resource to load.
* @param {string} [fallback=""] - Fallback URL if load of the desired URL fails.
* @param {} [extra=null]
* @returns {object}
*/
/// Returns the ID of the permutation/normal texture used for Perlin noise shader programs. This texture /// Returns the ID of the permutation/normal texture used for Perlin noise shader programs. This texture
/// has two lines: the first, a set of random numbers in [0, 255] to be used as permutation offsets, and /// has two lines: the first, a set of random numbers in [0, 255] to be used as permutation offsets, and
/// the second, a set of random unit vectors to be used as noise gradients. /// the second, a set of random unit vectors to be used as noise gradients.
@ -248,21 +196,10 @@ public:
gpu::ContextPointer getGPUContext() const { return _gpuContext; } gpu::ContextPointer getGPUContext() const { return _gpuContext; }
signals: signals:
/**jsdoc
* @function TextureCache.spectatorCameraFramebufferReset
* @returns {Signal}
*/
void spectatorCameraFramebufferReset(); void spectatorCameraFramebufferReset();
protected: protected:
/**jsdoc
* @function TextureCache.prefetch
* @param {string} url
* @param {number} type
* @param {number} [maxNumPixels=67108864]
* @returns {ResourceObject}
*/
// Overload ResourceCache::prefetch to allow specifying texture type for loads // Overload ResourceCache::prefetch to allow specifying texture type for loads
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type, int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS); Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type, int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS);
@ -273,6 +210,7 @@ private:
friend class ImageReader; friend class ImageReader;
friend class NetworkTexture; friend class NetworkTexture;
friend class DilatableNetworkTexture; friend class DilatableNetworkTexture;
friend class TextureCacheScriptingInterface;
TextureCache(); TextureCache();
virtual ~TextureCache(); virtual ~TextureCache();

View file

@ -0,0 +1,23 @@
//
// TextureCacheScriptingInterface.cpp
// libraries/mmodel-networking/src/model-networking
//
// Created by David Rowe on 25 Jul 2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "TextureCacheScriptingInterface.h"
TextureCacheScriptingInterface::TextureCacheScriptingInterface() :
ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get<TextureCache>())
{
connect(DependencyManager::get<TextureCache>().data(), &TextureCache::spectatorCameraFramebufferReset,
this, &TextureCacheScriptingInterface::spectatorCameraFramebufferReset);
}
ScriptableResource* TextureCacheScriptingInterface::prefetch(const QUrl& url, int type, int maxNumPixels) {
return DependencyManager::get<TextureCache>()->prefetch(url, type, maxNumPixels);
}

View file

@ -0,0 +1,65 @@
//
// TextureCacheScriptingInterface.h
// libraries/mmodel-networking/src/model-networking
//
// Created by David Rowe on 25 Jul 2018.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#pragma once
#ifndef hifi_TextureCacheScriptingInterface_h
#define hifi_TextureCacheScriptingInterface_h
#include <QObject>
#include <ResourceCache.h>
#include "TextureCache.h"
class TextureCacheScriptingInterface : public ScriptableResourceCache, public Dependency {
Q_OBJECT
// Properties are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* API to manage texture cache resources.
* @namespace TextureCache
*
* @hifi-interface
* @hifi-client-entity
*
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*
* @borrows ResourceCache.getResourceList as getResourceList
* @borrows ResourceCache.updateTotalSize as updateTotalSize
* @borrows ResourceCache.prefetch as prefetch
* @borrows ResourceCache.dirty as dirty
*/
public:
TextureCacheScriptingInterface();
/**jsdoc
* @function TextureCache.prefetch
* @param {string} url
* @param {number} type
* @param {number} [maxNumPixels=67108864]
* @returns {ResourceObject}
*/
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type, int maxNumPixels = ABSOLUTE_MAX_TEXTURE_NUM_PIXELS);
signals:
/**jsdoc
* @function TextureCache.spectatorCameraFramebufferReset
* @returns {Signal}
*/
void spectatorCameraFramebufferReset();
};
#endif // hifi_TextureCacheScriptingInterface_h

View file

@ -131,6 +131,24 @@ QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
return highestResource; return highestResource;
} }
ScriptableResourceCache::ScriptableResourceCache(QSharedPointer<ResourceCache> resourceCache) {
_resourceCache = resourceCache;
}
QVariantList ScriptableResourceCache::getResourceList() {
return _resourceCache->getResourceList();
}
void ScriptableResourceCache::updateTotalSize(const qint64& deltaSize) {
_resourceCache->updateTotalSize(deltaSize);
}
ScriptableResource* ScriptableResourceCache::prefetch(const QUrl& url, void* extra) {
return _resourceCache->prefetch(url, extra);
}
ScriptableResource::ScriptableResource(const QUrl& url) : ScriptableResource::ScriptableResource(const QUrl& url) :
QObject(nullptr), QObject(nullptr),
_url(url) { } _url(url) { }

View file

@ -124,9 +124,9 @@ public:
virtual ~ScriptableResource() = default; virtual ~ScriptableResource() = default;
/**jsdoc /**jsdoc
* Release this resource. * Release this resource.
* @function ResourceObject#release * @function ResourceObject#release
*/ */
Q_INVOKABLE void release(); Q_INVOKABLE void release();
const QUrl& getURL() const { return _url; } const QUrl& getURL() const { return _url; }
@ -186,15 +186,6 @@ Q_DECLARE_METATYPE(ScriptableResource*);
class ResourceCache : public QObject { class ResourceCache : public QObject {
Q_OBJECT Q_OBJECT
// JSDoc 3.5.5 doesn't augment namespaces with @property or @function definitions.
// The ResourceCache properties and functions are copied to the different exposed cache classes.
/**jsdoc
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*/
Q_PROPERTY(size_t numTotal READ getNumTotalResources NOTIFY dirty) Q_PROPERTY(size_t numTotal READ getNumTotalResources NOTIFY dirty)
Q_PROPERTY(size_t numCached READ getNumCachedResources NOTIFY dirty) Q_PROPERTY(size_t numCached READ getNumCachedResources NOTIFY dirty)
Q_PROPERTY(size_t sizeTotal READ getSizeTotalResources NOTIFY dirty) Q_PROPERTY(size_t sizeTotal READ getSizeTotalResources NOTIFY dirty)
@ -207,11 +198,6 @@ public:
size_t getNumCachedResources() const { return _numUnusedResources; } size_t getNumCachedResources() const { return _numUnusedResources; }
size_t getSizeCachedResources() const { return _unusedResourcesSize; } size_t getSizeCachedResources() const { return _unusedResourcesSize; }
/**jsdoc
* Get the list of all resource URLs.
* @function ResourceCache.getResourceList
* @returns {string[]}
*/
Q_INVOKABLE QVariantList getResourceList(); Q_INVOKABLE QVariantList getResourceList();
static void setRequestLimit(int limit); static void setRequestLimit(int limit);
@ -237,40 +223,17 @@ public:
signals: signals:
/**jsdoc
* @function ResourceCache.dirty
* @returns {Signal}
*/
void dirty(); void dirty();
protected slots: protected slots:
/**jsdoc
* @function ResourceCache.updateTotalSize
* @param {number} deltaSize
*/
void updateTotalSize(const qint64& deltaSize); void updateTotalSize(const qint64& deltaSize);
/**jsdoc
* Prefetches a resource.
* @function ResourceCache.prefetch
* @param {string} url - URL of the resource to prefetch.
* @param {object} [extra=null]
* @returns {ResourceObject}
*/
// Prefetches a resource to be held by the QScriptEngine. // Prefetches a resource to be held by the QScriptEngine.
// Left as a protected member so subclasses can overload prefetch // Left as a protected member so subclasses can overload prefetch
// and delegate to it (see TextureCache::prefetch(const QUrl&, int). // and delegate to it (see TextureCache::prefetch(const QUrl&, int).
ScriptableResource* prefetch(const QUrl& url, void* extra); ScriptableResource* prefetch(const QUrl& url, void* extra);
/**jsdoc
* Asynchronously loads a resource from the specified URL and returns it.
* @function ResourceCache.getResource
* @param {string} url - URL of the resource to load.
* @param {string} [fallback=""] - Fallback URL if load of the desired URL fails.
* @param {} [extra=null]
* @returns {object}
*/
// FIXME: The return type is not recognized by JavaScript. // FIXME: The return type is not recognized by JavaScript.
/// Loads a resource from the specified URL and returns it. /// Loads a resource from the specified URL and returns it.
/// If the caller is on a different thread than the ResourceCache, /// If the caller is on a different thread than the ResourceCache,
@ -306,6 +269,7 @@ protected:
private: private:
friend class Resource; friend class Resource;
friend class ScriptableResourceCache;
void reserveUnusedResource(qint64 resourceSize); void reserveUnusedResource(qint64 resourceSize);
void resetResourceCounters(); void resetResourceCounters();
@ -335,6 +299,66 @@ private:
QReadWriteLock _resourcesToBeGottenLock { QReadWriteLock::Recursive }; QReadWriteLock _resourcesToBeGottenLock { QReadWriteLock::Recursive };
}; };
/// Wrapper to expose resource caches to JS/QML
class ScriptableResourceCache : public QObject {
Q_OBJECT
// 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
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*/
Q_PROPERTY(size_t numTotal READ getNumTotalResources NOTIFY dirty)
Q_PROPERTY(size_t numCached READ getNumCachedResources NOTIFY dirty)
Q_PROPERTY(size_t sizeTotal READ getSizeTotalResources NOTIFY dirty)
Q_PROPERTY(size_t sizeCached READ getSizeCachedResources NOTIFY dirty)
public:
ScriptableResourceCache(QSharedPointer<ResourceCache> resourceCache);
/**jsdoc
* Get the list of all resource URLs.
* @function ResourceCache.getResourceList
* @returns {string[]}
*/
Q_INVOKABLE QVariantList getResourceList();
/**jsdoc
* @function ResourceCache.updateTotalSize
* @param {number} deltaSize
*/
Q_INVOKABLE void updateTotalSize(const qint64& deltaSize);
/**jsdoc
* Prefetches a resource.
* @function ResourceCache.prefetch
* @param {string} url - URL of the resource to prefetch.
* @param {object} [extra=null]
* @returns {ResourceObject}
*/
Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, void* extra = nullptr);
signals:
/**jsdoc
* @function ResourceCache.dirty
* @returns {Signal}
*/
void dirty();
private:
QSharedPointer<ResourceCache> _resourceCache;
size_t getNumTotalResources() const { return _resourceCache->getNumTotalResources(); }
size_t getSizeTotalResources() const { return _resourceCache->getSizeTotalResources(); }
size_t getNumCachedResources() const { return _resourceCache->getNumCachedResources(); }
size_t getSizeCachedResources() const { return _resourceCache->getSizeCachedResources(); }
};
/// Base class for resources. /// Base class for resources.
class Resource : public QObject { class Resource : public QObject {
Q_OBJECT Q_OBJECT