mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 03:17:06 +02:00
first cut at wiring up devices and inputs to JS
This commit is contained in:
parent
a5f0b75e25
commit
37f530f97f
5 changed files with 38 additions and 6 deletions
|
@ -91,6 +91,9 @@ public:
|
||||||
/// Get the name assigned to the Device when registered after creation, or "Unknown" if it hasn't been registered which should not happen.
|
/// Get the name assigned to the Device when registered after creation, or "Unknown" if it hasn't been registered which should not happen.
|
||||||
const Name& getName() const { return _name; }
|
const Name& getName() const { return _name; }
|
||||||
|
|
||||||
|
typedef std::map< Name, ID > Map;
|
||||||
|
static const Map& getDevices() { return Singleton::get()->_devicesMap; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DeviceTracker();
|
DeviceTracker();
|
||||||
virtual ~DeviceTracker();
|
virtual ~DeviceTracker();
|
||||||
|
@ -103,7 +106,6 @@ private:
|
||||||
void assignIDAndName( const ID id, const Name& name ) { _ID = id; _name = name; }
|
void assignIDAndName( const ID id, const Name& name ) { _ID = id; _name = name; }
|
||||||
|
|
||||||
typedef std::vector< DeviceTracker* > Vector;
|
typedef std::vector< DeviceTracker* > Vector;
|
||||||
typedef std::map< Name, ID > Map;
|
|
||||||
struct SingletonData {
|
struct SingletonData {
|
||||||
Map _devicesMap;
|
Map _devicesMap;
|
||||||
Vector _devicesVector;
|
Vector _devicesVector;
|
||||||
|
|
|
@ -111,7 +111,7 @@ void inputPairFromScriptValue(const QScriptValue& object, UserInputMapper::Input
|
||||||
inputPair.second = QString(object.property("inputName").toVariant().toString());
|
inputPair.second = QString(object.property("inputName").toVariant().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControllerScriptingInterface::registerControllerTypes(QScriptEngine* engine) {
|
void ControllerScriptingInterface::registerControllerTypes(ScriptEngine* engine) {
|
||||||
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::Action> >(engine);
|
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::Action> >(engine);
|
||||||
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputChannel> >(engine);
|
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputChannel> >(engine);
|
||||||
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputPair> >(engine);
|
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputPair> >(engine);
|
||||||
|
@ -119,6 +119,8 @@ void ControllerScriptingInterface::registerControllerTypes(QScriptEngine* engine
|
||||||
qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue);
|
qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue);
|
qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue);
|
qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue);
|
||||||
|
|
||||||
|
wireUpControllers(engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {
|
void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {
|
||||||
|
@ -381,6 +383,26 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const {
|
||||||
return qApp->getUiSize();
|
return qApp->getUiSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ControllerScriptingInterface::wireUpControllers(ScriptEngine* engine) {
|
||||||
|
|
||||||
|
qDebug() << "------------------- wire up controllers --------------------------";
|
||||||
|
///_registeredDevices
|
||||||
|
|
||||||
|
auto devices = DependencyManager::get<UserInputMapper>()->getDevices();
|
||||||
|
|
||||||
|
for(const auto& deviceMapping : devices) {
|
||||||
|
auto device = deviceMapping.second.get();
|
||||||
|
qDebug() << device->getName();
|
||||||
|
auto deviceInputs = device->getAvailabeInputs();
|
||||||
|
for (const auto& inputMapping : deviceInputs) {
|
||||||
|
auto input = inputMapping.first;
|
||||||
|
auto inputName = inputMapping.second;
|
||||||
|
qDebug() << device->getName() << "." << inputName << "["<< input.getID() <<"]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug() << "------------------- DONE wire up controllers --------------------------";
|
||||||
|
}
|
||||||
|
|
||||||
AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
|
AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
|
||||||
// This is where we retreive the Device Tracker category and then the sub tracker within it
|
// This is where we retreive the Device Tracker category and then the sub tracker within it
|
||||||
//TODO C++11 auto icIt = _inputControllers.find(0);
|
//TODO C++11 auto icIt = _inputControllers.find(0);
|
||||||
|
|
|
@ -56,7 +56,7 @@ class ControllerScriptingInterface : public AbstractControllerScriptingInterface
|
||||||
public:
|
public:
|
||||||
ControllerScriptingInterface();
|
ControllerScriptingInterface();
|
||||||
|
|
||||||
virtual void registerControllerTypes(QScriptEngine* engine);
|
virtual void registerControllerTypes(ScriptEngine* engine);
|
||||||
|
|
||||||
void emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); }
|
void emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); }
|
||||||
void emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }
|
void emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }
|
||||||
|
@ -164,6 +164,9 @@ private:
|
||||||
|
|
||||||
typedef std::map< AbstractInputController::Key, AbstractInputController* > InputControllerMap;
|
typedef std::map< AbstractInputController::Key, AbstractInputController* > InputControllerMap;
|
||||||
InputControllerMap _inputControllers;
|
InputControllerMap _inputControllers;
|
||||||
|
|
||||||
|
void wireUpControllers(ScriptEngine* engine);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const int NUMBER_OF_SPATIALCONTROLS_PER_PALM = 2; // the hand and the tip
|
const int NUMBER_OF_SPATIALCONTROLS_PER_PALM = 2; // the hand and the tip
|
||||||
|
|
|
@ -109,6 +109,7 @@ public:
|
||||||
class DeviceProxy {
|
class DeviceProxy {
|
||||||
public:
|
public:
|
||||||
DeviceProxy(QString name) { _name = name; }
|
DeviceProxy(QString name) { _name = name; }
|
||||||
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
ButtonGetter getButton = [] (const Input& input, int timestamp) -> bool { return false; };
|
ButtonGetter getButton = [] (const Input& input, int timestamp) -> bool { return false; };
|
||||||
|
@ -234,12 +235,14 @@ public:
|
||||||
|
|
||||||
UserInputMapper();
|
UserInputMapper();
|
||||||
|
|
||||||
|
typedef std::map<int, DeviceProxy::Pointer> DevicesMap;
|
||||||
|
DevicesMap getDevices() { return _registeredDevices; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void actionEvent(int action, float state);
|
void actionEvent(int action, float state);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::map<int, DeviceProxy::Pointer> DevicesMap;
|
|
||||||
DevicesMap _registeredDevices;
|
DevicesMap _registeredDevices;
|
||||||
uint16 _nextFreeDeviceID = 1;
|
uint16 _nextFreeDeviceID = 1;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "TouchEvent.h"
|
#include "TouchEvent.h"
|
||||||
#include "WheelEvent.h"
|
#include "WheelEvent.h"
|
||||||
|
|
||||||
|
class ScriptEngine;
|
||||||
|
|
||||||
class AbstractInputController : public QObject {
|
class AbstractInputController : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ class AbstractControllerScriptingInterface : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void registerControllerTypes(QScriptEngine* engine) = 0;
|
virtual void registerControllerTypes(ScriptEngine* engine) = 0;
|
||||||
|
|
||||||
virtual bool isPrimaryButtonPressed() const = 0;
|
virtual bool isPrimaryButtonPressed() const = 0;
|
||||||
virtual glm::vec2 getPrimaryJoystickPosition() const = 0;
|
virtual glm::vec2 getPrimaryJoystickPosition() const = 0;
|
||||||
|
|
Loading…
Reference in a new issue