From 9e002c59d4630510c7c89376519da186b1c8e0b3 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 13 Feb 2019 15:24:55 -0800 Subject: [PATCH] fix pal --- libraries/audio/src/Sound.h | 3 ++- libraries/gpu/src/gpu/Texture.h | 4 ++-- libraries/hfm/src/hfm/HFM.h | 1 + .../src/model-networking/ModelCache.cpp | 2 +- .../src/model-networking/TextureCache.cpp | 9 ++++++++- libraries/networking/src/ResourceCache.cpp | 15 +++++++++------ libraries/networking/src/ResourceCache.h | 3 ++- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/libraries/audio/src/Sound.h b/libraries/audio/src/Sound.h index 836e28d582..359b931cd4 100644 --- a/libraries/audio/src/Sound.h +++ b/libraries/audio/src/Sound.h @@ -61,7 +61,8 @@ class Sound : public Resource { public: Sound(const QUrl& url, bool isStereo = false, bool isAmbisonic = false); - + Sound(const Sound& other) : Resource(other), _audioData(other._audioData), _numChannels(other._numChannels) {} + bool isReady() const { return (bool)_audioData; } bool isStereo() const { return _audioData ? _audioData->isStereo() : false; } diff --git a/libraries/gpu/src/gpu/Texture.h b/libraries/gpu/src/gpu/Texture.h index 23bfff6873..517d7158e4 100755 --- a/libraries/gpu/src/gpu/Texture.h +++ b/libraries/gpu/src/gpu/Texture.h @@ -395,8 +395,6 @@ public: bool isDefined() const { return _defined; } Texture(TextureUsageType usageType); - Texture(const Texture& buf); // deep copy of the sysmem texture - Texture& operator=(const Texture& buf); // deep copy of the sysmem texture ~Texture(); Stamp getStamp() const { return _stamp; } @@ -690,8 +688,10 @@ class TextureSource { public: TextureSource(const QUrl& url, int type = 0) : _imageUrl(url), _type(type) {} + void setUrl(const QUrl& url) { _imageUrl = url; } const QUrl& getUrl() const { return _imageUrl; } const gpu::TexturePointer getGPUTexture() const { return _gpuTexture; } + void setType(int type) { _type = type; } int getType() const { return _type; } void resetTexture(gpu::TexturePointer texture); diff --git a/libraries/hfm/src/hfm/HFM.h b/libraries/hfm/src/hfm/HFM.h index cccfaa3f7d..f1b6b4bd68 100644 --- a/libraries/hfm/src/hfm/HFM.h +++ b/libraries/hfm/src/hfm/HFM.h @@ -119,6 +119,7 @@ public: /// A texture map. class Texture { public: + QString id; QString name; QByteArray filename; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index a4eba0c7a9..da4515392b 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -322,7 +322,7 @@ private: void GeometryDefinitionResource::setExtra(void* extra) { const GeometryExtra* geometryExtra = static_cast(extra); _mapping = geometryExtra ? geometryExtra->mapping : QVariantHash(); - _textureBaseUrl = resolveTextureBaseUrl(_url, geometryExtra ? geometryExtra->textureBaseUrl : QUrl()); + _textureBaseUrl = geometryExtra ? resolveTextureBaseUrl(_url, geometryExtra->textureBaseUrl) : QUrl(); _combineParts = geometryExtra ? geometryExtra->combineParts : true; } diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index d4cf7e6ce9..8c075f80fc 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -335,6 +335,7 @@ int networkTexturePointerMetaTypeId = qRegisterMetaTypetype : image::TextureUsage::DEFAULT_TEXTURE; _maxNumPixels = textureExtra ? textureExtra->maxNumPixels : ABSOLUTE_MAX_TEXTURE_NUM_PIXELS; - _textureSource = std::make_shared(_url, (int)_type); + if (_textureSource) { + _textureSource->setUrl(_url); + _textureSource->setType((int)_type); + } else { + _textureSource = std::make_shared(_url, (int)_type); + } _lowestRequestedMipLevel = 0; auto fileNameLowercase = _url.fileName().toLower(); diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index cb7b8c7c82..7345081380 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -362,7 +362,6 @@ QSharedPointer ResourceCache::getResource(const QUrl& url, const QUrl& resource->moveToThread(qApp->thread()); connect(resource.data(), &Resource::updateSize, this, &ResourceCache::updateTotalSize); resourcesWithExtraHash.insert(extraHash, resource); - removeUnusedResource(resource); resource->ensureLoading(); } } @@ -404,7 +403,7 @@ void ResourceCache::addUnusedResource(const QSharedPointer& resource) // If it doesn't fit or its size is unknown, remove it from the cache. if (resource->getBytes() == 0 || resource->getBytes() > _unusedResourcesMaxSize) { resource->setCache(nullptr); - removeResource(resource->getURL(), resource->getBytes()); + removeResource(resource->getURL(), resource->getExtraHash(), resource->getBytes()); resetTotalResourceCounter(); return; } @@ -443,7 +442,7 @@ void ResourceCache::reserveUnusedResource(qint64 resourceSize) { auto size = it.value()->getBytes(); locker.unlock(); - removeResource(it.value()->getURL(), size); + removeResource(it.value()->getURL(), it.value()->getExtraHash(), size); locker.relock(); _unusedResourcesSize -= size; @@ -489,9 +488,13 @@ void ResourceCache::resetResourceCounters() { emit dirty(); } -void ResourceCache::removeResource(const QUrl& url, qint64 size) { +void ResourceCache::removeResource(const QUrl& url, size_t extraHash, qint64 size) { QWriteLocker locker(&_resourcesLock); - _resources.remove(url); + auto& resources = _resources[url]; + resources.remove(extraHash); + if (resources.size() == 0) { + _resources.remove(url); + } _totalResourcesSize -= size; } @@ -664,7 +667,7 @@ void Resource::allReferencesCleared() { } else { if (_cache) { // remove from the cache - _cache->removeResource(getURL(), getBytes()); + _cache->removeResource(getURL(), getExtraHash(), getBytes()); _cache->resetTotalResourceCounter(); } diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 740bdadc48..e47a8836c0 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -271,7 +271,7 @@ private: friend class ScriptableResourceCache; void reserveUnusedResource(qint64 resourceSize); - void removeResource(const QUrl& url, qint64 size = 0); + void removeResource(const QUrl& url, size_t extraHash, qint64 size = 0); void resetTotalResourceCounter(); void resetUnusedResourceCounter(); @@ -418,6 +418,7 @@ public: virtual void setExtra(void* extra) {}; void setExtraHash(size_t extraHash) { _extraHash = extraHash; } + size_t getExtraHash() const { return _extraHash; } signals: /// Fired when the resource begins downloading.