InputManager: Fix mouse-mapped axes getting stuck
Regression from f0deab2
.
This commit is contained in:
parent
dc18ce2c2a
commit
c4e0e7fade
|
@ -1224,13 +1224,15 @@ void InputManager::GenerateRelativeMouseEvents()
|
||||||
{
|
{
|
||||||
PointerAxisState& state = s_pointer_state[device][axis];
|
PointerAxisState& state = s_pointer_state[device][axis];
|
||||||
const float delta = static_cast<float>(state.delta.exchange(0, std::memory_order_acquire)) / 65536.0f;
|
const float delta = static_cast<float>(state.delta.exchange(0, std::memory_order_acquire)) / 65536.0f;
|
||||||
if (delta == 0.0f)
|
const float unclamped_value = delta * s_pointer_axis_scale[axis];
|
||||||
|
const float value = std::clamp(unclamped_value, -1.0f, 1.0f);
|
||||||
|
if (value == state.last_value)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const float unclamped_value = delta * s_pointer_axis_scale[axis];
|
state.last_value = value;
|
||||||
|
|
||||||
const InputBindingKey key(MakePointerAxisKey(device, static_cast<InputPointerAxis>(axis)));
|
const InputBindingKey key(MakePointerAxisKey(device, static_cast<InputPointerAxis>(axis)));
|
||||||
if (axis >= static_cast<u32>(InputPointerAxis::WheelX) &&
|
if (device == 0 && axis >= static_cast<u32>(InputPointerAxis::WheelX) &&
|
||||||
ImGuiManager::ProcessPointerAxisEvent(key, unclamped_value))
|
ImGuiManager::ProcessPointerAxisEvent(key, unclamped_value))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -1239,12 +1241,7 @@ void InputManager::GenerateRelativeMouseEvents()
|
||||||
if (!system_running)
|
if (!system_running)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const float value = std::clamp(unclamped_value, -1.0f, 1.0f);
|
InvokeEvents(key, value, GenericInputBinding::Unknown);
|
||||||
if (value != state.last_value)
|
|
||||||
{
|
|
||||||
state.last_value = value;
|
|
||||||
InvokeEvents(key, value, GenericInputBinding::Unknown);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (delta != 0.0f)
|
if (delta != 0.0f)
|
||||||
{
|
{
|
||||||
|
@ -1302,18 +1299,27 @@ void InputManager::UpdatePointerAbsolutePosition(u32 index, float x, float y)
|
||||||
if (dx != 0.0f)
|
if (dx != 0.0f)
|
||||||
{
|
{
|
||||||
s_pointer_state[index][static_cast<u8>(InputPointerAxis::X)].delta.fetch_add(static_cast<s32>(dx * 65536.0f),
|
s_pointer_state[index][static_cast<u8>(InputPointerAxis::X)].delta.fetch_add(static_cast<s32>(dx * 65536.0f),
|
||||||
std::memory_order_release);
|
std::memory_order_acq_rel);
|
||||||
}
|
}
|
||||||
if (dy != 0.0f)
|
if (dy != 0.0f)
|
||||||
{
|
{
|
||||||
s_pointer_state[index][static_cast<u8>(InputPointerAxis::Y)].delta.fetch_add(static_cast<s32>(dy * 65536.0f),
|
s_pointer_state[index][static_cast<u8>(InputPointerAxis::Y)].delta.fetch_add(static_cast<s32>(dy * 65536.0f),
|
||||||
std::memory_order_release);
|
std::memory_order_acq_rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
ImGuiManager::UpdateMousePosition(x, y);
|
ImGuiManager::UpdateMousePosition(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputManager::ResetPointerRelativeDelta(u32 index)
|
||||||
|
{
|
||||||
|
if (index >= MAX_POINTER_DEVICES || s_relative_mouse_mode_active) [[unlikely]]
|
||||||
|
return;
|
||||||
|
|
||||||
|
s_pointer_state[index][static_cast<u8>(InputPointerAxis::X)].delta.store(0, std::memory_order_release);
|
||||||
|
s_pointer_state[index][static_cast<u8>(InputPointerAxis::Y)].delta.store(0, std::memory_order_release);
|
||||||
|
}
|
||||||
|
|
||||||
void InputManager::UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input)
|
void InputManager::UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input)
|
||||||
{
|
{
|
||||||
if (index >= MAX_POINTER_DEVICES || (axis < InputPointerAxis::WheelX && !s_relative_mouse_mode_active))
|
if (index >= MAX_POINTER_DEVICES || (axis < InputPointerAxis::WheelX && !s_relative_mouse_mode_active))
|
||||||
|
|
|
@ -338,6 +338,9 @@ std::pair<float, float> GetPointerAbsolutePosition(u32 index);
|
||||||
/// Updates absolute pointer position. Can call from UI thread, use when the host only reports absolute coordinates.
|
/// Updates absolute pointer position. Can call from UI thread, use when the host only reports absolute coordinates.
|
||||||
void UpdatePointerAbsolutePosition(u32 index, float x, float y);
|
void UpdatePointerAbsolutePosition(u32 index, float x, float y);
|
||||||
|
|
||||||
|
/// Resets the accumulated pointer movement. Use when pointer tracking was interrupted.
|
||||||
|
void ResetPointerRelativeDelta(u32 index);
|
||||||
|
|
||||||
/// Updates relative pointer position. Can call from the UI thread, use when host supports relative coordinate
|
/// Updates relative pointer position. Can call from the UI thread, use when host supports relative coordinate
|
||||||
/// reporting.
|
/// reporting.
|
||||||
void UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input = false);
|
void UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input = false);
|
||||||
|
|
Loading…
Reference in New Issue