mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-08 14:42:09 +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": [ {
|
||||
"type": "clamp",
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"max": 1
|
||||
}
|
||||
],
|
||||
"to": "Actions.Forward",
|
||||
"to": "Actions.Forward"
|
||||
}, {
|
||||
"from": "Standard.LY",
|
||||
"filters": [ {
|
||||
"type": "clamp",
|
||||
"min": -1,
|
||||
"max": 0,
|
||||
"max": 0
|
||||
}, {
|
||||
"type": "invert"
|
||||
}
|
||||
],
|
||||
"to": "Actions.Backward",
|
||||
"to": "Actions.Backward"
|
||||
}, {
|
||||
"from": "Standard.LX",
|
||||
"filters": [ {
|
||||
"type": "scale",
|
||||
"scale": 2.0,
|
||||
"scale": 2.0
|
||||
}
|
||||
],
|
||||
"to": "Actions.Yaw",
|
||||
"to": "Actions.Yaw"
|
||||
}, {
|
||||
"from": "Standard.A",
|
||||
"to": "Actions.Action0"
|
||||
|
|
|
@ -112,31 +112,6 @@ namespace controller {
|
|||
|
||||
ScriptingInterface::ScriptingInterface() {
|
||||
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";
|
||||
auto standardDevice = userInputMapper->getStandardDevice();
|
||||
// Expose the IDs to JS
|
||||
|
@ -151,6 +126,7 @@ namespace controller {
|
|||
_endpoints[standardInput] = std::make_shared<VirtualEndpoint>(standardInput);
|
||||
}
|
||||
|
||||
// FIXME allow custom user actions?
|
||||
auto actionNames = userInputMapper->getActionNames();
|
||||
int actionNumber = 0;
|
||||
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
|
||||
_endpoints[actionInput] = std::make_shared<VirtualEndpoint>();
|
||||
}
|
||||
|
||||
updateMaps();
|
||||
}
|
||||
|
||||
QObject* ScriptingInterface::newMapping(const QString& mappingName) {
|
||||
|
@ -260,6 +238,12 @@ namespace controller {
|
|||
|
||||
void ScriptingInterface::update() {
|
||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||
static auto deviceNames = userInputMapper->getDeviceNames();
|
||||
|
||||
if (deviceNames != userInputMapper->getDeviceNames()) {
|
||||
updateMaps();
|
||||
deviceNames = userInputMapper->getDeviceNames();
|
||||
}
|
||||
|
||||
_overrideValues.clear();
|
||||
EndpointSet readEndpoints;
|
||||
|
@ -437,6 +421,41 @@ namespace controller {
|
|||
// FIXME extract the rotation from the standard pose
|
||||
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
|
||||
|
||||
//var mapping = Controller.newMapping();
|
||||
|
|
|
@ -101,6 +101,7 @@ namespace controller {
|
|||
public slots:
|
||||
virtual void update();
|
||||
virtual void registerControllerTypes(QScriptEngine* engine) = 0;
|
||||
virtual void updateMaps();
|
||||
|
||||
private:
|
||||
friend class MappingBuilderProxy;
|
||||
|
|
Loading…
Reference in a new issue