mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 09:23:17 +02:00
Merge pull request #1512 from ey6es/retryagain
After failing to download textures or geometry, retry again after increasing delays.
This commit is contained in:
commit
a8bbe41642
4 changed files with 61 additions and 18 deletions
|
@ -251,18 +251,16 @@ QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url) {
|
|||
}
|
||||
|
||||
NetworkGeometry::NetworkGeometry(const QUrl& url) :
|
||||
_modelRequest(url),
|
||||
_modelReply(NULL),
|
||||
_mappingReply(NULL)
|
||||
_mappingReply(NULL),
|
||||
_attempts(0)
|
||||
{
|
||||
if (!url.isValid()) {
|
||||
return;
|
||||
}
|
||||
QNetworkRequest modelRequest(url);
|
||||
modelRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
||||
_modelReply = Application::getInstance()->getNetworkAccessManager()->get(modelRequest);
|
||||
|
||||
connect(_modelReply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(maybeReadModelWithMapping()));
|
||||
connect(_modelReply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleModelReplyError()));
|
||||
_modelRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
||||
makeModelRequest();
|
||||
|
||||
QUrl mappingURL = url;
|
||||
QString path = url.path();
|
||||
|
@ -312,12 +310,30 @@ glm::vec4 NetworkGeometry::computeAverageColor() const {
|
|||
return (totalTriangles == 0) ? glm::vec4(1.0f, 1.0f, 1.0f, 1.0f) : totalColor / totalTriangles;
|
||||
}
|
||||
|
||||
void NetworkGeometry::makeModelRequest() {
|
||||
_modelReply = Application::getInstance()->getNetworkAccessManager()->get(_modelRequest);
|
||||
|
||||
connect(_modelReply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(maybeReadModelWithMapping()));
|
||||
connect(_modelReply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleModelReplyError()));
|
||||
}
|
||||
|
||||
void NetworkGeometry::handleModelReplyError() {
|
||||
qDebug() << _modelReply->errorString() << "\n";
|
||||
QDebug debug = qDebug() << _modelReply->errorString();
|
||||
|
||||
_modelReply->disconnect(this);
|
||||
_modelReply->deleteLater();
|
||||
_modelReply = NULL;
|
||||
|
||||
// retry with increasing delays
|
||||
const int MAX_ATTEMPTS = 8;
|
||||
const int BASE_DELAY_MS = 1000;
|
||||
if (++_attempts < MAX_ATTEMPTS) {
|
||||
QTimer::singleShot(BASE_DELAY_MS * (int)pow(2.0, _attempts), this, SLOT(makeModelRequest()));
|
||||
debug << " -- retrying...\n";
|
||||
|
||||
} else {
|
||||
debug << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkGeometry::handleMappingReplyError() {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define __interface__GeometryCache__
|
||||
|
||||
#include <QHash>
|
||||
#include <QNetworkRequest>
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
#include <QWeakPointer>
|
||||
|
@ -67,15 +68,18 @@ public:
|
|||
|
||||
private slots:
|
||||
|
||||
void makeModelRequest();
|
||||
void handleModelReplyError();
|
||||
void handleMappingReplyError();
|
||||
void maybeReadModelWithMapping();
|
||||
|
||||
private:
|
||||
|
||||
QNetworkRequest _modelRequest;
|
||||
QNetworkReply* _modelReply;
|
||||
QNetworkReply* _mappingReply;
|
||||
|
||||
int _attempts;
|
||||
FBXGeometry _geometry;
|
||||
QVector<NetworkMesh> _meshes;
|
||||
};
|
||||
|
|
|
@ -252,16 +252,17 @@ Texture::~Texture() {
|
|||
glDeleteTextures(1, &_id);
|
||||
}
|
||||
|
||||
NetworkTexture::NetworkTexture(const QUrl& url, bool normalMap) : _reply(NULL), _averageColor(1.0f, 1.0f, 1.0f, 1.0f) {
|
||||
NetworkTexture::NetworkTexture(const QUrl& url, bool normalMap) :
|
||||
_request(url),
|
||||
_reply(NULL),
|
||||
_attempts(0),
|
||||
_averageColor(1.0f, 1.0f, 1.0f, 1.0f) {
|
||||
|
||||
if (!url.isValid()) {
|
||||
return;
|
||||
}
|
||||
QNetworkRequest request(url);
|
||||
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
||||
_reply = Application::getInstance()->getNetworkAccessManager()->get(request);
|
||||
|
||||
connect(_reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(handleDownloadProgress(qint64,qint64)));
|
||||
connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleReplyError()));
|
||||
_request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
||||
makeRequest();
|
||||
|
||||
// default to white/blue
|
||||
glBindTexture(GL_TEXTURE_2D, getID());
|
||||
|
@ -279,6 +280,13 @@ void NetworkTexture::imageLoaded(const QImage& image) {
|
|||
// nothing by default
|
||||
}
|
||||
|
||||
void NetworkTexture::makeRequest() {
|
||||
_reply = Application::getInstance()->getNetworkAccessManager()->get(_request);
|
||||
|
||||
connect(_reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(handleDownloadProgress(qint64,qint64)));
|
||||
connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleReplyError()));
|
||||
}
|
||||
|
||||
void NetworkTexture::handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||
if (bytesReceived < bytesTotal && !_reply->isFinished()) {
|
||||
return;
|
||||
|
@ -314,11 +322,22 @@ void NetworkTexture::handleDownloadProgress(qint64 bytesReceived, qint64 bytesTo
|
|||
}
|
||||
|
||||
void NetworkTexture::handleReplyError() {
|
||||
qDebug() << _reply->errorString() << "\n";
|
||||
QDebug debug = qDebug() << _reply->errorString();
|
||||
|
||||
_reply->disconnect(this);
|
||||
_reply->deleteLater();
|
||||
_reply = NULL;
|
||||
|
||||
// retry with increasing delays
|
||||
const int MAX_ATTEMPTS = 8;
|
||||
const int BASE_DELAY_MS = 1000;
|
||||
if (++_attempts < MAX_ATTEMPTS) {
|
||||
QTimer::singleShot(BASE_DELAY_MS * (int)pow(2.0, _attempts), this, SLOT(makeRequest()));
|
||||
debug << " -- retrying...\n";
|
||||
|
||||
} else {
|
||||
debug << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
DilatableNetworkTexture::DilatableNetworkTexture(const QUrl& url, bool normalMap) :
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <QHash>
|
||||
#include <QImage>
|
||||
#include <QMap>
|
||||
#include <QNetworkRequest>
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
#include <QWeakPointer>
|
||||
|
@ -126,12 +127,15 @@ protected:
|
|||
|
||||
private slots:
|
||||
|
||||
void makeRequest();
|
||||
void handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
void handleReplyError();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
QNetworkRequest _request;
|
||||
QNetworkReply* _reply;
|
||||
int _attempts;
|
||||
glm::vec4 _averageColor;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue