Testing function destination and fixing bug in rule ordering for multi-soure

This commit is contained in:
Brad Davis 2015-10-22 10:00:11 -07:00
parent 5d4cbfdacb
commit 6cf0bdcffe
2 changed files with 30 additions and 5 deletions

View file

@ -1,11 +1,13 @@
ControllerTest = function() {
var standard = Controller.Standard;
var actions = Controller.Actions;
var xbox = Controller.Hardware.GamePad;
this.mappingEnabled = false;
this.mapping = Controller.newMapping();
this.mapping.from(standard.RX).to(actions.StepYaw);
this.mapping.from(standard.RY).invert().to(actions.Pitch);
var testMakeAxis = false;
if (testMakeAxis) {
this.mapping.makeAxis(standard.LB, standard.RB).pulse(0.25).scale(40.0).to(actions.StepYaw);
@ -17,12 +19,22 @@ ControllerTest = function() {
this.mapping.from(standard.RB).pulse(0.10).scale(15.0).to(actions.StepYaw);
}
var testFunctionSource = true;
var testFunctionSource = false;
if (testFunctionSource) {
this.mapping.from(function(){
return Math.sin(Date.now() / 250);
}).to(actions.Yaw);
}
var testFunctionDest = true;
if (testFunctionDest) {
this.mapping.from(standard.DU).pulse(1.0).to(function(value){
if (value != 0.0) {
print(value);
}
});
}
this.mapping.enable();
this.mappingEnabled = true;

View file

@ -195,7 +195,20 @@ class AnyEndpoint : public Endpoint {
friend class UserInputMapper;
public:
using Pointer = std::shared_ptr<AnyEndpoint>;
AnyEndpoint() : Endpoint(Input::INVALID_INPUT) {}
AnyEndpoint(Endpoint::List children) : Endpoint(Input::INVALID_INPUT), _children(children) {
bool standard = true;
// Ensure if we're building a composite of standard devices the composite itself
// is treated as a standard device for rule processing order
for (auto endpoint : children) {
if (endpoint->getInput().device != UserInputMapper::STANDARD_DEVICE) {
standard = false;
break;
}
}
if (standard) {
this->_input = INVALID_STANDARD_INPUT;
}
}
virtual float value() override {
float result = 0;
@ -1020,15 +1033,15 @@ Endpoint::Pointer UserInputMapper::parseDestination(const QJsonValue& value) {
Endpoint::Pointer UserInputMapper::parseSource(const QJsonValue& value) {
if (value.isArray()) {
AnyEndpoint::Pointer result = std::make_shared<AnyEndpoint>();
Endpoint::List children;
for (auto arrayItem : value.toArray()) {
Endpoint::Pointer destination = parseEndpoint(arrayItem);
if (!destination) {
return Endpoint::Pointer();
}
result->_children.push_back(destination);
children.push_back(destination);
}
return result;
return std::make_shared<AnyEndpoint>(children);
}
return parseEndpoint(value);