mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 01:00:44 +02:00
Fixing logging errors on initial load of controller routes
This commit is contained in:
parent
50a081db00
commit
85019b2b5e
6 changed files with 74 additions and 50 deletions
|
@ -2,9 +2,6 @@
|
||||||
"name": "Standard to Action",
|
"name": "Standard to Action",
|
||||||
"when": "Application.NavigationFocused",
|
"when": "Application.NavigationFocused",
|
||||||
"channels": [
|
"channels": [
|
||||||
{ "disabled_from": { "makeAxis" : [ "Standard.DD", "Standard.DU" ] }, "to": "Actions.UiNavVertical" },
|
|
||||||
{ "disabled_from": { "makeAxis" : [ "Standard.DL", "Standard.DR" ] }, "to": "Actions.UiNavLateral" },
|
|
||||||
{ "disabled_from": { "makeAxis" : [ "Standard.LB", "Standard.RB" ] }, "to": "Actions.UiNavGroup" },
|
|
||||||
{ "from": "Standard.DU", "to": "Actions.UiNavVertical" },
|
{ "from": "Standard.DU", "to": "Actions.UiNavVertical" },
|
||||||
{ "from": "Standard.DD", "to": "Actions.UiNavVertical", "filters": "invert" },
|
{ "from": "Standard.DD", "to": "Actions.UiNavVertical", "filters": "invert" },
|
||||||
{ "from": "Standard.DL", "to": "Actions.UiNavLateral", "filters": "invert" },
|
{ "from": "Standard.DL", "to": "Actions.UiNavLateral", "filters": "invert" },
|
||||||
|
|
|
@ -380,6 +380,11 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const QString STATE_IN_HMD = "InHMD";
|
||||||
|
static const QString STATE_SNAP_TURN = "SnapTurn";
|
||||||
|
static const QString STATE_GROUNDED = "Grounded";
|
||||||
|
static const QString STATE_NAV_FOCUSED = "NavigationFocused";
|
||||||
|
|
||||||
bool setupEssentials(int& argc, char** argv) {
|
bool setupEssentials(int& argc, char** argv) {
|
||||||
unsigned int listenPort = 0; // bind to an ephemeral port by default
|
unsigned int listenPort = 0; // bind to an ephemeral port by default
|
||||||
const char** constArgv = const_cast<const char**>(argv);
|
const char** constArgv = const_cast<const char**>(argv);
|
||||||
|
@ -449,6 +454,7 @@ bool setupEssentials(int& argc, char** argv) {
|
||||||
DependencyManager::set<InterfaceActionFactory>();
|
DependencyManager::set<InterfaceActionFactory>();
|
||||||
DependencyManager::set<AudioInjectorManager>();
|
DependencyManager::set<AudioInjectorManager>();
|
||||||
DependencyManager::set<MessagesClient>();
|
DependencyManager::set<MessagesClient>();
|
||||||
|
controller::StateController::setStateVariables({ { STATE_IN_HMD, STATE_SNAP_TURN, STATE_GROUNDED, STATE_NAV_FOCUSED } });
|
||||||
DependencyManager::set<UserInputMapper>();
|
DependencyManager::set<UserInputMapper>();
|
||||||
DependencyManager::set<controller::ScriptingInterface, ControllerScriptingInterface>();
|
DependencyManager::set<controller::ScriptingInterface, ControllerScriptingInterface>();
|
||||||
DependencyManager::set<InterfaceParentFinder>();
|
DependencyManager::set<InterfaceParentFinder>();
|
||||||
|
@ -898,6 +904,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
} else if (action == controller::toInt(controller::Action::CONTEXT_MENU)) {
|
} else if (action == controller::toInt(controller::Action::CONTEXT_MENU)) {
|
||||||
auto reticlePosition = getApplicationCompositor().getReticlePosition();
|
auto reticlePosition = getApplicationCompositor().getReticlePosition();
|
||||||
offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QPoint(reticlePosition.x, reticlePosition.y)));
|
offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QPoint(reticlePosition.x, reticlePosition.y)));
|
||||||
|
} else if (action == controller::toInt(controller::Action::UI_NAV_SELECT)) {
|
||||||
|
if (!offscreenUi->navigationFocused()) {
|
||||||
|
auto reticlePosition = getApplicationCompositor().getReticlePosition();
|
||||||
|
offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QPoint(reticlePosition.x, reticlePosition.y)));
|
||||||
|
}
|
||||||
} else if (action == controller::toInt(controller::Action::RETICLE_X)) {
|
} else if (action == controller::toInt(controller::Action::RETICLE_X)) {
|
||||||
auto oldPos = getApplicationCompositor().getReticlePosition();
|
auto oldPos = getApplicationCompositor().getReticlePosition();
|
||||||
getApplicationCompositor().setReticlePosition({ oldPos.x + state, oldPos.y });
|
getApplicationCompositor().setReticlePosition({ oldPos.x + state, oldPos.y });
|
||||||
|
@ -910,28 +921,23 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// A new controllerInput device used to reflect current values from the application state
|
_applicationStateDevice = userInputMapper->getStateDevice();
|
||||||
_applicationStateDevice = std::make_shared<controller::StateController>();
|
|
||||||
|
|
||||||
_applicationStateDevice->addInputVariant(QString("InHMD"), controller::StateController::ReadLambda([]() -> float {
|
_applicationStateDevice->setInputVariant(STATE_IN_HMD, []() -> float {
|
||||||
return (float)qApp->isHMDMode();
|
return qApp->isHMDMode() ? 1 : 0;
|
||||||
}));
|
});
|
||||||
_applicationStateDevice->addInputVariant(QString("SnapTurn"), controller::StateController::ReadLambda([]() -> float {
|
_applicationStateDevice->setInputVariant(STATE_SNAP_TURN, []() -> float {
|
||||||
return (float)qApp->getMyAvatar()->getSnapTurn();
|
return qApp->getMyAvatar()->getSnapTurn() ? 1 : 0;
|
||||||
}));
|
});
|
||||||
_applicationStateDevice->addInputVariant(QString("Grounded"), controller::StateController::ReadLambda([]() -> float {
|
_applicationStateDevice->setInputVariant(STATE_GROUNDED, []() -> float {
|
||||||
return (float)qApp->getMyAvatar()->getCharacterController()->onGround();
|
return qApp->getMyAvatar()->getCharacterController()->onGround() ? 1 : 0;
|
||||||
}));
|
});
|
||||||
_applicationStateDevice->addInputVariant(QString("NavigationFocused"), controller::StateController::ReadLambda([]() -> float {
|
_applicationStateDevice->setInputVariant(STATE_NAV_FOCUSED, []() -> float {
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
return DependencyManager::get<OffscreenUi>()->navigationFocused() ? 1 : 0;
|
||||||
return offscreenUi->navigationFocused() ? 1.0 : 0.0;
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
userInputMapper->registerDevice(_applicationStateDevice);
|
|
||||||
|
|
||||||
// Setup the keyboardMouseDevice and the user input mapper with the default bindings
|
// Setup the keyboardMouseDevice and the user input mapper with the default bindings
|
||||||
userInputMapper->registerDevice(_keyboardMouseDevice->getInputDevice());
|
userInputMapper->registerDevice(_keyboardMouseDevice->getInputDevice());
|
||||||
userInputMapper->loadDefaultMapping(userInputMapper->getStandardDeviceID());
|
|
||||||
|
|
||||||
// force the model the look at the correct directory (weird order of operations issue)
|
// force the model the look at the correct directory (weird order of operations issue)
|
||||||
scriptEngines->setScriptsLocation(scriptEngines->getScriptsLocation());
|
scriptEngines->setScriptsLocation(scriptEngines->getScriptsLocation());
|
||||||
|
|
|
@ -19,32 +19,37 @@
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
|
static QStringList stateVariables;
|
||||||
|
|
||||||
|
void StateController::setStateVariables(const QStringList& newStateVariables) {
|
||||||
|
stateVariables = newStateVariables;
|
||||||
|
}
|
||||||
|
|
||||||
StateController::StateController() : InputDevice("Application") {
|
StateController::StateController() : InputDevice("Application") {
|
||||||
|
_deviceID = UserInputMapper::STANDARD_DEVICE;
|
||||||
|
for (const auto& variable : stateVariables) {
|
||||||
|
_namedReadLambdas[variable] = [] { return 0; };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StateController::~StateController() {
|
void StateController::setInputVariant(const QString& name, ReadLambda lambda) {
|
||||||
}
|
// All state variables must be predeclared;
|
||||||
|
Q_ASSERT(_namedReadLambdas.contains(name));
|
||||||
void StateController::update(float deltaTime, const InputCalibrationData& inputCalibrationData, bool jointsCaptured) {}
|
_namedReadLambdas[name] = lambda;
|
||||||
|
|
||||||
void StateController::focusOutEvent() {}
|
|
||||||
|
|
||||||
void StateController::addInputVariant(QString name, ReadLambda lambda) {
|
|
||||||
_namedReadLambdas.push_back(NamedReadLambda(name, lambda));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Input::NamedVector StateController::getAvailableInputs() const {
|
Input::NamedVector StateController::getAvailableInputs() const {
|
||||||
Input::NamedVector availableInputs;
|
Input::NamedVector availableInputs;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto& pair : _namedReadLambdas) {
|
for (const auto& name : stateVariables) {
|
||||||
availableInputs.push_back(Input::NamedPair(Input(_deviceID, i, ChannelType::BUTTON), pair.first));
|
availableInputs.push_back(Input::NamedPair(Input(_deviceID, i, ChannelType::BUTTON), name));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return availableInputs;
|
return availableInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
EndpointPointer StateController::createEndpoint(const Input& input) const {
|
EndpointPointer StateController::createEndpoint(const Input& input) const {
|
||||||
return std::make_shared<LambdaEndpoint>(_namedReadLambdas[input.getChannel()].second);
|
return std::make_shared<LambdaEndpoint>(_namedReadLambdas[stateVariables[input.getChannel()]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,26 +24,28 @@ class StateController : public QObject, public InputDevice {
|
||||||
Q_PROPERTY(QString name READ getName)
|
Q_PROPERTY(QString name READ getName)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
using Pointer = std::shared_ptr<StateController>;
|
||||||
|
using ReadLambda = std::function<float()>;
|
||||||
|
using NamedReadLambda = QPair<QString, ReadLambda>;
|
||||||
|
|
||||||
|
static void setStateVariables(const QStringList& stateVariables);
|
||||||
|
|
||||||
|
StateController();
|
||||||
|
|
||||||
const QString& getName() const { return _name; }
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
// Device functions
|
// Device functions
|
||||||
virtual Input::NamedVector getAvailableInputs() const override;
|
virtual Input::NamedVector getAvailableInputs() const override;
|
||||||
virtual void update(float deltaTime, const InputCalibrationData& inputCalibrationData, bool jointsCaptured) override;
|
|
||||||
virtual void focusOutEvent() override;
|
|
||||||
|
|
||||||
StateController();
|
void update(float deltaTime, const InputCalibrationData& inputCalibrationData, bool jointsCaptured) override {}
|
||||||
virtual ~StateController();
|
void focusOutEvent() override {}
|
||||||
|
|
||||||
using ReadLambda = std::function<float()>;
|
void setInputVariant(const QString& name, ReadLambda lambda);
|
||||||
using NamedReadLambda = QPair<QString, ReadLambda>;
|
|
||||||
|
|
||||||
void addInputVariant(QString name, ReadLambda lambda);
|
|
||||||
|
|
||||||
virtual EndpointPointer createEndpoint(const Input& input) const override;
|
|
||||||
|
|
||||||
|
EndpointPointer createEndpoint(const Input& input) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVector<NamedReadLambda> _namedReadLambdas;
|
QHash<QString, ReadLambda> _namedReadLambdas;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,15 @@
|
||||||
|
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
const uint16_t UserInputMapper::ACTIONS_DEVICE = Input::INVALID_DEVICE - 0xFF;
|
|
||||||
const uint16_t UserInputMapper::STANDARD_DEVICE = 0;
|
const uint16_t UserInputMapper::STANDARD_DEVICE = 0;
|
||||||
|
const uint16_t UserInputMapper::ACTIONS_DEVICE = Input::INVALID_DEVICE - 0x00FF;
|
||||||
|
const uint16_t UserInputMapper::STATE_DEVICE = Input::INVALID_DEVICE - 0x0100;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default contruct allocate the poutput size with the current hardcoded action channels
|
// Default contruct allocate the poutput size with the current hardcoded action channels
|
||||||
controller::UserInputMapper::UserInputMapper() {
|
controller::UserInputMapper::UserInputMapper() {
|
||||||
registerDevice(std::make_shared<ActionsDevice>());
|
registerDevice(std::make_shared<ActionsDevice>());
|
||||||
|
registerDevice(_stateDevice = std::make_shared<StateController>());
|
||||||
registerDevice(std::make_shared<StandardController>());
|
registerDevice(std::make_shared<StandardController>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +237,10 @@ void fixBisectedAxis(float& full, float& negative, float& positive) {
|
||||||
|
|
||||||
void UserInputMapper::update(float deltaTime) {
|
void UserInputMapper::update(float deltaTime) {
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
|
|
||||||
|
static uint64_t updateCount = 0;
|
||||||
|
++updateCount;
|
||||||
|
|
||||||
// Reset the axis state for next loop
|
// Reset the axis state for next loop
|
||||||
for (auto& channel : _actionStates) {
|
for (auto& channel : _actionStates) {
|
||||||
channel = 0.0f;
|
channel = 0.0f;
|
||||||
|
@ -694,7 +700,7 @@ Pose UserInputMapper::getPose(const Input& input) const {
|
||||||
return getPose(endpoint);
|
return getPose(endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mapping::Pointer UserInputMapper::loadMapping(const QString& jsonFile) {
|
Mapping::Pointer UserInputMapper::loadMapping(const QString& jsonFile, bool enable) {
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
if (jsonFile.isEmpty()) {
|
if (jsonFile.isEmpty()) {
|
||||||
return Mapping::Pointer();
|
return Mapping::Pointer();
|
||||||
|
@ -707,7 +713,11 @@ Mapping::Pointer UserInputMapper::loadMapping(const QString& jsonFile) {
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
return parseMapping(json);
|
auto result = parseMapping(json);
|
||||||
|
if (enable) {
|
||||||
|
enableMapping(result->name);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
MappingPointer UserInputMapper::loadMappings(const QStringList& jsonFiles) {
|
MappingPointer UserInputMapper::loadMappings(const QStringList& jsonFiles) {
|
||||||
|
@ -1033,7 +1043,7 @@ Mapping::Pointer UserInputMapper::parseMapping(const QJsonValue& json) {
|
||||||
Route::Pointer route = parseRoute(channelIt);
|
Route::Pointer route = parseRoute(channelIt);
|
||||||
|
|
||||||
if (!route) {
|
if (!route) {
|
||||||
qWarning() << "Couldn't parse route:" << mapping->name << channelIt;
|
qWarning() << "Couldn't parse route:" << mapping->name << QString(QJsonDocument(channelIt.toObject()).toJson());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "DeviceProxy.h"
|
#include "DeviceProxy.h"
|
||||||
#include "StandardControls.h"
|
#include "StandardControls.h"
|
||||||
#include "Actions.h"
|
#include "Actions.h"
|
||||||
|
#include "StateController.h"
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
|
@ -55,8 +56,9 @@ namespace controller {
|
||||||
using uint16 = uint16_t;
|
using uint16 = uint16_t;
|
||||||
using uint32 = uint32_t;
|
using uint32 = uint32_t;
|
||||||
|
|
||||||
static const uint16_t ACTIONS_DEVICE;
|
|
||||||
static const uint16_t STANDARD_DEVICE;
|
static const uint16_t STANDARD_DEVICE;
|
||||||
|
static const uint16_t ACTIONS_DEVICE;
|
||||||
|
static const uint16_t STATE_DEVICE;
|
||||||
|
|
||||||
UserInputMapper();
|
UserInputMapper();
|
||||||
virtual ~UserInputMapper();
|
virtual ~UserInputMapper();
|
||||||
|
@ -100,10 +102,11 @@ namespace controller {
|
||||||
const DevicesMap& getDevices() { return _registeredDevices; }
|
const DevicesMap& getDevices() { return _registeredDevices; }
|
||||||
uint16 getStandardDeviceID() const { return STANDARD_DEVICE; }
|
uint16 getStandardDeviceID() const { return STANDARD_DEVICE; }
|
||||||
InputDevice::Pointer getStandardDevice() { return _registeredDevices[getStandardDeviceID()]; }
|
InputDevice::Pointer getStandardDevice() { return _registeredDevices[getStandardDeviceID()]; }
|
||||||
|
StateController::Pointer getStateDevice() { return _stateDevice; }
|
||||||
|
|
||||||
MappingPointer newMapping(const QString& mappingName);
|
MappingPointer newMapping(const QString& mappingName);
|
||||||
MappingPointer parseMapping(const QString& json);
|
MappingPointer parseMapping(const QString& json);
|
||||||
MappingPointer loadMapping(const QString& jsonFile);
|
MappingPointer loadMapping(const QString& jsonFile, bool enable = false);
|
||||||
MappingPointer loadMappings(const QStringList& jsonFiles);
|
MappingPointer loadMappings(const QStringList& jsonFiles);
|
||||||
|
|
||||||
void loadDefaultMapping(uint16 deviceID);
|
void loadDefaultMapping(uint16 deviceID);
|
||||||
|
@ -120,6 +123,7 @@ namespace controller {
|
||||||
// GetFreeDeviceID should be called before registering a device to use an ID not used by a different device.
|
// GetFreeDeviceID should be called before registering a device to use an ID not used by a different device.
|
||||||
uint16 getFreeDeviceID() { return _nextFreeDeviceID++; }
|
uint16 getFreeDeviceID() { return _nextFreeDeviceID++; }
|
||||||
DevicesMap _registeredDevices;
|
DevicesMap _registeredDevices;
|
||||||
|
StateController::Pointer _stateDevice;
|
||||||
uint16 _nextFreeDeviceID = STANDARD_DEVICE + 1;
|
uint16 _nextFreeDeviceID = STANDARD_DEVICE + 1;
|
||||||
|
|
||||||
std::vector<float> _actionStates = std::vector<float>(toInt(Action::NUM_ACTIONS), 0.0f);
|
std::vector<float> _actionStates = std::vector<float>(toInt(Action::NUM_ACTIONS), 0.0f);
|
||||||
|
|
Loading…
Reference in a new issue