Use settings values for Input settings

revert-6246b479
elsid 1 year ago
parent 5a27ccacb7
commit 6c18723bc7
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -8,6 +8,7 @@
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/files/conversion.hpp> #include <components/files/conversion.hpp>
#include <components/sdlutil/sdlmappings.hpp> #include <components/sdlutil/sdlmappings.hpp>
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp" #include "../mwbase/inputmanager.hpp"
@ -29,9 +30,7 @@ namespace MWInput
const std::filesystem::path& userControllerBindingsFile, const std::filesystem::path& controllerBindingsFile) const std::filesystem::path& userControllerBindingsFile, const std::filesystem::path& controllerBindingsFile)
: mBindingsManager(bindingsManager) : mBindingsManager(bindingsManager)
, mMouseManager(mouseManager) , mMouseManager(mouseManager)
, mJoystickEnabled(Settings::Manager::getBool("enable controller", "Input"))
, mGyroAvailable(false) , mGyroAvailable(false)
, mGamepadCursorSpeed(Settings::Manager::getFloat("gamepad cursor speed", "Input"))
, mGamepadGuiCursorEnabled(true) , mGamepadGuiCursorEnabled(true)
, mGuiCursorEnabled(true) , mGuiCursorEnabled(true)
, mJoystickLastUsed(false) , mJoystickLastUsed(false)
@ -64,18 +63,7 @@ namespace MWInput
} }
} }
float deadZoneRadius = Settings::Manager::getFloat("joystick dead zone", "Input"); mBindingsManager->setJoystickDeadZone(Settings::input().mJoystickDeadZone);
deadZoneRadius = std::clamp(deadZoneRadius, 0.f, 0.5f);
mBindingsManager->setJoystickDeadZone(deadZoneRadius);
}
void ControllerManager::processChangedSettings(const Settings::CategorySettingVector& changed)
{
for (const auto& setting : changed)
{
if (setting.first == "Input" && setting.second == "enable controller")
mJoystickEnabled = Settings::Manager::getBool("enable controller", "Input");
}
} }
void ControllerManager::update(float dt) void ControllerManager::update(float dt)
@ -92,8 +80,9 @@ namespace MWInput
// We keep track of our own mouse position, so that moving the mouse while in // We keep track of our own mouse position, so that moving the mouse while in
// game mode does not move the position of the GUI cursor // game mode does not move the position of the GUI cursor
float uiScale = MWBase::Environment::get().getWindowManager()->getScalingFactor(); float uiScale = MWBase::Environment::get().getWindowManager()->getScalingFactor();
float xMove = xAxis * dt * 1500.0f / uiScale * mGamepadCursorSpeed; const float gamepadCursorSpeed = Settings::input().mEnableController;
float yMove = yAxis * dt * 1500.0f / uiScale * mGamepadCursorSpeed; const float xMove = xAxis * dt * 1500.0f / uiScale * gamepadCursorSpeed;
const float yMove = yAxis * dt * 1500.0f / uiScale * gamepadCursorSpeed;
float mouseWheelMove = -zAxis * dt * 1500.0f; float mouseWheelMove = -zAxis * dt * 1500.0f;
if (xMove != 0 || yMove != 0 || mouseWheelMove != 0) if (xMove != 0 || yMove != 0 || mouseWheelMove != 0)
@ -120,7 +109,7 @@ namespace MWInput
void ControllerManager::buttonPressed(int deviceID, const SDL_ControllerButtonEvent& arg) void ControllerManager::buttonPressed(int deviceID, const SDL_ControllerButtonEvent& arg)
{ {
if (!mJoystickEnabled || mBindingsManager->isDetectingBindingState()) if (!Settings::input().mEnableController || mBindingsManager->isDetectingBindingState())
return; return;
MWBase::Environment::get().getLuaManager()->inputEvent( MWBase::Environment::get().getLuaManager()->inputEvent(
@ -170,13 +159,13 @@ namespace MWInput
return; return;
} }
if (mJoystickEnabled) if (Settings::input().mEnableController)
{ {
MWBase::Environment::get().getLuaManager()->inputEvent( MWBase::Environment::get().getLuaManager()->inputEvent(
{ MWBase::LuaManager::InputEvent::ControllerReleased, arg.button }); { MWBase::LuaManager::InputEvent::ControllerReleased, arg.button });
} }
if (!mJoystickEnabled || MWBase::Environment::get().getInputManager()->controlsDisabled()) if (!Settings::input().mEnableController || MWBase::Environment::get().getInputManager()->controlsDisabled())
return; return;
mJoystickLastUsed = true; mJoystickLastUsed = true;
@ -208,7 +197,7 @@ namespace MWInput
void ControllerManager::axisMoved(int deviceID, const SDL_ControllerAxisEvent& arg) void ControllerManager::axisMoved(int deviceID, const SDL_ControllerAxisEvent& arg)
{ {
if (!mJoystickEnabled || MWBase::Environment::get().getInputManager()->controlsDisabled()) if (!Settings::input().mEnableController || MWBase::Environment::get().getInputManager()->controlsDisabled())
return; return;
mJoystickLastUsed = true; mJoystickLastUsed = true;

@ -33,8 +33,6 @@ namespace MWInput
void touchpadPressed(int deviceId, const SDLUtil::TouchEvent& arg) override; void touchpadPressed(int deviceId, const SDLUtil::TouchEvent& arg) override;
void touchpadReleased(int deviceId, const SDLUtil::TouchEvent& arg) override; void touchpadReleased(int deviceId, const SDLUtil::TouchEvent& arg) override;
void processChangedSettings(const Settings::CategorySettingVector& changed);
void setJoystickLastUsed(bool enabled) { mJoystickLastUsed = enabled; } void setJoystickLastUsed(bool enabled) { mJoystickLastUsed = enabled; }
bool joystickLastUsed() const { return mJoystickLastUsed; } bool joystickLastUsed() const { return mJoystickLastUsed; }
@ -59,9 +57,7 @@ namespace MWInput
BindingsManager* mBindingsManager; BindingsManager* mBindingsManager;
MouseManager* mMouseManager; MouseManager* mMouseManager;
bool mJoystickEnabled;
bool mGyroAvailable; bool mGyroAvailable;
float mGamepadCursorSpeed;
bool mGamepadGuiCursorEnabled; bool mGamepadGuiCursorEnabled;
bool mGuiCursorEnabled; bool mGuiCursorEnabled;
bool mJoystickLastUsed; bool mJoystickLastUsed;

@ -5,98 +5,67 @@
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
#include <components/settings/values.hpp>
namespace MWInput namespace MWInput
{ {
GyroManager::GyroscopeAxis GyroManager::gyroscopeAxisFromString(std::string_view s) namespace
{
if (s == "x")
return GyroscopeAxis::X;
else if (s == "y")
return GyroscopeAxis::Y;
else if (s == "z")
return GyroscopeAxis::Z;
else if (s == "-x")
return GyroscopeAxis::Minus_X;
else if (s == "-y")
return GyroscopeAxis::Minus_Y;
else if (s == "-z")
return GyroscopeAxis::Minus_Z;
return GyroscopeAxis::Unknown;
}
GyroManager::GyroManager()
: mEnabled(Settings::Manager::getBool("enable gyroscope", "Input"))
, mGuiCursorEnabled(true)
, mSensitivityH(Settings::Manager::getFloat("gyro horizontal sensitivity", "Input"))
, mSensitivityV(Settings::Manager::getFloat("gyro vertical sensitivity", "Input"))
, mInputThreshold(Settings::Manager::getFloat("gyro input threshold", "Input"))
, mAxisH(gyroscopeAxisFromString(Settings::Manager::getString("gyro horizontal axis", "Input")))
, mAxisV(gyroscopeAxisFromString(Settings::Manager::getString("gyro vertical axis", "Input")))
{ {
float getAxisValue(Settings::GyroscopeAxis axis, float threshold, std::array<float, 3> values)
{
const float value = [&] {
switch (axis)
{
case Settings::GyroscopeAxis::X:
return values[0];
case Settings::GyroscopeAxis::Y:
return values[1];
case Settings::GyroscopeAxis::Z:
return values[2];
case Settings::GyroscopeAxis::MinusX:
return -values[0];
case Settings::GyroscopeAxis::MinusY:
return -values[1];
case Settings::GyroscopeAxis::MinusZ:
return -values[2];
};
return 0.0f;
}();
if (std::abs(value) <= threshold)
return 0;
return value;
}
} }
void GyroManager::update(float dt, std::array<float, 3> values) const void GyroManager::update(float dt, std::array<float, 3> values) const
{ {
if (!mGuiCursorEnabled) if (mGuiCursorEnabled)
{ return;
float gyroH = getAxisValue(mAxisH, values);
float gyroV = getAxisValue(mAxisV, values);
if (gyroH == 0.f && gyroV == 0.f) const float threshold = Settings::input().mGyroInputThreshold;
return; const float gyroH = getAxisValue(Settings::input().mGyroHorizontalAxis, threshold, values);
const float gyroV = getAxisValue(Settings::input().mGyroVerticalAxis, threshold, values);
float rot[3]; if (gyroH == 0.f && gyroV == 0.f)
rot[0] = -gyroV * dt * mSensitivityV; return;
rot[1] = 0.0f;
rot[2] = -gyroH * dt * mSensitivityH;
// Only actually turn player when we're not in vanity mode const float rot[3] = {
bool playerLooking = MWBase::Environment::get().getInputManager()->getControlSwitch("playerlooking"); -gyroV * dt * Settings::input().mGyroVerticalSensitivity,
if (!MWBase::Environment::get().getWorld()->vanityRotateCamera(rot) && playerLooking) 0.0f,
{ -gyroH * dt * Settings::input().mGyroHorizontalSensitivity,
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer(); };
player.yaw(-rot[2]);
player.pitch(-rot[0]);
}
else if (!playerLooking)
MWBase::Environment::get().getWorld()->disableDeferredPreviewRotation();
MWBase::Environment::get().getInputManager()->resetIdleTime(); // Only actually turn player when we're not in vanity mode
} const bool playerLooking = MWBase::Environment::get().getInputManager()->getControlSwitch("playerlooking");
} if (!MWBase::Environment::get().getWorld()->vanityRotateCamera(rot) && playerLooking)
void GyroManager::processChangedSettings(const Settings::CategorySettingVector& changed)
{
for (const auto& setting : changed)
{ {
if (setting.first != "Input") MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
continue; player.yaw(-rot[2]);
player.pitch(-rot[0]);
if (setting.second == "enable gyroscope")
mEnabled = Settings::Manager::getBool("enable gyroscope", "Input");
else if (setting.second == "gyro horizontal sensitivity")
mSensitivityH = Settings::Manager::getFloat("gyro horizontal sensitivity", "Input");
else if (setting.second == "gyro vertical sensitivity")
mSensitivityV = Settings::Manager::getFloat("gyro vertical sensitivity", "Input");
else if (setting.second == "gyro input threshold")
mInputThreshold = Settings::Manager::getFloat("gyro input threshold", "Input");
else if (setting.second == "gyro horizontal axis")
mAxisH = gyroscopeAxisFromString(Settings::Manager::getString("gyro horizontal axis", "Input"));
else if (setting.second == "gyro vertical axis")
mAxisV = gyroscopeAxisFromString(Settings::Manager::getString("gyro vertical axis", "Input"));
} }
} else if (!playerLooking)
MWBase::Environment::get().getWorld()->disableDeferredPreviewRotation();
float GyroManager::getAxisValue(GyroscopeAxis axis, std::array<float, 3> values) const MWBase::Environment::get().getInputManager()->resetIdleTime();
{
if (axis == GyroscopeAxis::Unknown)
return 0;
float value = values[std::abs(axis) - 1];
if (axis < 0)
value *= -1;
if (std::abs(value) <= mInputThreshold)
value = 0;
return value;
} }
} }

@ -1,46 +1,19 @@
#ifndef MWINPUT_GYROMANAGER #ifndef MWINPUT_GYROMANAGER
#define MWINPUT_GYROMANAGER #define MWINPUT_GYROMANAGER
#include <components/settings/settings.hpp> #include <array>
namespace MWInput namespace MWInput
{ {
class GyroManager class GyroManager
{ {
public: public:
GyroManager();
bool isEnabled() const { return mEnabled; }
void update(float dt, std::array<float, 3> values) const; void update(float dt, std::array<float, 3> values) const;
void processChangedSettings(const Settings::CategorySettingVector& changed);
void setGuiCursorEnabled(bool enabled) { mGuiCursorEnabled = enabled; } void setGuiCursorEnabled(bool enabled) { mGuiCursorEnabled = enabled; }
private: private:
enum GyroscopeAxis bool mGuiCursorEnabled = true;
{
Unknown = 0,
X = 1,
Y = 2,
Z = 3,
Minus_X = -1,
Minus_Y = -2,
Minus_Z = -3
};
static GyroscopeAxis gyroscopeAxisFromString(std::string_view s);
bool mEnabled;
bool mGuiCursorEnabled;
float mSensitivityH;
float mSensitivityV;
float mInputThreshold;
GyroscopeAxis mAxisH;
GyroscopeAxis mAxisV;
float getAxisValue(GyroscopeAxis axis, std::array<float, 3> values) const;
}; };
} }

@ -5,6 +5,7 @@
#include <components/esm3/esmreader.hpp> #include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp> #include <components/esm3/esmwriter.hpp>
#include <components/sdlutil/sdlinputwrapper.hpp> #include <components/sdlutil/sdlinputwrapper.hpp>
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
@ -79,7 +80,7 @@ namespace MWInput
mSensorManager->update(dt); mSensorManager->update(dt);
mActionManager->update(dt); mActionManager->update(dt);
if (mGyroManager->isEnabled()) if (Settings::input().mEnableGyroscope)
{ {
bool controllerAvailable = mControllerManager->isGyroAvailable(); bool controllerAvailable = mControllerManager->isGyroAvailable();
bool sensorAvailable = mSensorManager->isGyroAvailable(); bool sensorAvailable = mSensorManager->isGyroAvailable();
@ -118,9 +119,7 @@ namespace MWInput
void InputManager::processChangedSettings(const Settings::CategorySettingVector& changed) void InputManager::processChangedSettings(const Settings::CategorySettingVector& changed)
{ {
mMouseManager->processChangedSettings(changed);
mSensorManager->processChangedSettings(changed); mSensorManager->processChangedSettings(changed);
mGyroManager->processChangedSettings(changed);
} }
bool InputManager::getControlSwitch(std::string_view sw) bool InputManager::getControlSwitch(std::string_view sw)

@ -6,6 +6,7 @@
#include <components/sdlutil/sdlinputwrapper.hpp> #include <components/sdlutil/sdlinputwrapper.hpp>
#include <components/sdlutil/sdlmappings.hpp> #include <components/sdlutil/sdlmappings.hpp>
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp" #include "../mwbase/inputmanager.hpp"
@ -21,12 +22,7 @@ namespace MWInput
{ {
MouseManager::MouseManager( MouseManager::MouseManager(
BindingsManager* bindingsManager, SDLUtil::InputWrapper* inputWrapper, SDL_Window* window) BindingsManager* bindingsManager, SDLUtil::InputWrapper* inputWrapper, SDL_Window* window)
: mInvertX(Settings::Manager::getBool("invert x axis", "Input")) : mBindingsManager(bindingsManager)
, mInvertY(Settings::Manager::getBool("invert y axis", "Input"))
, mGrabCursor(Settings::Manager::getBool("grab cursor", "Input"))
, mCameraSensitivity(Settings::Manager::getFloat("camera sensitivity", "Input"))
, mCameraYMultiplier(Settings::Manager::getFloat("camera y multiplier", "Input"))
, mBindingsManager(bindingsManager)
, mInputWrapper(inputWrapper) , mInputWrapper(inputWrapper)
, mGuiCursorX(0) , mGuiCursorX(0)
, mGuiCursorY(0) , mGuiCursorY(0)
@ -44,24 +40,6 @@ namespace MWInput
mGuiCursorY = h / (2.f * uiScale); mGuiCursorY = h / (2.f * uiScale);
} }
void MouseManager::processChangedSettings(const Settings::CategorySettingVector& changed)
{
for (const auto& setting : changed)
{
if (setting.first == "Input" && setting.second == "invert x axis")
mInvertX = Settings::Manager::getBool("invert x axis", "Input");
if (setting.first == "Input" && setting.second == "invert y axis")
mInvertY = Settings::Manager::getBool("invert y axis", "Input");
if (setting.first == "Input" && setting.second == "camera sensitivity")
mCameraSensitivity = Settings::Manager::getFloat("camera sensitivity", "Input");
if (setting.first == "Input" && setting.second == "grab cursor")
mGrabCursor = Settings::Manager::getBool("grab cursor", "Input");
}
}
void MouseManager::mouseMoved(const SDLUtil::MouseMotionEvent& arg) void MouseManager::mouseMoved(const SDLUtil::MouseMotionEvent& arg)
{ {
mBindingsManager->mouseMoved(arg); mBindingsManager->mouseMoved(arg);
@ -96,8 +74,10 @@ namespace MWInput
{ {
MWBase::World* world = MWBase::Environment::get().getWorld(); MWBase::World* world = MWBase::Environment::get().getWorld();
float x = arg.xrel * mCameraSensitivity * (mInvertX ? -1 : 1) / 256.f; const float cameraSensitivity = Settings::input().mCameraSensitivity;
float y = arg.yrel * mCameraSensitivity * (mInvertY ? -1 : 1) * mCameraYMultiplier / 256.f; float x = arg.xrel * cameraSensitivity * (Settings::input().mInvertXAxis ? -1 : 1) / 256.f;
float y = arg.yrel * cameraSensitivity * (Settings::input().mInvertYAxis ? -1 : 1)
* Settings::input().mCameraYMultiplier / 256.f;
float rot[3]; float rot[3];
rot[0] = -y; rot[0] = -y;
@ -194,7 +174,7 @@ namespace MWInput
mInputWrapper->setMouseRelative(isRelative); mInputWrapper->setMouseRelative(isRelative);
// we let the mouse escape in the main menu // we let the mouse escape in the main menu
mInputWrapper->setGrabPointer(grab && (mGrabCursor || isRelative)); mInputWrapper->setGrabPointer(grab && (Settings::input().mGrabCursor || isRelative));
// we switched to non-relative mode, move our cursor to where the in-game // we switched to non-relative mode, move our cursor to where the in-game
// cursor is // cursor is
@ -216,10 +196,13 @@ namespace MWInput
if (xAxis == 0 && yAxis == 0) if (xAxis == 0 && yAxis == 0)
return; return;
float rot[3]; const float cameraSensitivity = Settings::input().mCameraSensitivity;
rot[0] = -yAxis * dt * 1000.0f * mCameraSensitivity * (mInvertY ? -1 : 1) * mCameraYMultiplier / 256.f; const float rot[3] = {
rot[1] = 0.0f; -yAxis * dt * 1000.0f * cameraSensitivity * (Settings::input().mInvertYAxis ? -1 : 1)
rot[2] = -xAxis * dt * 1000.0f * mCameraSensitivity * (mInvertX ? -1 : 1) / 256.f; * Settings::input().mCameraYMultiplier / 256.f,
0.0f,
-xAxis * dt * 1000.0f * cameraSensitivity * (Settings::input().mInvertXAxis ? -1 : 1) / 256.f,
};
// Only actually turn player when we're not in vanity mode // Only actually turn player when we're not in vanity mode
bool controls = MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols"); bool controls = MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols");

@ -28,8 +28,6 @@ namespace MWInput
void mouseReleased(const SDL_MouseButtonEvent& arg, Uint8 id) override; void mouseReleased(const SDL_MouseButtonEvent& arg, Uint8 id) override;
void mouseWheelMoved(const SDL_MouseWheelEvent& arg) override; void mouseWheelMoved(const SDL_MouseWheelEvent& arg) override;
void processChangedSettings(const Settings::CategorySettingVector& changed);
bool injectMouseButtonPress(Uint8 button); bool injectMouseButtonPress(Uint8 button);
bool injectMouseButtonRelease(Uint8 button); bool injectMouseButtonRelease(Uint8 button);
void injectMouseMove(float xMove, float yMove, float mouseWheelMove); void injectMouseMove(float xMove, float yMove, float mouseWheelMove);
@ -42,12 +40,6 @@ namespace MWInput
int getMouseMoveY() const { return mMouseMoveY; } int getMouseMoveY() const { return mMouseMoveY; }
private: private:
bool mInvertX;
bool mInvertY;
bool mGrabCursor;
float mCameraSensitivity;
float mCameraYMultiplier;
BindingsManager* mBindingsManager; BindingsManager* mBindingsManager;
SDLUtil::InputWrapper* mInputWrapper; SDLUtil::InputWrapper* mInputWrapper;

@ -1,6 +1,7 @@
#include "sensormanager.hpp" #include "sensormanager.hpp"
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/settings/values.hpp>
namespace MWInput namespace MWInput
{ {
@ -30,7 +31,7 @@ namespace MWInput
void SensorManager::correctGyroscopeAxes() void SensorManager::correctGyroscopeAxes()
{ {
if (!Settings::Manager::getBool("enable gyroscope", "Input")) if (!Settings::input().mEnableGyroscope)
return; return;
// Treat setting from config as axes for landscape mode. // Treat setting from config as axes for landscape mode.
@ -71,7 +72,7 @@ namespace MWInput
void SensorManager::updateSensors() void SensorManager::updateSensors()
{ {
if (Settings::Manager::getBool("enable gyroscope", "Input")) if (Settings::input().mEnableGyroscope)
{ {
int numSensors = SDL_NumSensors(); int numSensors = SDL_NumSensors();
for (int i = 0; i < numSensors; ++i) for (int i = 0; i < numSensors; ++i)
@ -128,7 +129,7 @@ namespace MWInput
void SensorManager::sensorUpdated(const SDL_SensorEvent& arg) void SensorManager::sensorUpdated(const SDL_SensorEvent& arg)
{ {
if (!Settings::Manager::getBool("enable gyroscope", "Input")) if (!Settings::input().mEnableGyroscope)
return; return;
SDL_Sensor* sensor = SDL_SensorFromInstanceID(arg.which); SDL_Sensor* sensor = SDL_SensorFromInstanceID(arg.which);

@ -30,10 +30,8 @@ namespace Settings
SettingValue<float> mJoystickDeadZone{ mIndex, "Input", "joystick dead zone", SettingValue<float> mJoystickDeadZone{ mIndex, "Input", "joystick dead zone",
makeClampSanitizerFloat(0, 0.5f) }; makeClampSanitizerFloat(0, 0.5f) };
SettingValue<bool> mEnableGyroscope{ mIndex, "Input", "enable gyroscope" }; SettingValue<bool> mEnableGyroscope{ mIndex, "Input", "enable gyroscope" };
SettingValue<std::string> mGyroHorizontalAxis{ mIndex, "Input", "gyro horizontal axis", SettingValue<GyroscopeAxis> mGyroHorizontalAxis{ mIndex, "Input", "gyro horizontal axis" };
makeEnumSanitizerString({ "x", "y", "z", "-x", "-y", "-z" }) }; SettingValue<GyroscopeAxis> mGyroVerticalAxis{ mIndex, "Input", "gyro vertical axis" };
SettingValue<std::string> mGyroVerticalAxis{ mIndex, "Input", "gyro vertical axis",
makeEnumSanitizerString({ "x", "y", "z", "-x", "-y", "-z" }) };
SettingValue<float> mGyroInputThreshold{ mIndex, "Input", "gyro input threshold", makeMaxSanitizerFloat(0) }; SettingValue<float> mGyroInputThreshold{ mIndex, "Input", "gyro input threshold", makeMaxSanitizerFloat(0) };
SettingValue<float> mGyroHorizontalSensitivity{ mIndex, "Input", "gyro horizontal sensitivity", SettingValue<float> mGyroHorizontalSensitivity{ mIndex, "Input", "gyro horizontal sensitivity",
makeMaxStrictSanitizerFloat(0) }; makeMaxStrictSanitizerFloat(0) };

@ -0,0 +1,17 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_GYROSCOPEAXIS_H
#define OPENMW_COMPONENTS_SETTINGS_GYROSCOPEAXIS_H
namespace Settings
{
enum class GyroscopeAxis
{
X,
Y,
Z,
MinusX,
MinusY,
MinusZ,
};
}
#endif

@ -464,4 +464,21 @@ namespace Settings
sInitialized.emplace(category, setting); sInitialized.emplace(category, setting);
} }
GyroscopeAxis parseGyroscopeAxis(std::string_view value)
{
if (value == "x")
return GyroscopeAxis::X;
else if (value == "y")
return GyroscopeAxis::Y;
else if (value == "z")
return GyroscopeAxis::Z;
else if (value == "-x")
return GyroscopeAxis::MinusX;
else if (value == "-y")
return GyroscopeAxis::MinusY;
else if (value == "-z")
return GyroscopeAxis::MinusZ;
throw std::runtime_error("Invalid gyroscope axis: " + std::string(value));
}
} }

@ -2,6 +2,7 @@
#define COMPONENTS_SETTINGS_H #define COMPONENTS_SETTINGS_H
#include "categories.hpp" #include "categories.hpp"
#include "gyroscopeaxis.hpp"
#include "components/detournavigator/collisionshapetype.hpp" #include "components/detournavigator/collisionshapetype.hpp"
@ -197,6 +198,14 @@ namespace Settings
{ {
return MyGUI::Colour::parse(getString(setting, category)); return MyGUI::Colour::parse(getString(setting, category));
} }
GyroscopeAxis parseGyroscopeAxis(std::string_view value);
template <>
inline GyroscopeAxis Manager::getImpl<GyroscopeAxis>(std::string_view setting, std::string_view category)
{
return parseGyroscopeAxis(getString(setting, category));
}
} }
#endif // COMPONENTS_SETTINGS_H #endif // COMPONENTS_SETTINGS_H

@ -1,6 +1,7 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_SETTINGVALUE_H #ifndef OPENMW_COMPONENTS_SETTINGS_SETTINGVALUE_H
#define OPENMW_COMPONENTS_SETTINGS_SETTINGVALUE_H #define OPENMW_COMPONENTS_SETTINGS_SETTINGVALUE_H
#include "gyroscopeaxis.hpp"
#include "sanitizer.hpp" #include "sanitizer.hpp"
#include "settings.hpp" #include "settings.hpp"
@ -36,6 +37,7 @@ namespace Settings
CollisionShapeType, CollisionShapeType,
StringArray, StringArray,
MyGuiColour, MyGuiColour,
GyroscopeAxis,
}; };
template <class T> template <class T>
@ -131,6 +133,12 @@ namespace Settings
return SettingValueType::MyGuiColour; return SettingValueType::MyGuiColour;
} }
template <>
inline constexpr SettingValueType getSettingValueType<GyroscopeAxis>()
{
return SettingValueType::GyroscopeAxis;
}
inline constexpr std::string_view getSettingValueTypeName(SettingValueType type) inline constexpr std::string_view getSettingValueTypeName(SettingValueType type)
{ {
switch (type) switch (type)
@ -165,6 +173,8 @@ namespace Settings
return "string array"; return "string array";
case SettingValueType::MyGuiColour: case SettingValueType::MyGuiColour:
return "colour"; return "colour";
case SettingValueType::GyroscopeAxis:
return "gyroscope axis";
} }
return "unsupported"; return "unsupported";
} }

Loading…
Cancel
Save