mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Fix broken xbox controllers
This commit is contained in:
parent
d8310cc6b1
commit
4c78c0b330
4 changed files with 32 additions and 5 deletions
|
@ -26,7 +26,7 @@ void StateController::setStateVariables(const QStringList& newStateVariables) {
|
|||
}
|
||||
|
||||
StateController::StateController() : InputDevice("Application") {
|
||||
_deviceID = UserInputMapper::STANDARD_DEVICE;
|
||||
_deviceID = UserInputMapper::STATE_DEVICE;
|
||||
for (const auto& variable : stateVariables) {
|
||||
_namedReadLambdas[variable] = []()->float{ return 0; };
|
||||
}
|
||||
|
@ -49,7 +49,9 @@ Input::NamedVector StateController::getAvailableInputs() const {
|
|||
}
|
||||
|
||||
EndpointPointer StateController::createEndpoint(const Input& input) const {
|
||||
return std::make_shared<LambdaEndpoint>(_namedReadLambdas[stateVariables[input.getChannel()]]);
|
||||
auto name = stateVariables[input.getChannel()];
|
||||
ReadLambda& readLambda = const_cast<QHash<QString, ReadLambda>&>(_namedReadLambdas)[name];
|
||||
return std::make_shared<LambdaRefEndpoint>(readLambda);
|
||||
}
|
||||
|
||||
}
|
|
@ -140,7 +140,6 @@ void UserInputMapper::loadDefaultMapping(uint16 deviceID) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
auto mapping = loadMappings(proxyEntry->second->getDefaultMappingConfigs());
|
||||
if (mapping) {
|
||||
auto prevMapping = _mappingsByDevice[deviceID];
|
||||
|
@ -705,6 +704,12 @@ Mapping::Pointer UserInputMapper::loadMapping(const QString& jsonFile, bool enab
|
|||
if (jsonFile.isEmpty()) {
|
||||
return Mapping::Pointer();
|
||||
}
|
||||
// Each mapping only needs to be loaded once
|
||||
static QSet<QString> loaded;
|
||||
if (loaded.contains(jsonFile)) {
|
||||
return Mapping::Pointer();
|
||||
}
|
||||
loaded.insert(jsonFile);
|
||||
QString json;
|
||||
{
|
||||
QFile file(jsonFile);
|
||||
|
@ -971,7 +976,7 @@ Route::Pointer UserInputMapper::parseRoute(const QJsonValue& value) {
|
|||
result->json = QString(QJsonDocument(obj).toJson());
|
||||
result->source = parseSource(obj[JSON_CHANNEL_FROM]);
|
||||
result->debug = obj[JSON_CHANNEL_DEBUG].toBool();
|
||||
result->debug = obj[JSON_CHANNEL_PEEK].toBool();
|
||||
result->peek = obj[JSON_CHANNEL_PEEK].toBool();
|
||||
if (!result->source) {
|
||||
qWarning() << "Invalid route source " << obj[JSON_CHANNEL_FROM];
|
||||
return Route::Pointer();
|
||||
|
|
|
@ -12,5 +12,8 @@
|
|||
// warning LNK4221: This object file does not define any previously undefined public symbols,
|
||||
// so it will not be used by any link operation that consumes this library
|
||||
//
|
||||
//#include "Endpoint.h"
|
||||
#include "Endpoint.h"
|
||||
|
||||
namespace controller {
|
||||
Endpoint::WriteLambda DEFAULT_WRITE_LAMBDA = [](float) {};
|
||||
}
|
||||
|
|
|
@ -67,6 +67,23 @@ namespace controller {
|
|||
WriteLambda _writeLambda;
|
||||
};
|
||||
|
||||
extern Endpoint::WriteLambda DEFAULT_WRITE_LAMBDA;
|
||||
|
||||
class LambdaRefEndpoint : public Endpoint {
|
||||
public:
|
||||
using Endpoint::apply;
|
||||
LambdaRefEndpoint(const ReadLambda& readLambda, const WriteLambda& writeLambda = DEFAULT_WRITE_LAMBDA)
|
||||
: Endpoint(Input::INVALID_INPUT), _readLambda(readLambda), _writeLambda(writeLambda) {
|
||||
}
|
||||
|
||||
virtual float peek() const override { return _readLambda(); }
|
||||
virtual void apply(float value, const Pointer& source) override { _writeLambda(value); }
|
||||
|
||||
private:
|
||||
const ReadLambda& _readLambda;
|
||||
const WriteLambda& _writeLambda;
|
||||
};
|
||||
|
||||
|
||||
class VirtualEndpoint : public Endpoint {
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue