summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/input/input_sdl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/input/input_sdl.cpp')
-rw-r--r--src/osd/modules/input/input_sdl.cpp81
1 files changed, 47 insertions, 34 deletions
diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp
index ae1ef1515eb..f1fb0241b40 100644
--- a/src/osd/modules/input/input_sdl.cpp
+++ b/src/osd/modules/input/input_sdl.cpp
@@ -1318,26 +1318,20 @@ public:
~sdl_joystick_device()
{
- if (m_joydevice)
- {
- if (m_hapdevice)
- {
- SDL_HapticClose(m_hapdevice);
- m_hapdevice = nullptr;
- }
- SDL_JoystickClose(m_joydevice);
- m_joydevice = nullptr;
- }
+ close_device();
}
virtual void reset() override
{
sdl_joystick_device_base::reset();
- memset(&m_joystick, 0, sizeof(m_joystick));
+ clear_buffer();
}
virtual void process_event(SDL_Event const &event) override
{
+ if (!m_joydevice)
+ return;
+
switch (event.type)
{
case SDL_JOYAXISMOTION:
@@ -1373,17 +1367,8 @@ public:
case SDL_JOYDEVICEREMOVED:
osd_printf_verbose("Joystick: %s [ID %s] disconnected\n", name(), id());
clear_instance();
- reset();
- if (m_joydevice)
- {
- if (m_hapdevice)
- {
- SDL_HapticClose(m_hapdevice);
- m_hapdevice = nullptr;
- }
- SDL_JoystickClose(m_joydevice);
- m_joydevice = nullptr;
- }
+ clear_buffer();
+ close_device();
break;
}
}
@@ -1420,6 +1405,25 @@ protected:
private:
SDL_Joystick *m_joydevice;
SDL_Haptic *m_hapdevice;
+
+ void clear_buffer()
+ {
+ memset(&m_joystick, 0, sizeof(m_joystick));
+ }
+
+ void close_device()
+ {
+ if (m_joydevice)
+ {
+ if (m_hapdevice)
+ {
+ SDL_HapticClose(m_hapdevice);
+ m_hapdevice = nullptr;
+ }
+ SDL_JoystickClose(m_joydevice);
+ m_joydevice = nullptr;
+ }
+ }
};
@@ -1486,11 +1490,7 @@ public:
~sdl_game_controller_device()
{
- if (m_ctrldevice)
- {
- SDL_GameControllerClose(m_ctrldevice);
- m_ctrldevice = nullptr;
- }
+ close_device();
}
virtual void configure(input_device &device) override
@@ -2052,11 +2052,14 @@ public:
virtual void reset() override
{
sdl_joystick_device_base::reset();
- memset(&m_controller, 0, sizeof(m_controller));
+ clear_buffer();
}
virtual void process_event(SDL_Event const &event) override
{
+ if (!m_ctrldevice)
+ return;
+
switch (event.type)
{
case SDL_CONTROLLERAXISMOTION:
@@ -2083,12 +2086,8 @@ public:
case SDL_CONTROLLERDEVICEREMOVED:
osd_printf_verbose("Game Controller: %s [ID %s] disconnected\n", name(), id());
clear_instance();
- reset();
- if (m_ctrldevice)
- {
- SDL_GameControllerClose(m_ctrldevice);
- m_ctrldevice = nullptr;
- }
+ clear_buffer();
+ close_device();
break;
}
}
@@ -2114,6 +2113,20 @@ private:
sdl_controller_state m_controller;
SDL_GameController *m_ctrldevice;
+
+ void clear_buffer()
+ {
+ memset(&m_controller, 0, sizeof(m_controller));
+ }
+
+ void close_device()
+ {
+ if (m_ctrldevice)
+ {
+ SDL_GameControllerClose(m_ctrldevice);
+ m_ctrldevice = nullptr;
+ }
+ }
};