Added desktop and no-sound modes.

When -desktop is given on the command line then the settings menu is shown on
the desktop instead of an vr overlay.
When -nosound is given on the command line then there are no sound
effects.
This commit is contained in:
2016-12-04 23:37:00 +01:00
parent 4e15b9dea8
commit b766dc72cc
11 changed files with 137 additions and 102 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ ComboBox {
onActivated: { onActivated: {
if (activeFocus) { if (activeFocus) {
MyResources.activationSound.play() MyResources.playActivationSound()
} }
} }
+1 -1
View File
@@ -25,7 +25,7 @@ Button {
onClicked: { onClicked: {
if (activationSoundEnabled) { if (activationSoundEnabled) {
MyResources.activationSound.play() MyResources.playActivationSound()
} }
} }
} }
+1 -1
View File
@@ -24,6 +24,6 @@ Button {
} }
onClicked: { onClicked: {
MyResources.activationSound.play() MyResources.playActivationSound()
} }
} }
+11
View File
@@ -1,8 +1,19 @@
pragma Singleton pragma Singleton
import QtQuick 2.7 import QtQuick 2.7
import QtMultimedia 5.6 import QtMultimedia 5.6
import matzman666.advsettings 1.0
QtObject { QtObject {
function playActivationSound() {
if (!OverlayController.soundDisabled()) {
activationSound.play()
}
}
function playFocusChangedSound() {
if (!OverlayController.soundDisabled()) {
focusChangedSound.play()
}
}
property SoundEffect activationSound: SoundEffect { property SoundEffect activationSound: SoundEffect {
source: vrRuntimePath + "tools/content/panorama/sounds/activation.wav" source: vrRuntimePath + "tools/content/panorama/sounds/activation.wav"
} }
+1 -1
View File
@@ -46,7 +46,7 @@ Slider {
onValueChanged: { onValueChanged: {
if (activeFocus) { if (activeFocus) {
MyResources.activationSound.play() MyResources.playActivationSound()
} }
} }
} }
+1 -1
View File
@@ -43,7 +43,7 @@ Rectangle {
} }
} }
onClicked: { onClicked: {
MyResources.focusChangedSound.play() MyResources.playFocusChangedSound()
stackView.pop() stackView.pop()
} }
} }
+1 -1
View File
@@ -48,6 +48,6 @@ CheckBox {
} }
onClicked: { onClicked: {
MyResources.activationSound.play() MyResources.playActivationSound()
} }
} }
+7 -7
View File
@@ -27,7 +27,7 @@ MyStackViewPage {
text: "SteamVR" text: "SteamVR"
Layout.fillWidth: true Layout.fillWidth: true
onClicked: { onClicked: {
MyResources.focusChangedSound.play() MyResources.playFocusChangedSound()
mainView.push(steamVRPage) mainView.push(steamVRPage)
} }
} }
@@ -38,7 +38,7 @@ MyStackViewPage {
text: "Chaperone" text: "Chaperone"
Layout.fillWidth: true Layout.fillWidth: true
onClicked: { onClicked: {
MyResources.focusChangedSound.play() MyResources.playFocusChangedSound()
mainView.push(chaperonePage) mainView.push(chaperonePage)
} }
} }
@@ -49,7 +49,7 @@ MyStackViewPage {
text: "Play Space" text: "Play Space"
Layout.fillWidth: true Layout.fillWidth: true
onClicked: { onClicked: {
MyResources.focusChangedSound.play() MyResources.playFocusChangedSound()
mainView.push(playspacePage) mainView.push(playspacePage)
} }
} }
@@ -60,7 +60,7 @@ MyStackViewPage {
text: "Floor Fix" text: "Floor Fix"
Layout.fillWidth: true Layout.fillWidth: true
onClicked: { onClicked: {
MyResources.focusChangedSound.play() MyResources.playFocusChangedSound()
mainView.push(fixFloorPage) mainView.push(fixFloorPage)
} }
} }
@@ -71,7 +71,7 @@ MyStackViewPage {
text: "Audio" text: "Audio"
Layout.fillWidth: true Layout.fillWidth: true
onClicked: { onClicked: {
MyResources.focusChangedSound.play() MyResources.playFocusChangedSound()
mainView.push(audioPage) mainView.push(audioPage)
} }
} }
@@ -82,7 +82,7 @@ MyStackViewPage {
text: "Statistics" text: "Statistics"
Layout.fillWidth: true Layout.fillWidth: true
onClicked: { onClicked: {
MyResources.focusChangedSound.play() MyResources.playFocusChangedSound()
mainView.push(statisticsPage) mainView.push(statisticsPage)
} }
} }
@@ -98,7 +98,7 @@ MyStackViewPage {
text: "Settings" text: "Settings"
Layout.fillWidth: true Layout.fillWidth: true
onClicked: { onClicked: {
MyResources.focusChangedSound.play() MyResources.playFocusChangedSound()
mainView.push(settingsPage) mainView.push(settingsPage)
} }
} }
+19 -3
View File
@@ -44,6 +44,7 @@ void myQtMessageHandler(QtMsgType type, const QMessageLogContext &context, const
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// Configure logger // Configure logger
START_EASYLOGGINGPP(argc, argv); START_EASYLOGGINGPP(argc, argv);
el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog); el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog);
@@ -56,6 +57,19 @@ int main(int argc, char *argv[]) {
el::Loggers::reconfigureAllLoggers(conf); el::Loggers::reconfigureAllLoggers(conf);
} }
bool desktopMode = false;
bool noSound = false;
// Parse command line arguments
for (int i = 1; i < argc; i++) {
if (std::string(argv[i]).compare("-desktop") == 0) {
LOG(INFO) << "Desktop mode enabled.";
desktopMode = true;
} else if (std::string(argv[i]).compare("-nosound") == 0) {
noSound = true;
}
}
LOG(INFO) << "Starting Application."; LOG(INFO) << "Starting Application.";
try { try {
QApplication a(argc, argv); QApplication a(argc, argv);
@@ -67,7 +81,7 @@ int main(int argc, char *argv[]) {
QQmlEngine qmlEngine; QQmlEngine qmlEngine;
advsettings::OverlayController* controller = advsettings::OverlayController::getInstance(); advsettings::OverlayController* controller = advsettings::OverlayController::createInstance(desktopMode, noSound);
controller->Init(&qmlEngine); controller->Init(&qmlEngine);
QQmlComponent component(&qmlEngine, QUrl::fromLocalFile("res/qml/mainwidget.qml")); QQmlComponent component(&qmlEngine, QUrl::fromLocalFile("res/qml/mainwidget.qml"));
@@ -78,6 +92,7 @@ int main(int argc, char *argv[]) {
auto quickObj = component.create(); auto quickObj = component.create();
controller->SetWidget(qobject_cast<QQuickItem*>(quickObj), advsettings::OverlayController::applicationName, advsettings::OverlayController::applicationKey); controller->SetWidget(qobject_cast<QQuickItem*>(quickObj), advsettings::OverlayController::applicationName, advsettings::OverlayController::applicationKey);
if (!desktopMode) {
std::string manifestPath = QApplication::applicationDirPath().toStdString() + "\\advancedsettings.vrmanifest"; std::string manifestPath = QApplication::applicationDirPath().toStdString() + "\\advancedsettings.vrmanifest";
if (QFile::exists(QString::fromStdString(manifestPath))) { if (QFile::exists(QString::fromStdString(manifestPath))) {
bool firstTime = false; bool firstTime = false;
@@ -96,13 +111,14 @@ int main(int argc, char *argv[]) {
} else { } else {
LOG(ERROR) << "Could not find application manifest: " << manifestPath; LOG(ERROR) << "Could not find application manifest: " << manifestPath;
} }
}
#ifdef DEBUG_DESKTOP_WINDOW if (desktopMode) {
auto m_pWindow = new QQuickWindow(); auto m_pWindow = new QQuickWindow();
qobject_cast<QQuickItem*>(quickObj)->setParentItem(m_pWindow->contentItem()); qobject_cast<QQuickItem*>(quickObj)->setParentItem(m_pWindow->contentItem());
m_pWindow->setGeometry(0, 0, qobject_cast<QQuickItem*>(quickObj)->width(), qobject_cast<QQuickItem*>(quickObj)->height()); m_pWindow->setGeometry(0, 0, qobject_cast<QQuickItem*>(quickObj)->width(), qobject_cast<QQuickItem*>(quickObj)->height());
m_pWindow->show(); m_pWindow->show();
#endif }
return a.exec(); return a.exec();
+14 -10
View File
@@ -130,6 +130,7 @@ void OverlayController::Init(QQmlEngine* qmlEngine) {
void OverlayController::SetWidget(QQuickItem* quickItem, const std::string& name, const std::string& key) { void OverlayController::SetWidget(QQuickItem* quickItem, const std::string& name, const std::string& key) {
if (!desktopMode) {
vr::VROverlayError overlayError = vr::VROverlay()->CreateDashboardOverlay(key.c_str(), name.c_str(), &m_ulOverlayHandle, &m_ulOverlayThumbnailHandle); vr::VROverlayError overlayError = vr::VROverlay()->CreateDashboardOverlay(key.c_str(), name.c_str(), &m_ulOverlayHandle, &m_ulOverlayThumbnailHandle);
if (overlayError != vr::VROverlayError_None) { if (overlayError != vr::VROverlayError_None) {
if (overlayError == vr::VROverlayError_KeyInUse) { if (overlayError == vr::VROverlayError_KeyInUse) {
@@ -147,11 +148,6 @@ void OverlayController::SetWidget(QQuickItem* quickItem, const std::string& name
LOG(ERROR) << "Could not find thumbnail icon \"" << thumbIconPath << "\""; LOG(ERROR) << "Could not find thumbnail icon \"" << thumbIconPath << "\"";
} }
m_pPumpEventsTimer.reset(new QTimer());
connect(m_pPumpEventsTimer.get(), SIGNAL(timeout()), this, SLOT(OnTimeoutPumpEvents()));
m_pPumpEventsTimer->setInterval(20);
m_pPumpEventsTimer->start();
// Too many render calls in too short time overwhelm Qt and an assertion gets thrown. // Too many render calls in too short time overwhelm Qt and an assertion gets thrown.
// Therefore we use an timer to delay render calls // Therefore we use an timer to delay render calls
m_pRenderTimer.reset(new QTimer()); m_pRenderTimer.reset(new QTimer());
@@ -164,7 +160,6 @@ void OverlayController::SetWidget(QQuickItem* quickItem, const std::string& name
fboFormat.setTextureTarget(GL_TEXTURE_2D); fboFormat.setTextureTarget(GL_TEXTURE_2D);
m_pFbo.reset(new QOpenGLFramebufferObject(quickItem->width(), quickItem->height(), fboFormat)); m_pFbo.reset(new QOpenGLFramebufferObject(quickItem->width(), quickItem->height(), fboFormat));
#ifndef DEBUG_DESKTOP_WINDOW
m_pRenderControl.reset(new QQuickRenderControl()); m_pRenderControl.reset(new QQuickRenderControl());
m_pWindow.reset(new QQuickWindow(m_pRenderControl.get())); m_pWindow.reset(new QQuickWindow(m_pRenderControl.get()));
m_pWindow->setRenderTarget(m_pFbo.get()); m_pWindow->setRenderTarget(m_pFbo.get());
@@ -180,7 +175,12 @@ void OverlayController::SetWidget(QQuickItem* quickItem, const std::string& name
connect(m_pRenderControl.get(), SIGNAL(renderRequested()), this, SLOT(OnRenderRequest())); connect(m_pRenderControl.get(), SIGNAL(renderRequested()), this, SLOT(OnRenderRequest()));
connect(m_pRenderControl.get(), SIGNAL(sceneChanged()), this, SLOT(OnRenderRequest())); connect(m_pRenderControl.get(), SIGNAL(sceneChanged()), this, SLOT(OnRenderRequest()));
#endif }
m_pPumpEventsTimer.reset(new QTimer());
connect(m_pPumpEventsTimer.get(), SIGNAL(timeout()), this, SLOT(OnTimeoutPumpEvents()));
m_pPumpEventsTimer->setInterval(20);
m_pPumpEventsTimer->start();
steamVRTabController.initStage2(this, m_pWindow.get()); steamVRTabController.initStage2(this, m_pWindow.get());
chaperoneTabController.initStage2(this, m_pWindow.get()); chaperoneTabController.initStage2(this, m_pWindow.get());
@@ -199,11 +199,10 @@ void OverlayController::OnRenderRequest() {
} }
void OverlayController::renderOverlay() { void OverlayController::renderOverlay() {
if (!desktopMode) {
// skip rendering if the overlay isn't visible // skip rendering if the overlay isn't visible
if (!vr::VROverlay() || !vr::VROverlay()->IsOverlayVisible(m_ulOverlayHandle) && !vr::VROverlay()->IsOverlayVisible(m_ulOverlayThumbnailHandle)) if (!vr::VROverlay() || !vr::VROverlay()->IsOverlayVisible(m_ulOverlayHandle) && !vr::VROverlay()->IsOverlayVisible(m_ulOverlayThumbnailHandle))
return; return;
#ifndef DEBUG_DESKTOP_WINDOW
m_pRenderControl->polishItems(); m_pRenderControl->polishItems();
m_pRenderControl->sync(); m_pRenderControl->sync();
m_pRenderControl->render(); m_pRenderControl->render();
@@ -219,7 +218,7 @@ void OverlayController::renderOverlay() {
vr::VROverlay()->SetOverlayTexture(m_ulOverlayHandle, &texture); vr::VROverlay()->SetOverlayTexture(m_ulOverlayHandle, &texture);
} }
m_pOpenGLContext->functions()->glFlush(); // We need to flush otherwise the texture may be empty.*/ m_pOpenGLContext->functions()->glFlush(); // We need to flush otherwise the texture may be empty.*/
#endif }
} }
@@ -472,6 +471,11 @@ QUrl OverlayController::getVRRuntimePathUrl() {
} }
bool OverlayController::soundDisabled() {
return noSound;
}
void OverlayController::showKeyboard(QString existingText, unsigned long userValue) { void OverlayController::showKeyboard(QString existingText, unsigned long userValue) {
vr::VROverlay()->ShowKeyboardForOverlay(m_ulOverlayHandle, vr::k_EGamepadTextInputModeNormal, vr::k_EGamepadTextInputLineModeSingleLine, "Advanced Settings Overlay", 1024, existingText.toStdString().c_str(), false, userValue); vr::VROverlay()->ShowKeyboardForOverlay(m_ulOverlayHandle, vr::k_EGamepadTextInputModeNormal, vr::k_EGamepadTextInputLineModeSingleLine, "Advanced Settings Overlay", 1024, existingText.toStdString().c_str(), false, userValue);
} }
+10 -6
View File
@@ -31,9 +31,6 @@
#include "tabcontrollers/SettingsTabController.h" #include "tabcontrollers/SettingsTabController.h"
// Show a window on the desktop instead of an overlay in vr
//#define DEBUG_DESKTOP_WINDOW
// application namespace // application namespace
namespace advsettings { namespace advsettings {
@@ -63,6 +60,9 @@ private:
QPoint m_ptLastMouse; QPoint m_ptLastMouse;
Qt::MouseButtons m_lastMouseButtons = 0; Qt::MouseButtons m_lastMouseButtons = 0;
bool desktopMode;
bool noSound;
QUrl m_runtimePathUrl; QUrl m_runtimePathUrl;
SteamVRTabController steamVRTabController; SteamVRTabController steamVRTabController;
@@ -74,7 +74,7 @@ private:
SettingsTabController settingsTabController; SettingsTabController settingsTabController;
private: private:
OverlayController() : QObject() {} OverlayController(bool desktopMode, bool noSound) : QObject(), desktopMode(desktopMode), noSound(noSound) {}
public: public:
virtual ~OverlayController(); virtual ~OverlayController();
@@ -95,6 +95,8 @@ public:
Q_INVOKABLE QString getVersionString(); Q_INVOKABLE QString getVersionString();
Q_INVOKABLE QUrl getVRRuntimePathUrl(); Q_INVOKABLE QUrl getVRRuntimePathUrl();
Q_INVOKABLE bool soundDisabled();
public slots: public slots:
void renderOverlay(); void renderOverlay();
void OnRenderRequest(); void OnRenderRequest();
@@ -111,9 +113,11 @@ private:
public: public:
static OverlayController* getInstance() { static OverlayController* getInstance() {
if (!singleton) { return singleton.get();
singleton.reset(new advsettings::OverlayController());
} }
static OverlayController* createInstance(bool desktopMode, bool noSound) {
singleton.reset(new advsettings::OverlayController(desktopMode, noSound));
return singleton.get(); return singleton.get();
} }