From 57be59935d79e6594eced9e44320c133f93a967f Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 17 Oct 2015 19:11:09 -0700 Subject: [PATCH] Move controller test to app --- .../resources/qml}/ScrollingGraph.qml | 2 +- interface/resources/qml/TestControllers.qml | 171 ++++++++++++++++++ .../qml/controller}/AnalogButton.qml | 2 +- .../resources/qml/controller}/AnalogStick.qml | 4 +- .../resources/qml/controller}/Hydra.qml | 3 +- .../qml/controller}/ToggleButton.qml | 2 +- .../resources/qml/controller}/Xbox.qml | 3 +- .../qml/controller}/hydra/HydraButtons.qml | 2 +- .../qml/controller}/hydra/HydraStick.qml | 2 +- .../resources/qml/controller}/hydra/hydra.png | Bin .../resources/qml/controller}/xbox/DPad.qml | 3 +- .../qml/controller}/xbox/LeftAnalogStick.qml | 2 +- .../qml/controller}/xbox/RightAnalogStick.qml | 2 +- .../qml/controller}/xbox/XboxButtons.qml | 2 +- .../xbox/xbox360-controller-md.png | Bin interface/src/Application.cpp | 112 +++++++----- interface/src/Application.h | 21 ++- .../src/controllers/ScriptingInterface.cpp | 76 ++++---- .../src/controllers/ScriptingInterface.h | 5 +- .../controllers/impl/MappingBuilderProxy.cpp | 7 +- .../controllers/impl/MappingBuilderProxy.h | 1 + .../controllers/impl/RouteBuilderProxy.cpp | 6 + .../src/controllers/impl/RouteBuilderProxy.h | 1 + .../src/EntityTreeRenderer.cpp | 3 +- .../render-utils/src/OffscreenQmlSurface.cpp | 6 + .../render-utils/src/OffscreenQmlSurface.h | 1 + .../src/AbstractScriptingServicesInterface.h | 11 -- libraries/script-engine/src/ScriptEngine.cpp | 11 +- libraries/script-engine/src/ScriptEngine.h | 2 - libraries/shared/src/DependencyManager.h | 22 ++- tests/controllers/qml/content.qml | 157 ---------------- tests/controllers/qml/main.qml | 10 +- tests/controllers/src/main.cpp | 36 +++- 33 files changed, 391 insertions(+), 297 deletions(-) rename {tests/controllers/qml/controls => interface/resources/qml}/ScrollingGraph.qml (98%) create mode 100644 interface/resources/qml/TestControllers.qml rename {tests/controllers/qml/controls => interface/resources/qml/controller}/AnalogButton.qml (95%) rename {tests/controllers/qml/controls => interface/resources/qml/controller}/AnalogStick.qml (92%) rename {tests/controllers/qml => interface/resources/qml/controller}/Hydra.qml (94%) rename {tests/controllers/qml/controls => interface/resources/qml/controller}/ToggleButton.qml (93%) rename {tests/controllers/qml => interface/resources/qml/controller}/Xbox.qml (95%) rename {tests/controllers/qml => interface/resources/qml/controller}/hydra/HydraButtons.qml (91%) rename {tests/controllers/qml => interface/resources/qml/controller}/hydra/HydraStick.qml (99%) rename {tests/controllers/qml => interface/resources/qml/controller}/hydra/hydra.png (100%) rename {tests/controllers/qml => interface/resources/qml/controller}/xbox/DPad.qml (96%) rename {tests/controllers/qml => interface/resources/qml/controller}/xbox/LeftAnalogStick.qml (92%) rename {tests/controllers/qml => interface/resources/qml/controller}/xbox/RightAnalogStick.qml (92%) rename {tests/controllers/qml => interface/resources/qml/controller}/xbox/XboxButtons.qml (97%) rename {tests/controllers/qml => interface/resources/qml/controller}/xbox/xbox360-controller-md.png (100%) delete mode 100644 tests/controllers/qml/content.qml diff --git a/tests/controllers/qml/controls/ScrollingGraph.qml b/interface/resources/qml/ScrollingGraph.qml similarity index 98% rename from tests/controllers/qml/controls/ScrollingGraph.qml rename to interface/resources/qml/ScrollingGraph.qml index 471d142d27..b5eaac6f89 100644 --- a/tests/controllers/qml/controls/ScrollingGraph.qml +++ b/interface/resources/qml/ScrollingGraph.qml @@ -22,7 +22,7 @@ Item { property string label: "" function update() { - value = Controllers.getValue(controlId); + value = Controller.getValue(controlId); canvas.requestPaint(); } diff --git a/interface/resources/qml/TestControllers.qml b/interface/resources/qml/TestControllers.qml new file mode 100644 index 0000000000..388e452335 --- /dev/null +++ b/interface/resources/qml/TestControllers.qml @@ -0,0 +1,171 @@ +import QtQuick 2.3 +import QtQuick.Controls 1.2 +import QtQuick.Layouts 1.0 +import QtQuick.Dialogs 1.0 + +import "controller" +import "controls" as HifiControls +import "styles" + +HifiControls.VrDialog { + id: root + HifiConstants { id: hifi } + title: "Controller Test" + resizable: true + contentImplicitWidth: clientArea.implicitWidth + contentImplicitHeight: clientArea.implicitHeight + backgroundColor: "beige" + + property var actions: Controller.Actions + property var standard: Controller.Standard + property var hydra: null + property var testMapping: null + property var xbox: null + + + Component.onCompleted: { + enabled = true + var xboxRegex = /^X360Controller/; + var hydraRegex = /^Hydra/; + for (var prop in Controller.Hardware) { + if(xboxRegex.test(prop)) { + root.xbox = Controller.Hardware[prop] + print("found xbox") + continue + } + if (hydraRegex.test(prop)) { + root.hydra = Controller.Hardware[prop] + print("found hydra") + continue + } + } + } + + Column { + id: clientArea + spacing: 12 + x: root.clientX + y: root.clientY + + Row { + spacing: 8 + Button { + text: "Default Mapping" + onClicked: { + var mapping = Controller.newMapping("Default"); + mapping.from(xbox.A).to(standard.A); + mapping.from(xbox.B).to(standard.B); + mapping.from(xbox.X).to(standard.X); + mapping.from(xbox.Y).to(standard.Y); + mapping.from(xbox.Up).to(standard.DU); + mapping.from(xbox.Down).to(standard.DD); + mapping.from(xbox.Left).to(standard.DL); + mapping.from(xbox.Right).to(standard.Right); + mapping.from(xbox.LB).to(standard.LB); + mapping.from(xbox.RB).to(standard.RB); + mapping.from(xbox.LS).to(standard.LS); + mapping.from(xbox.RS).to(standard.RS); + mapping.from(xbox.Start).to(standard.Start); + mapping.from(xbox.Back).to(standard.Back); + mapping.from(xbox.LY).to(standard.LY); + mapping.from(xbox.LX).to(standard.LX); + mapping.from(xbox.RY).to(standard.RY); + mapping.from(xbox.RX).to(standard.RX); + mapping.from(xbox.LT).to(standard.LT); + mapping.from(xbox.RT).to(standard.RT); + Controller.enableMapping("Default"); + enabled = false; + text = "Built" + } + } + + Button { + text: "Build Mapping" + onClicked: { + var mapping = Controller.newMapping(); + // Inverting a value + mapping.from(hydra.RY).invert().to(standard.RY); + mapping.from(hydra.RX).to(standard.RX); + mapping.from(hydra.LY).to(standard.LY); + mapping.from(hydra.LY).to(standard.LX); + // Assigning a value from a function + // mapping.from(function() { return Math.sin(Date.now() / 250); }).to(standard.RX); + // Constrainting a value to -1, 0, or 1, with a deadzone +// mapping.from(xbox.LY).deadZone(0.5).constrainToInteger().to(standard.LY); + mapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw); +// mapping.from(actions.Yaw).clamp(0, 1).invert().to(actions.YAW_RIGHT); +// mapping.from(actions.Yaw).clamp(-1, 0).to(actions.YAW_LEFT); + // mapping.modifier(keyboard.Ctrl).scale(2.0) +// mapping.from(keyboard.A).to(actions.TranslateLeft) +// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft) +// mapping.from(keyboard.A, keyboard.Shift, keyboard.Ctrl).scale(2.0).to(actions.TurnLeft) +// // First loopbacks +// // Then non-loopbacks by constraint level (number of inputs) +// mapping.from(xbox.RX).deadZone(0.2).to(xbox.RX) +// mapping.from(standard.RB, standard.LB, keyboard.Shift).to(actions.TurnLeft) +// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft) +// mapping.from(keyboard.W).when(keyboard.Shift).to(actions.Forward) + testMapping = mapping; + enabled = false + text = "Built" + } + } + + Button { + text: "Enable Mapping" + onClicked: root.testMapping.enable() + } + + Button { + text: "Disable Mapping" + onClicked: root.testMapping.disable() + } + + Button { + text: "Enable Mapping" + onClicked: print(Controller.getValue(root.xbox.LY)); + } + } + + Row { + Xbox { device: root.standard; label: "Standard"; width: 360 } + } + + Row { + spacing: 8 + Xbox { device: root.xbox; label: "XBox"; width: 360 } + Hydra { device: root.hydra; width: 360 } + } +// Row { +// spacing: 8 +// ScrollingGraph { +// controlId: Controller.Actions.Yaw +// label: "Yaw" +// min: -3.0 +// max: 3.0 +// size: 128 +// } +// +// ScrollingGraph { +// controlId: Controller.Actions.YAW_LEFT +// label: "Yaw Left" +// min: -3.0 +// max: 3.0 +// size: 128 +// } +// +// ScrollingGraph { +// controlId: Controller.Actions.YAW_RIGHT +// label: "Yaw Right" +// min: -3.0 +// max: 3.0 +// size: 128 +// } +// } + } +} // dialog + + + + + diff --git a/tests/controllers/qml/controls/AnalogButton.qml b/interface/resources/qml/controller/AnalogButton.qml similarity index 95% rename from tests/controllers/qml/controls/AnalogButton.qml rename to interface/resources/qml/controller/AnalogButton.qml index 141c131063..d027332d42 100644 --- a/tests/controllers/qml/controls/AnalogButton.qml +++ b/interface/resources/qml/controller/AnalogButton.qml @@ -13,7 +13,7 @@ Item { property color color: 'black' function update() { - value = Controllers.getValue(controlId); + value = Controller.getValue(controlId); canvas.requestPaint(); } diff --git a/tests/controllers/qml/controls/AnalogStick.qml b/interface/resources/qml/controller/AnalogStick.qml similarity index 92% rename from tests/controllers/qml/controls/AnalogStick.qml rename to interface/resources/qml/controller/AnalogStick.qml index 4e8ceb5736..499e0e9ce9 100644 --- a/tests/controllers/qml/controls/AnalogStick.qml +++ b/interface/resources/qml/controller/AnalogStick.qml @@ -17,8 +17,8 @@ Item { function update() { value = Qt.vector2d( - Controllers.getValue(controlIds[0]), - Controllers.getValue(controlIds[1]) + Controller.getValue(controlIds[0]), + Controller.getValue(controlIds[1]) ); if (root.invertY) { value.y = value.y * -1.0 diff --git a/tests/controllers/qml/Hydra.qml b/interface/resources/qml/controller/Hydra.qml similarity index 94% rename from tests/controllers/qml/Hydra.qml rename to interface/resources/qml/controller/Hydra.qml index 5ef47c4d83..19f3b4c193 100644 --- a/tests/controllers/qml/Hydra.qml +++ b/interface/resources/qml/controller/Hydra.qml @@ -3,8 +3,7 @@ import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import QtQuick.Dialogs 1.0 -import "./hydra" -import "./controls" +import "hydra" Item { id: root diff --git a/tests/controllers/qml/controls/ToggleButton.qml b/interface/resources/qml/controller/ToggleButton.qml similarity index 93% rename from tests/controllers/qml/controls/ToggleButton.qml rename to interface/resources/qml/controller/ToggleButton.qml index 46a7b4bdfd..6481045dd0 100644 --- a/tests/controllers/qml/controls/ToggleButton.qml +++ b/interface/resources/qml/controller/ToggleButton.qml @@ -15,7 +15,7 @@ Item { Timer { interval: 50; running: true; repeat: true onTriggered: { - root.value = Controllers.getValue(root.controlId); + root.value = Controller.getValue(root.controlId); canvas.requestPaint(); } } diff --git a/tests/controllers/qml/Xbox.qml b/interface/resources/qml/controller/Xbox.qml similarity index 95% rename from tests/controllers/qml/Xbox.qml rename to interface/resources/qml/controller/Xbox.qml index bc9acd5a43..165ac596fe 100644 --- a/tests/controllers/qml/Xbox.qml +++ b/interface/resources/qml/controller/Xbox.qml @@ -3,8 +3,7 @@ import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import QtQuick.Dialogs 1.0 -import "./xbox" -import "./controls" +import "xbox" Item { id: root diff --git a/tests/controllers/qml/hydra/HydraButtons.qml b/interface/resources/qml/controller/hydra/HydraButtons.qml similarity index 91% rename from tests/controllers/qml/hydra/HydraButtons.qml rename to interface/resources/qml/controller/hydra/HydraButtons.qml index 6c3070d2b1..aa8927f5b6 100644 --- a/tests/controllers/qml/hydra/HydraButtons.qml +++ b/interface/resources/qml/controller/hydra/HydraButtons.qml @@ -3,7 +3,7 @@ import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import QtQuick.Dialogs 1.0 -import "./../controls" +import ".." Item { id: root diff --git a/tests/controllers/qml/hydra/HydraStick.qml b/interface/resources/qml/controller/hydra/HydraStick.qml similarity index 99% rename from tests/controllers/qml/hydra/HydraStick.qml rename to interface/resources/qml/controller/hydra/HydraStick.qml index 3c22789f6d..d082a20b10 100644 --- a/tests/controllers/qml/hydra/HydraStick.qml +++ b/interface/resources/qml/controller/hydra/HydraStick.qml @@ -3,7 +3,7 @@ import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import QtQuick.Dialogs 1.0 -import "./../controls" +import ".." Item { id: root diff --git a/tests/controllers/qml/hydra/hydra.png b/interface/resources/qml/controller/hydra/hydra.png similarity index 100% rename from tests/controllers/qml/hydra/hydra.png rename to interface/resources/qml/controller/hydra/hydra.png diff --git a/tests/controllers/qml/xbox/DPad.qml b/interface/resources/qml/controller/xbox/DPad.qml similarity index 96% rename from tests/controllers/qml/xbox/DPad.qml rename to interface/resources/qml/controller/xbox/DPad.qml index 8efe6c2b30..2cfb6412e7 100644 --- a/tests/controllers/qml/xbox/DPad.qml +++ b/interface/resources/qml/controller/xbox/DPad.qml @@ -3,8 +3,7 @@ import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import QtQuick.Dialogs 1.0 -import "./../controls" - +import ".." Item { id: root diff --git a/tests/controllers/qml/xbox/LeftAnalogStick.qml b/interface/resources/qml/controller/xbox/LeftAnalogStick.qml similarity index 92% rename from tests/controllers/qml/xbox/LeftAnalogStick.qml rename to interface/resources/qml/controller/xbox/LeftAnalogStick.qml index ed2689e7c8..8e2de1eb36 100644 --- a/tests/controllers/qml/xbox/LeftAnalogStick.qml +++ b/interface/resources/qml/controller/xbox/LeftAnalogStick.qml @@ -3,7 +3,7 @@ import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import QtQuick.Dialogs 1.0 -import "./../controls" +import ".." Item { id: root diff --git a/tests/controllers/qml/xbox/RightAnalogStick.qml b/interface/resources/qml/controller/xbox/RightAnalogStick.qml similarity index 92% rename from tests/controllers/qml/xbox/RightAnalogStick.qml rename to interface/resources/qml/controller/xbox/RightAnalogStick.qml index 611b4d8f92..0cdfeda2cf 100644 --- a/tests/controllers/qml/xbox/RightAnalogStick.qml +++ b/interface/resources/qml/controller/xbox/RightAnalogStick.qml @@ -3,7 +3,7 @@ import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import QtQuick.Dialogs 1.0 -import "./../controls" +import ".." Item { id: root diff --git a/tests/controllers/qml/xbox/XboxButtons.qml b/interface/resources/qml/controller/xbox/XboxButtons.qml similarity index 97% rename from tests/controllers/qml/xbox/XboxButtons.qml rename to interface/resources/qml/controller/xbox/XboxButtons.qml index 4a9e87799e..e26a4a0b98 100644 --- a/tests/controllers/qml/xbox/XboxButtons.qml +++ b/interface/resources/qml/controller/xbox/XboxButtons.qml @@ -3,7 +3,7 @@ import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import QtQuick.Dialogs 1.0 -import "./../controls" +import ".." Item { id: root diff --git a/tests/controllers/qml/xbox/xbox360-controller-md.png b/interface/resources/qml/controller/xbox/xbox360-controller-md.png similarity index 100% rename from tests/controllers/qml/xbox/xbox360-controller-md.png rename to interface/resources/qml/controller/xbox/xbox360-controller-md.png diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c01e89c6d9..b0c0109b71 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -17,27 +17,32 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include #include #include @@ -120,6 +125,7 @@ #include "scripting/SettingsScriptingInterface.h" #include "scripting/WebWindowClass.h" #include "scripting/WindowScriptingInterface.h" +#include "scripting/ControllerScriptingInterface.h" #if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SpeechRecognizer.h" #endif @@ -316,6 +322,7 @@ bool setupEssentials(int& argc, char** argv) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + #if defined(Q_OS_MAC) || defined(Q_OS_WIN) DependencyManager::set(); #endif @@ -327,7 +334,7 @@ bool setupEssentials(int& argc, char** argv) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); - + DependencyManager::set(); return true; } @@ -374,6 +381,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : setInstance(this); + auto controllerScriptingInterface = DependencyManager::get().data(); + _controllerScriptingInterface = dynamic_cast(controllerScriptingInterface); // to work around the Qt constant wireless scanning, set the env for polling interval very high const QByteArray EXTREME_BEARER_POLL_TIMEOUT = QString::number(INT_MAX).toLocal8Bit(); qputenv("QT_BEARER_POLL_TIMEOUT", EXTREME_BEARER_POLL_TIMEOUT); @@ -618,7 +627,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : // Setup the userInputMapper with the actions auto userInputMapper = DependencyManager::get(); - connect(userInputMapper.data(), &UserInputMapper::actionEvent, &_controllerScriptingInterface, &ControllerScriptingInterface::actionEvent); + connect(userInputMapper.data(), &UserInputMapper::actionEvent, _controllerScriptingInterface, &ControllerScriptingInterface::actionEvent); connect(userInputMapper.data(), &UserInputMapper::actionEvent, [this](int action, float state) { if (state) { switch (action) { @@ -975,6 +984,8 @@ void Application::initializeUi() { offscreenUi->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/")); offscreenUi->load("Root.qml"); offscreenUi->load("RootMenu.qml"); + auto scriptingInterface = DependencyManager::get(); + offscreenUi->getRootContext()->setContextProperty("Controller", scriptingInterface.data()); _glWidget->installEventFilter(offscreenUi.data()); VrMenu::load(); VrMenu::executeQueuedLambdas(); @@ -1456,7 +1467,7 @@ bool Application::event(QEvent* event) { } if (HFActionEvent::types().contains(event->type())) { - _controllerScriptingInterface.handleMetaEvent(static_cast(event)); + _controllerScriptingInterface->handleMetaEvent(static_cast(event)); } return QApplication::event(event); @@ -1470,7 +1481,7 @@ bool Application::eventFilter(QObject* object, QEvent* event) { } // Filter out captured keys before they're used for shortcut actions. - if (_controllerScriptingInterface.isKeyCaptured(static_cast(event))) { + if (_controllerScriptingInterface->isKeyCaptured(static_cast(event))) { event->accept(); return true; } @@ -1485,10 +1496,10 @@ void Application::keyPressEvent(QKeyEvent* event) { _altPressed = event->key() == Qt::Key_Alt; _keysPressed.insert(event->key()); - _controllerScriptingInterface.emitKeyPressEvent(event); // send events to any registered scripts + _controllerScriptingInterface->emitKeyPressEvent(event); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isKeyCaptured(event)) { + if (_controllerScriptingInterface->isKeyCaptured(event)) { return; } @@ -1518,6 +1529,13 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isMeta) { auto offscreenUi = DependencyManager::get(); offscreenUi->load("Browser.qml"); + } + break; + + case Qt::Key_X: + if (isMeta && isShifted) { + auto offscreenUi = DependencyManager::get(); + offscreenUi->load("TestControllers.qml"); } break; @@ -1752,10 +1770,10 @@ void Application::keyReleaseEvent(QKeyEvent* event) { _keysPressed.remove(event->key()); - _controllerScriptingInterface.emitKeyReleaseEvent(event); // send events to any registered scripts + _controllerScriptingInterface->emitKeyReleaseEvent(event); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isKeyCaptured(event)) { + if (_controllerScriptingInterface->isKeyCaptured(event)) { return; } @@ -1844,10 +1862,10 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { _entities.mouseMoveEvent(&mappedEvent, deviceID); - _controllerScriptingInterface.emitMouseMoveEvent(&mappedEvent, deviceID); // send events to any registered scripts + _controllerScriptingInterface->emitMouseMoveEvent(&mappedEvent, deviceID); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isMouseCaptured()) { + if (_controllerScriptingInterface->isMouseCaptured()) { return; } @@ -1872,10 +1890,10 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { _entities.mousePressEvent(&mappedEvent, deviceID); } - _controllerScriptingInterface.emitMousePressEvent(&mappedEvent); // send events to any registered scripts + _controllerScriptingInterface->emitMousePressEvent(&mappedEvent); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isMouseCaptured()) { + if (_controllerScriptingInterface->isMouseCaptured()) { return; } @@ -1897,11 +1915,11 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { void Application::mouseDoublePressEvent(QMouseEvent* event, unsigned int deviceID) { // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isMouseCaptured()) { + if (_controllerScriptingInterface->isMouseCaptured()) { return; } - _controllerScriptingInterface.emitMouseDoublePressEvent(event); + _controllerScriptingInterface->emitMouseDoublePressEvent(event); } void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { @@ -1917,10 +1935,10 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { _entities.mouseReleaseEvent(&mappedEvent, deviceID); } - _controllerScriptingInterface.emitMouseReleaseEvent(&mappedEvent); // send events to any registered scripts + _controllerScriptingInterface->emitMouseReleaseEvent(&mappedEvent); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isMouseCaptured()) { + if (_controllerScriptingInterface->isMouseCaptured()) { return; } @@ -1943,12 +1961,12 @@ void Application::touchUpdateEvent(QTouchEvent* event) { if (event->type() == QEvent::TouchUpdate) { TouchEvent thisEvent(*event, _lastTouchEvent); - _controllerScriptingInterface.emitTouchUpdateEvent(thisEvent); // send events to any registered scripts + _controllerScriptingInterface->emitTouchUpdateEvent(thisEvent); // send events to any registered scripts _lastTouchEvent = thisEvent; } // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isTouchCaptured()) { + if (_controllerScriptingInterface->isTouchCaptured()) { return; } @@ -1960,13 +1978,13 @@ void Application::touchUpdateEvent(QTouchEvent* event) { void Application::touchBeginEvent(QTouchEvent* event) { _altPressed = false; TouchEvent thisEvent(*event); // on touch begin, we don't compare to last event - _controllerScriptingInterface.emitTouchBeginEvent(thisEvent); // send events to any registered scripts + _controllerScriptingInterface->emitTouchBeginEvent(thisEvent); // send events to any registered scripts _lastTouchEvent = thisEvent; // and we reset our last event to this event before we call our update touchUpdateEvent(event); // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isTouchCaptured()) { + if (_controllerScriptingInterface->isTouchCaptured()) { return; } @@ -1979,11 +1997,11 @@ void Application::touchBeginEvent(QTouchEvent* event) { void Application::touchEndEvent(QTouchEvent* event) { _altPressed = false; TouchEvent thisEvent(*event, _lastTouchEvent); - _controllerScriptingInterface.emitTouchEndEvent(thisEvent); // send events to any registered scripts + _controllerScriptingInterface->emitTouchEndEvent(thisEvent); // send events to any registered scripts _lastTouchEvent = thisEvent; // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isTouchCaptured()) { + if (_controllerScriptingInterface->isTouchCaptured()) { return; } @@ -1996,10 +2014,10 @@ void Application::touchEndEvent(QTouchEvent* event) { void Application::wheelEvent(QWheelEvent* event) { _altPressed = false; - _controllerScriptingInterface.emitWheelEvent(event); // send events to any registered scripts + _controllerScriptingInterface->emitWheelEvent(event); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it - if (_controllerScriptingInterface.isWheelCaptured()) { + if (_controllerScriptingInterface->isWheelCaptured()) { return; } @@ -2709,12 +2727,12 @@ void Application::update(float deltaTime) { } // Dispatch input events - _controllerScriptingInterface.update(); + _controllerScriptingInterface->update(); // Transfer the user inputs to the driveKeys myAvatar->clearDriveKeys(); if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) { - if (!_controllerScriptingInterface.areActionsCaptured()) { + if (!_controllerScriptingInterface->areActionsCaptured()) { myAvatar->setDriveKeys(FWD, userInputMapper->getActionState(UserInputMapper::LONGITUDINAL_FORWARD)); myAvatar->setDriveKeys(BACK, userInputMapper->getActionState(UserInputMapper::LONGITUDINAL_BACKWARD)); myAvatar->setDriveKeys(UP, userInputMapper->getActionState(UserInputMapper::VERTICAL_UP)); diff --git a/interface/src/Application.h b/interface/src/Application.h index 61421c34d6..829265c9fb 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -14,13 +14,15 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include + +#include + +#include +#include #include #include @@ -161,7 +163,7 @@ public: ToolWindow* getToolWindow() { return _toolWindow ; } - virtual controller::ScriptingInterface* getControllerScriptingInterface() { return &_controllerScriptingInterface; } + virtual controller::ScriptingInterface* getControllerScriptingInterface() { return _controllerScriptingInterface; } virtual void registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine); QImage renderAvatarBillboard(RenderArgs* renderArgs); @@ -474,8 +476,7 @@ private: NodeToJurisdictionMap _entityServerJurisdictions; NodeToOctreeSceneStats _octreeServerSceneStats; - - ControllerScriptingInterface _controllerScriptingInterface; + ControllerScriptingInterface* _controllerScriptingInterface{ nullptr }; QPointer _logDialog; QPointer _snapshotShareDialog; diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index 9f9ca85dd4..6d4ad1a566 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -26,7 +26,6 @@ #include "Logging.h" #include "InputDevice.h" - namespace controller { class VirtualEndpoint : public Endpoint { @@ -144,39 +143,9 @@ namespace controller { } return deviceMap; } + - ScriptingInterface::ScriptingInterface() { - auto userInputMapper = DependencyManager::get(); - qCDebug(controllers) << "Setting up standard controller abstraction"; - auto standardDevice = userInputMapper->getStandardDevice(); - // Expose the IDs to JS - _standard = createDeviceMap(standardDevice.get()); - // Create the endpoints - for (const auto& inputMapping : standardDevice->getAvailabeInputs()) { - const auto& standardInput = inputMapping.first; - // Ignore aliases - if (_endpoints.count(standardInput)) { - continue; - } - _endpoints[standardInput] = std::make_shared(standardInput); - } - - // FIXME allow custom user actions? - auto actionNames = userInputMapper->getActionNames(); - int actionNumber = 0; - qCDebug(controllers) << "Setting up standard actions"; - for (const auto& actionName : actionNames) { - UserInputMapper::Input actionInput(UserInputMapper::Input::ACTIONS_DEVICE, actionNumber++, UserInputMapper::ChannelType::AXIS); - qCDebug(controllers) << "\tAction: " << actionName << " " << QString::number(actionInput.getID(), 16); - // Expose the IDs to JS - QString cleanActionName = QString(actionName).remove(ScriptingInterface::SANITIZE_NAME_EXPRESSION); - _actions.insert(cleanActionName, actionInput.getID()); - - // Create the action endpoints - _endpoints[actionInput] = std::make_shared(actionInput); - } - - updateMaps(); + ScriptingInterface::~ScriptingInterface() { } QObject* ScriptingInterface::newMapping(const QString& mappingName) { @@ -235,7 +204,7 @@ namespace controller { if (request->getResult() == ResourceRequest::Success) { result = parseMapping(QString(request->getData())); } else { - qDebug() << "Failed to load mapping url <" << jsonUrl << ">" << endl; + qCWarning(controllers) << "Failed to load mapping url <" << jsonUrl << ">" << endl; } request->deleteLater(); } @@ -245,6 +214,7 @@ namespace controller { Q_INVOKABLE QObject* newMapping(const QJsonObject& json); void ScriptingInterface::enableMapping(const QString& mappingName, bool enable) { + qCDebug(controllers) << "Attempting to enable mapping " << mappingName; auto iterator = _mappingsByName.find(mappingName); if (_mappingsByName.end() == iterator) { qCWarning(controllers) << "Request to enable / disable unknown mapping " << mappingName; @@ -524,9 +494,45 @@ namespace controller { } } } - } // namespace controllers + +using namespace controller; +// FIXME this throws a hissy fit on MSVC if I put it in the main controller namespace block +ScriptingInterface::ScriptingInterface() { + auto userInputMapper = DependencyManager::get(); + qCDebug(controllers) << "Setting up standard controller abstraction"; + auto standardDevice = userInputMapper->getStandardDevice(); + // Expose the IDs to JS + _standard = createDeviceMap(standardDevice.get()); + // Create the endpoints + for (const auto& inputMapping : standardDevice->getAvailabeInputs()) { + const auto& standardInput = inputMapping.first; + // Ignore aliases + if (_endpoints.count(standardInput)) { + continue; + } + _endpoints[standardInput] = std::make_shared(standardInput); + } + + // FIXME allow custom user actions? + auto actionNames = userInputMapper->getActionNames(); + int actionNumber = 0; + qCDebug(controllers) << "Setting up standard actions"; + for (const auto& actionName : actionNames) { + UserInputMapper::Input actionInput(UserInputMapper::Input::ACTIONS_DEVICE, actionNumber++, UserInputMapper::ChannelType::AXIS); + qCDebug(controllers) << "\tAction: " << actionName << " " << QString::number(actionInput.getID(), 16); + // Expose the IDs to JS + QString cleanActionName = QString(actionName).remove(ScriptingInterface::SANITIZE_NAME_EXPRESSION); + _actions.insert(cleanActionName, actionInput.getID()); + + // Create the action endpoints + _endpoints[actionInput] = std::make_shared(actionInput); + } + + updateMaps(); +} + //var mapping = Controller.newMapping(); //mapping.map(hydra.LeftButton0, actions.ContextMenu); //mapping.map(hydra.LeftButton0).to(xbox.RT); diff --git a/libraries/controllers/src/controllers/ScriptingInterface.h b/libraries/controllers/src/controllers/ScriptingInterface.h index 07ddd625f5..ef9d61c32d 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.h +++ b/libraries/controllers/src/controllers/ScriptingInterface.h @@ -28,6 +28,8 @@ #include #include +#include + #include "UserInputMapper.h" #include "StandardControls.h" #include "Mapping.h" @@ -55,7 +57,7 @@ namespace controller { }; /// handles scripting of input controller commands from JS - class ScriptingInterface : public QObject { + class ScriptingInterface : public QObject, public Dependency { Q_OBJECT Q_PROPERTY(QVariantMap Hardware READ getHardware CONSTANT FINAL) Q_PROPERTY(QVariantMap Actions READ getActions CONSTANT FINAL) @@ -63,6 +65,7 @@ namespace controller { public: ScriptingInterface(); + virtual ~ScriptingInterface(); Q_INVOKABLE float getValue(const int& source) const; Q_INVOKABLE float getButtonValue(StandardButtonChannel source, uint16_t device = 0) const; diff --git a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp index c6031d45d2..e75068b311 100644 --- a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp +++ b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp @@ -14,13 +14,18 @@ #include #include - #include "RouteBuilderProxy.h" #include "../ScriptingInterface.h" #include "../Logging.h" using namespace controller; +QObject* MappingBuilderProxy::from(int input) { + qCDebug(controllers) << "Creating new Route builder proxy from " << input; + auto sourceEndpoint = _parent.endpointFor(UserInputMapper::Input(input)); + return from(sourceEndpoint); +} + QObject* MappingBuilderProxy::from(const QJSValue& source) { qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString(); auto sourceEndpoint = _parent.endpointFor(source); diff --git a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.h b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.h index a29f7ade39..53db901436 100644 --- a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.h +++ b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.h @@ -31,6 +31,7 @@ public: MappingBuilderProxy(ScriptingInterface& parent, Mapping::Pointer mapping) : _parent(parent), _mapping(mapping) { } + Q_INVOKABLE QObject* from(int sourceInput); Q_INVOKABLE QObject* from(const QJSValue& source); Q_INVOKABLE QObject* from(const QScriptValue& source); Q_INVOKABLE QObject* makeAxis(const QJSValue& source1, const QJSValue& source2); diff --git a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.cpp b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.cpp index 033e94daa0..ba2cd60c8b 100644 --- a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.cpp +++ b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.cpp @@ -20,6 +20,12 @@ namespace controller { +void RouteBuilderProxy::to(int destinationInput) { + qCDebug(controllers) << "Completing route " << destinationInput; + auto destinationEndpoint = _parent.endpointFor(UserInputMapper::Input(destinationInput)); + return to(destinationEndpoint); +} + void RouteBuilderProxy::to(const QJSValue& destination) { qCDebug(controllers) << "Completing route " << destination.toString(); auto destinationEndpoint = _parent.endpointFor(destination); diff --git a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h index 6fd5f1467a..8e3b3404cc 100644 --- a/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h +++ b/libraries/controllers/src/controllers/impl/RouteBuilderProxy.h @@ -30,6 +30,7 @@ class RouteBuilderProxy : public QObject { RouteBuilderProxy(ScriptingInterface& parent, Mapping::Pointer mapping, Route::Pointer route) : _parent(parent), _mapping(mapping), _route(route) { } + Q_INVOKABLE void to(int destination); Q_INVOKABLE void to(const QJSValue& destination); Q_INVOKABLE void to(const QScriptValue& destination); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 8f316af276..5ac8ce8f13 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -106,8 +106,7 @@ void EntityTreeRenderer::init() { entityTree->setFBXService(this); if (_wantScripts) { - _entitiesScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities", - _scriptingServices->getControllerScriptingInterface()); + _entitiesScriptEngine = new ScriptEngine(NO_SCRIPT, "Entities"); _scriptingServices->registerScriptEngineWithApplicationServices(_entitiesScriptEngine); _entitiesScriptEngine->runInThread(); DependencyManager::get()->setEntitiesScriptEngine(_entitiesScriptEngine); diff --git a/libraries/render-utils/src/OffscreenQmlSurface.cpp b/libraries/render-utils/src/OffscreenQmlSurface.cpp index 6c68b60f42..b53ff37436 100644 --- a/libraries/render-utils/src/OffscreenQmlSurface.cpp +++ b/libraries/render-utils/src/OffscreenQmlSurface.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include "GLEscrow.h" @@ -614,3 +615,8 @@ QQuickWindow* OffscreenQmlSurface::getWindow() { QSize OffscreenQmlSurface::size() const { return _renderer->_quickWindow->geometry().size(); } + +QQmlContext* OffscreenQmlSurface::getRootContext() { + return _qmlEngine->rootContext(); +} + diff --git a/libraries/render-utils/src/OffscreenQmlSurface.h b/libraries/render-utils/src/OffscreenQmlSurface.h index 01dd2b88f9..67315b0783 100644 --- a/libraries/render-utils/src/OffscreenQmlSurface.h +++ b/libraries/render-utils/src/OffscreenQmlSurface.h @@ -60,6 +60,7 @@ public: QQuickItem* getRootItem(); QQuickWindow* getWindow(); QObject* getEventHandler(); + QQmlContext* getRootContext(); QPointF mapToVirtualScreen(const QPointF& originalPoint, QObject* originalWidget); virtual bool eventFilter(QObject* originalDestination, QEvent* event); diff --git a/libraries/script-engine/src/AbstractScriptingServicesInterface.h b/libraries/script-engine/src/AbstractScriptingServicesInterface.h index 565a415f63..de18338fca 100644 --- a/libraries/script-engine/src/AbstractScriptingServicesInterface.h +++ b/libraries/script-engine/src/AbstractScriptingServicesInterface.h @@ -12,24 +12,13 @@ #ifndef hifi_AbstractScriptingServicesInterface_h #define hifi_AbstractScriptingServicesInterface_h -namespace controller { - class ScriptingInterface; -} - -class Transform; class ScriptEngine; -class QThread; /// Interface provided by Application to other objects that need access to scripting services of the application class AbstractScriptingServicesInterface { public: - - /// Returns the controller interface for the application - virtual controller::ScriptingInterface* getControllerScriptingInterface() = 0; - /// Registers application specific services with a script engine. virtual void registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine) = 0; - }; diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 494f038a61..0dfc2fe09e 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -84,8 +84,7 @@ void inputControllerFromScriptValue(const QScriptValue &object, controller::Inpu out = qobject_cast(object.toQObject()); } -ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, - controller::ScriptingInterface* controllerScriptingInterface, bool wantSignals) : +ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, bool wantSignals) : _scriptContents(scriptContents), _isFinished(false), @@ -93,7 +92,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam _isInitialized(false), _timerFunctionMap(), _wantSignals(wantSignals), - _controllerScriptingInterface(controllerScriptingInterface), _fileNameString(fileNameString), _quatLibrary(), _vec3Library(), @@ -310,7 +308,8 @@ void ScriptEngine::init() { registerGlobalObject("Script", this); registerGlobalObject("Audio", &AudioScriptingInterface::getInstance()); - registerGlobalObject("Controller", _controllerScriptingInterface); + auto scriptingInterface = DependencyManager::get(); + registerGlobalObject("Controller", scriptingInterface.data()); registerGlobalObject("Entities", entityScriptingInterface.data()); registerGlobalObject("Quat", &_quatLibrary); registerGlobalObject("Vec3", &_vec3Library); @@ -320,8 +319,8 @@ void ScriptEngine::init() { // constants globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE))); - if (_controllerScriptingInterface) { - _controllerScriptingInterface->registerControllerTypes(this); + if (scriptingInterface) { + scriptingInterface->registerControllerTypes(this); } diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 642159339e..5a0fb64ae2 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -55,7 +55,6 @@ class ScriptEngine : public QScriptEngine, public ScriptUser, public EntitiesScr public: ScriptEngine(const QString& scriptContents = NO_SCRIPT, const QString& fileNameString = QString(""), - controller::ScriptingInterface* controllerScriptingInterface = nullptr, bool wantSignals = true); ~ScriptEngine(); @@ -184,7 +183,6 @@ private: QObject* setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot); void stopTimer(QTimer* timer); - controller::ScriptingInterface* _controllerScriptingInterface; QString _fileNameString; Quat _quatLibrary; Vec3 _vec3Library; diff --git a/libraries/shared/src/DependencyManager.h b/libraries/shared/src/DependencyManager.h index 01b755fdd0..db41e72e1e 100644 --- a/libraries/shared/src/DependencyManager.h +++ b/libraries/shared/src/DependencyManager.h @@ -51,7 +51,10 @@ public: template static QSharedPointer set(Args&&... args); - + + template + static QSharedPointer set(Args&&... args); + template static void destroy(); @@ -89,13 +92,26 @@ QSharedPointer DependencyManager::get() { template QSharedPointer DependencyManager::set(Args&&... args) { static size_t hashCode = _manager.getHashCode(); - + QSharedPointer& instance = _manager.safeGet(hashCode); instance.clear(); // Clear instance before creation of new one to avoid edge cases QSharedPointer newInstance(new T(args...), &T::customDeleter); QSharedPointer storedInstance = qSharedPointerCast(newInstance); instance.swap(storedInstance); - + + return newInstance; +} + +template +QSharedPointer DependencyManager::set(Args&&... args) { + static size_t hashCode = _manager.getHashCode(); + + QSharedPointer& instance = _manager.safeGet(hashCode); + instance.clear(); // Clear instance before creation of new one to avoid edge cases + QSharedPointer newInstance(new I(args...), &I::customDeleter); + QSharedPointer storedInstance = qSharedPointerCast(newInstance); + instance.swap(storedInstance); + return newInstance; } diff --git a/tests/controllers/qml/content.qml b/tests/controllers/qml/content.qml deleted file mode 100644 index 5d81ead2fd..0000000000 --- a/tests/controllers/qml/content.qml +++ /dev/null @@ -1,157 +0,0 @@ -import QtQuick 2.1 -import QtQuick.Controls 1.0 -import QtQuick.Layouts 1.0 -import QtQuick.Dialogs 1.0 - -import "./xbox" -import "./controls" - -Column { - id: root - property var actions: Controllers.Actions - property var standard: Controllers.Standard - property var hydra: null - property var testMapping: null - property var xbox: null - - - Component.onCompleted: { - var xboxRegex = /^X360Controller/; - var hydraRegex = /^Hydra/; - for (var prop in Controllers.Hardware) { - if(xboxRegex.test(prop)) { - root.xbox = Controllers.Hardware[prop] - print("found xbox") - continue - } - if (hydraRegex.test(prop)) { - root.hydra = Controllers.Hardware[prop] - print("found hydra") - continue - } - } - } - - spacing: 12 - - Timer { - interval: 50; running: true; repeat: true - onTriggered: { - Controllers.update(); - } - } - - Row { - spacing: 8 - Button { - text: "Default Mapping" - onClicked: { - var mapping = Controllers.newMapping("Default"); - mapping.from(xbox.A).to(standard.A); - mapping.from(xbox.B).to(standard.B); - mapping.from(xbox.X).to(standard.X); - mapping.from(xbox.Y).to(standard.Y); - mapping.from(xbox.Up).to(standard.DU); - mapping.from(xbox.Down).to(standard.DD); - mapping.from(xbox.Left).to(standard.DL); - mapping.from(xbox.Right).to(standard.Right); - mapping.from(xbox.LB).to(standard.LB); - mapping.from(xbox.RB).to(standard.RB); - mapping.from(xbox.LS).to(standard.LS); - mapping.from(xbox.RS).to(standard.RS); - mapping.from(xbox.Start).to(standard.Start); - mapping.from(xbox.Back).to(standard.Back); - mapping.from(xbox.LY).to(standard.LY); - mapping.from(xbox.LX).to(standard.LX); - mapping.from(xbox.RY).to(standard.RY); - mapping.from(xbox.RX).to(standard.RX); - mapping.from(xbox.LT).to(standard.LT); - mapping.from(xbox.RT).to(standard.RT); - Controllers.enableMapping("Default"); - enabled = false; - text = "Built" - } - } - - Button { - text: "Build Mapping" - onClicked: { - var mapping = Controllers.newMapping(); - // Inverting a value - mapping.from(xbox.RY).invert().to(standard.RY); - // Assigning a value from a function - mapping.from(function() { return Math.sin(Date.now() / 250); }).to(standard.RX); - // Constrainting a value to -1, 0, or 1, with a deadzone - mapping.from(xbox.LY).deadZone(0.5).constrainToInteger().to(standard.LY); - mapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw); - mapping.from(actions.Yaw).clamp(0, 1).invert().to(actions.YAW_RIGHT); - mapping.from(actions.Yaw).clamp(-1, 0).to(actions.YAW_LEFT); - // mapping.modifier(keyboard.Ctrl).scale(2.0) -// mapping.from(keyboard.A).to(actions.TranslateLeft) -// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft) -// mapping.from(keyboard.A, keyboard.Shift, keyboard.Ctrl).scale(2.0).to(actions.TurnLeft) -// // First loopbacks -// // Then non-loopbacks by constraint level (number of inputs) -// mapping.from(xbox.RX).deadZone(0.2).to(xbox.RX) -// mapping.from(standard.RB, standard.LB, keyboard.Shift).to(actions.TurnLeft) -// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft) -// mapping.from(keyboard.W).when(keyboard.Shift).to(actions.Forward) - testMapping = mapping; - enabled = false - text = "Built" - } - } - - Button { - text: "Enable Mapping" - onClicked: root.testMapping.enable() - } - - Button { - text: "Disable Mapping" - onClicked: root.testMapping.disable() - } - } - - Row { - Xbox { device: root.standard; label: "Standard"; width: 360 } - } - - Row { - spacing: 8 - Xbox { device: root.xbox; label: "XBox"; width: 360 } - } - - Row { - spacing: 8 - Hydra { device: root.hydra; width: 360 } - } - - Row { - spacing: 8 - ScrollingGraph { - controlId: Controllers.Actions.Yaw - label: "Yaw" - min: -3.0 - max: 3.0 - size: 128 - } - - ScrollingGraph { - controlId: Controllers.Actions.YAW_LEFT - label: "Yaw Left" - min: -3.0 - max: 3.0 - size: 128 - } - - ScrollingGraph { - controlId: Controllers.Actions.YAW_RIGHT - label: "Yaw Right" - min: -3.0 - max: 3.0 - size: 128 - } - } -} - diff --git a/tests/controllers/qml/main.qml b/tests/controllers/qml/main.qml index 5ed68cc1fb..66060399a6 100644 --- a/tests/controllers/qml/main.qml +++ b/tests/controllers/qml/main.qml @@ -7,8 +7,16 @@ ApplicationWindow { id: window visible: true + Timer { + interval: 50; running: true; repeat: true + onTriggered: { + Controller.update(); + } + } + + Loader { id: pageLoader - source: "content.qml" + source: ResourcePath + "TestControllers.qml" } } diff --git a/tests/controllers/src/main.cpp b/tests/controllers/src/main.cpp index 0c5ef09867..ccd670640c 100644 --- a/tests/controllers/src/main.cpp +++ b/tests/controllers/src/main.cpp @@ -43,17 +43,37 @@ #include #include -const QString& getQmlDir() { +const QString& getResourcesDir() { static QString dir; if (dir.isEmpty()) { QDir path(__FILE__); path.cdUp(); - dir = path.cleanPath(path.absoluteFilePath("../qml/")) + "/"; + dir = path.cleanPath(path.absoluteFilePath("../../../interface/resources/")) + "/"; + qDebug() << "Resources Path: " << dir; + } + return dir; +} + +const QString& getQmlDir() { + static QString dir; + if (dir.isEmpty()) { + dir = getResourcesDir() + "qml/"; qDebug() << "Qml Path: " << dir; } return dir; } +const QString& getTestQmlDir() { + static QString dir; + if (dir.isEmpty()) { + QDir path(__FILE__); + path.cdUp(); + dir = path.cleanPath(path.absoluteFilePath("../")) + "/qml/"; + qDebug() << "Qml Test Path: " << dir; + } + return dir; +} + using namespace controller; @@ -88,6 +108,7 @@ public: int main(int argc, char** argv) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; + auto rootContext = engine.rootContext(); new PluginContainerProxy(); // Simulate our application idle loop @@ -119,11 +140,16 @@ int main(int argc, char** argv) { } inputPlugin->pluginUpdate(0, false); } - auto rootContext = engine.rootContext(); rootContext->setContextProperty("Controllers", new MyControllerScriptingInterface()); } - - engine.load(getQmlDir() + "main.qml"); + qDebug() << getQmlDir(); + rootContext->setContextProperty("ResourcePath", getQmlDir()); + engine.setBaseUrl(QUrl::fromLocalFile(getQmlDir())); + engine.addImportPath(getQmlDir()); + engine.load(getTestQmlDir() + "main.qml"); + for (auto pathItem : engine.importPathList()) { + qDebug() << pathItem; + } app.exec(); return 0; }