mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 12:57:38 +02:00
wiring the actions
This commit is contained in:
parent
d44beca29f
commit
43d7fe491e
3 changed files with 27 additions and 2 deletions
|
@ -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]);
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue