mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
And adding the StateCOntroller class
This commit is contained in:
parent
92ca658aae
commit
37f967bc33
2 changed files with 110 additions and 0 deletions
61
libraries/controllers/src/controllers/StateController.cpp
Normal file
61
libraries/controllers/src/controllers/StateController.cpp
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
//
|
||||||
|
// StateController.cpp
|
||||||
|
// controllers/src/controllers
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 2015-10-27.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "StateController.h"
|
||||||
|
|
||||||
|
#include <PathUtils.h>
|
||||||
|
|
||||||
|
#include "DeviceProxy.h"
|
||||||
|
#include "UserInputMapper.h"
|
||||||
|
#include "impl/Endpoint.h"
|
||||||
|
|
||||||
|
namespace controller {
|
||||||
|
|
||||||
|
StateController::StateController() : InputDevice("Application") {
|
||||||
|
}
|
||||||
|
|
||||||
|
StateController::~StateController() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateController::update(float deltaTime, bool jointsCaptured) {}
|
||||||
|
|
||||||
|
void StateController::focusOutEvent() {}
|
||||||
|
|
||||||
|
void StateController::addInputVariant(QString name, ReadLambda& lambda) {
|
||||||
|
namedReadLambdas.push_back(NamedReadLambda(name, lambda));
|
||||||
|
}
|
||||||
|
void StateController::buildDeviceProxy(DeviceProxy::Pointer proxy) {
|
||||||
|
proxy->_name = _name;
|
||||||
|
proxy->getButton = [this] (const Input& input, int timestamp) -> bool { return getButton(input.getChannel()); };
|
||||||
|
proxy->getAxis = [this] (const Input& input, int timestamp) -> float { return getAxis(input.getChannel()); };
|
||||||
|
proxy->getAvailabeInputs = [this] () -> QVector<Input::NamedPair> {
|
||||||
|
|
||||||
|
|
||||||
|
QVector<Input::NamedPair> availableInputs;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (auto pair : namedReadLambdas) {
|
||||||
|
availableInputs.push_back(Input::NamedPair(Input(_deviceID, i, ChannelType::BUTTON), pair.first));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return availableInputs;
|
||||||
|
};
|
||||||
|
proxy->createEndpoint = [this] (const Input& input) -> Endpoint::Pointer {
|
||||||
|
if (input.getChannel() < namedReadLambdas.size()) {
|
||||||
|
return std::make_shared<LambdaEndpoint>(namedReadLambdas[input.getChannel()].second);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Endpoint::Pointer();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
49
libraries/controllers/src/controllers/StateController.h
Normal file
49
libraries/controllers/src/controllers/StateController.h
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
//
|
||||||
|
// StateController.h
|
||||||
|
// controllers/src/controllers
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 2015-10-27.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_StateController_h
|
||||||
|
#define hifi_StateController_h
|
||||||
|
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
#include <QtCore/QVector>
|
||||||
|
|
||||||
|
#include "InputDevice.h"
|
||||||
|
|
||||||
|
namespace controller {
|
||||||
|
|
||||||
|
class StateController : public QObject, public InputDevice {
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ getName)
|
||||||
|
|
||||||
|
public:
|
||||||
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
|
// Device functions
|
||||||
|
virtual void buildDeviceProxy(DeviceProxy::Pointer proxy) override;
|
||||||
|
virtual QString getDefaultMappingConfig() override { return QString(); }
|
||||||
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
|
StateController();
|
||||||
|
virtual ~StateController();
|
||||||
|
|
||||||
|
using ReadLambda = std::function<float()>;
|
||||||
|
using NamedReadLambda = QPair<QString, ReadLambda>;
|
||||||
|
|
||||||
|
void addInputVariant(QString name, ReadLambda& lambda);
|
||||||
|
|
||||||
|
QVector<NamedReadLambda> namedReadLambdas;
|
||||||
|
QVector<Input::NamedPair> availableInputs;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // hifi_StateController_h
|
Loading…
Reference in a new issue