From 54af58834a9038c517c7acf749816d7efbe29fcd Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 8 Mar 2016 18:19:01 -0800 Subject: [PATCH] Mark Resource loaded after postprocessing --- libraries/animation/src/AnimationCache.cpp | 1 + libraries/audio/src/Sound.cpp | 2 ++ .../src/model-networking/ShaderCache.cpp | 1 + .../src/model-networking/TextureCache.cpp | 2 -- .../src/model-networking/TextureCache.h | 3 +-- libraries/networking/src/ResourceCache.cpp | 5 ----- libraries/networking/src/ResourceCache.h | 15 +++++++++------ libraries/recording/src/recording/ClipCache.cpp | 1 + 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libraries/animation/src/AnimationCache.cpp b/libraries/animation/src/AnimationCache.cpp index 149e1a3761..ca666443fa 100644 --- a/libraries/animation/src/AnimationCache.cpp +++ b/libraries/animation/src/AnimationCache.cpp @@ -132,6 +132,7 @@ void Animation::animationParseSuccess(FBXGeometry* geometry) { void Animation::animationParseError(int error, QString str) { qCCritical(animation) << "Animation failure parsing " << _url.toDisplayString() << "code =" << error << str; emit failed(QNetworkReply::UnknownContentError); + finishedLoading(false); } AnimationDetails::AnimationDetails() : diff --git a/libraries/audio/src/Sound.cpp b/libraries/audio/src/Sound.cpp index 089ff7544b..9816b1b61d 100644 --- a/libraries/audio/src/Sound.cpp +++ b/libraries/audio/src/Sound.cpp @@ -80,6 +80,8 @@ void Sound::downloadFinished(const QByteArray& data) { qCDebug(audio) << "Unknown sound file type"; } + finishedLoading(true); + _isReady = true; emit ready(); } diff --git a/libraries/model-networking/src/model-networking/ShaderCache.cpp b/libraries/model-networking/src/model-networking/ShaderCache.cpp index d0c5d6631f..7e52052c30 100644 --- a/libraries/model-networking/src/model-networking/ShaderCache.cpp +++ b/libraries/model-networking/src/model-networking/ShaderCache.cpp @@ -15,6 +15,7 @@ NetworkShader::NetworkShader(const QUrl& url, bool delayLoad) void NetworkShader::downloadFinished(const QByteArray& data) { _source = QString::fromUtf8(data); + finishedLoading(true); } ShaderCache& ShaderCache::instance() { diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 82a0b35cc9..a2cd3284ef 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -344,9 +344,7 @@ void NetworkTexture::setImage(const QImage& image, void* voidTexture, int origin _width = _height = 0; } - _isCacheable = true; finishedLoading(true); emit networkTextureCreated(qWeakPointerCast (_self)); } - diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index ee2279540b..72a09a8b3f 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -132,7 +132,7 @@ signals: protected: - virtual bool isCacheable() const override { return _isCacheable; } + virtual bool isCacheable() const override { return _loaded; } virtual void downloadFinished(const QByteArray& data) override; @@ -148,7 +148,6 @@ private: int _originalHeight { 0 }; int _width { 0 }; int _height { 0 }; - bool _isCacheable { false }; }; #endif // hifi_TextureCache_h diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index b312067d49..dabf1b098b 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -371,7 +371,6 @@ void Resource::handleReplyFinished() { auto extraInfo = _url == _activeUrl ? "" : QString(", %1").arg(_activeUrl.toDisplayString()); qCDebug(networking).noquote() << QString("Request finished for %1%2").arg(_url.toDisplayString(), extraInfo); - finishedLoading(true); emit loaded(_data); downloadFinished(_data); } else { @@ -409,10 +408,6 @@ void Resource::handleReplyFinished() { _request = nullptr; } - -void Resource::downloadFinished(const QByteArray& data) { -} - uint qHash(const QPointer& value, uint seed) { return qHash(value.data(), seed); } diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 2a89ad9b92..6fbf54c49d 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -177,13 +177,14 @@ public: const QByteArray& getData() const { return _data; } signals: - /// Fired when the resource has been loaded. + /// Fired when the resource has been downloaded. + /// This can be used instead of downloadFinished to access data before it is processed. void loaded(const QByteArray& request); - /// Fired when resource failed to load. + /// Fired when the resource failed to load. void failed(QNetworkReply::NetworkError error); - /// Fired when resource is refreshed. + /// Fired when the resource is refreshed. void onRefresh(); protected slots: @@ -195,10 +196,12 @@ protected: /// Checks whether the resource is cacheable. virtual bool isCacheable() const { return true; } - /// Called when the download has finished - virtual void downloadFinished(const QByteArray& data); + /// Called when the download has finished. + /// This should be overridden by subclasses that need to process the data once it is downloaded. + virtual void downloadFinished(const QByteArray& data) { finishedLoading(true); } - /// Should be called by subclasses when all the loading that will be done has been done. + /// Called when the download is finished and processed. + /// This should be called by subclasses that override downloadFinished to mark the end of processing. Q_INVOKABLE void finishedLoading(bool success); /// Reinserts this resource into the cache. diff --git a/libraries/recording/src/recording/ClipCache.cpp b/libraries/recording/src/recording/ClipCache.cpp index fb09245bf9..37c15b0ca4 100644 --- a/libraries/recording/src/recording/ClipCache.cpp +++ b/libraries/recording/src/recording/ClipCache.cpp @@ -23,6 +23,7 @@ void NetworkClip::init(const QByteArray& clipData) { void NetworkClipLoader::downloadFinished(const QByteArray& data) { _clip->init(data); + finishedLoading(true); } ClipCache& ClipCache::instance() {