mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 07:53:51 +00:00
Merge remote-tracking branch 'remotes/origin/thumbstick_deadzones' into openxr_vr_geometryshader_feature_branch
This commit is contained in:
commit
43f5e6c167
8 changed files with 90 additions and 17 deletions
|
@ -20,7 +20,7 @@
|
|||
namespace MWVR
|
||||
{
|
||||
|
||||
OpenXRActionSet::OpenXRActionSet(const std::string& actionSetName)
|
||||
OpenXRActionSet::OpenXRActionSet(const std::string& actionSetName, std::shared_ptr<AxisAction::Deadzone> deadzone)
|
||||
: mActionSet(nullptr)
|
||||
, mLocalizedName(actionSetName)
|
||||
, mInternalName(Misc::StringUtils::lowerCase(actionSetName))
|
||||
|
@ -74,19 +74,19 @@ namespace MWVR
|
|||
createMWAction<ButtonPressAction>(MWInput::A_CycleWeaponRight, "cycle_weapon_right", "Cycle Weapon Right");
|
||||
createMWAction<ButtonHoldAction>(MWInput::A_Sneak, "sneak", "Sneak");
|
||||
createMWAction<ButtonPressAction>(MWInput::A_QuickKeysMenu, "quick_menu", "Quick Menu");
|
||||
createMWAction<AxisAction>(MWInput::A_LookLeftRight, "look_left_right", "Look Left Right");
|
||||
createMWAction<AxisAction>(MWInput::A_MoveForwardBackward, "move_forward_backward", "Move Forward Backward");
|
||||
createMWAction<AxisAction>(MWInput::A_MoveLeftRight, "move_left_right", "Move Left Right");
|
||||
createMWAction<AxisAction>(MWInput::A_LookLeftRight, "look_left_right", "Look Left Right", deadzone);
|
||||
createMWAction<AxisAction>(MWInput::A_MoveForwardBackward, "move_forward_backward", "Move Forward Backward", deadzone);
|
||||
createMWAction<AxisAction>(MWInput::A_MoveLeftRight, "move_left_right", "Move Left Right", deadzone);
|
||||
createMWAction<ButtonPressAction>(MWInput::A_Journal, "journal_book", "Journal Book");
|
||||
createMWAction<ButtonPressAction>(MWInput::A_QuickSave, "quick_save", "Quick Save");
|
||||
createMWAction<ButtonPressAction>(MWInput::A_Rest, "rest", "Rest");
|
||||
createMWAction<AxisAction>(A_ActivateTouch, "activate_touched", "Activate Touch");
|
||||
createMWAction<AxisAction>(A_ActivateTouch, "activate_touched", "Activate Touch", deadzone);
|
||||
createMWAction<ButtonPressAction>(MWInput::A_AlwaysRun, "always_run", "Always Run");
|
||||
createMWAction<ButtonPressAction>(MWInput::A_AutoMove, "auto_move", "Auto Move");
|
||||
createMWAction<ButtonPressAction>(MWInput::A_ToggleHUD, "toggle_hud", "Toggle HUD");
|
||||
createMWAction<ButtonPressAction>(MWInput::A_ToggleDebug, "toggle_debug", "Toggle the debug hud");
|
||||
createMWAction<AxisAction>(A_MenuUpDown, "menu_up_down", "Menu Up Down");
|
||||
createMWAction<AxisAction>(A_MenuLeftRight, "menu_left_right", "Menu Left Right");
|
||||
createMWAction<AxisAction>(A_MenuUpDown, "menu_up_down", "Menu Up Down", deadzone);
|
||||
createMWAction<AxisAction>(A_MenuLeftRight, "menu_left_right", "Menu Left Right", deadzone);
|
||||
createMWAction<ButtonPressAction>(A_MenuSelect, "menu_select", "Menu Select");
|
||||
createMWAction<ButtonPressAction>(A_MenuBack, "menu_back", "Menu Back");
|
||||
createPoseAction(TrackedLimb::LEFT_HAND, "left_hand_pose", "Left Hand Pose");
|
||||
|
@ -113,17 +113,31 @@ namespace MWVR
|
|||
mHapticsMap.emplace(limb, new HapticsAction(std::move(createXRAction(XR_ACTION_TYPE_VIBRATION_OUTPUT, actionName, localName))));
|
||||
}
|
||||
|
||||
template<typename A, XrActionType AT>
|
||||
template<typename A>
|
||||
void
|
||||
OpenXRActionSet::createMWAction(
|
||||
int openMWAction,
|
||||
const std::string& actionName,
|
||||
const std::string& localName)
|
||||
{
|
||||
auto xrAction = createXRAction(AT, mInternalName + "_" + actionName, mLocalizedName + " " + localName);
|
||||
auto xrAction = createXRAction(A::ActionType, mInternalName + "_" + actionName, mLocalizedName + " " + localName);
|
||||
mActionMap.emplace(actionName, new A(openMWAction, std::move(xrAction)));
|
||||
}
|
||||
|
||||
template<typename A>
|
||||
void
|
||||
OpenXRActionSet::createMWAction(
|
||||
int openMWAction,
|
||||
const std::string& actionName,
|
||||
const std::string& localName,
|
||||
std::shared_ptr<AxisAction::Deadzone> deadzone)
|
||||
{
|
||||
auto xrAction = createXRAction(AxisAction::ActionType, mInternalName + "_" + actionName, mLocalizedName + " " + localName);
|
||||
mActionMap.emplace(actionName, new AxisAction(openMWAction, std::move(xrAction), deadzone));
|
||||
}
|
||||
|
||||
|
||||
|
||||
XrActionSet
|
||||
OpenXRActionSet::createActionSet(const std::string& name)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace MWVR
|
|||
public:
|
||||
using Actions = MWInput::Actions;
|
||||
|
||||
OpenXRActionSet(const std::string& actionSetName);
|
||||
OpenXRActionSet(const std::string& actionSetName, std::shared_ptr<AxisAction::Deadzone> deadzone);
|
||||
|
||||
//! Update all controls and queue any actions
|
||||
void updateControls();
|
||||
|
@ -32,8 +32,10 @@ namespace MWVR
|
|||
void suggestBindings(std::vector<XrActionSuggestedBinding>& xrSuggestedBindings, const SuggestedBindings& mwSuggestedBindings);
|
||||
|
||||
protected:
|
||||
template<typename A, XrActionType AT = A::ActionType>
|
||||
template<typename A>
|
||||
void createMWAction(int openMWAction, const std::string& actionName, const std::string& localName);
|
||||
template<typename A>
|
||||
void createMWAction(int openMWAction, const std::string& actionName, const std::string& localName, std::shared_ptr<AxisAction::Deadzone> deadzone);
|
||||
void createPoseAction(TrackedLimb limb, const std::string& actionName, const std::string& localName);
|
||||
void createHapticsAction(TrackedLimb limb, const std::string& actionName, const std::string& localName);
|
||||
std::unique_ptr<OpenXRAction> createXRAction(XrActionType actionType, const std::string& actionName, const std::string& localName);
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
namespace MWVR
|
||||
{
|
||||
|
||||
OpenXRInput::OpenXRInput()
|
||||
OpenXRInput::OpenXRInput(std::shared_ptr<AxisAction::Deadzone> deadzone)
|
||||
{
|
||||
mActionSets.emplace(ActionSet::Gameplay, "Gameplay");
|
||||
mActionSets.emplace(ActionSet::GUI, "GUI");
|
||||
mActionSets.emplace(ActionSet::Gameplay, OpenXRActionSet("Gameplay", deadzone));
|
||||
mActionSets.emplace(ActionSet::GUI, OpenXRActionSet("GUI", deadzone));
|
||||
};
|
||||
|
||||
OpenXRActionSet& OpenXRInput::getActionSet(ActionSet actionSet)
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace MWVR
|
|||
using XrProfileSuggestedBindings = std::map<std::string, XrSuggestedBindings>;
|
||||
|
||||
//! Default constructor, creates two ActionSets: Gameplay and GUI
|
||||
OpenXRInput();
|
||||
OpenXRInput(std::shared_ptr<AxisAction::Deadzone> deadzone);
|
||||
|
||||
//! Get the specified actionSet.
|
||||
OpenXRActionSet& getActionSet(ActionSet actionSet);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <deque>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
namespace MWVR
|
||||
{
|
||||
|
@ -131,10 +132,17 @@ namespace MWVR
|
|||
}
|
||||
|
||||
|
||||
AxisAction::AxisAction(int openMWAction, std::unique_ptr<OpenXRAction> xrAction, std::shared_ptr<AxisAction::Deadzone> deadzone)
|
||||
: Action(openMWAction, std::move(xrAction))
|
||||
, mDeadzone(deadzone)
|
||||
{
|
||||
}
|
||||
|
||||
void AxisAction::update()
|
||||
{
|
||||
mActive = false;
|
||||
mXRAction->getFloat(0, mValue);
|
||||
mDeadzone->applyDeadzone(mValue);
|
||||
|
||||
if (std::fabs(mValue) > gAxisEpsilon)
|
||||
mActive = true;
|
||||
|
@ -142,4 +150,24 @@ namespace MWVR
|
|||
mValue = 0.f;
|
||||
}
|
||||
|
||||
void AxisAction::Deadzone::applyDeadzone(float& value)
|
||||
{
|
||||
float sign = std::copysignf(1.f, value);
|
||||
float magnitude = std::fabsf(value);
|
||||
magnitude = std::min(mActiveRadiusOuter, magnitude);
|
||||
magnitude = std::max(0.f, magnitude - mActiveRadiusInner);
|
||||
value = sign * magnitude * mActiveScale;
|
||||
|
||||
}
|
||||
|
||||
void AxisAction::Deadzone::setDeadzoneRadius(float deadzoneRadius)
|
||||
{
|
||||
deadzoneRadius = std::min(std::max(deadzoneRadius, 0.0f), 0.5f - 1e-5f);
|
||||
mActiveRadiusInner = deadzoneRadius;
|
||||
mActiveRadiusOuter = 1.f - deadzoneRadius;
|
||||
float activeRadius = mActiveRadiusOuter - mActiveRadiusInner;
|
||||
assert(activeRadius > 0.f);
|
||||
mActiveScale = 1.f / activeRadius;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -192,13 +192,29 @@ namespace MWVR
|
|||
class AxisAction : public Action
|
||||
{
|
||||
public:
|
||||
using Action::Action;
|
||||
class Deadzone
|
||||
{
|
||||
public:
|
||||
void applyDeadzone(float& value);
|
||||
|
||||
void setDeadzoneRadius(float deadzoneRadius);
|
||||
|
||||
private:
|
||||
float mActiveRadiusInner{ 0.f };
|
||||
float mActiveRadiusOuter{ 1.f };
|
||||
float mActiveScale{ 1.f };
|
||||
};
|
||||
|
||||
public:
|
||||
AxisAction(int openMWAction, std::unique_ptr<OpenXRAction> xrAction, std::shared_ptr<AxisAction::Deadzone> deadzone);
|
||||
|
||||
static const XrActionType ActionType = XR_ACTION_TYPE_FLOAT_INPUT;
|
||||
|
||||
void update() override;
|
||||
|
||||
virtual bool shouldQueue() const override { return mActive || onDeactivate(); }
|
||||
|
||||
std::shared_ptr<AxisAction::Deadzone> mDeadzone;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -186,6 +186,10 @@ namespace MWVR
|
|||
{
|
||||
mHapticsEnabled = Settings::Manager::getBool("haptics enabled", "VR");
|
||||
}
|
||||
if (it->first == "Input" && it->second == "joystick dead zone")
|
||||
{
|
||||
setThumbstickDeadzone(Settings::Manager::getFloat("joystick dead zone", "Input"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,6 +275,11 @@ namespace MWVR
|
|||
mXRInput->suggestBindings(actionSet, interactionProfilePath, suggestedBindings);
|
||||
}
|
||||
|
||||
void VRInputManager::setThumbstickDeadzone(float deadzoneRadius)
|
||||
{
|
||||
mAxisDeadzone->setDeadzoneRadius(deadzoneRadius);
|
||||
}
|
||||
|
||||
void VRInputManager::requestRecenter()
|
||||
{
|
||||
// TODO: Hack, should have a cleaner way of accessing this
|
||||
|
@ -298,7 +307,7 @@ namespace MWVR
|
|||
userControllerBindingsFile,
|
||||
controllerBindingsFile,
|
||||
grab)
|
||||
, mXRInput(new OpenXRInput)
|
||||
, mXRInput(new OpenXRInput(mAxisDeadzone))
|
||||
, mXrControllerSuggestionsFile(xrControllerSuggestionsFile)
|
||||
, mHapticsEnabled{ Settings::Manager::getBool("haptics enabled", "VR") }
|
||||
{
|
||||
|
@ -341,6 +350,7 @@ namespace MWVR
|
|||
}
|
||||
|
||||
mXRInput->attachActionSets();
|
||||
setThumbstickDeadzone(Settings::Manager::getFloat("joystick dead zone", "Input"));
|
||||
}
|
||||
|
||||
VRInputManager::~VRInputManager()
|
||||
|
|
|
@ -75,7 +75,10 @@ namespace MWVR
|
|||
void readInteractionProfile(TiXmlElement* element);
|
||||
void readInteractionProfileActionSet(TiXmlElement* element, ActionSet actionSet, std::string profilePath);
|
||||
|
||||
void setThumbstickDeadzone(float deadzoneRadius);
|
||||
|
||||
private:
|
||||
std::shared_ptr<AxisAction::Deadzone> mAxisDeadzone{ new AxisAction::Deadzone };
|
||||
std::unique_ptr<OpenXRInput> mXRInput;
|
||||
std::unique_ptr<RealisticCombat::StateMachine> mRealisticCombat;
|
||||
std::string mXrControllerSuggestionsFile;
|
||||
|
|
Loading…
Reference in a new issue