summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/input/input_sdl.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2023-02-24 19:31:12 +1100
committer Vas Crabb <vas@vastheman.com>2023-02-24 19:31:12 +1100
commit65aeb63a2a1f4f65a6fa0dedabba1b852a189f96 (patch)
tree42a56bcf4d22b624dbb117946e376981e691a5f0 /src/osd/modules/input/input_sdl.cpp
parent3b5dbeea3bad50ad04c966de4afffb864a9856d0 (diff)
Update accumulating relative inputs exactly once per frame.
This fixes "amplification" effects that would happen if the frame rate rose above 100 Hz (whether by unthrottling or otherwise). Synchronise with wall clock any time inputs are read. Not doing this has weird effects on relative inputs with frame skipping and contributes to unresponsiveness of menus. Reduce visual latency for mouse movement on menus when paused or skipping frames. The rest of the code changes to menus won't provide benefits until draw can happen after event handling.
Diffstat (limited to 'src/osd/modules/input/input_sdl.cpp')
-rw-r--r--src/osd/modules/input/input_sdl.cpp39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp
index ff52fbee478..1eaed99f16b 100644
--- a/src/osd/modules/input/input_sdl.cpp
+++ b/src/osd/modules/input/input_sdl.cpp
@@ -573,9 +573,9 @@ public:
{
}
- virtual void poll() override
+ virtual void poll(bool relative_reset) override
{
- sdl_device::poll();
+ sdl_device::poll(relative_reset);
#ifdef __APPLE__
if (m_keyboard.state[SDL_SCANCODE_CAPSLOCK] && (std::chrono::steady_clock::now() > (m_capslock_pressed + std::chrono::milliseconds(30))))
@@ -655,22 +655,30 @@ class sdl_mouse_device : public sdl_device
public:
sdl_mouse_device(std::string &&name, std::string &&id, input_module &module) :
sdl_device(std::move(name), std::move(id), module),
- m_mouse({0})
+ m_mouse({0}),
+ m_x(0),
+ m_y(0),
+ m_v(0),
+ m_h(0)
{
}
- virtual void poll() override
+ virtual void poll(bool relative_reset) override
{
- m_mouse.lX = 0;
- m_mouse.lY = 0;
- m_mouse.lV = 0;
- m_mouse.lH = 0;
- sdl_device::poll();
+ sdl_device::poll(relative_reset);
+ if (relative_reset)
+ {
+ m_mouse.lX = std::exchange(m_x, 0);
+ m_mouse.lY = std::exchange(m_y, 0);
+ m_mouse.lV = std::exchange(m_v, 0);
+ m_mouse.lH = std::exchange(m_h, 0);
+ }
}
virtual void reset() override
{
memset(&m_mouse, 0, sizeof(m_mouse));
+ m_x = m_y = m_v = m_h = 0;
}
virtual void configure(input_device &device) override
@@ -720,8 +728,8 @@ public:
switch (event.type)
{
case SDL_MOUSEMOTION:
- m_mouse.lX += event.motion.xrel * input_device::RELATIVE_PER_PIXEL;
- m_mouse.lY += event.motion.yrel * input_device::RELATIVE_PER_PIXEL;
+ m_x += event.motion.xrel * input_device::RELATIVE_PER_PIXEL;
+ m_y += event.motion.yrel * input_device::RELATIVE_PER_PIXEL;
break;
case SDL_MOUSEBUTTONDOWN:
@@ -734,11 +742,11 @@ public:
case SDL_MOUSEWHEEL:
#if SDL_VERSION_ATLEAST(2, 0, 18)
- m_mouse.lV += event.wheel.preciseY * input_device::RELATIVE_PER_PIXEL;
- m_mouse.lH += event.wheel.preciseX * input_device::RELATIVE_PER_PIXEL;
+ m_v += event.wheel.preciseY * input_device::RELATIVE_PER_PIXEL;
+ m_h += event.wheel.preciseX * input_device::RELATIVE_PER_PIXEL;
#else
- m_mouse.lV += event.wheel.y * input_device::RELATIVE_PER_PIXEL;
- m_mouse.lH += event.wheel.x * input_device::RELATIVE_PER_PIXEL;
+ m_v += event.wheel.y * input_device::RELATIVE_PER_PIXEL;
+ m_h += event.wheel.x * input_device::RELATIVE_PER_PIXEL;
#endif
break;
}
@@ -753,6 +761,7 @@ private:
};
mouse_state m_mouse;
+ s32 m_x, m_y, m_v, m_h;
};