mirror of
https://github.com/overte-org/overte.git
synced 2025-04-09 07:12:45 +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.
|
||||
const Name& getName() const { return _name; }
|
||||
|
||||
typedef std::map< Name, ID > Map;
|
||||
static const Map& getDevices() { return Singleton::get()->_devicesMap; }
|
||||
|
||||
protected:
|
||||
DeviceTracker();
|
||||
virtual ~DeviceTracker();
|
||||
|
@ -103,7 +106,6 @@ private:
|
|||
void assignIDAndName( const ID id, const Name& name ) { _ID = id; _name = name; }
|
||||
|
||||
typedef std::vector< DeviceTracker* > Vector;
|
||||
typedef std::map< Name, ID > Map;
|
||||
struct SingletonData {
|
||||
Map _devicesMap;
|
||||
Vector _devicesVector;
|
||||
|
|
|
@ -111,7 +111,7 @@ void inputPairFromScriptValue(const QScriptValue& object, UserInputMapper::Input
|
|||
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::InputChannel> >(engine);
|
||||
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputPair> >(engine);
|
||||
|
@ -119,6 +119,8 @@ void ControllerScriptingInterface::registerControllerTypes(QScriptEngine* engine
|
|||
qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue);
|
||||
|
||||
wireUpControllers(engine);
|
||||
}
|
||||
|
||||
void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {
|
||||
|
@ -381,6 +383,26 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const {
|
|||
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) {
|
||||
// This is where we retreive the Device Tracker category and then the sub tracker within it
|
||||
//TODO C++11 auto icIt = _inputControllers.find(0);
|
||||
|
|
|
@ -56,7 +56,7 @@ class ControllerScriptingInterface : public AbstractControllerScriptingInterface
|
|||
public:
|
||||
ControllerScriptingInterface();
|
||||
|
||||
virtual void registerControllerTypes(QScriptEngine* engine);
|
||||
virtual void registerControllerTypes(ScriptEngine* engine);
|
||||
|
||||
void emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); }
|
||||
void emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); }
|
||||
|
@ -164,6 +164,9 @@ private:
|
|||
|
||||
typedef std::map< AbstractInputController::Key, AbstractInputController* > InputControllerMap;
|
||||
InputControllerMap _inputControllers;
|
||||
|
||||
void wireUpControllers(ScriptEngine* engine);
|
||||
|
||||
};
|
||||
|
||||
const int NUMBER_OF_SPATIALCONTROLS_PER_PALM = 2; // the hand and the tip
|
||||
|
|
|
@ -109,7 +109,8 @@ public:
|
|||
class DeviceProxy {
|
||||
public:
|
||||
DeviceProxy(QString name) { _name = name; }
|
||||
|
||||
const QString& getName() const { return _name; }
|
||||
|
||||
QString _name;
|
||||
ButtonGetter getButton = [] (const Input& input, int timestamp) -> bool { return false; };
|
||||
AxisGetter getAxis = [] (const Input& input, int timestamp) -> float { return 0.0f; };
|
||||
|
@ -234,12 +235,14 @@ public:
|
|||
|
||||
UserInputMapper();
|
||||
|
||||
typedef std::map<int, DeviceProxy::Pointer> DevicesMap;
|
||||
DevicesMap getDevices() { return _registeredDevices; }
|
||||
|
||||
signals:
|
||||
void actionEvent(int action, float state);
|
||||
|
||||
|
||||
protected:
|
||||
typedef std::map<int, DeviceProxy::Pointer> DevicesMap;
|
||||
DevicesMap _registeredDevices;
|
||||
uint16 _nextFreeDeviceID = 1;
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "TouchEvent.h"
|
||||
#include "WheelEvent.h"
|
||||
|
||||
class ScriptEngine;
|
||||
|
||||
class AbstractInputController : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -52,7 +54,7 @@ class AbstractControllerScriptingInterface : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
virtual void registerControllerTypes(QScriptEngine* engine) = 0;
|
||||
virtual void registerControllerTypes(ScriptEngine* engine) = 0;
|
||||
|
||||
virtual bool isPrimaryButtonPressed() const = 0;
|
||||
virtual glm::vec2 getPrimaryJoystickPosition() const = 0;
|
||||
|
|
Loading…
Reference in a new issue