mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
more script caching cleanup
This commit is contained in:
parent
74d50a9250
commit
e2d8d82096
7 changed files with 2 additions and 225 deletions
|
@ -165,22 +165,6 @@ QString EntityTreeRenderer::loadScriptContents(const QString& scriptMaybeURLorTe
|
|||
qDebug() << "ERROR Loading file:" << fileName;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
QNetworkRequest networkRequest = QNetworkRequest(url);
|
||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
QNetworkReply* reply = networkAccessManager.get(networkRequest);
|
||||
qDebug() << "Downloading script at" << url;
|
||||
QEventLoop loop;
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||
scriptContents = reply->readAll();
|
||||
} else {
|
||||
qDebug() << "ERROR Loading file:" << url.toString();
|
||||
}
|
||||
delete reply;
|
||||
*/
|
||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||
scriptContents = scriptCache->getScript(url, this, isPending);
|
||||
}
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
//
|
||||
// Script.cpp
|
||||
// libraries/script-engine/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 2015-03-30
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
/*
|
||||
#include <stdint.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtNetwork/QNetworkRequest>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <qendian.h>
|
||||
|
||||
#include <LimitedNodeList.h>
|
||||
#include <NetworkAccessManager.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "AudioRingBuffer.h"
|
||||
#include "AudioFormat.h"
|
||||
#include "AudioBuffer.h"
|
||||
#include "AudioEditBuffer.h"
|
||||
*/
|
||||
|
||||
#include "Script.h"
|
||||
|
||||
Script::Script(const QUrl& url) :
|
||||
Resource(url),
|
||||
_isReady(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Script::downloadFinished(QNetworkReply* reply) {
|
||||
// replace our byte array with the downloaded data
|
||||
_contents = reply->readAll();
|
||||
qDebug() << "Script downloaded from:" << getURL();
|
||||
_isReady = true;
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
//
|
||||
// Script.h
|
||||
// libraries/script-engine/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 2015-03-30
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_Script_h
|
||||
#define hifi_Script_h
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtScript/qscriptengine.h>
|
||||
|
||||
#include <ResourceCache.h>
|
||||
|
||||
class Script : public Resource {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Script(const QUrl& url);
|
||||
bool isReady() const { return _isReady; }
|
||||
const QString& getContents() { return _contents; }
|
||||
|
||||
private:
|
||||
QString _contents;
|
||||
bool _isReady;
|
||||
|
||||
virtual void downloadFinished(QNetworkReply* reply);
|
||||
};
|
||||
|
||||
typedef QSharedPointer<Script> SharedScriptPointer;
|
||||
|
||||
#endif // hifi_Script_h
|
|
@ -24,8 +24,6 @@ ScriptCache::ScriptCache(QObject* parent) {
|
|||
// nothing to do here...
|
||||
}
|
||||
|
||||
// QHash<QUrl, QString> _scriptCache;
|
||||
|
||||
QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending) {
|
||||
QString scriptContents;
|
||||
if (_scriptCache.contains(url)) {
|
||||
|
@ -52,8 +50,7 @@ void ScriptCache::scriptDownloaded() {
|
|||
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||
_scriptCache[url] = reply->readAll();
|
||||
qDebug() << "_scriptCache.size:" << _scriptCache.size();
|
||||
|
||||
|
||||
foreach(ScriptUser* user, scriptUsers) {
|
||||
user->scriptContentsAvailable(url, _scriptCache[url]);
|
||||
}
|
||||
|
@ -66,90 +63,4 @@ void ScriptCache::scriptDownloaded() {
|
|||
reply->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
QString ScriptCache::getScript(const QUrl& url) {
|
||||
qDebug() << "Script requested: " << url.toString();
|
||||
QString scriptContents;
|
||||
if (_scriptCache.contains(url)) {
|
||||
qDebug() << "Script found in cache: " << url.toString();
|
||||
scriptContents = _scriptCache[url];
|
||||
} else {
|
||||
qDebug() << "Script not found in cache: " << url.toString();
|
||||
|
||||
if (_blockingScriptsPending.contains(url)) {
|
||||
// if we're already downloading this script, wait for it to complete...
|
||||
qDebug() << "Already downloading script: " << url.toString();
|
||||
while (_blockingScriptsPending.contains(url)) {
|
||||
QEventLoop loop;
|
||||
qDebug() << "about to call loop.processEvents()....";
|
||||
loop.processEvents(QEventLoop::AllEvents, 1);
|
||||
qDebug() << "AFTER loop.processEvents()....";
|
||||
}
|
||||
qDebug() << "Done waiting on downloading script: " << url.toString();
|
||||
scriptContents = _scriptCache[url];
|
||||
} else {
|
||||
_blockingScriptsPending.insert(url);
|
||||
qDebug() << "_blockingScriptsPending: " << _blockingScriptsPending;
|
||||
|
||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
QNetworkRequest networkRequest = QNetworkRequest(url);
|
||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
QNetworkReply* reply = networkAccessManager.get(networkRequest);
|
||||
|
||||
|
||||
connect(reply, &QNetworkReply::finished, this, &ScriptCache::scriptDownloadedSyncronously);
|
||||
qDebug() << "Downloading script at" << url.toString();
|
||||
//QEventLoop loop;
|
||||
//QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
//qDebug() << "starting loop....";
|
||||
//loop.exec();
|
||||
//qDebug() << "after loop....";
|
||||
|
||||
/*
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||
scriptContents = reply->readAll();
|
||||
_scriptCache[url] = scriptContents;
|
||||
qDebug() << "_scriptCache.size:" << _scriptCache.size();
|
||||
} else {
|
||||
qDebug() << "ERROR Loading file:" << url.toString();
|
||||
}
|
||||
delete reply;
|
||||
_blockingScriptsPending.remove(url);
|
||||
qDebug() << "_blockingScriptsPending: " << _blockingScriptsPending;
|
||||
*/
|
||||
while (_blockingScriptsPending.contains(url)) {
|
||||
QEventLoop loop;
|
||||
qDebug() << "about to call loop.processEvents()....";
|
||||
loop.processEvents(QEventLoop::AllEvents, 1);
|
||||
qDebug() << "AFTER loop.processEvents()....";
|
||||
}
|
||||
qDebug() << "Done waiting on downloading script: " << url.toString();
|
||||
scriptContents = _scriptCache[url];
|
||||
}
|
||||
}
|
||||
return scriptContents;
|
||||
}
|
||||
|
||||
void ScriptCache::scriptDownloadedSyncronously() {
|
||||
|
||||
qDebug() << "ScriptCache::scriptDownloadedSyncronously()....";
|
||||
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
QUrl url = reply->url();
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||
_scriptCache[url] = reply->readAll();
|
||||
qDebug() << "_scriptCache.size:" << _scriptCache.size();
|
||||
} else {
|
||||
qDebug() << "ERROR Loading file:" << reply->url().toString();
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
|
||||
_blockingScriptsPending.remove(url);
|
||||
qDebug() << "_blockingScriptsPending: " << _blockingScriptsPending;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#define hifi_ScriptCache_h
|
||||
|
||||
#include <ResourceCache.h>
|
||||
#include "Script.h"
|
||||
|
||||
class ScriptUser {
|
||||
public:
|
||||
|
@ -27,22 +26,16 @@ class ScriptCache : public QObject, public Dependency {
|
|||
SINGLETON_DEPENDENCY
|
||||
|
||||
public:
|
||||
QString getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending); // asynchronous
|
||||
|
||||
|
||||
//QString getScript(const QUrl& url); // blocking call
|
||||
QString getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending);
|
||||
|
||||
private slots:
|
||||
void scriptDownloaded();
|
||||
//void scriptDownloadedSyncronously();
|
||||
|
||||
|
||||
private:
|
||||
ScriptCache(QObject* parent = NULL);
|
||||
|
||||
QHash<QUrl, QString> _scriptCache;
|
||||
QMultiMap<QUrl, ScriptUser*> _scriptUsers;
|
||||
QSet<QUrl> _blockingScriptsPending;
|
||||
};
|
||||
|
||||
#endif // hifi_ScriptCache_h
|
|
@ -280,13 +280,6 @@ void ScriptEngine::loadURL(const QUrl& scriptURL) {
|
|||
emit errorLoadingScript(_fileNameString);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
QNetworkRequest networkRequest = QNetworkRequest(url);
|
||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
QNetworkReply* reply = networkAccessManager.get(networkRequest);
|
||||
connect(reply, &QNetworkReply::finished, this, &ScriptEngine::handleScriptDownload);
|
||||
*/
|
||||
bool isPending;
|
||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||
scriptCache->getScript(url, this, isPending);
|
||||
|
@ -295,22 +288,6 @@ void ScriptEngine::loadURL(const QUrl& scriptURL) {
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::handleScriptDownload() {
|
||||
/*
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||
_scriptContents = reply->readAll();
|
||||
emit scriptLoaded(_fileNameString);
|
||||
} else {
|
||||
qDebug() << "ERROR Loading file:" << reply->url().toString();
|
||||
emit errorLoadingScript(_fileNameString);
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
*/
|
||||
}
|
||||
|
||||
void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) {
|
||||
_scriptContents = scriptContents;
|
||||
emit scriptLoaded(_fileNameString);
|
||||
|
|
|
@ -164,8 +164,6 @@ private:
|
|||
ArrayBufferClass* _arrayBufferClass;
|
||||
|
||||
QHash<QUuid, quint16> _outgoingScriptAudioSequenceNumbers;
|
||||
private slots:
|
||||
void handleScriptDownload();
|
||||
|
||||
private:
|
||||
static QSet<ScriptEngine*> _allKnownScriptEngines;
|
||||
|
|
Loading…
Reference in a new issue