diff --git a/libraries/animation/src/AnimationCache.cpp b/libraries/animation/src/AnimationCache.cpp index 9364045857..482c4211cb 100644 --- a/libraries/animation/src/AnimationCache.cpp +++ b/libraries/animation/src/AnimationCache.cpp @@ -36,7 +36,7 @@ AnimationPointer AnimationCache::getAnimation(const QUrl& url) { } QSharedPointer AnimationCache::createResource(const QUrl& url, const QSharedPointer& fallback, - bool delayLoad, const void* extra) { + const void* extra) { return QSharedPointer(new Animation(url), &Resource::deleter); } diff --git a/libraries/animation/src/AnimationCache.h b/libraries/animation/src/AnimationCache.h index 59a4ad0498..9da649e66e 100644 --- a/libraries/animation/src/AnimationCache.h +++ b/libraries/animation/src/AnimationCache.h @@ -35,8 +35,8 @@ public: protected: - virtual QSharedPointer createResource(const QUrl& url, - const QSharedPointer& fallback, bool delayLoad, const void* extra); + virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, + const void* extra); private: explicit AnimationCache(QObject* parent = NULL); virtual ~AnimationCache() { } diff --git a/libraries/audio/src/SoundCache.cpp b/libraries/audio/src/SoundCache.cpp index 2752c6669f..96a2cee204 100644 --- a/libraries/audio/src/SoundCache.cpp +++ b/libraries/audio/src/SoundCache.cpp @@ -35,7 +35,7 @@ SharedSoundPointer SoundCache::getSound(const QUrl& url) { } QSharedPointer SoundCache::createResource(const QUrl& url, const QSharedPointer& fallback, - bool delayLoad, const void* extra) { + const void* extra) { qCDebug(audio) << "Requesting sound at" << url.toString(); return QSharedPointer(new Sound(url), &Resource::deleter); } diff --git a/libraries/audio/src/SoundCache.h b/libraries/audio/src/SoundCache.h index 7942e16010..59a25dd847 100644 --- a/libraries/audio/src/SoundCache.h +++ b/libraries/audio/src/SoundCache.h @@ -25,8 +25,8 @@ public: Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url); protected: - virtual QSharedPointer createResource(const QUrl& url, - const QSharedPointer& fallback, bool delayLoad, const void* extra); + virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, + const void* extra); private: SoundCache(QObject* parent = NULL); }; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 24834967d6..8cd6d9b65e 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -71,7 +71,7 @@ void GeometryMappingResource::downloadFinished(const QByteArray& data) { GeometryExtra extra{ mapping, _textureBaseUrl }; // Get the raw GeometryResource, not the wrapped NetworkGeometry - _geometryResource = modelCache->getResource(url, QUrl(), false, &extra).staticCast(); + _geometryResource = modelCache->getResource(url, QUrl(), &extra).staticCast(); // Avoid caching nested resources - their references will be held by the parent _geometryResource->_isCacheable = false; @@ -236,7 +236,7 @@ ModelCache::ModelCache() { } QSharedPointer ModelCache::createResource(const QUrl& url, const QSharedPointer& fallback, - bool delayLoad, const void* extra) { + const void* extra) { Resource* resource = nullptr; if (url.path().toLower().endsWith(".fst")) { resource = new GeometryMappingResource(url); @@ -252,7 +252,7 @@ QSharedPointer ModelCache::createResource(const QUrl& url, const QShar std::shared_ptr ModelCache::getGeometry(const QUrl& url, const QVariantHash& mapping, const QUrl& textureBaseUrl) { GeometryExtra geometryExtra = { mapping, textureBaseUrl }; - GeometryResource::Pointer resource = getResource(url, QUrl(), true, &geometryExtra).staticCast(); + GeometryResource::Pointer resource = getResource(url, QUrl(), &geometryExtra).staticCast(); if (resource) { if (resource->isLoaded() && resource->shouldSetTextures()) { resource->setTextures(); diff --git a/libraries/model-networking/src/model-networking/ModelCache.h b/libraries/model-networking/src/model-networking/ModelCache.h index bf47f293e8..f15e1106e2 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.h +++ b/libraries/model-networking/src/model-networking/ModelCache.h @@ -44,8 +44,8 @@ public: protected: friend class GeometryMappingResource; - virtual QSharedPointer createResource(const QUrl& url, - const QSharedPointer& fallback, bool delayLoad, const void* extra); + virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, + const void* extra); private: ModelCache(); diff --git a/libraries/model-networking/src/model-networking/ShaderCache.cpp b/libraries/model-networking/src/model-networking/ShaderCache.cpp index 3e14a99f87..bf7ade07f7 100644 --- a/libraries/model-networking/src/model-networking/ShaderCache.cpp +++ b/libraries/model-networking/src/model-networking/ShaderCache.cpp @@ -7,11 +7,8 @@ // #include "ShaderCache.h" -NetworkShader::NetworkShader(const QUrl& url, bool delayLoad) - : Resource(url, delayLoad) -{ - -} +NetworkShader::NetworkShader(const QUrl& url) : + Resource(url) {} void NetworkShader::downloadFinished(const QByteArray& data) { _source = QString::fromUtf8(data); @@ -24,10 +21,11 @@ ShaderCache& ShaderCache::instance() { } NetworkShaderPointer ShaderCache::getShader(const QUrl& url) { - return ResourceCache::getResource(url, QUrl(), false, nullptr).staticCast(); + return ResourceCache::getResource(url, QUrl(), nullptr).staticCast(); } -QSharedPointer ShaderCache::createResource(const QUrl& url, const QSharedPointer& fallback, bool delayLoad, const void* extra) { - return QSharedPointer(new NetworkShader(url, delayLoad), &Resource::deleter); +QSharedPointer ShaderCache::createResource(const QUrl& url, const QSharedPointer& fallback, + const void* extra) { + return QSharedPointer(new NetworkShader(url), &Resource::deleter); } diff --git a/libraries/model-networking/src/model-networking/ShaderCache.h b/libraries/model-networking/src/model-networking/ShaderCache.h index ffe8d437ce..4af12fdbfa 100644 --- a/libraries/model-networking/src/model-networking/ShaderCache.h +++ b/libraries/model-networking/src/model-networking/ShaderCache.h @@ -13,7 +13,7 @@ class NetworkShader : public Resource { public: - NetworkShader(const QUrl& url, bool delayLoad); + NetworkShader(const QUrl& url); virtual void downloadFinished(const QByteArray& data) override; QString _source; @@ -28,7 +28,8 @@ public: NetworkShaderPointer getShader(const QUrl& url); protected: - virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, bool delayLoad, const void* extra) override; + virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, + const void* extra) override; }; #endif diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 2aaddace88..000ca67989 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -167,7 +167,7 @@ ScriptableResource* TextureCache::prefetch(const QUrl& url, int type) { NetworkTexturePointer TextureCache::getTexture(const QUrl& url, Type type, const QByteArray& content) { TextureExtra extra = { type, content }; - return ResourceCache::getResource(url, QUrl(), content.isEmpty(), &extra).staticCast(); + return ResourceCache::getResource(url, QUrl(), &extra).staticCast(); } @@ -231,8 +231,8 @@ gpu::TexturePointer TextureCache::getImageTexture(const QString& path, Type type return gpu::TexturePointer(loader(image, QUrl::fromLocalFile(path).fileName().toStdString())); } -QSharedPointer TextureCache::createResource(const QUrl& url, - const QSharedPointer& fallback, bool delayLoad, const void* extra) { +QSharedPointer TextureCache::createResource(const QUrl& url, const QSharedPointer& fallback, + const void* extra) { const TextureExtra* textureExtra = static_cast(extra); auto type = textureExtra ? textureExtra->type : Type::DEFAULT_TEXTURE; auto content = textureExtra ? textureExtra->content : QByteArray(); @@ -241,7 +241,7 @@ QSharedPointer TextureCache::createResource(const QUrl& url, } NetworkTexture::NetworkTexture(const QUrl& url, Type type, const QByteArray& content) : - Resource(url, !content.isEmpty()), + Resource(url), _type(type) { _textureSource = std::make_shared(); diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index 8fd0b12369..f3c6a86b49 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -131,8 +131,8 @@ protected: // Overload ResourceCache::prefetch to allow specifying texture type for loads Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url, int type); - virtual QSharedPointer createResource(const QUrl& url, - const QSharedPointer& fallback, bool delayLoad, const void* extra); + virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, + const void* extra); private: TextureCache(); diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index e3b333aae9..36828b3992 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -179,7 +179,7 @@ ScriptableResource* ResourceCache::prefetch(const QUrl& url, void* extra) { result = new ScriptableResource(url); - auto resource = getResource(url, QUrl(), false, extra); + auto resource = getResource(url, QUrl(), extra); result->_resource = resource; result->setObjectName(url.toString()); @@ -316,8 +316,7 @@ void ResourceCache::setRequestLimit(int limit) { } } -QSharedPointer ResourceCache::getResource(const QUrl& url, const QUrl& fallback, - bool delayLoad, void* extra) { +QSharedPointer ResourceCache::getResource(const QUrl& url, const QUrl& fallback, void* extra) { QSharedPointer resource; { QReadLocker locker(&_resourcesLock); @@ -330,19 +329,20 @@ QSharedPointer ResourceCache::getResource(const QUrl& url, const QUrl& if (QThread::currentThread() != thread()) { qCDebug(networking) << "Fetching asynchronously:" << url; - assert(delayLoad); QMetaObject::invokeMethod(this, "getResource", - Q_ARG(QUrl, url), Q_ARG(QUrl, fallback), Q_ARG(bool, delayLoad)); + Q_ARG(QUrl, url), Q_ARG(QUrl, fallback)); // Cannot use extra parameter as it might be freed before the invocation return QSharedPointer(); } if (!url.isValid() && !url.isEmpty() && fallback.isValid()) { - return getResource(fallback, QUrl(), delayLoad); + return getResource(fallback, QUrl()); } - resource = createResource(url, fallback.isValid() ? - getResource(fallback, QUrl(), true) : QSharedPointer(), delayLoad, extra); + resource = createResource( + url, + fallback.isValid() ? getResource(fallback, QUrl()) : QSharedPointer(), + extra); resource->setSelf(resource); resource->setCache(this); connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize); @@ -494,7 +494,7 @@ const int DEFAULT_REQUEST_LIMIT = 10; int ResourceCache::_requestLimit = DEFAULT_REQUEST_LIMIT; int ResourceCache::_requestsActive = 0; -Resource::Resource(const QUrl& url, bool delayLoad) : +Resource::Resource(const QUrl& url) : _url(url), _activeUrl(url), _request(nullptr) { diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 6678c3157a..11b80ca349 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -187,12 +187,13 @@ protected slots: // and delegate to it (see TextureCache::prefetch(const QUrl&, int). ScriptableResource* prefetch(const QUrl& url, void* extra); - /// Loads a resource from the specified URL. + /// Loads a resource from the specified URL and returns it. + /// If the caller is on a different thread than the ResourceCache, + /// returns an empty smart pointer and loads its asynchronously. /// \param fallback a fallback URL to load if the desired one is unavailable - /// \param delayLoad if true, don't load the resource immediately; wait until load is first requested /// \param extra extra data to pass to the creator, if appropriate QSharedPointer getResource(const QUrl& url, const QUrl& fallback = QUrl(), - bool delayLoad = false, void* extra = NULL); + void* extra = NULL); private slots: void clearATPAssets(); @@ -205,8 +206,8 @@ protected: Q_INVOKABLE ScriptableResource* prefetch(const QUrl& url) { return prefetch(url, nullptr); } /// Creates a new resource. - virtual QSharedPointer createResource(const QUrl& url, - const QSharedPointer& fallback, bool delayLoad, const void* extra) = 0; + virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, + const void* extra) = 0; void addUnusedResource(const QSharedPointer& resource); void removeUnusedResource(const QSharedPointer& resource); @@ -257,7 +258,7 @@ class Resource : public QObject { public: - Resource(const QUrl& url, bool delayLoad = false); + Resource(const QUrl& url); ~Resource(); /// Returns the key last used to identify this resource in the unused map. diff --git a/libraries/recording/src/recording/ClipCache.cpp b/libraries/recording/src/recording/ClipCache.cpp index 145ecfc7b9..66d5fb0d88 100644 --- a/libraries/recording/src/recording/ClipCache.cpp +++ b/libraries/recording/src/recording/ClipCache.cpp @@ -9,12 +9,9 @@ #include "impl/PointerClip.h" using namespace recording; -NetworkClipLoader::NetworkClipLoader(const QUrl& url, bool delayLoad) - : Resource(url, delayLoad), _clip(std::make_shared(url)) -{ - -} - +NetworkClipLoader::NetworkClipLoader(const QUrl& url) : + Resource(url), + _clip(std::make_shared(url)) {} void NetworkClip::init(const QByteArray& clipData) { _clipData = clipData; @@ -32,10 +29,10 @@ ClipCache& ClipCache::instance() { } NetworkClipLoaderPointer ClipCache::getClipLoader(const QUrl& url) { - return ResourceCache::getResource(url, QUrl(), false, nullptr).staticCast(); + return ResourceCache::getResource(url, QUrl(), nullptr).staticCast(); } -QSharedPointer ClipCache::createResource(const QUrl& url, const QSharedPointer& fallback, bool delayLoad, const void* extra) { - return QSharedPointer(new NetworkClipLoader(url, delayLoad), &Resource::deleter); +QSharedPointer ClipCache::createResource(const QUrl& url, const QSharedPointer& fallback, const void* extra) { + return QSharedPointer(new NetworkClipLoader(url), &Resource::deleter); } diff --git a/libraries/recording/src/recording/ClipCache.h b/libraries/recording/src/recording/ClipCache.h index c72d45648d..7df83efdbf 100644 --- a/libraries/recording/src/recording/ClipCache.h +++ b/libraries/recording/src/recording/ClipCache.h @@ -31,7 +31,7 @@ private: class NetworkClipLoader : public Resource { public: - NetworkClipLoader(const QUrl& url, bool delayLoad); + NetworkClipLoader(const QUrl& url); virtual void downloadFinished(const QByteArray& data) override; ClipPointer getClip() { return _clip; } bool completed() { return _failedToLoad || isLoaded(); } @@ -49,7 +49,7 @@ public: NetworkClipLoaderPointer getClipLoader(const QUrl& url); protected: - virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, bool delayLoad, const void* extra) override; + virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, const void* extra) override; }; }