History

Merging old and new controller interfaces

Brad Davis committed 11 years ago

Commit 0063f9a1 parent 619fce043 files · +1088 −1103Browse files

Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 43 files). Show all

Unified · Split

interface/src/scripting/ControllerScriptingInterface.cpp+52−92
@@ -9,21 +9,19 @@ · 8 unmodified lines
9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html9// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10//10//
11 11
12#include "ControllerScriptingInterface.h"
13
12#include <avatar/AvatarManager.h>14#include <avatar/AvatarManager.h>
13#include <avatar/MyAvatar.h>15#include <avatar/MyAvatar.h>
14#include <HandData.h>16#include <HandData.h>
15#include <HFBackEvent.h>17#include <HFBackEvent.h>
16 18
17#include <controllers/NewControllerScriptingInterface.h>
18
19#include "Application.h"19#include "Application.h"
20#include "devices/MotionTracker.h"20#include "devices/MotionTracker.h"
21#include "ControllerScriptingInterface.h"
22 21
23// TODO: this needs to be removed, as well as any related controller-specific information22// TODO: this needs to be removed, as well as any related controller-specific information
24#include <input-plugins/SixenseManager.h>23#include <input-plugins/SixenseManager.h>
25 24
26
27ControllerScriptingInterface::ControllerScriptingInterface() :25ControllerScriptingInterface::ControllerScriptingInterface() :
28 _mouseCaptured(false),26 _mouseCaptured(false),
29 _touchCaptured(false),27 _touchCaptured(false),
@@ -34,7 +32,6 @@ ControllerScriptingInterface::ControllerScriptingInterface() : · 4 unmodified lines
34}32}
35 33
36ControllerScriptingInterface::~ControllerScriptingInterface() {34ControllerScriptingInterface::~ControllerScriptingInterface() {
37 delete _newControllerScriptingInterface;
38}35}
39 36
40 37
@@ -126,13 +123,6 @@ void ControllerScriptingInterface::registerControllerTypes(ScriptEngine* engine) · 85 unmodified lines
126 qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue);123 qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue);
127 qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue);124 qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue);
128 qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue);125 qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue);
129
130 wireUpControllers(engine);
131
132 // hack in the new controller scripting interface...
133 _newControllerScriptingInterface = new controller::NewControllerScriptingInterface();
134 engine->registerGlobalObject("NewControllers", _newControllerScriptingInterface);
135
136}126}
137 127
138void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {128void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {
@@ -192,6 +182,7 @@ const PalmData* ControllerScriptingInterface::getActivePalm(int palmIndex) const · 53 unmodified lines
192 return NULL;182 return NULL;
193}183}
194 184
185/*
195bool ControllerScriptingInterface::isPrimaryButtonPressed() const {186bool ControllerScriptingInterface::isPrimaryButtonPressed() const {
196 const PalmData* primaryPalm = getPrimaryPalm();187 const PalmData* primaryPalm = getPrimaryPalm();
197 if (primaryPalm) {188 if (primaryPalm) {
@@ -345,6 +336,7 @@ glm::vec3 ControllerScriptingInterface::getSpatialControlNormal(int controlIndex · 147 unmodified lines
345 }336 }
346 return glm::vec3(0); // bad index337 return glm::vec3(0); // bad index
347}338}
339*/
348 340
349bool ControllerScriptingInterface::isKeyCaptured(QKeyEvent* event) const {341bool ControllerScriptingInterface::isKeyCaptured(QKeyEvent* event) const {
350 return isKeyCaptured(KeyEvent(*event));342 return isKeyCaptured(KeyEvent(*event));
@@ -395,96 +387,49 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { · 44 unmodified lines
395 return qApp->getUiSize();387 return qApp->getUiSize();
396}388}
397 389
398QString ControllerScriptingInterface::sanatizeName(const QString& name) {390controller::InputController::Pointer ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
399 QString cleanName { name };
400 cleanName.remove(QRegularExpression{"[\\(\\)\\.\\s]"});
401 return cleanName;
402}
403
404void ControllerScriptingInterface::wireUpControllers(ScriptEngine* engine) {
405
406 // Controller.Standard.*
407 auto standardDevice = DependencyManager::get<UserInputMapper>()->getStandardDevice();
408 if (standardDevice) {
409 auto deviceName = sanatizeName(standardDevice->getName());
410 auto deviceInputs = standardDevice->getAvailabeInputs();
411 for (const auto& inputMapping : deviceInputs) {
412 auto input = inputMapping.first;
413 auto inputName = sanatizeName(inputMapping.second);
414 QString deviceInputName{ "Controller." + deviceName + "." + inputName };
415 engine->registerValue(deviceInputName, input.getID());
416 }
417 }
418
419 // Controller.Hardware.*
420 auto devices = DependencyManager::get<UserInputMapper>()->getDevices();
421 for(const auto& deviceMapping : devices) {
422 auto device = deviceMapping.second.get();
423 auto deviceName = sanatizeName(device->getName());
424 auto deviceInputs = device->getAvailabeInputs();
425 for (const auto& inputMapping : deviceInputs) {
426 auto input = inputMapping.first;
427 auto inputName = sanatizeName(inputMapping.second);
428 QString deviceInputName { "Controller.Hardware." + deviceName + "." + inputName };
429 engine->registerValue(deviceInputName, input.getID());
430 }
431 }
432
433 // Controller.Actions.*
434 auto actionNames = DependencyManager::get<UserInputMapper>()->getActionNames();
435 int actionNumber = 0;
436 for (const auto& actionName : actionNames) {
437 QString safeActionName { "Controller.Actions." + sanatizeName(actionName) };
438 engine->registerValue(safeActionName, actionNumber);
439 actionNumber++;
440 }
441}
442
443AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
444 // This is where we retreive the Device Tracker category and then the sub tracker within it391 // This is where we retreive the Device Tracker category and then the sub tracker within it
445 //TODO C++11 auto icIt = _inputControllers.find(0);392 auto icIt = _inputControllers.find(0);
446 InputControllerMap::iterator icIt = _inputControllers.find(0);
447
448 if (icIt != _inputControllers.end()) {393 if (icIt != _inputControllers.end()) {
449 return (*icIt).second;394 return (*icIt).second;
450 } else {395 }
451 396
452 // Look for device397
453 DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString());398 // Look for device
454 if (deviceID < 0) {399 DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString());
455 deviceID = 0;400 if (deviceID < 0) {
456 }401 deviceID = 0;
457 // TODO in this current implementation, we just pick the device assuming there is one (normally the Leapmotion)402 }
458 // in the near future we need to change that to a real mapping between the devices and the deviceName403 // TODO in this current implementation, we just pick the device assuming there is one (normally the Leapmotion)
459 // ALso we need to expand the spec so we can fall back on the "default" controller per categories404 // in the near future we need to change that to a real mapping between the devices and the deviceName
460 405 // ALso we need to expand the spec so we can fall back on the "default" controller per categories
461 if (deviceID >= 0) {406
462 // TODO here again the assumption it's the LeapMotion and so it's a MOtionTracker, this would need to be changed to support different types of devices407 if (deviceID >= 0) {
463 MotionTracker* motionTracker = dynamic_cast< MotionTracker* > (DeviceTracker::getDevice(deviceID));408 // TODO here again the assumption it's the LeapMotion and so it's a MOtionTracker, this would need to be changed to support different types of devices
464 if (motionTracker) {409 MotionTracker* motionTracker = dynamic_cast< MotionTracker* > (DeviceTracker::getDevice(deviceID));
465 MotionTracker::Index trackerID = motionTracker->findJointIndex(tracker.toStdString());410 if (motionTracker) {
466 if (trackerID >= 0) {411 MotionTracker::Index trackerID = motionTracker->findJointIndex(tracker.toStdString());
467 AbstractInputController* inputController = new InputController(deviceID, trackerID, this);412 if (trackerID >= 0) {
468 413 controller::InputController::Pointer inputController = std::make_shared<InputController>(deviceID, trackerID, this);
469 _inputControllers.insert(InputControllerMap::value_type(inputController->getKey(), inputController));414 controller::InputController::Key key = inputController->getKey();
470 415 _inputControllers.insert(InputControllerMap::value_type(inputController->getKey(), inputController));
471 return inputController;416 return inputController;
472 }
473 }417 }
474 }418 }
475
476 return 0;
477 }419 }
420
421 return controller::InputController::Pointer();
478}422}
479 423
480void ControllerScriptingInterface::releaseInputController(AbstractInputController* input) {424void ControllerScriptingInterface::releaseInputController(controller::InputController::Pointer input) {
481 _inputControllers.erase(input->getKey());425 _inputControllers.erase(input->getKey());
482}426}
483 427
484void ControllerScriptingInterface::updateInputControllers() {428void ControllerScriptingInterface::update() {
485 //TODO C++11 for (auto it = _inputControllers.begin(); it != _inputControllers.end(); it++) {429 controller::ScriptingInterface::update();
486 for (InputControllerMap::iterator it = _inputControllers.begin(); it != _inputControllers.end(); it++) {430
487 (*it).second->update();431 for (auto entry : _inputControllers) {
432 entry.second->update();
488 }433 }
489}434}
490 435
@@ -545,7 +490,6 @@ QVector<QString> ControllerScriptingInterface::getActionNames() const { · 54 unmodified lines
545}490}
546 491
547InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) :492InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) :
548 AbstractInputController(),
549 _deviceTrackerId(deviceTrackerId),493 _deviceTrackerId(deviceTrackerId),
550 _subTrackerId(subTrackerId),494 _subTrackerId(subTrackerId),
551 _isActive(false)495 _isActive(false)
@@ -568,7 +512,7 @@ void InputController::update() { · 16 unmodified lines
568 joint->getLocFrame().getRotation(_eventCache.locRotation);512 joint->getLocFrame().getRotation(_eventCache.locRotation);
569 513
570 _isActive = true;514 _isActive = true;
571 emit spatialEvent(_eventCache);515 //emit spatialEvent(_eventCache);
572 }516 }
573 }517 }
574 }518 }
@@ -580,3 +524,19 @@ const unsigned int INPUTCONTROLLER_KEY_DEVICE_MASK = 16; · 5 unmodified lines
580InputController::Key InputController::getKey() const {524InputController::Key InputController::getKey() const {
581 return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId);525 return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId);
582}526}
527
528
529void ControllerScriptingInterface::emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); }
530void ControllerScriptingInterface::emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }
531
532void ControllerScriptingInterface::emitMouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { emit mouseMoveEvent(MouseEvent(*event, deviceID)); }
533void ControllerScriptingInterface::emitMousePressEvent(QMouseEvent* event, unsigned int deviceID) { emit mousePressEvent(MouseEvent(*event, deviceID)); }
534void ControllerScriptingInterface::emitMouseDoublePressEvent(QMouseEvent* event, unsigned int deviceID) { emit mouseDoublePressEvent(MouseEvent(*event, deviceID)); }
535void ControllerScriptingInterface::emitMouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { emit mouseReleaseEvent(MouseEvent(*event, deviceID)); }
536
537void ControllerScriptingInterface::emitTouchBeginEvent(const TouchEvent& event) { emit touchBeginEvent(event); }
538void ControllerScriptingInterface::emitTouchEndEvent(const TouchEvent& event) { emit touchEndEvent(event); }
539void ControllerScriptingInterface::emitTouchUpdateEvent(const TouchEvent& event) { emit touchUpdateEvent(event); }
540
541void ControllerScriptingInterface::emitWheelEvent(QWheelEvent* event) { emit wheelEvent(*event); }
542