From f26ddc6f8b447f1b5b97a2ef75019097c75e54ca Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 26 Oct 2016 14:47:53 -0700 Subject: [PATCH 1/8] Add getter for SteamVR's buildID to SteamClient --- interface/src/Application.cpp | 1 + .../src/steamworks-wrapper/SteamClient.cpp | 26 +++++++++++++++++++ .../src/steamworks-wrapper/SteamClient.h | 1 + 3 files changed, 28 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fcfbe0f3b1..af6be8021f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -569,6 +569,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _deadlockWatchdogThread = new DeadlockWatchdogThread(); _deadlockWatchdogThread->start(); + qCDebug(interfaceapp) << "[VERSION] SteamVR buildID:" << SteamClient::getSteamVRBuildID(); qCDebug(interfaceapp) << "[VERSION] Build sequence:" << qPrintable(applicationVersion()); qCDebug(interfaceapp) << "[VERSION] MODIFIED_ORGANIZATION:" << BuildInfo::MODIFIED_ORGANIZATION; qCDebug(interfaceapp) << "[VERSION] VERSION:" << BuildInfo::VERSION; diff --git a/libraries/steamworks-wrapper/src/steamworks-wrapper/SteamClient.cpp b/libraries/steamworks-wrapper/src/steamworks-wrapper/SteamClient.cpp index 235d258d21..9936027302 100644 --- a/libraries/steamworks-wrapper/src/steamworks-wrapper/SteamClient.cpp +++ b/libraries/steamworks-wrapper/src/steamworks-wrapper/SteamClient.cpp @@ -245,6 +245,32 @@ void SteamClient::shutdown() { steamCallbackManager.getTicketRequests().stopAll(); } +int SteamClient::getSteamVRBuildID() { + if (initialized) { + static const int MAX_PATH_SIZE = 512; + static const int STEAMVR_APPID = 250820; + char rawPath[MAX_PATH_SIZE]; + SteamApps()->GetAppInstallDir(STEAMVR_APPID, rawPath, MAX_PATH_SIZE); + + QString path(rawPath); + path += "\\bin\\version.txt"; + qDebug() << "SteamVR version file path:" << path; + + QFile file(path); + if (file.open(QIODevice::ReadOnly)) { + QString buildIDString = file.readLine(); + + bool ok = false; + int buildID = buildIDString.toInt(&ok); + if (ok) { + return buildID; + } + } + } + return 0; +} + + void SteamClient::runCallbacks() { if (!initialized) { return; diff --git a/libraries/steamworks-wrapper/src/steamworks-wrapper/SteamClient.h b/libraries/steamworks-wrapper/src/steamworks-wrapper/SteamClient.h index 5bf0d4db56..a191adee97 100644 --- a/libraries/steamworks-wrapper/src/steamworks-wrapper/SteamClient.h +++ b/libraries/steamworks-wrapper/src/steamworks-wrapper/SteamClient.h @@ -37,6 +37,7 @@ public: static void openInviteOverlay(); static void joinLobby(QString lobbyId); + static int getSteamVRBuildID(); }; class SteamScriptingInterface : public QObject { From 10e6157ab9517ac1f58cfb8d263dac041b5026ba Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 26 Oct 2016 15:16:29 -0700 Subject: [PATCH 2/8] Fix race condition in BatchLoader --- libraries/script-engine/src/BatchLoader.cpp | 27 +++++++++++++-------- libraries/script-engine/src/BatchLoader.h | 11 ++++++++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/libraries/script-engine/src/BatchLoader.cpp b/libraries/script-engine/src/BatchLoader.cpp index 605d7e95bd..ef8cf90656 100644 --- a/libraries/script-engine/src/BatchLoader.cpp +++ b/libraries/script-engine/src/BatchLoader.cpp @@ -44,33 +44,40 @@ void BatchLoader::start() { return; } + for (const auto& rawURL : _urls) { QUrl url = expandScriptUrl(normalizeScriptURL(rawURL)); qCDebug(scriptengine) << "Loading script at " << url; - QPointer self = this; - DependencyManager::get()->getScriptContents(url.toString(), [this, self](const QString& url, const QString& contents, bool isURL, bool success) { - if (!self) { - return; - } + auto scriptCache = DependencyManager::get(); - // Because the ScriptCache may call this callback from differents threads, - // we need to make sure this is thread-safe. - std::lock_guard lock(_dataLock); + // Use a proxy callback to handle the call and emit the signal in a thread-safe way. + // If BatchLoader is deleted before the callback is called, the subsequent "emit" call will not do + // anything. + ScriptCacheSignalProxy* proxy = new ScriptCacheSignalProxy(scriptCache.data()); + scriptCache->getScriptContents(url.toString(), [proxy](const QString& url, const QString& contents, bool isURL, bool success) { + proxy->receivedContent(url, contents, isURL, success); + proxy->deleteLater(); + }, false); + connect(proxy, &ScriptCacheSignalProxy::contentAvailable, this, [this](const QString& url, const QString& contents, bool isURL, bool success) { if (isURL && success) { _data.insert(url, contents); qCDebug(scriptengine) << "Loaded: " << url; } else { _data.insert(url, QString()); - qCDebug(scriptengine) << "Could not load" << url; + qCDebug(scriptengine) << "Could not load: " << url; } if (!_finished && _urls.size() == _data.size()) { _finished = true; emit finished(_data); } - }, false); + }); } } + +void ScriptCacheSignalProxy::receivedContent(const QString& url, const QString& contents, bool isURL, bool success) { + emit contentAvailable(url, contents, isURL, success); +} diff --git a/libraries/script-engine/src/BatchLoader.h b/libraries/script-engine/src/BatchLoader.h index 40b43d23b6..55acc11c26 100644 --- a/libraries/script-engine/src/BatchLoader.h +++ b/libraries/script-engine/src/BatchLoader.h @@ -21,6 +21,16 @@ #include +class ScriptCacheSignalProxy : public QObject { + Q_OBJECT +public: + ScriptCacheSignalProxy(QObject* parent) : QObject(parent) { } + void receivedContent(const QString& url, const QString& contents, bool isURL, bool success); + +signals: + void contentAvailable(const QString& url, const QString& contents, bool isURL, bool success); +}; + class BatchLoader : public QObject { Q_OBJECT public: @@ -39,7 +49,6 @@ private: bool _finished; QSet _urls; QMap _data; - std::mutex _dataLock; }; #endif // hifi_BatchLoader_h From 76344f325334e4469e6c1fe7f2dbb57faca4fd86 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 26 Oct 2016 22:41:56 -0700 Subject: [PATCH 3/8] add a menu item to run audio stats script --- interface/src/Menu.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index cd8d39b739..d357713bff 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -620,6 +620,14 @@ Menu::Menu() { // Developer > Audio >>> MenuWrapper* audioDebugMenu = developerMenu->addMenu("Audio"); + action = addActionToQMenuAndActionHash(audioDebugMenu, "Stats..."); + connect(action, &QAction::triggered, [] { + auto scriptEngines = DependencyManager::get(); + QUrl defaultScriptsLoc = defaultScriptsLocation(); + defaultScriptsLoc.setPath(defaultScriptsLoc.path() + "developer/utilities/audio/stats.js"); + scriptEngines->loadScript(defaultScriptsLoc.toString()); + }); + action = addActionToQMenuAndActionHash(audioDebugMenu, "Buffers..."); connect(action, &QAction::triggered, [] { DependencyManager::get()->toggle(QString("hifi/dialogs/AudioPreferencesDialog.qml"), "AudioPreferencesDialog"); From 946f3782f36c44b751c89a566eda56e637f13546 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 27 Oct 2016 09:59:17 -0700 Subject: [PATCH 4/8] Fix indentation in BatchLoader --- libraries/script-engine/src/BatchLoader.cpp | 24 ++++++++++----------- libraries/script-engine/src/BatchLoader.h | 10 ++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libraries/script-engine/src/BatchLoader.cpp b/libraries/script-engine/src/BatchLoader.cpp index ef8cf90656..65c1bc5a2a 100644 --- a/libraries/script-engine/src/BatchLoader.cpp +++ b/libraries/script-engine/src/BatchLoader.cpp @@ -50,18 +50,18 @@ void BatchLoader::start() { qCDebug(scriptengine) << "Loading script at " << url; - auto scriptCache = DependencyManager::get(); + auto scriptCache = DependencyManager::get(); - // Use a proxy callback to handle the call and emit the signal in a thread-safe way. - // If BatchLoader is deleted before the callback is called, the subsequent "emit" call will not do - // anything. - ScriptCacheSignalProxy* proxy = new ScriptCacheSignalProxy(scriptCache.data()); - scriptCache->getScriptContents(url.toString(), [proxy](const QString& url, const QString& contents, bool isURL, bool success) { - proxy->receivedContent(url, contents, isURL, success); - proxy->deleteLater(); - }, false); + // Use a proxy callback to handle the call and emit the signal in a thread-safe way. + // If BatchLoader is deleted before the callback is called, the subsequent "emit" call will not do + // anything. + ScriptCacheSignalProxy* proxy = new ScriptCacheSignalProxy(scriptCache.data()); + scriptCache->getScriptContents(url.toString(), [proxy](const QString& url, const QString& contents, bool isURL, bool success) { + proxy->receivedContent(url, contents, isURL, success); + proxy->deleteLater(); + }, false); - connect(proxy, &ScriptCacheSignalProxy::contentAvailable, this, [this](const QString& url, const QString& contents, bool isURL, bool success) { + connect(proxy, &ScriptCacheSignalProxy::contentAvailable, this, [this](const QString& url, const QString& contents, bool isURL, bool success) { if (isURL && success) { _data.insert(url, contents); qCDebug(scriptengine) << "Loaded: " << url; @@ -74,10 +74,10 @@ void BatchLoader::start() { _finished = true; emit finished(_data); } - }); + }); } } void ScriptCacheSignalProxy::receivedContent(const QString& url, const QString& contents, bool isURL, bool success) { - emit contentAvailable(url, contents, isURL, success); + emit contentAvailable(url, contents, isURL, success); } diff --git a/libraries/script-engine/src/BatchLoader.h b/libraries/script-engine/src/BatchLoader.h index 55acc11c26..a03a8d80c6 100644 --- a/libraries/script-engine/src/BatchLoader.h +++ b/libraries/script-engine/src/BatchLoader.h @@ -22,19 +22,19 @@ #include class ScriptCacheSignalProxy : public QObject { - Q_OBJECT + Q_OBJECT public: - ScriptCacheSignalProxy(QObject* parent) : QObject(parent) { } - void receivedContent(const QString& url, const QString& contents, bool isURL, bool success); + ScriptCacheSignalProxy(QObject* parent) : QObject(parent) { } + void receivedContent(const QString& url, const QString& contents, bool isURL, bool success); signals: - void contentAvailable(const QString& url, const QString& contents, bool isURL, bool success); + void contentAvailable(const QString& url, const QString& contents, bool isURL, bool success); }; class BatchLoader : public QObject { Q_OBJECT public: - BatchLoader(const QList& urls) ; + BatchLoader(const QList& urls); void start(); bool isFinished() const { return _finished; }; From d778b3b4ce89c826937d736775952ca5506274c7 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 27 Oct 2016 10:00:48 -0700 Subject: [PATCH 5/8] fix the timing of the launchedFromSteam property --- interface/src/Application.cpp | 4 +++- interface/src/Application.h | 2 +- interface/src/main.cpp | 4 +--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fcfbe0f3b1..a2473aa3b8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -506,7 +506,7 @@ Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context); Setting::Handle sessionRunTime{ "sessionRunTime", 0 }; -Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runServer, QString runServerPathOption) : +Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runServer, QString runServerPathOption, bool launchedFromSteam) : QApplication(argc, argv), _shouldRunServer(runServer), _runServerPath(runServerPathOption), @@ -534,6 +534,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _maxOctreePPS(maxOctreePacketsPerSecond.get()), _lastFaceTrackerUpdate(0) { + setProperty("com.highfidelity.launchedFromSteam", launchedFromSteam); + _runningMarker.startRunningMarker(); PluginContainer* pluginContainer = dynamic_cast(this); // set the container for any plugins that care diff --git a/interface/src/Application.h b/interface/src/Application.h index 1a0041223e..24e4d9be34 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -139,7 +139,7 @@ public: static void initPlugins(const QStringList& arguments); static void shutdownPlugins(); - Application(int& argc, char** argv, QElapsedTimer& startup_time, bool runServer, QString runServerPathOption); + Application(int& argc, char** argv, QElapsedTimer& startup_time, bool runServer, QString runServerPathOption, bool launchedFromSteam); ~Application(); void postLambdaEvent(std::function f) override; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index ab4ab689f7..59cf4647b2 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -159,10 +159,8 @@ int main(int argc, const char* argv[]) { int exitCode; { QSettings::setDefaultFormat(QSettings::IniFormat); - Application app(argc, const_cast(argv), startupTime, runServer, serverContentPathOptionValue); - bool launchedFromSteam = SteamClient::isRunning(); - app.setProperty("com.highfidelity.launchedFromSteam", launchedFromSteam); + Application app(argc, const_cast(argv), startupTime, runServer, serverContentPathOptionValue, launchedFromSteam); // If we failed the OpenGLVersion check, log it. if (override) { From c6d89f181a061e228c6c1d9c38d0b795c5916087 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 27 Oct 2016 10:08:16 -0700 Subject: [PATCH 6/8] CR feedback --- interface/src/Application.cpp | 4 ++-- interface/src/Application.h | 2 +- interface/src/main.cpp | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a2473aa3b8..a32f50f25c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -506,7 +506,7 @@ Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context); Setting::Handle sessionRunTime{ "sessionRunTime", 0 }; -Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runServer, QString runServerPathOption, bool launchedFromSteam) : +Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runServer, QString runServerPathOption) : QApplication(argc, argv), _shouldRunServer(runServer), _runServerPath(runServerPathOption), @@ -534,7 +534,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _maxOctreePPS(maxOctreePacketsPerSecond.get()), _lastFaceTrackerUpdate(0) { - setProperty("com.highfidelity.launchedFromSteam", launchedFromSteam); + setProperty("com.highfidelity.launchedFromSteam", SteamClient::isRunning()); _runningMarker.startRunningMarker(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 24e4d9be34..1a0041223e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -139,7 +139,7 @@ public: static void initPlugins(const QStringList& arguments); static void shutdownPlugins(); - Application(int& argc, char** argv, QElapsedTimer& startup_time, bool runServer, QString runServerPathOption, bool launchedFromSteam); + Application(int& argc, char** argv, QElapsedTimer& startup_time, bool runServer, QString runServerPathOption); ~Application(); void postLambdaEvent(std::function f) override; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 59cf4647b2..5b0da4f578 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -159,8 +159,7 @@ int main(int argc, const char* argv[]) { int exitCode; { QSettings::setDefaultFormat(QSettings::IniFormat); - bool launchedFromSteam = SteamClient::isRunning(); - Application app(argc, const_cast(argv), startupTime, runServer, serverContentPathOptionValue, launchedFromSteam); + Application app(argc, const_cast(argv), startupTime, runServer, serverContentPathOptionValue); // If we failed the OpenGLVersion check, log it. if (override) { From a801832a5573d65ee1880c9588338c9758d24ea9 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 27 Oct 2016 11:12:31 -0700 Subject: [PATCH 7/8] Fix away.js allowing any user to disable away.js --- scripts/system/away.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/away.js b/scripts/system/away.js index 79ec22967d..bbb18b26a1 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -304,7 +304,7 @@ function setEnabled(value) { var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable"; var handleMessage = function(channel, message, sender) { - if (channel === CHANNEL_AWAY_ENABLE) { + if (channel === CHANNEL_AWAY_ENABLE && sender === MyAvatar.sessionUUID) { print("away.js | Got message on Hifi-Away-Enable: ", message); setEnabled(message === 'enable'); } From 1782f97dbd9bacf23b0942beedb21d60f3a61fab Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 27 Oct 2016 11:12:41 -0700 Subject: [PATCH 8/8] Fix away.js not unsubscribing on shutdown --- scripts/system/away.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/system/away.js b/scripts/system/away.js index bbb18b26a1..96813031f1 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -344,6 +344,7 @@ Script.scriptEnding.connect(function () { Controller.mousePressEvent.disconnect(goActive); Controller.keyPressEvent.disconnect(maybeGoActive); Messages.messageReceived.disconnect(handleMessage); + Messages.unsubscribe(CHANNEL_AWAY_ENABLE); }); if (HMD.active && !HMD.mounted) {