wiring the actions

This commit is contained in:
samcake 2015-10-15 17:53:53 -07:00
parent d44beca29f
commit 43d7fe491e
3 changed files with 27 additions and 2 deletions

View file

@ -14,7 +14,7 @@
myFirstMapping = function() {
return {
"name": "example mapping from Standard to actions",
"name": "example",
"channels": [ {
"from": "Keyboard.A",
"filters": [ {
@ -56,6 +56,8 @@ print('myFirstMappingJSON' + JSON.stringify(myFirstMappingJSON));
var mapping = Controller.parseMapping(JSON.stringify(myFirstMappingJSON));
Controller.enableMapping("example");
Object.keys(Controller.Standard).forEach(function (input) {
print("Controller.Standard." + input + ":" + Controller.Standard[input]);
});

View file

@ -94,6 +94,25 @@ namespace controller {
Endpoint::Pointer _second;
};
class ActionEndpoint : public Endpoint {
public:
ActionEndpoint(const UserInputMapper::Input& id = UserInputMapper::Input(-1))
: Endpoint(id) {
}
virtual float value() override { return _currentValue; }
virtual void apply(float newValue, float oldValue, const Pointer& source) override {
_currentValue = newValue;
if (!(_id == UserInputMapper::Input::INVALID_INPUT)) {
auto userInputMapper = DependencyManager::get<UserInputMapper>();
userInputMapper->setActionState(UserInputMapper::Action(_id.getChannel()), newValue);
}
}
private:
float _currentValue{ 0.0f };
};
QRegularExpression ScriptingInterface::SANITIZE_NAME_EXPRESSION{ "[\\(\\)\\.\\s]" };
@ -139,7 +158,8 @@ namespace controller {
// Create the endpoints
// 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>();
_endpoints[actionInput] = std::make_shared<ActionEndpoint>();
}
updateMaps();
@ -171,6 +191,7 @@ namespace controller {
_mappingsByName[mapping->_name] = mapping;
return mappingBuilder;
} else {
qDebug() << "Mapping json Document is not an object" << endl;
}

View file

@ -214,6 +214,8 @@ public:
QVector<QString> getActionNames() const;
void assignDefaulActionScales();
void setActionState(Action action, float value) { _actionStates[action] = value; }
// Add input channel to the mapper and check that all the used channels are registered.
// Return true if theinput channel is created correctly, false either
bool addInputChannel(Action action, const Input& input, float scale = 1.0f);