mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-31 15:32:45 +00:00
Merge branch 'settings_values_input' into 'master'
Use settings values for Input settings (#6876) See merge request OpenMW/openmw!3265
This commit is contained in:
commit
f5677aa352
@ -377,7 +377,7 @@ namespace MWBase
|
|||||||
virtual bool isFirstPerson() const = 0;
|
virtual bool isFirstPerson() const = 0;
|
||||||
virtual bool isPreviewModeEnabled() const = 0;
|
virtual bool isPreviewModeEnabled() const = 0;
|
||||||
virtual bool toggleVanityMode(bool enable) = 0;
|
virtual bool toggleVanityMode(bool enable) = 0;
|
||||||
virtual bool vanityRotateCamera(float* rot) = 0;
|
virtual bool vanityRotateCamera(const float* rot) = 0;
|
||||||
virtual void applyDeferredPreviewRotationToPlayer(float dt) = 0;
|
virtual void applyDeferredPreviewRotationToPlayer(float dt) = 0;
|
||||||
virtual void disableDeferredPreviewRotation() = 0;
|
virtual void disableDeferredPreviewRotation() = 0;
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
const float threshold = Settings::input().mGyroInputThreshold;
|
||||||
|
const float gyroH = getAxisValue(Settings::input().mGyroHorizontalAxis, threshold, values);
|
||||||
|
const float gyroV = getAxisValue(Settings::input().mGyroVerticalAxis, threshold, values);
|
||||||
|
|
||||||
|
if (gyroH == 0.f && gyroV == 0.f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const float rot[3] = {
|
||||||
|
-gyroV * dt * Settings::input().mGyroVerticalSensitivity,
|
||||||
|
0.0f,
|
||||||
|
-gyroH * dt * Settings::input().mGyroHorizontalSensitivity,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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)
|
||||||
{
|
{
|
||||||
float gyroH = getAxisValue(mAxisH, values);
|
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
|
||||||
float gyroV = getAxisValue(mAxisV, values);
|
player.yaw(-rot[2]);
|
||||||
|
player.pitch(-rot[0]);
|
||||||
if (gyroH == 0.f && gyroV == 0.f)
|
|
||||||
return;
|
|
||||||
|
|
||||||
float rot[3];
|
|
||||||
rot[0] = -gyroV * dt * mSensitivityV;
|
|
||||||
rot[1] = 0.0f;
|
|
||||||
rot[2] = -gyroH * dt * mSensitivityH;
|
|
||||||
|
|
||||||
// Only actually turn player when we're not in vanity mode
|
|
||||||
bool playerLooking = MWBase::Environment::get().getInputManager()->getControlSwitch("playerlooking");
|
|
||||||
if (!MWBase::Environment::get().getWorld()->vanityRotateCamera(rot) && playerLooking)
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
else if (!playerLooking)
|
||||||
|
MWBase::Environment::get().getWorld()->disableDeferredPreviewRotation();
|
||||||
|
|
||||||
void GyroManager::processChangedSettings(const Settings::CategorySettingVector& changed)
|
MWBase::Environment::get().getInputManager()->resetIdleTime();
|
||||||
{
|
|
||||||
for (const auto& setting : changed)
|
|
||||||
{
|
|
||||||
if (setting.first != "Input")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
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"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float GyroManager::getAxisValue(GyroscopeAxis axis, std::array<float, 3> values) const
|
|
||||||
{
|
|
||||||
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);
|
||||||
|
@ -2300,7 +2300,7 @@ namespace MWWorld
|
|||||||
return mRendering->getCamera();
|
return mRendering->getCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::vanityRotateCamera(float* rot)
|
bool World::vanityRotateCamera(const float* rot)
|
||||||
{
|
{
|
||||||
auto* camera = mRendering->getCamera();
|
auto* camera = mRendering->getCamera();
|
||||||
if (!camera->isVanityOrPreviewModeEnabled())
|
if (!camera->isVanityOrPreviewModeEnabled())
|
||||||
|
@ -472,7 +472,7 @@ namespace MWWorld
|
|||||||
bool toggleVanityMode(bool enable) override;
|
bool toggleVanityMode(bool enable) override;
|
||||||
|
|
||||||
MWRender::Camera* getCamera() override;
|
MWRender::Camera* getCamera() override;
|
||||||
bool vanityRotateCamera(float* rot) override;
|
bool vanityRotateCamera(const float* rot) override;
|
||||||
|
|
||||||
void applyDeferredPreviewRotationToPlayer(float dt) override;
|
void applyDeferredPreviewRotationToPlayer(float dt) override;
|
||||||
void disableDeferredPreviewRotation() override;
|
void disableDeferredPreviewRotation() override;
|
||||||
|
@ -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) };
|
||||||
|
17
components/settings/gyroscopeaxis.hpp
Normal file
17
components/settings/gyroscopeaxis.hpp
Normal file
@ -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…
x
Reference in New Issue
Block a user