Handle threading inside AssetServer

This commit is contained in:
Atlante45 2016-02-26 16:06:57 -08:00
parent f0ccada945
commit 4944d0a8d0
5 changed files with 16 additions and 18 deletions

View file

@ -1071,11 +1071,6 @@ void Application::cleanupBeforeQuit() {
DependencyManager::destroy<OffscreenUi>();
}
void Application::emptyLocalCache() {
auto assetClient = DependencyManager::get<AssetClient>();
QMetaObject::invokeMethod(assetClient.data(), "clearCache", Qt::QueuedConnection);
}
Application::~Application() {
EntityTreePointer tree = getEntities()->getTree();
tree->setSimulation(NULL);
@ -3061,7 +3056,7 @@ void Application::reloadResourceCaches() {
_viewFrustum.setOrientation(glm::quat());
queryOctree(NodeType::EntityServer, PacketType::EntityQuery, _entityServerJurisdictions);
emptyLocalCache();
DependencyManager::get<AssetClient>()->clearCache();
DependencyManager::get<AnimationCache>()->refreshAll();
DependencyManager::get<ModelCache>()->refreshAll();

View file

@ -330,8 +330,6 @@ private:
void cleanupBeforeQuit();
void emptyLocalCache();
void update(float deltaTime);
void setPalmData(Hand* hand, const controller::Pose& pose, float deltaTime, HandData::Hand whichHand, float triggerValue);

View file

@ -103,12 +103,10 @@ void DiskCacheEditor::makeDialog() {
}
void DiskCacheEditor::refresh() {
auto assetClient = DependencyManager::get<AssetClient>();
QMetaObject::invokeMethod(assetClient.data() , "cacheInfoRequest", Qt::QueuedConnection,
Q_ARG(QObject*, this), Q_ARG(QString, "update"));
DependencyManager::get<AssetClient>()->cacheInfoRequest(this, "cacheInfoCallback");
}
void DiskCacheEditor::update(QString cacheDirectory, qint64 cacheSize, qint64 maximumCacheSize) {
void DiskCacheEditor::cacheInfoCallback(QString cacheDirectory, qint64 cacheSize, qint64 maximumCacheSize) {
static const auto stringify = [](qint64 number) {
static const QStringList UNITS = QStringList() << "B" << "KB" << "MB" << "GB";
static const qint64 CHUNK = 1024;
@ -141,7 +139,6 @@ void DiskCacheEditor::clear() {
"are you sure you want to do that?",
QMessageBox::Ok | QMessageBox::Cancel);
if (buttonClicked == QMessageBox::Ok) {
auto assetClient = DependencyManager::get<AssetClient>();
QMetaObject::invokeMethod(assetClient.data() , "clearCache", Qt::QueuedConnection);
DependencyManager::get<AssetClient>()->clearCache();
}
}

View file

@ -33,9 +33,9 @@ public slots:
private slots:
void refresh();
void update(QString cacheDirectory, qint64 cacheSize, qint64 maximumCacheSize);
void cacheInfoCallback(QString cacheDirectory, qint64 cacheSize, qint64 maximumCacheSize);
void clear();
private:
void makeDialog();

View file

@ -66,7 +66,12 @@ void AssetClient::init() {
void AssetClient::cacheInfoRequest(QObject* reciever, QString slot) {
Q_ASSERT(QThread::currentThread() == thread());
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "cacheInfoRequest", Qt::QueuedConnection,
Q_ARG(QObject*, reciever), Q_ARG(QString, slot));
return;
}
if (auto* cache = qobject_cast<QNetworkDiskCache*>(NetworkAccessManager::getInstance().cache())) {
QMetaObject::invokeMethod(reciever, slot.toStdString().data(), Qt::QueuedConnection,
@ -79,7 +84,10 @@ void AssetClient::cacheInfoRequest(QObject* reciever, QString slot) {
}
void AssetClient::clearCache() {
Q_ASSERT(QThread::currentThread() == thread());
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "clearCache", Qt::QueuedConnection);
return;
}
if (auto cache = NetworkAccessManager::getInstance().cache()) {
qDebug() << "AssetClient::clearCache(): Clearing disk cache.";