mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 17:41:12 +02:00
Merge pull request #6092 from jherico/controllers
Controllers Branch - Fix hardware access from JS...
This commit is contained in:
commit
d44beca29f
3 changed files with 51 additions and 31 deletions
|
@ -5,29 +5,29 @@
|
||||||
"filters": [ {
|
"filters": [ {
|
||||||
"type": "clamp",
|
"type": "clamp",
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 1,
|
"max": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"to": "Actions.Forward",
|
"to": "Actions.Forward"
|
||||||
}, {
|
}, {
|
||||||
"from": "Standard.LY",
|
"from": "Standard.LY",
|
||||||
"filters": [ {
|
"filters": [ {
|
||||||
"type": "clamp",
|
"type": "clamp",
|
||||||
"min": -1,
|
"min": -1,
|
||||||
"max": 0,
|
"max": 0
|
||||||
}, {
|
}, {
|
||||||
"type": "invert"
|
"type": "invert"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"to": "Actions.Backward",
|
"to": "Actions.Backward"
|
||||||
}, {
|
}, {
|
||||||
"from": "Standard.LX",
|
"from": "Standard.LX",
|
||||||
"filters": [ {
|
"filters": [ {
|
||||||
"type": "scale",
|
"type": "scale",
|
||||||
"scale": 2.0,
|
"scale": 2.0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"to": "Actions.Yaw",
|
"to": "Actions.Yaw"
|
||||||
}, {
|
}, {
|
||||||
"from": "Standard.A",
|
"from": "Standard.A",
|
||||||
"to": "Actions.Action0"
|
"to": "Actions.Action0"
|
||||||
|
|
|
@ -112,31 +112,6 @@ namespace controller {
|
||||||
|
|
||||||
ScriptingInterface::ScriptingInterface() {
|
ScriptingInterface::ScriptingInterface() {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
auto devices = userInputMapper->getDevices();
|
|
||||||
for (const auto& deviceMapping : devices) {
|
|
||||||
auto device = deviceMapping.second.get();
|
|
||||||
auto deviceName = QString(device->getName()).remove(ScriptingInterface::SANITIZE_NAME_EXPRESSION);
|
|
||||||
qCDebug(controllers) << "Device" << deviceMapping.first << ":" << deviceName;
|
|
||||||
// Expose the IDs to JS
|
|
||||||
_hardware.insert(deviceName, createDeviceMap(device));
|
|
||||||
|
|
||||||
// Create the endpoints
|
|
||||||
for (const auto& inputMapping : device->getAvailabeInputs()) {
|
|
||||||
const auto& input = inputMapping.first;
|
|
||||||
// Ignore aliases
|
|
||||||
if (_endpoints.count(input)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
_endpoints[input] = std::make_shared<LambdaEndpoint>([=] {
|
|
||||||
auto deviceProxy = userInputMapper->getDeviceProxy(input);
|
|
||||||
if (!deviceProxy) {
|
|
||||||
return 0.0f;
|
|
||||||
}
|
|
||||||
return deviceProxy->getValue(input, 0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qCDebug(controllers) << "Setting up standard controller abstraction";
|
qCDebug(controllers) << "Setting up standard controller abstraction";
|
||||||
auto standardDevice = userInputMapper->getStandardDevice();
|
auto standardDevice = userInputMapper->getStandardDevice();
|
||||||
// Expose the IDs to JS
|
// Expose the IDs to JS
|
||||||
|
@ -151,6 +126,7 @@ namespace controller {
|
||||||
_endpoints[standardInput] = std::make_shared<VirtualEndpoint>(standardInput);
|
_endpoints[standardInput] = std::make_shared<VirtualEndpoint>(standardInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME allow custom user actions?
|
||||||
auto actionNames = userInputMapper->getActionNames();
|
auto actionNames = userInputMapper->getActionNames();
|
||||||
int actionNumber = 0;
|
int actionNumber = 0;
|
||||||
qCDebug(controllers) << "Setting up standard actions";
|
qCDebug(controllers) << "Setting up standard actions";
|
||||||
|
@ -165,6 +141,8 @@ namespace controller {
|
||||||
// FIXME action endpoints need to accumulate values, and have them cleared at each frame
|
// FIXME action endpoints need to accumulate values, and have them cleared at each frame
|
||||||
_endpoints[actionInput] = std::make_shared<VirtualEndpoint>();
|
_endpoints[actionInput] = std::make_shared<VirtualEndpoint>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* ScriptingInterface::newMapping(const QString& mappingName) {
|
QObject* ScriptingInterface::newMapping(const QString& mappingName) {
|
||||||
|
@ -260,6 +238,12 @@ namespace controller {
|
||||||
|
|
||||||
void ScriptingInterface::update() {
|
void ScriptingInterface::update() {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
|
static auto deviceNames = userInputMapper->getDeviceNames();
|
||||||
|
|
||||||
|
if (deviceNames != userInputMapper->getDeviceNames()) {
|
||||||
|
updateMaps();
|
||||||
|
deviceNames = userInputMapper->getDeviceNames();
|
||||||
|
}
|
||||||
|
|
||||||
_overrideValues.clear();
|
_overrideValues.clear();
|
||||||
EndpointSet readEndpoints;
|
EndpointSet readEndpoints;
|
||||||
|
@ -437,6 +421,41 @@ namespace controller {
|
||||||
// FIXME extract the rotation from the standard pose
|
// FIXME extract the rotation from the standard pose
|
||||||
return quat();
|
return quat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptingInterface::updateMaps() {
|
||||||
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
|
auto devices = userInputMapper->getDevices();
|
||||||
|
QSet<QString> foundDevices;
|
||||||
|
for (const auto& deviceMapping : devices) {
|
||||||
|
auto device = deviceMapping.second.get();
|
||||||
|
auto deviceName = QString(device->getName()).remove(ScriptingInterface::SANITIZE_NAME_EXPRESSION);
|
||||||
|
qCDebug(controllers) << "Device" << deviceMapping.first << ":" << deviceName;
|
||||||
|
foundDevices.insert(device->getName());
|
||||||
|
if (_hardware.contains(deviceName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expose the IDs to JS
|
||||||
|
_hardware.insert(deviceName, createDeviceMap(device));
|
||||||
|
|
||||||
|
// Create the endpoints
|
||||||
|
for (const auto& inputMapping : device->getAvailabeInputs()) {
|
||||||
|
const auto& input = inputMapping.first;
|
||||||
|
// Ignore aliases
|
||||||
|
if (_endpoints.count(input)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_endpoints[input] = std::make_shared<LambdaEndpoint>([=] {
|
||||||
|
auto deviceProxy = userInputMapper->getDeviceProxy(input);
|
||||||
|
if (!deviceProxy) {
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
return deviceProxy->getValue(input, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace controllers
|
} // namespace controllers
|
||||||
|
|
||||||
//var mapping = Controller.newMapping();
|
//var mapping = Controller.newMapping();
|
||||||
|
|
|
@ -101,6 +101,7 @@ namespace controller {
|
||||||
public slots:
|
public slots:
|
||||||
virtual void update();
|
virtual void update();
|
||||||
virtual void registerControllerTypes(QScriptEngine* engine) = 0;
|
virtual void registerControllerTypes(QScriptEngine* engine) = 0;
|
||||||
|
virtual void updateMaps();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class MappingBuilderProxy;
|
friend class MappingBuilderProxy;
|
||||||
|
|
Loading…
Reference in a new issue