History

almost finished plugin architecture, general plugin improvements. menu actions don't work all the time, joint controllers need to be handled better, and activate/deactive aren't always called correctly

Anthony J. Thibault committed 11 years ago

Commit 060f6c11 parent 108353420 files · +367 −204Browse files

Showing the changes to interface/src/Application.cpp (1 of 20 files). Show all

Unified · Split

interface/src/Application.cpp+125−31
@@ -64,6 +64,7 @@ · 63 unmodified lines
6464 #include <DeferredLightingEffect.h>
6565 #include <DependencyManager.h>
6666 #include <display-plugins/DisplayPlugin.h>
67+
6768 #include <EntityScriptingInterface.h>
6869 #include <ErrorDialog.h>
6970 #include <GlowEffect.h>
@@ -74,6 +75,9 @@ · 4 unmodified lines
7475 #include <HFActionEvent.h>
7576 #include <HFBackEvent.h>
7677 #include <InfoView.h>
78+#include <input-plugins/InputPlugin.h>
79+#include <input-plugins/Joystick.h> // this should probably be removed
80+#include <input-plugins/SixenseManager.h> // this definitely should be removed
7781 #include <LogHandler.h>
7882 #include <MainWindow.h>
7983 #include <MessageDialog.h>
@@ -123,9 +127,6 @@ · 43 unmodified lines
123127 #include "devices/Leapmotion.h"
124128 #include "devices/RealSense.h"
125129 #include "devices/MIDIManager.h"
126−#include <input-plugins/SDL2Manager.h>
127−#include <input-plugins/SixenseManager.h>
128−#include <input-plugins/ViveControllerManager.h>
129130 #include "RenderDeferredTask.h"
130131 #include "scripting/AccountScriptingInterface.h"
131132 #include "scripting/AudioDeviceScriptingInterface.h"
@@ -621,9 +622,19 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 489 unmodified lines
621622 auto userInputMapper = DependencyManager::get<UserInputMapper>();
622623 connect(userInputMapper.data(), &UserInputMapper::actionEvent, &_controllerScriptingInterface, &AbstractControllerScriptingInterface::actionEvent);
623624
625+ auto inputPlugins = getInputPlugins();
626+ foreach(auto inputPlugin, inputPlugins) {
627+ QString name = inputPlugin->getName();
628+ if (name == KeyboardMouseDevice::NAME) {
629+ _keyboardMouseDevice = static_cast<KeyboardMouseDevice*>(inputPlugin.data()); // TODO: this seems super hacky
630+ }
631+ }
632+
633+ //updateInputModes(); // TODO: shouldn't have to call this explicitly
634+
624635 // Setup the keyboardMouseDevice and the user input mapper with the default bindings
625− _keyboardMouseDevice.registerToUserInputMapper(*userInputMapper);
626− _keyboardMouseDevice.assignDefaultInputMapping(*userInputMapper);
636+ _keyboardMouseDevice->registerToUserInputMapper(*userInputMapper);
637+ _keyboardMouseDevice->assignDefaultInputMapping(*userInputMapper);
627638
628639 // check first run...
629640 if (_firstRun.get()) {
@@ -676,11 +687,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 46 unmodified lines
676687 connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled);
677688 #endif
678689
679− if (ViveControllerManager::getInstance().isSupported()) {
680− ViveControllerManager::getInstance().init();
681− ViveControllerManager::getInstance().activate(NULL);
682− }
683−
684690 _oldHandMouseX[0] = -1;
685691 _oldHandMouseY[0] = -1;
686692 _oldHandMouseX[1] = -1;
@@ -771,6 +777,15 @@ Application::~Application() { · 84 unmodified lines
771777
772778 getActiveDisplayPlugin()->deactivate();
773779
780+ auto inputPlugins = getInputPlugins();
781+ foreach(auto inputPlugin, inputPlugins) {
782+ QString name = inputPlugin->getName();
783+ QAction* action = Menu::getInstance()->getActionForOption(name);
784+ if (action->isChecked()) {
785+ inputPlugin->deactivate();
786+ }
787+ }
788+
774789 // remove avatars from physics engine
775790 DependencyManager::get<AvatarManager>()->clearOtherAvatars();
776791 _physicsEngine.deleteObjects(DependencyManager::get<AvatarManager>()->getObjectsToDelete());
@@ -1344,7 +1359,9 @@ void Application::keyPressEvent(QKeyEvent* event) { · 567 unmodified lines
13441359 }
13451360
13461361 if (hasFocus()) {
1347− _keyboardMouseDevice.keyPressEvent(event);
1362+ if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) {
1363+ _keyboardMouseDevice->keyPressEvent(event);
1364+ }
13481365
13491366 bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier);
13501367 bool isMeta = event->modifiers().testFlag(Qt::ControlModifier);
@@ -1614,7 +1631,9 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 263 unmodified lines
16141631 return;
16151632 }
16161633
1617− _keyboardMouseDevice.keyReleaseEvent(event);
1634+ if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) {
1635+ _keyboardMouseDevice->keyReleaseEvent(event);
1636+ }
16181637
16191638 switch (event->key()) {
16201639 case Qt::Key_Space: {
@@ -1641,10 +1660,14 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 20 unmodified lines
16411660 }
16421661
16431662 void Application::focusOutEvent(QFocusEvent* event) {
1644− _keyboardMouseDevice.pluginFocusOutEvent();
1645− SixenseManager::getInstance().pluginFocusOutEvent();
1646− SDL2Manager::getInstance()->pluginFocusOutEvent();
1647− ViveControllerManager::getInstance().pluginFocusOutEvent();
1663+ auto inputPlugins = getInputPlugins();
1664+ foreach(auto inputPlugin, inputPlugins) {
1665+ QString name = inputPlugin->getName();
1666+ QAction* action = Menu::getInstance()->getActionForOption(name);
1667+ if (action->isChecked()) {
1668+ inputPlugin->pluginFocusOutEvent();
1669+ }
1670+ }
16481671
16491672 // synthesize events for keys currently pressed, since we may not get their release events
16501673 foreach (int key, _keysPressed) {
@@ -1687,7 +1710,9 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { · 36 unmodified lines
16871710 return;
16881711 }
16891712
1690− _keyboardMouseDevice.mouseMoveEvent(event, deviceID);
1713+ if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) {
1714+ _keyboardMouseDevice->mouseMoveEvent(event, deviceID);
1715+ }
16911716
16921717 }
16931718
@@ -1708,7 +1733,9 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 14 unmodified lines
17081733
17091734
17101735 if (hasFocus()) {
1711− _keyboardMouseDevice.mousePressEvent(event);
1736+ if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) {
1737+ _keyboardMouseDevice->mousePressEvent(event);
1738+ }
17121739
17131740 if (event->button() == Qt::LeftButton) {
17141741 _mouseDragStarted = getTrueMouse();
@@ -1748,7 +1775,9 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 33 unmodified lines
17481775 }
17491776
17501777 if (hasFocus()) {
1751− _keyboardMouseDevice.mouseReleaseEvent(event);
1778+ if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) {
1779+ _keyboardMouseDevice->mouseReleaseEvent(event);
1780+ }
17521781
17531782 if (event->button() == Qt::LeftButton) {
17541783 _mousePressed = false;
@@ -1775,7 +1804,9 @@ void Application::touchUpdateEvent(QTouchEvent* event) { · 20 unmodified lines
17751804 return;
17761805 }
17771806
1778− _keyboardMouseDevice.touchUpdateEvent(event);
1807+ if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) {
1808+ _keyboardMouseDevice->touchUpdateEvent(event);
1809+ }
17791810
17801811 bool validTouch = false;
17811812 if (hasFocus()) {
@@ -1809,7 +1840,9 @@ void Application::touchBeginEvent(QTouchEvent* event) { · 27 unmodified lines
18091840 return;
18101841 }
18111842
1812− _keyboardMouseDevice.touchBeginEvent(event);
1843+ if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) {
1844+ _keyboardMouseDevice->touchBeginEvent(event);
1845+ }
18131846
18141847 }
18151848
@@ -1824,7 +1857,9 @@ void Application::touchEndEvent(QTouchEvent* event) { · 8 unmodified lines
18241857 return;
18251858 }
18261859
1827− _keyboardMouseDevice.touchEndEvent(event);
1860+ if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) {
1861+ _keyboardMouseDevice->touchEndEvent(event);
1862+ }
18281863
18291864 // put any application specific touch behavior below here..
18301865 _touchDragStartedAvg = _touchAvg;
@@ -1840,8 +1875,10 @@ void Application::wheelEvent(QWheelEvent* event) { · 9 unmodified lines
18401875 if (_controllerScriptingInterface.isWheelCaptured()) {
18411876 return;
18421877 }
1843−
1844− _keyboardMouseDevice.wheelEvent(event);
1878+
1879+ if (Menu::getInstance()->isOptionChecked(KeyboardMouseDevice::NAME)) {
1880+ _keyboardMouseDevice->wheelEvent(event);
1881+ }
18451882 }
18461883
18471884 void Application::dropEvent(QDropEvent *event) {
@@ -1964,6 +2001,14 @@ void Application::idle() { · 116 unmodified lines
19642001 PerformanceTimer perfTimer("updateGL");
19652002 PerformanceWarning warn(showWarnings, "Application::idle()... updateGL()");
19662003 getActiveDisplayPlugin()->idle();
2004+ auto inputPlugins = getInputPlugins();
2005+ foreach(auto inputPlugin, inputPlugins) {
2006+ QString name = inputPlugin->getName();
2007+ QAction* action = Menu::getInstance()->getActionForOption(name);
2008+ if (action->isChecked()) {
2009+ inputPlugin->idle();
2010+ }
2011+ }
19672012 }
19682013 {
19692014 PerformanceTimer perfTimer("rest");
@@ -2625,10 +2670,14 @@ void Application::update(float deltaTime) { · 655 unmodified lines
26252670 userInputMapper->setSensorToWorldMat(_myAvatar->getSensorToWorldMatrix());
26262671 userInputMapper->update(deltaTime);
26272672
2628− _keyboardMouseDevice.pluginUpdate(deltaTime);
2629− SixenseManager::getInstance().pluginUpdate(deltaTime);
2630− SDL2Manager::getInstance()->pluginUpdate(deltaTime);
2631− ViveControllerManager::getInstance().pluginUpdate(deltaTime);
2673+ auto inputPlugins = getInputPlugins();
2674+ foreach(auto inputPlugin, inputPlugins) {
2675+ QString name = inputPlugin->getName();
2676+ QAction* action = Menu::getInstance()->getActionForOption(name);
2677+ if (action->isChecked()) {
2678+ inputPlugin->pluginUpdate(deltaTime); // add flag to prevent multiple devices from modifying joints
2679+ }
2680+ }
26322681
26332682 // Dispatch input events
26342683 _controllerScriptingInterface.updateInputControllers();
@@ -2826,7 +2875,7 @@ void Application::setPalmData(Hand* hand, UserInputMapper::PoseValue pose, int i · 191 unmodified lines
28262875
28272876 palm->setActive(pose.isValid());
28282877
2829− // TODO: velocity filters, tip velocities, et.c
2878+ // TODO: velocity filters, tip velocities, etc.
28302879 // see SixenseManager
28312880
28322881 // transform from sensor space, to world space, to avatar model space.
@@ -2872,8 +2921,7 @@ void Application::emulateMouse(Hand* hand, float click, float shift, int index) · 39 unmodified lines
28722921 float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)M_PI_2));
28732922 auto canvasSize = qApp->getCanvasSize();
28742923 // Get the pixel range over which the xAngle and yAngle are scaled
2875− // TODO: move this from SixenseManager
2876− float cursorRange = canvasSize.x * SixenseManager::getInstance().getCursorPixelRangeMult();
2924+ float cursorRange = canvasSize.x * InputDevice::getCursorPixelRangeMult();
28772925
28782926 pos.setX(canvasSize.x / 2.0f + cursorRange * xAngle);
28792927 pos.setY(canvasSize.y / 2.0f + cursorRange * yAngle);
@@ -5128,6 +5176,51 @@ void Application::updateDisplayMode() { · 2248 unmodified lines
51285176 Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin");
51295177 }
51305178
5179+static QVector<QPair<QString, QString>> _currentInputPluginActions;
5180+
5181+void Application::updateInputModes() {
5182+ auto menu = Menu::getInstance();
5183+ auto inputPlugins = getInputPlugins();
5184+ auto offscreenUi = DependencyManager::get<OffscreenUi>();
5185+
5186+ InputPluginPointer newInputPlugin = InputPluginPointer(nullptr);
5187+ InputPluginPointer removedInputPlugin = InputPluginPointer(nullptr);
5188+ foreach(InputPluginPointer inputPlugin, inputPlugins) {
5189+ QString name = inputPlugin->getName();
5190+ QAction* action = menu->getActionForOption(name);
5191+ if (action->isChecked() && !_activeInputPlugins.contains(inputPlugin)) {
5192+ _activeInputPlugins.append(inputPlugin);
5193+ newInputPlugin = inputPlugin;
5194+ break;
5195+ } else if (!action->isChecked() && _activeInputPlugins.contains(inputPlugin)) {
5196+ _activeInputPlugins.removeOne(inputPlugin);
5197+ removedInputPlugin = inputPlugin;
5198+ break;
5199+ }
5200+ }
5201+
5202+ // A plugin was checked
5203+ if (newInputPlugin) {
5204+ newInputPlugin->activate(this);
5205+ newInputPlugin->installEventFilter(qApp);
5206+ newInputPlugin->installEventFilter(offscreenUi.data());
5207+ } else if (removedInputPlugin) { // A plugin was unchecked
5208+ removedInputPlugin->deactivate();
5209+ removedInputPlugin->removeEventFilter(qApp);
5210+ removedInputPlugin->removeEventFilter(offscreenUi.data());
5211+ }
5212+
5213+ if (newInputPlugin || removedInputPlugin) {
5214+ if (!_currentInputPluginActions.isEmpty()) {
5215+ auto menu = Menu::getInstance();
5216+ foreach(auto itemInfo, _currentInputPluginActions) {
5217+ menu->removeMenuItem(itemInfo.first, itemInfo.second);
5218+ }
5219+ _currentInputPluginActions.clear();
5220+ }
5221+ }
5222+}
5223+
51315224 void Application::addMenuItem(const QString& path, const QString& name, std::function<void()> onClicked, bool checkable, bool checked, const QString& groupName) {
51325225 auto menu = Menu::getInstance();
51335226 MenuWrapper* parentItem = menu->getMenu(path);
@@ -5136,6 +5229,7 @@ void Application::addMenuItem(const QString& path, const QString& name, std::fun · 2 unmodified lines
51365229 onClicked();
51375230 });
51385231 _currentDisplayPluginActions.push_back({ path, name });
5232+ _currentInputPluginActions.push_back({ path, name });
51395233 }
51405234
51415235 GlWindow* Application::getVisibleWindow() {