Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 43 files). Show all
Unified · Split
| @@ -9,21 +9,19 @@ · 8 unmodified lines | ||
| 9 | 9 | // 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 | 14 | #include <avatar/AvatarManager.h> |
| 13 | 15 | #include <avatar/MyAvatar.h> |
| 14 | 16 | #include <HandData.h> |
| 15 | 17 | #include <HFBackEvent.h> |
| 16 | 18 | |
| 17 | −#include <controllers/NewControllerScriptingInterface.h> | |
| 18 | − | |
| 19 | 19 | #include "Application.h" |
| 20 | 20 | #include "devices/MotionTracker.h" |
| 21 | −#include "ControllerScriptingInterface.h" | |
| 22 | 21 | |
| 23 | 22 | // TODO: this needs to be removed, as well as any related controller-specific information |
| 24 | 23 | #include <input-plugins/SixenseManager.h> |
| 25 | 24 | |
| 26 | − | |
| 27 | 25 | ControllerScriptingInterface::ControllerScriptingInterface() : |
| 28 | 26 | _mouseCaptured(false), |
| 29 | 27 | _touchCaptured(false), |
| @@ -34,7 +32,6 @@ ControllerScriptingInterface::ControllerScriptingInterface() : · 4 unmodified lines | ||
| 34 | 32 | } |
| 35 | 33 | |
| 36 | 34 | ControllerScriptingInterface::~ControllerScriptingInterface() { |
| 37 | − delete _newControllerScriptingInterface; | |
| 38 | 35 | } |
| 39 | 36 | |
| 40 | 37 | |
| @@ -126,13 +123,6 @@ void ControllerScriptingInterface::registerControllerTypes(ScriptEngine* engine) · 85 unmodified lines | ||
| 126 | 123 | qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue); |
| 127 | 124 | qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue); |
| 128 | 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 | |
| 138 | 128 | void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) { |
| @@ -192,6 +182,7 @@ const PalmData* ControllerScriptingInterface::getActivePalm(int palmIndex) const · 53 unmodified lines | ||
| 192 | 182 | return NULL; |
| 193 | 183 | } |
| 194 | 184 | |
| 185 | +/* | |
| 195 | 186 | bool ControllerScriptingInterface::isPrimaryButtonPressed() const { |
| 196 | 187 | const PalmData* primaryPalm = getPrimaryPalm(); |
| 197 | 188 | if (primaryPalm) { |
| @@ -345,6 +336,7 @@ glm::vec3 ControllerScriptingInterface::getSpatialControlNormal(int controlIndex · 147 unmodified lines | ||
| 345 | 336 | } |
| 346 | 337 | return glm::vec3(0); // bad index |
| 347 | 338 | } |
| 339 | +*/ | |
| 348 | 340 | |
| 349 | 341 | bool ControllerScriptingInterface::isKeyCaptured(QKeyEvent* event) const { |
| 350 | 342 | return isKeyCaptured(KeyEvent(*event)); |
| @@ -395,96 +387,49 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { · 44 unmodified lines | ||
| 395 | 387 | return qApp->getUiSize(); |
| 396 | 388 | } |
| 397 | 389 | |
| 398 | −QString ControllerScriptingInterface::sanatizeName(const QString& name) { | |
| 399 | − QString cleanName { name }; | |
| 400 | − cleanName.remove(QRegularExpression{"[\\(\\)\\.\\s]"}); | |
| 401 | − return cleanName; | |
| 402 | −} | |
| 403 | − | |
| 404 | −void 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 | − | |
| 443 | −AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { | |
| 390 | +controller::InputController::Pointer ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { | |
| 444 | 391 | // 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); | |
| 446 | − InputControllerMap::iterator icIt = _inputControllers.find(0); | |
| 447 | − | |
| 392 | + auto icIt = _inputControllers.find(0); | |
| 448 | 393 | if (icIt != _inputControllers.end()) { |
| 449 | 394 | return (*icIt).second; |
| 450 | − } else { | |
| 395 | + } | |
| 451 | 396 | |
| 452 | − // Look for device | |
| 453 | − DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString()); | |
| 454 | − if (deviceID < 0) { | |
| 455 | − deviceID = 0; | |
| 456 | − } | |
| 457 | − // TODO in this current implementation, we just pick the device assuming there is one (normally the Leapmotion) | |
| 458 | − // in the near future we need to change that to a real mapping between the devices and the deviceName | |
| 459 | − // ALso we need to expand the spec so we can fall back on the "default" controller per categories | |
| 460 | − | |
| 461 | − if (deviceID >= 0) { | |
| 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 devices | |
| 463 | − MotionTracker* motionTracker = dynamic_cast< MotionTracker* > (DeviceTracker::getDevice(deviceID)); | |
| 464 | − if (motionTracker) { | |
| 465 | − MotionTracker::Index trackerID = motionTracker->findJointIndex(tracker.toStdString()); | |
| 466 | − if (trackerID >= 0) { | |
| 467 | − AbstractInputController* inputController = new InputController(deviceID, trackerID, this); | |
| 468 | − | |
| 469 | − _inputControllers.insert(InputControllerMap::value_type(inputController->getKey(), inputController)); | |
| 470 | − | |
| 471 | − return inputController; | |
| 472 | − } | |
| 397 | + | |
| 398 | + // Look for device | |
| 399 | + DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString()); | |
| 400 | + if (deviceID < 0) { | |
| 401 | + deviceID = 0; | |
| 402 | + } | |
| 403 | + // TODO in this current implementation, we just pick the device assuming there is one (normally the Leapmotion) | |
| 404 | + // in the near future we need to change that to a real mapping between the devices and the deviceName | |
| 405 | + // ALso we need to expand the spec so we can fall back on the "default" controller per categories | |
| 406 | + | |
| 407 | + if (deviceID >= 0) { | |
| 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 | |
| 409 | + MotionTracker* motionTracker = dynamic_cast< MotionTracker* > (DeviceTracker::getDevice(deviceID)); | |
| 410 | + if (motionTracker) { | |
| 411 | + MotionTracker::Index trackerID = motionTracker->findJointIndex(tracker.toStdString()); | |
| 412 | + if (trackerID >= 0) { | |
| 413 | + controller::InputController::Pointer inputController = std::make_shared<InputController>(deviceID, trackerID, this); | |
| 414 | + controller::InputController::Key key = inputController->getKey(); | |
| 415 | + _inputControllers.insert(InputControllerMap::value_type(inputController->getKey(), inputController)); | |
| 416 | + return inputController; | |
| 473 | 417 | } |
| 474 | 418 | } |
| 475 | − | |
| 476 | − return 0; | |
| 477 | 419 | } |
| 420 | + | |
| 421 | + return controller::InputController::Pointer(); | |
| 478 | 422 | } |
| 479 | 423 | |
| 480 | −void ControllerScriptingInterface::releaseInputController(AbstractInputController* input) { | |
| 424 | +void ControllerScriptingInterface::releaseInputController(controller::InputController::Pointer input) { | |
| 481 | 425 | _inputControllers.erase(input->getKey()); |
| 482 | 426 | } |
| 483 | 427 | |
| 484 | −void ControllerScriptingInterface::updateInputControllers() { | |
| 485 | − //TODO C++11 for (auto it = _inputControllers.begin(); it != _inputControllers.end(); it++) { | |
| 486 | − for (InputControllerMap::iterator it = _inputControllers.begin(); it != _inputControllers.end(); it++) { | |
| 487 | − (*it).second->update(); | |
| 428 | +void ControllerScriptingInterface::update() { | |
| 429 | + controller::ScriptingInterface::update(); | |
| 430 | + | |
| 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 | |
| 547 | 492 | InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : |
| 548 | − AbstractInputController(), | |
| 549 | 493 | _deviceTrackerId(deviceTrackerId), |
| 550 | 494 | _subTrackerId(subTrackerId), |
| 551 | 495 | _isActive(false) |
| @@ -568,7 +512,7 @@ void InputController::update() { · 16 unmodified lines | ||
| 568 | 512 | joint->getLocFrame().getRotation(_eventCache.locRotation); |
| 569 | 513 | |
| 570 | 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 | ||
| 580 | 524 | InputController::Key InputController::getKey() const { |
| 581 | 525 | return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId); |
| 582 | 526 | } |
| 527 | + | |
| 528 | + | |
| 529 | +void ControllerScriptingInterface::emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); } | |
| 530 | +void ControllerScriptingInterface::emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); } | |
| 531 | + | |
| 532 | +void ControllerScriptingInterface::emitMouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { emit mouseMoveEvent(MouseEvent(*event, deviceID)); } | |
| 533 | +void ControllerScriptingInterface::emitMousePressEvent(QMouseEvent* event, unsigned int deviceID) { emit mousePressEvent(MouseEvent(*event, deviceID)); } | |
| 534 | +void ControllerScriptingInterface::emitMouseDoublePressEvent(QMouseEvent* event, unsigned int deviceID) { emit mouseDoublePressEvent(MouseEvent(*event, deviceID)); } | |
| 535 | +void ControllerScriptingInterface::emitMouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { emit mouseReleaseEvent(MouseEvent(*event, deviceID)); } | |
| 536 | + | |
| 537 | +void ControllerScriptingInterface::emitTouchBeginEvent(const TouchEvent& event) { emit touchBeginEvent(event); } | |
| 538 | +void ControllerScriptingInterface::emitTouchEndEvent(const TouchEvent& event) { emit touchEndEvent(event); } | |
| 539 | +void ControllerScriptingInterface::emitTouchUpdateEvent(const TouchEvent& event) { emit touchUpdateEvent(event); } | |
| 540 | + | |
| 541 | +void ControllerScriptingInterface::emitWheelEvent(QWheelEvent* event) { emit wheelEvent(*event); } | |
| 542 | + | |