mirror of
https://github.com/overte-org/overte.git
synced 2025-08-12 11:54:16 +02:00
Add prefetch to all resource caches
This commit is contained in:
parent
e3131d2098
commit
74e1f817a5
2 changed files with 27 additions and 0 deletions
|
@ -169,6 +169,11 @@ void ResourceCache::clearATPAssets() {
|
|||
}
|
||||
|
||||
void ResourceCache::refreshAll() {
|
||||
// Remove refs to prefetching resources
|
||||
_prefetchingResourcesLock.lock();
|
||||
_prefetchingResources.clear();
|
||||
_prefetchingResourcesLock.unlock();
|
||||
|
||||
// Clear all unused resources so we don't have to reload them
|
||||
clearUnusedResource();
|
||||
resetResourceCounters();
|
||||
|
@ -217,6 +222,23 @@ QVariantList ResourceCache::getResourceList() {
|
|||
return list;
|
||||
}
|
||||
|
||||
void ResourceCache::prefetch(const QUrl& url) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "prefetch", Q_ARG(QUrl, url));
|
||||
} else {
|
||||
auto resource = getResource(url);
|
||||
// If it is not loaded, hold a ref until it is
|
||||
if (!resource->isLoaded()) {
|
||||
QMutexLocker lock(&_prefetchingResourcesLock);
|
||||
_prefetchingResources.insert(url, resource);
|
||||
connect(resource.data(), &Resource::finishedLoading, [this, url]{
|
||||
QMutexLocker lock(&_prefetchingResourcesLock);
|
||||
this->_prefetchingResources.remove(url);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceCache::setRequestLimit(int limit) {
|
||||
_requestLimit = limit;
|
||||
|
||||
|
|
|
@ -96,6 +96,8 @@ public:
|
|||
|
||||
Q_INVOKABLE QVariantList getResourceList();
|
||||
|
||||
Q_INVOKABLE void prefetch(const QUrl& url);
|
||||
|
||||
static void setRequestLimit(int limit);
|
||||
static int getRequestLimit() { return _requestLimit; }
|
||||
|
||||
|
@ -175,6 +177,9 @@ private:
|
|||
qint64 _unusedResourcesMaxSize = DEFAULT_UNUSED_MAX_SIZE;
|
||||
QReadWriteLock _unusedResourcesLock { QReadWriteLock::Recursive };
|
||||
QMap<int, QSharedPointer<Resource>> _unusedResources;
|
||||
|
||||
QMutex _prefetchingResourcesLock{ QMutex::Recursive };
|
||||
QMap<QUrl, QSharedPointer<Resource>> _prefetchingResources;
|
||||
};
|
||||
|
||||
/// Base class for resources.
|
||||
|
|
Loading…
Reference in a new issue