mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 00:19:40 +02:00
Add "enabled" setting for SDL2 joystick; bail in update if not enabled
This commit is contained in:
parent
5abd254a58
commit
361bc1ce03
4 changed files with 55 additions and 5 deletions
|
@ -17,7 +17,7 @@ PreferencesDialog {
|
||||||
id: root
|
id: root
|
||||||
objectName: "GeneralPreferencesDialog"
|
objectName: "GeneralPreferencesDialog"
|
||||||
title: "General Settings"
|
title: "General Settings"
|
||||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect"]
|
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "SDL2 Joystick", "Sixense Controllers", "Perception Neuron", "Kinect"]
|
||||||
property var settings: Settings {
|
property var settings: Settings {
|
||||||
category: root.objectName
|
category: root.objectName
|
||||||
property alias x: root.x
|
property alias x: root.x
|
||||||
|
|
|
@ -32,6 +32,6 @@ StackView {
|
||||||
TabletPreferencesDialog {
|
TabletPreferencesDialog {
|
||||||
id: root
|
id: root
|
||||||
objectName: "TabletGeneralPreferences"
|
objectName: "TabletGeneralPreferences"
|
||||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect", "Vive Pucks Configuration"]
|
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "SDL2 Joystick", "Sixense Controllers", "Perception Neuron", "Kinect", "Vive Pucks Configuration"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,10 @@
|
||||||
|
|
||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
|
|
||||||
#include <PerfStat.h>
|
|
||||||
#include <controllers/UserInputMapper.h>
|
#include <controllers/UserInputMapper.h>
|
||||||
|
#include <PerfStat.h>
|
||||||
|
#include <Preferences.h>
|
||||||
|
#include <SettingHandle.h>
|
||||||
|
|
||||||
#include "SDL2Manager.h"
|
#include "SDL2Manager.h"
|
||||||
|
|
||||||
|
@ -38,10 +40,13 @@ static_assert(
|
||||||
(int)controller::RY == (int)SDL_CONTROLLER_AXIS_RIGHTY &&
|
(int)controller::RY == (int)SDL_CONTROLLER_AXIS_RIGHTY &&
|
||||||
(int)controller::LT == (int)SDL_CONTROLLER_AXIS_TRIGGERLEFT &&
|
(int)controller::LT == (int)SDL_CONTROLLER_AXIS_TRIGGERLEFT &&
|
||||||
(int)controller::RT == (int)SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
|
(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::NAME = "SDL2";
|
||||||
|
const char* SDL2Manager::SDL2_ID_STRING = "SDL2";
|
||||||
|
|
||||||
|
const bool DEFAULT_ENABLED = false;
|
||||||
|
|
||||||
SDL_JoystickID SDL2Manager::getInstanceId(SDL_GameController* controller) {
|
SDL_JoystickID SDL2Manager::getInstanceId(SDL_GameController* controller) {
|
||||||
SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controller);
|
SDL_Joystick* joystick = SDL_GameControllerGetJoystick(controller);
|
||||||
|
@ -49,6 +54,20 @@ SDL_JoystickID SDL2Manager::getInstanceId(SDL_GameController* controller) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL2Manager::init() {
|
void SDL2Manager::init() {
|
||||||
|
loadSettings();
|
||||||
|
|
||||||
|
auto preferences = DependencyManager::get<Preferences>();
|
||||||
|
static const QString SDL2_PLUGIN { "SDL2 Joystick" };
|
||||||
|
{
|
||||||
|
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);
|
bool initSuccess = (SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) == 0);
|
||||||
|
|
||||||
if (initSuccess) {
|
if (initSuccess) {
|
||||||
|
@ -110,6 +129,27 @@ void SDL2Manager::deactivate() {
|
||||||
InputPlugin::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 {
|
bool SDL2Manager::isSupported() const {
|
||||||
return true;
|
return true;
|
||||||
|
@ -122,6 +162,10 @@ void SDL2Manager::pluginFocusOutEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL2Manager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
void SDL2Manager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||||
|
if (!_isEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_isInitialized) {
|
if (_isInitialized) {
|
||||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||||
for (auto joystick : _openJoysticks) {
|
for (auto joystick : _openJoysticks) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ public:
|
||||||
// Plugin functions
|
// Plugin functions
|
||||||
bool isSupported() const override;
|
bool isSupported() const override;
|
||||||
const QString getName() const override { return NAME; }
|
const QString getName() const override { return NAME; }
|
||||||
|
const QString getID() const override { return SDL2_ID_STRING; }
|
||||||
|
|
||||||
QStringList getSubdeviceNames() override;
|
QStringList getSubdeviceNames() override;
|
||||||
|
|
||||||
|
@ -39,6 +40,9 @@ public:
|
||||||
void pluginFocusOutEvent() override;
|
void pluginFocusOutEvent() override;
|
||||||
void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
|
void pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
|
||||||
|
|
||||||
|
virtual void saveSettings() const override;
|
||||||
|
virtual void loadSettings() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void joystickAdded(Joystick* joystick);
|
void joystickAdded(Joystick* joystick);
|
||||||
void joystickRemoved(Joystick* joystick);
|
void joystickRemoved(Joystick* joystick);
|
||||||
|
@ -77,8 +81,10 @@ private:
|
||||||
int buttonRelease() const { return SDL_RELEASED; }
|
int buttonRelease() const { return SDL_RELEASED; }
|
||||||
|
|
||||||
QMap<SDL_JoystickID, Joystick::Pointer> _openJoysticks;
|
QMap<SDL_JoystickID, Joystick::Pointer> _openJoysticks;
|
||||||
bool _isInitialized { false } ;
|
bool _isEnabled { false };
|
||||||
|
bool _isInitialized { false };
|
||||||
static const char* NAME;
|
static const char* NAME;
|
||||||
|
static const char* SDL2_ID_STRING;
|
||||||
QStringList _subdeviceNames;
|
QStringList _subdeviceNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue