This commit is contained in:
Philip Rosedale 2014-07-03 15:54:29 -07:00
commit 3280691491
5 changed files with 45 additions and 17 deletions

View file

@ -210,12 +210,15 @@ void Agent::run() {
NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
QNetworkReply *reply = networkAccessManager.get(QNetworkRequest(scriptURL));
QNetworkDiskCache* cache = new QNetworkDiskCache(&networkAccessManager);
// Make sure cache on same thread than its parent (NetworkAccessManager)
QNetworkDiskCache* cache = new QNetworkDiskCache();
cache->moveToThread(networkAccessManager.thread());
cache->setParent(&networkAccessManager);
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
cache->setCacheDirectory(!cachePath.isEmpty() ? cachePath : "agentCache");
QMetaObject::invokeMethod(&networkAccessManager, "setCache",
Qt::BlockingQueuedConnection,
Q_ARG(QAbstractNetworkCache*, cache));
networkAccessManager.setCache(cache);
qDebug() << "Downloading script at" << scriptURL.toString();

View file

@ -316,11 +316,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
QNetworkDiskCache* cache = new QNetworkDiskCache(&networkAccessManager);
// Make sure cache on same thread than its parent (NetworkAccessManager)
QNetworkDiskCache* cache = new QNetworkDiskCache();
cache->moveToThread(networkAccessManager.thread());
cache->setParent(&networkAccessManager);
cache->setCacheDirectory(!cachePath.isEmpty() ? cachePath : "interfaceCache");
QMetaObject::invokeMethod(&networkAccessManager, "setCache",
Qt::BlockingQueuedConnection,
Q_ARG(QAbstractNetworkCache*, cache));
networkAccessManager.setCache(cache);
ResourceCache::setRequestLimit(3);

View file

@ -71,6 +71,16 @@ void SixenseManager::setFilter(bool filter) {
void SixenseManager::update(float deltaTime) {
#ifdef HAVE_SIXENSE
// if the controllers haven't been moved in a while, disable
const unsigned int MOVEMENT_DISABLE_SECONDS = 3;
if (usecTimestampNow() - _lastMovement > (MOVEMENT_DISABLE_SECONDS * USECS_PER_SECOND)) {
Hand* hand = Application::getInstance()->getAvatar()->getHand();
for (std::vector<PalmData>::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) {
it->setActive(false);
}
_lastMovement = usecTimestampNow();
}
if (sixenseGetNumActiveControllers() == 0) {
_hydrasConnected = false;
return;
@ -154,6 +164,11 @@ void SixenseManager::update(float deltaTime) {
// no latency.
float velocityFilter = glm::clamp(1.0f - glm::length(rawVelocity), 0.0f, 1.0f);
palm->setRawPosition(palm->getRawPosition() * velocityFilter + position * (1.0f - velocityFilter));
// adjustment for hydra controllers fit into hands
float sign = (i == 0) ? -1.0f : 1.0f;
rotation *= glm::angleAxis(sign * PI/4.0f, glm::vec3(0.0f, 0.0f, 1.0f));
palm->setRawRotation(safeMix(palm->getRawRotation(), rotation, 1.0f - velocityFilter));
// use the velocity to determine whether there's any movement (if the hand isn't new)
@ -180,14 +195,6 @@ void SixenseManager::update(float deltaTime) {
if (numActiveControllers == 2) {
updateCalibration(controllers);
}
// if the controllers haven't been moved in a while, disable
const unsigned int MOVEMENT_DISABLE_SECONDS = 3;
if (usecTimestampNow() - _lastMovement > (MOVEMENT_DISABLE_SECONDS * USECS_PER_SECOND)) {
for (std::vector<PalmData>::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) {
it->setActive(false);
}
}
#endif // HAVE_SIXENSE
}

View file

@ -10,6 +10,7 @@
//
#include <QMetaObject>
#include <QAbstractNetworkCache>
#include <QThread>
#include "NetworkAccessManager.h"
@ -146,4 +147,15 @@ QNetworkReply* NetworkAccessManager::sendCustomRequest(const QNetworkRequest& re
return result;
}
return QNetworkAccessManager::sendCustomRequest(request, verb, data);
}
void NetworkAccessManager::setCache(QAbstractNetworkCache* cache) {
if (QThread::currentThread() != thread()) {
qRegisterMetaType<QAbstractNetworkCache*>();
QMetaObject::invokeMethod(this,
"setCache",
Qt::QueuedConnection,
Q_ARG(QAbstractNetworkCache*, cache));
}
QNetworkAccessManager::setCache(cache);
}

View file

@ -18,7 +18,9 @@
/// Wrapper around QNetworkAccessManager wo that we only use one instance
/// For any other method you should need, make sure to be on the right thread
/// or call the method using QMetaObject::invokeMethod()
/// or if it is not but is a slot, use QMetaObject::invokeMethod()
/// In the case what you want to call isn't a slot and you aren't on the same thread,
/// then add then method to the method to the wrapper with the Q_INVKABLE flag
class NetworkAccessManager : public QNetworkAccessManager {
Q_OBJECT
public:
@ -33,6 +35,7 @@ public:
Q_INVOKABLE QNetworkReply* put(const QNetworkRequest& request, QHttpMultiPart* multiPart);
Q_INVOKABLE QNetworkReply* put(const QNetworkRequest& request, const QByteArray& data);
Q_INVOKABLE QNetworkReply* sendCustomRequest(const QNetworkRequest& request, const QByteArray& verb, QIODevice* data = 0);
Q_INVOKABLE void setCache(QAbstractNetworkCache* cache);
private:
NetworkAccessManager();