mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 15:43:24 +02:00
Move scriptable caches into scripting interfaces
Removed non-working getResource() API functions.
This commit is contained in:
parent
fe5b13b781
commit
16e06de9cd
18 changed files with 430 additions and 290 deletions
|
@ -19,6 +19,7 @@
|
|||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QThread>
|
||||
|
||||
#include <AnimationCacheScriptingInterface.h>
|
||||
#include <AssetClient.h>
|
||||
#include <AvatarHashMap.h>
|
||||
#include <AudioInjectorManager.h>
|
||||
|
@ -31,6 +32,7 @@
|
|||
#include <udt/PacketHeaders.h>
|
||||
#include <ResourceCache.h>
|
||||
#include <ScriptCache.h>
|
||||
#include <SoundCacheScriptingInterface.h>
|
||||
#include <ScriptEngines.h>
|
||||
#include <SoundCache.h>
|
||||
#include <UsersScriptingInterface.h>
|
||||
|
@ -454,8 +456,8 @@ void Agent::executeScript() {
|
|||
// register ourselves to the script engine
|
||||
_scriptEngine->registerGlobalObject("Agent", this);
|
||||
|
||||
_scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
|
||||
_scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
||||
_scriptEngine->registerGlobalObject("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data()));
|
||||
_scriptEngine->registerGlobalObject("AnimationCache", new AnimationCacheScriptingInterface(DependencyManager::get<AnimationCache>().data()));
|
||||
|
||||
QScriptValue webSocketServerConstructorValue = _scriptEngine->newFunction(WebSocketServerClass::constructor);
|
||||
_scriptEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <ResourceManager.h>
|
||||
#include <ScriptCache.h>
|
||||
#include <ScriptEngines.h>
|
||||
#include <SoundCache.h>
|
||||
#include <SoundCacheScriptingInterface.h>
|
||||
#include <UUID.h>
|
||||
#include <WebSocketServerClass.h>
|
||||
|
||||
|
@ -438,7 +438,7 @@ void EntityScriptServer::resetEntitiesScriptEngine() {
|
|||
auto webSocketServerConstructorValue = newEngine->newFunction(WebSocketServerClass::constructor);
|
||||
newEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
|
||||
|
||||
newEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
|
||||
newEngine->registerGlobalObject("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data()));
|
||||
|
||||
// connect this script engines printedMessage signal to the global ScriptEngines these various messages
|
||||
auto scriptEngines = DependencyManager::get<ScriptEngines>().data();
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
#include <AddressManager.h>
|
||||
#include <AnimDebugDraw.h>
|
||||
#include <BuildInfo.h>
|
||||
#include <AnimationCacheScriptingInterface.h>
|
||||
#include <AssetClient.h>
|
||||
#include <AssetUpload.h>
|
||||
#include <AutoUpdater.h>
|
||||
|
@ -98,6 +99,8 @@
|
|||
#include <MainWindow.h>
|
||||
#include <MappingRequest.h>
|
||||
#include <MessagesClient.h>
|
||||
#include <model-networking/ModelCacheScriptingInterface.h>
|
||||
#include <model-networking/TextureCacheScriptingInterface.h>
|
||||
#include <ModelEntityItem.h>
|
||||
#include <NetworkAccessManager.h>
|
||||
#include <NetworkingConstants.h>
|
||||
|
@ -127,7 +130,7 @@
|
|||
#include <ScriptEngines.h>
|
||||
#include <ScriptCache.h>
|
||||
#include <ShapeEntityItem.h>
|
||||
#include <SoundCache.h>
|
||||
#include <SoundCacheScriptingInterface.h>
|
||||
#include <ui/TabletScriptingInterface.h>
|
||||
#include <ui/ToolbarScriptingInterface.h>
|
||||
#include <InteractiveWindow.h>
|
||||
|
@ -2989,10 +2992,10 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) {
|
|||
surfaceContext->setContextProperty("LocationBookmarks", DependencyManager::get<LocationBookmarks>().data());
|
||||
|
||||
// Caches
|
||||
surfaceContext->setContextProperty("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
||||
surfaceContext->setContextProperty("TextureCache", DependencyManager::get<TextureCache>().data());
|
||||
surfaceContext->setContextProperty("ModelCache", DependencyManager::get<ModelCache>().data());
|
||||
surfaceContext->setContextProperty("SoundCache", DependencyManager::get<SoundCache>().data());
|
||||
surfaceContext->setContextProperty("AnimationCache", new AnimationCacheScriptingInterface(DependencyManager::get<AnimationCache>().data()));
|
||||
surfaceContext->setContextProperty("TextureCache", new TextureCacheScriptingInterface(DependencyManager::get<TextureCache>().data()));
|
||||
surfaceContext->setContextProperty("ModelCache", new ModelCacheScriptingInterface(DependencyManager::get<ModelCache>().data()));
|
||||
surfaceContext->setContextProperty("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data()));
|
||||
surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data());
|
||||
|
||||
surfaceContext->setContextProperty("Account", AccountServicesScriptingInterface::getInstance()); // DEPRECATED - TO BE REMOVED
|
||||
|
@ -6612,10 +6615,10 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
|
|||
scriptEngine->registerGlobalObject("Pointers", DependencyManager::get<PointerScriptingInterface>().data());
|
||||
|
||||
// Caches
|
||||
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
||||
scriptEngine->registerGlobalObject("TextureCache", DependencyManager::get<TextureCache>().data());
|
||||
scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get<ModelCache>().data());
|
||||
scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
|
||||
scriptEngine->registerGlobalObject("AnimationCache", new AnimationCacheScriptingInterface(DependencyManager::get<AnimationCache>().data()));
|
||||
scriptEngine->registerGlobalObject("TextureCache", new TextureCacheScriptingInterface(DependencyManager::get<TextureCache>().data()));
|
||||
scriptEngine->registerGlobalObject("ModelCache", new ModelCacheScriptingInterface(DependencyManager::get<ModelCache>().data()));
|
||||
scriptEngine->registerGlobalObject("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data()));
|
||||
|
||||
scriptEngine->registerGlobalObject("DialogsManager", _dialogsManagerScriptingInterface);
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
#include "scripting/AccountServicesScriptingInterface.h"
|
||||
#include <plugins/InputConfiguration.h>
|
||||
#include "ui/Snapshot.h"
|
||||
#include "SoundCache.h"
|
||||
#include "SoundCacheScriptingInterface.h"
|
||||
#include "raypick/PointerScriptingInterface.h"
|
||||
#include <display-plugins/CompositorHelper.h>
|
||||
#include "AboutUtil.h"
|
||||
|
@ -253,7 +253,7 @@ void Web3DOverlay::setupQmlSurface() {
|
|||
_webSurface->getSurfaceContext()->setContextProperty("AvatarList", DependencyManager::get<AvatarManager>().data());
|
||||
_webSurface->getSurfaceContext()->setContextProperty("DialogsManager", DialogsManagerScriptingInterface::getInstance());
|
||||
_webSurface->getSurfaceContext()->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data());
|
||||
_webSurface->getSurfaceContext()->setContextProperty("SoundCache", DependencyManager::get<SoundCache>().data());
|
||||
_webSurface->getSurfaceContext()->setContextProperty("SoundCache", new SoundCacheScriptingInterface(DependencyManager::get<SoundCache>().data()));
|
||||
_webSurface->getSurfaceContext()->setContextProperty("MenuInterface", MenuScriptingInterface::getInstance());
|
||||
_webSurface->getSurfaceContext()->setContextProperty("Settings", SettingsScriptingInterface::getInstance());
|
||||
_webSurface->getSurfaceContext()->setContextProperty("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data());
|
||||
|
|
|
@ -24,71 +24,12 @@ class Animation;
|
|||
|
||||
typedef QSharedPointer<Animation> AnimationPointer;
|
||||
|
||||
/// Scriptable interface for FBX animation loading.
|
||||
class AnimationCache : public ResourceCache, public Dependency {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
|
||||
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 QUrl& url);
|
||||
|
||||
|
|
21
libraries/animation/src/AnimationCacheScriptingInterface.cpp
Normal file
21
libraries/animation/src/AnimationCacheScriptingInterface.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// 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(AnimationCache* animationCache) :
|
||||
_animationCache(animationCache),
|
||||
ScriptableResourceCache::ScriptableResourceCache(animationCache)
|
||||
{ }
|
||||
|
||||
AnimationPointer AnimationCacheScriptingInterface::getAnimation(const QUrl& url) {
|
||||
return _animationCache->getAnimation(url);
|
||||
}
|
62
libraries/animation/src/AnimationCacheScriptingInterface.h
Normal file
62
libraries/animation/src/AnimationCacheScriptingInterface.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
//
|
||||
// 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 {
|
||||
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(AnimationCache* animationCache);
|
||||
|
||||
/**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 QUrl& url);
|
||||
|
||||
private:
|
||||
AnimationCache* _animationCache;
|
||||
};
|
||||
|
||||
#endif // hifi_AnimationCacheScriptingInterface_h
|
|
@ -16,73 +16,13 @@
|
|||
|
||||
#include "Sound.h"
|
||||
|
||||
/// Scriptable interface for sound loading.
|
||||
class SoundCache : public ResourceCache, public Dependency {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
|
||||
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);
|
||||
|
||||
protected:
|
||||
virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback,
|
||||
const void* extra) override;
|
||||
|
|
21
libraries/audio/src/SoundCacheScriptingInterface.cpp
Normal file
21
libraries/audio/src/SoundCacheScriptingInterface.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// 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(SoundCache* soundCache) :
|
||||
_soundCache(soundCache),
|
||||
ScriptableResourceCache::ScriptableResourceCache(soundCache)
|
||||
{ }
|
||||
|
||||
SharedSoundPointer SoundCacheScriptingInterface::getSound(const QUrl& url) {
|
||||
return _soundCache->getSound(url);
|
||||
}
|
61
libraries/audio/src/SoundCacheScriptingInterface.h
Normal file
61
libraries/audio/src/SoundCacheScriptingInterface.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
//
|
||||
// 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 {
|
||||
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(SoundCache* soundCache);
|
||||
|
||||
/**jsdoc
|
||||
* @function SoundCache.getSound
|
||||
* @param {string} url
|
||||
* @returns {SoundObject}
|
||||
*/
|
||||
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
|
||||
|
||||
private:
|
||||
SoundCache* _soundCache;
|
||||
};
|
||||
|
||||
#endif // hifi_SoundCacheScriptingInterface_h
|
|
@ -140,58 +140,6 @@ class ModelCache : public ResourceCache, public Dependency {
|
|||
|
||||
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,
|
||||
const QVariantHash& mapping = QVariantHash(),
|
||||
const QUrl& textureBaseUrl = QUrl());
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// 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(ModelCache* modelCache) :
|
||||
_ModelCache(modelCache),
|
||||
ScriptableResourceCache::ScriptableResourceCache(modelCache)
|
||||
{ }
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// 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 {
|
||||
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(ModelCache* modelCache);
|
||||
|
||||
private:
|
||||
ModelCache* _ModelCache;
|
||||
};
|
||||
|
||||
#endif // hifi_ModelCacheScriptingInterface_h
|
|
@ -156,58 +156,6 @@ class TextureCache : public ResourceCache, public Dependency {
|
|||
|
||||
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
|
||||
/// 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.
|
||||
|
@ -248,21 +196,10 @@ public:
|
|||
gpu::ContextPointer getGPUContext() const { return _gpuContext; }
|
||||
|
||||
signals:
|
||||
/**jsdoc
|
||||
* @function TextureCache.spectatorCameraFramebufferReset
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void spectatorCameraFramebufferReset();
|
||||
|
||||
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
|
||||
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 NetworkTexture;
|
||||
friend class DilatableNetworkTexture;
|
||||
friend class TextureCacheScriptingInterface;
|
||||
|
||||
TextureCache();
|
||||
virtual ~TextureCache();
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// 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(TextureCache* textureCache) :
|
||||
_textureCache(textureCache),
|
||||
ScriptableResourceCache::ScriptableResourceCache(textureCache)
|
||||
{
|
||||
connect(_textureCache, &TextureCache::spectatorCameraFramebufferReset,
|
||||
this, &TextureCacheScriptingInterface::spectatorCameraFramebufferReset);
|
||||
}
|
||||
|
||||
ScriptableResource* TextureCacheScriptingInterface::prefetch(const QUrl& url, int type, int maxNumPixels) {
|
||||
return _textureCache->prefetch(url, type, maxNumPixels);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// 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 {
|
||||
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(TextureCache* textureCache);
|
||||
|
||||
/**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();
|
||||
|
||||
private:
|
||||
TextureCache* _textureCache;
|
||||
};
|
||||
|
||||
#endif // hifi_TextureCacheScriptingInterface_h
|
|
@ -131,6 +131,24 @@ QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
|
|||
return highestResource;
|
||||
}
|
||||
|
||||
|
||||
ScriptableResourceCache::ScriptableResourceCache(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) :
|
||||
QObject(nullptr),
|
||||
_url(url) { }
|
||||
|
|
|
@ -124,9 +124,9 @@ public:
|
|||
virtual ~ScriptableResource() = default;
|
||||
|
||||
/**jsdoc
|
||||
* Release this resource.
|
||||
* @function ResourceObject#release
|
||||
*/
|
||||
* Release this resource.
|
||||
* @function ResourceObject#release
|
||||
*/
|
||||
Q_INVOKABLE void release();
|
||||
|
||||
const QUrl& getURL() const { return _url; }
|
||||
|
@ -186,15 +186,6 @@ Q_DECLARE_METATYPE(ScriptableResource*);
|
|||
class ResourceCache : public QObject {
|
||||
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 numCached READ getNumCachedResources NOTIFY dirty)
|
||||
Q_PROPERTY(size_t sizeTotal READ getSizeTotalResources NOTIFY dirty)
|
||||
|
@ -207,11 +198,6 @@ public:
|
|||
size_t getNumCachedResources() const { return _numUnusedResources; }
|
||||
size_t getSizeCachedResources() const { return _unusedResourcesSize; }
|
||||
|
||||
/**jsdoc
|
||||
* Get the list of all resource URLs.
|
||||
* @function ResourceCache.getResourceList
|
||||
* @returns {string[]}
|
||||
*/
|
||||
Q_INVOKABLE QVariantList getResourceList();
|
||||
|
||||
static void setRequestLimit(int limit);
|
||||
|
@ -237,40 +223,17 @@ public:
|
|||
|
||||
signals:
|
||||
|
||||
/**jsdoc
|
||||
* @function ResourceCache.dirty
|
||||
* @returns {Signal}
|
||||
*/
|
||||
void dirty();
|
||||
|
||||
protected slots:
|
||||
|
||||
/**jsdoc
|
||||
* @function ResourceCache.updateTotalSize
|
||||
* @param {number} 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.
|
||||
// Left as a protected member so subclasses can overload prefetch
|
||||
// and delegate to it (see TextureCache::prefetch(const QUrl&, int).
|
||||
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.
|
||||
/// Loads a resource from the specified URL and returns it.
|
||||
/// If the caller is on a different thread than the ResourceCache,
|
||||
|
@ -306,6 +269,7 @@ protected:
|
|||
|
||||
private:
|
||||
friend class Resource;
|
||||
friend class ScriptableResourceCache;
|
||||
|
||||
void reserveUnusedResource(qint64 resourceSize);
|
||||
void resetResourceCounters();
|
||||
|
@ -335,6 +299,66 @@ private:
|
|||
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 namespaces 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(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:
|
||||
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.
|
||||
class Resource : public QObject {
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Reference in a new issue