From 38bc8634de226b4534e4801fceaf2a2d466a8f21 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Tue, 25 Aug 2015 21:26:46 -0700 Subject: [PATCH] displayPlugin is not thread safe, and switch from simulate rate to interval in prep for sleep. --- interface/src/Application.cpp | 2 +- interface/src/avatar/AvatarUpdate.cpp | 9 +++++---- interface/src/avatar/AvatarUpdate.h | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 919816a643..50f39c87bb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2588,7 +2588,7 @@ void Application::updateMyAvatarLookAtPosition() { } else { // I am not looking at anyone else, so just look forward if (isHMD) { - glm::mat4 headPose = getActiveDisplayPlugin()->getHeadPose(); + glm::mat4 headPose = _avatarUpdate->getHeadPose(); glm::quat headRotation = glm::quat_cast(headPose); lookAtSpot = _myCamera.getPosition() + _myAvatar->getOrientation() * (headRotation * glm::vec3(0.0f, 0.0f, -TREE_SCALE)); diff --git a/interface/src/avatar/AvatarUpdate.cpp b/interface/src/avatar/AvatarUpdate.cpp index acab5a46ad..4335cbd16d 100644 --- a/interface/src/avatar/AvatarUpdate.cpp +++ b/interface/src/avatar/AvatarUpdate.cpp @@ -13,6 +13,7 @@ #include "Application.h" #include "AvatarManager.h" #include "AvatarUpdate.h" +#include #include "InterfaceLogging.h" // GenericThread accepts an optional "parent" argument, defaulting to nullptr. @@ -27,9 +28,9 @@ AvatarUpdate::AvatarUpdate() : QObject(nullptr), _timer(nullptr), _lastAvatarUp setObjectName("Avatar Update"); // GenericThread::initialize uses this to set the thread name. Settings settings; const int DEFAULT_TARGET_AVATAR_SIMRATE = 60; - _targetSimrate = settings.value("AvatarUpdateTargetSimrate", DEFAULT_TARGET_AVATAR_SIMRATE).toInt(); + _targetInterval = USECS_PER_SECOND / settings.value("AvatarUpdateTargetSimrate", DEFAULT_TARGET_AVATAR_SIMRATE).toInt(); _type = settings.value("AvatarUpdateType", UpdateType::Synchronous).toInt(); - qCDebug(interfaceapp) << "AvatarUpdate using" << _type << "at" << _targetSimrate << "sims/second"; + qCDebug(interfaceapp) << "AvatarUpdate using" << _type << "at" << _targetInterval << "microseconds"; } // We could have the constructor call initialize(), but GenericThread::initialize can take parameters. // Keeping it separately called by the client allows that client to pass those without our @@ -59,16 +60,16 @@ void AvatarUpdate::threadRoutine() { } } void AvatarUpdate::initTimer() { - const qint64 AVATAR_UPDATE_INTERVAL_MSECS = 1000 / _targetSimrate; _timer = new QTimer(this); connect(_timer, &QTimer::timeout, this, &AvatarUpdate::process); - _timer->start(AVATAR_UPDATE_INTERVAL_MSECS); + _timer->start(_targetInterval / USECS_PER_MSEC); } void AvatarUpdate::synchronousProcess() { // Keep our own updated value, so that our asynchronous code can consult it. _isHMDMode = Application::getInstance()->isHMDMode(); + _headPose = Application::getInstance()->getActiveDisplayPlugin()->getHeadPose(); if (_updateBillboard) { Application::getInstance()->getMyAvatar()->doUpdateBillboard(); diff --git a/interface/src/avatar/AvatarUpdate.h b/interface/src/avatar/AvatarUpdate.h index 6a70aeb1f9..93192ae50d 100644 --- a/interface/src/avatar/AvatarUpdate.h +++ b/interface/src/avatar/AvatarUpdate.h @@ -36,7 +36,7 @@ public: private: virtual bool process(); // No reason for other classes to invoke this. void initTimer(); - int _targetSimrate; + quint64 _targetInterval; bool _updateBillboard; QTimer* _timer; quint64 _lastAvatarUpdate; @@ -58,11 +58,13 @@ private: QThread* _thread; void initThread(); - // Goes away if Applicaiton::isHMDMode() is made thread safe: + // Goes away if Applicaiton::isHMDMode() and friends are made thread safe: public: bool isHMDMode() { return _isHMDMode; } + glm::mat4 getHeadPose() { return _headPose; } private: bool _isHMDMode; + glm::mat4 _headPose; };