mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 21:33:00 +02:00
Merge pull request #10821 from ctrlaltdavid/21418
Don't execute body of controllers' plugin update methods if not enabled
This commit is contained in:
commit
9d1fba3a3b
10 changed files with 109 additions and 53 deletions
|
@ -17,7 +17,7 @@ PreferencesDialog {
|
|||
id: root
|
||||
objectName: "GeneralPreferencesDialog"
|
||||
title: "General Settings"
|
||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect", "Leap Motion"]
|
||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Game Controller", "Sixense Controllers", "Perception Neuron", "Kinect", "Leap Motion"]
|
||||
property var settings: Settings {
|
||||
category: root.objectName
|
||||
property alias x: root.x
|
||||
|
|
|
@ -32,6 +32,6 @@ StackView {
|
|||
TabletPreferencesDialog {
|
||||
id: root
|
||||
objectName: "TabletGeneralPreferences"
|
||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect", "Vive Pucks Configuration", "Leap Motion"]
|
||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Game Controller", "Sixense Controllers", "Perception Neuron", "Kinect", "Leap Motion"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -305,17 +305,6 @@ void setupPreferences() {
|
|||
preferences->addPreference(preference);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
auto getter = []()->float { return controller::InputDevice::getReticleMoveSpeed(); };
|
||||
auto setter = [](float value) { controller::InputDevice::setReticleMoveSpeed(value); };
|
||||
auto preference = new SpinnerPreference("Sixense Controllers", "Reticle movement speed", getter, setter);
|
||||
preference->setMin(0);
|
||||
preference->setMax(100);
|
||||
preference->setStep(1);
|
||||
preferences->addPreference(preference);
|
||||
}
|
||||
|
||||
{
|
||||
static const QString RENDER("Graphics");
|
||||
auto renderConfig = qApp->getRenderEngine()->getConfiguration();
|
||||
|
|
|
@ -15,20 +15,6 @@
|
|||
|
||||
namespace controller {
|
||||
|
||||
const float DEFAULT_HAND_RETICLE_MOVE_SPEED = 37.5f;
|
||||
float InputDevice::_reticleMoveSpeed = DEFAULT_HAND_RETICLE_MOVE_SPEED;
|
||||
|
||||
//Constants for getCursorPixelRangeMultiplier()
|
||||
const float MIN_PIXEL_RANGE_MULT = 0.4f;
|
||||
const float MAX_PIXEL_RANGE_MULT = 2.0f;
|
||||
const float RANGE_MULT = (MAX_PIXEL_RANGE_MULT - MIN_PIXEL_RANGE_MULT) * 0.01f;
|
||||
|
||||
//Returns a multiplier to be applied to the cursor range for the controllers
|
||||
float InputDevice::getCursorPixelRangeMult() {
|
||||
//scales (0,100) to (MINIMUM_PIXEL_RANGE_MULT, MAXIMUM_PIXEL_RANGE_MULT)
|
||||
return InputDevice::_reticleMoveSpeed * RANGE_MULT + MIN_PIXEL_RANGE_MULT;
|
||||
}
|
||||
|
||||
float InputDevice::getButton(int channel) const {
|
||||
if (!_buttonPressedMap.empty()) {
|
||||
if (_buttonPressedMap.find(channel) != _buttonPressedMap.end()) {
|
||||
|
|
|
@ -73,10 +73,6 @@ public:
|
|||
int getDeviceID() { return _deviceID; }
|
||||
void setDeviceID(int deviceID) { _deviceID = deviceID; }
|
||||
|
||||
static float getCursorPixelRangeMult();
|
||||
static float getReticleMoveSpeed() { return _reticleMoveSpeed; }
|
||||
static void setReticleMoveSpeed(float reticleMoveSpeed) { _reticleMoveSpeed = reticleMoveSpeed; }
|
||||
|
||||
Input makeInput(StandardButtonChannel button) const;
|
||||
Input makeInput(StandardAxisChannel axis) const;
|
||||
Input makeInput(StandardPoseChannel pose) const;
|
||||
|
@ -99,9 +95,6 @@ protected:
|
|||
ButtonPressedMap _buttonPressedMap;
|
||||
AxisStateMap _axisStateMap;
|
||||
PoseStateMap _poseStateMap;
|
||||
|
||||
private:
|
||||
static float _reticleMoveSpeed;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -367,6 +367,12 @@ void NeuronPlugin::init() {
|
|||
|
||||
auto preferences = DependencyManager::get<Preferences>();
|
||||
static const QString NEURON_PLUGIN { "Perception Neuron" };
|
||||
{
|
||||
auto getter = [this]()->bool { return _enabled; };
|
||||
auto setter = [this](bool value) { _enabled = value; saveSettings(); };
|
||||
auto preference = new CheckPreference(NEURON_PLUGIN, "Enabled", getter, setter);
|
||||
preferences->addPreference(preference);
|
||||
}
|
||||
{
|
||||
auto getter = [this]()->QString { return _serverAddress; };
|
||||
auto setter = [this](const QString& value) { _serverAddress = value; saveSettings(); };
|
||||
|
@ -387,12 +393,6 @@ void NeuronPlugin::init() {
|
|||
preference->setStep(1);
|
||||
preferences->addPreference(preference);
|
||||
}
|
||||
{
|
||||
auto getter = [this]()->bool { return _enabled; };
|
||||
auto setter = [this](bool value) { _enabled = value; saveSettings(); };
|
||||
auto preference = new CheckPreference(NEURON_PLUGIN, "Enabled", getter, setter);
|
||||
preferences->addPreference(preference);
|
||||
}
|
||||
}
|
||||
|
||||
bool NeuronPlugin::isSupported() const {
|
||||
|
@ -455,6 +455,10 @@ void NeuronPlugin::deactivate() {
|
|||
}
|
||||
|
||||
void NeuronPlugin::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||
if (!_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<NeuronJoint> joints;
|
||||
{
|
||||
// lock and copy
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
|
||||
#include <qapplication.h>
|
||||
|
||||
#include <PerfStat.h>
|
||||
#include <controllers/UserInputMapper.h>
|
||||
#include <PerfStat.h>
|
||||
#include <Preferences.h>
|
||||
#include <SettingHandle.h>
|
||||
|
||||
#include "SDL2Manager.h"
|
||||
|
||||
|
@ -38,10 +40,13 @@ static_assert(
|
|||
(int)controller::RY == (int)SDL_CONTROLLER_AXIS_RIGHTY &&
|
||||
(int)controller::LT == (int)SDL_CONTROLLER_AXIS_TRIGGERLEFT &&
|
||||
(int)controller::RT == (int)SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
|
||||
"SDL2 equvalence: Enums and values from StandardControls.h are assumed to match enums from SDL_gamecontroller.h");
|
||||
"SDL2 equivalence: Enums and values from StandardControls.h are assumed to match enums from SDL_gamecontroller.h");
|
||||
|
||||
|
||||
const char* SDL2Manager::NAME = "SDL2";
|
||||
const char* SDL2Manager::SDL2_ID_STRING = "SDL2";
|
||||
|
||||
const bool DEFAULT_ENABLED = false;
|
||||
|
||||
SDL_JoystickID SDL2Manager::getInstanceId(SDL_GameController* controller) {
|
||||
SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controller);
|
||||
|
@ -49,6 +54,20 @@ SDL_JoystickID SDL2Manager::getInstanceId(SDL_GameController* controller) {
|
|||
}
|
||||
|
||||
void SDL2Manager::init() {
|
||||
loadSettings();
|
||||
|
||||
auto preferences = DependencyManager::get<Preferences>();
|
||||
static const QString SDL2_PLUGIN { "Game Controller" };
|
||||
{
|
||||
auto getter = [this]()->bool { return _isEnabled; };
|
||||
auto setter = [this](bool value) {
|
||||
_isEnabled = value;
|
||||
saveSettings();
|
||||
};
|
||||
auto preference = new CheckPreference(SDL2_PLUGIN, "Enabled", getter, setter);
|
||||
preferences->addPreference(preference);
|
||||
}
|
||||
|
||||
bool initSuccess = (SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) == 0);
|
||||
|
||||
if (initSuccess) {
|
||||
|
@ -110,6 +129,27 @@ void SDL2Manager::deactivate() {
|
|||
InputPlugin::deactivate();
|
||||
}
|
||||
|
||||
const char* SETTINGS_ENABLED_KEY = "enabled";
|
||||
|
||||
void SDL2Manager::saveSettings() const {
|
||||
Settings settings;
|
||||
QString idString = getID();
|
||||
settings.beginGroup(idString);
|
||||
{
|
||||
settings.setValue(QString(SETTINGS_ENABLED_KEY), _isEnabled);
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void SDL2Manager::loadSettings() {
|
||||
Settings settings;
|
||||
QString idString = getID();
|
||||
settings.beginGroup(idString);
|
||||
{
|
||||
_isEnabled = settings.value(SETTINGS_ENABLED_KEY, QVariant(DEFAULT_ENABLED)).toBool();
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
bool SDL2Manager::isSupported() const {
|
||||
return true;
|
||||
|
@ -122,6 +162,10 @@ void SDL2Manager::pluginFocusOutEvent() {
|
|||
}
|
||||
|
||||
void SDL2Manager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||
if (!_isEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isInitialized) {
|
||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||
for (auto joystick : _openJoysticks) {
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
// Plugin functions
|
||||
bool isSupported() const override;
|
||||
const QString getName() const override { return NAME; }
|
||||
const QString getID() const override { return SDL2_ID_STRING; }
|
||||
|
||||
QStringList getSubdeviceNames() override;
|
||||
|
||||
|
@ -39,6 +40,9 @@ public:
|
|||
void pluginFocusOutEvent() override;
|
||||
void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
|
||||
|
||||
virtual void saveSettings() const override;
|
||||
virtual void loadSettings() override;
|
||||
|
||||
signals:
|
||||
void joystickAdded(Joystick* joystick);
|
||||
void joystickRemoved(Joystick* joystick);
|
||||
|
@ -77,8 +81,10 @@ private:
|
|||
int buttonRelease() const { return SDL_RELEASED; }
|
||||
|
||||
QMap<SDL_JoystickID, Joystick::Pointer> _openJoysticks;
|
||||
bool _isInitialized { false } ;
|
||||
bool _isEnabled { false };
|
||||
bool _isInitialized { false };
|
||||
static const char* NAME;
|
||||
static const char* SDL2_ID_STRING;
|
||||
QStringList _subdeviceNames;
|
||||
};
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <PathUtils.h>
|
||||
#include <PerfStat.h>
|
||||
#include <ui-plugins/PluginContainer.h>
|
||||
#include <Preferences.h>
|
||||
#include <SettingHandle.h>
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
@ -46,19 +47,26 @@ static const unsigned int BUTTON_TRIGGER = 1U << 8;
|
|||
|
||||
const glm::vec3 SixenseManager::DEFAULT_AVATAR_POSITION { -0.25f, -0.35f, -0.3f }; // in hydra frame
|
||||
const float SixenseManager::CONTROLLER_THRESHOLD { 0.35f };
|
||||
|
||||
bool SixenseManager::_isEnabled = false;
|
||||
bool SixenseManager::_sixenseLoaded = false;
|
||||
|
||||
#define BAIL_IF_NOT_ENABLED \
|
||||
if (!_isEnabled) { \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define BAIL_IF_NOT_LOADED \
|
||||
if (!_sixenseLoaded) { \
|
||||
return; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char* SixenseManager::NAME { "Sixense" };
|
||||
const char* SixenseManager::HYDRA_ID_STRING { "Razer Hydra" };
|
||||
const char* SixenseManager::SIXENSE_ID_STRING { "Sixense" };
|
||||
|
||||
const char* MENU_PARENT { "Developer" };
|
||||
const bool DEFAULT_ENABLED = false;
|
||||
|
||||
const char* MENU_PARENT{ "Developer" };
|
||||
const char* MENU_NAME { "Sixense" };
|
||||
const char* MENU_PATH { "Developer" ">" "Sixense" };
|
||||
const char* TOGGLE_SMOOTH { "Smooth Sixense Movement" };
|
||||
|
@ -73,6 +81,22 @@ bool SixenseManager::isSupported() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
void SixenseManager::init() {
|
||||
loadSettings();
|
||||
|
||||
auto preferences = DependencyManager::get<Preferences>();
|
||||
static const QString SIXENSE_PLUGIN { "Sixense Controllers" };
|
||||
{
|
||||
auto getter = [this]()->bool { return _isEnabled; };
|
||||
auto setter = [this](bool value) {
|
||||
_isEnabled = value;
|
||||
saveSettings();
|
||||
};
|
||||
auto preference = new CheckPreference(SIXENSE_PLUGIN, "Enabled", getter, setter);
|
||||
preferences->addPreference(preference);
|
||||
}
|
||||
}
|
||||
|
||||
bool SixenseManager::activate() {
|
||||
InputPlugin::activate();
|
||||
|
||||
|
@ -133,6 +157,7 @@ void SixenseManager::setSixenseFilter(bool filter) {
|
|||
}
|
||||
|
||||
void SixenseManager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||
BAIL_IF_NOT_ENABLED
|
||||
BAIL_IF_NOT_LOADED
|
||||
|
||||
#ifdef HAVE_SIXENSE
|
||||
|
@ -553,14 +578,19 @@ QString SixenseManager::InputDevice::getDefaultMappingConfig() const {
|
|||
return MAPPING_JSON;
|
||||
}
|
||||
|
||||
const char* SETTINGS_ENABLED_KEY = "enabled";
|
||||
const char* SETTINGS_AVATAR_POSITION_KEY = "avatarPosition";
|
||||
const char* SETTINGS_AVATAR_ROTATION_KEY = "avatarPosition";
|
||||
|
||||
// virtual
|
||||
void SixenseManager::saveSettings() const {
|
||||
Settings settings;
|
||||
QString idString = getID();
|
||||
settings.beginGroup(idString);
|
||||
{
|
||||
settings.setVec3Value(QString("avatarPosition"), _inputDevice->_avatarPosition);
|
||||
settings.setQuatValue(QString("avatarRotation"), _inputDevice->_avatarRotation);
|
||||
settings.setValue(QString(SETTINGS_ENABLED_KEY), _isEnabled);
|
||||
settings.setVec3Value(QString(SETTINGS_AVATAR_POSITION_KEY), _inputDevice->_avatarPosition);
|
||||
settings.setQuatValue(QString(SETTINGS_AVATAR_ROTATION_KEY), _inputDevice->_avatarRotation);
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
@ -570,8 +600,9 @@ void SixenseManager::loadSettings() {
|
|||
QString idString = getID();
|
||||
settings.beginGroup(idString);
|
||||
{
|
||||
settings.getVec3ValueIfValid(QString("avatarPosition"), _inputDevice->_avatarPosition);
|
||||
settings.getQuatValueIfValid(QString("avatarRotation"), _inputDevice->_avatarRotation);
|
||||
_isEnabled = settings.value(SETTINGS_ENABLED_KEY, QVariant(DEFAULT_ENABLED)).toBool();
|
||||
settings.getVec3ValueIfValid(QString(SETTINGS_AVATAR_POSITION_KEY), _inputDevice->_avatarPosition);
|
||||
settings.getQuatValueIfValid(QString(SETTINGS_AVATAR_ROTATION_KEY), _inputDevice->_avatarRotation);
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
|
|
@ -29,12 +29,14 @@ public:
|
|||
// Plugin functions
|
||||
virtual bool isSupported() const override;
|
||||
virtual const QString getName() const override { return NAME; }
|
||||
virtual const QString getID() const override { return HYDRA_ID_STRING; }
|
||||
virtual const QString getID() const override { return SIXENSE_ID_STRING; }
|
||||
|
||||
// Sixense always seems to initialize even if the hydras are not present. Is there
|
||||
// a way we can properly detect whether the hydras are present?
|
||||
// bool isHandController() const override { return true; }
|
||||
|
||||
virtual void init() override;
|
||||
|
||||
virtual bool activate() override;
|
||||
virtual void deactivate() override;
|
||||
|
||||
|
@ -93,8 +95,9 @@ private:
|
|||
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
|
||||
|
||||
static const char* NAME;
|
||||
static const char* HYDRA_ID_STRING;
|
||||
static const char* SIXENSE_ID_STRING;
|
||||
|
||||
static bool _isEnabled;
|
||||
static bool _sixenseLoaded;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue