Skip to content

Commit

Permalink
SDL handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Oct 16, 2022
1 parent fafae1c commit d9f4070
Show file tree
Hide file tree
Showing 22 changed files with 1,040 additions and 24 deletions.
2 changes: 1 addition & 1 deletion rpcs3/Emu/Io/Null/NullPadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class NullPadHandler final : public PadHandlerBase
return true;
}

void ThreadProc() override
void process() override
{
}
};
2 changes: 1 addition & 1 deletion rpcs3/Emu/Io/PadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ void PadHandlerBase::get_mapping(const pad_ensemble& binding)
}
}

void PadHandlerBase::ThreadProc()
void PadHandlerBase::process()
{
for (usz i = 0; i < m_bindings.size(); ++i)
{
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/Emu/Io/PadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class PadHandlerBase
u32 connected_devices = 0;

pad_handler m_type;
bool m_is_init = false;

std::string name_string() const;
usz max_devices() const;
Expand All @@ -200,7 +201,7 @@ class PadHandlerBase
// Return list of devices for that handler
virtual std::vector<pad_list_entry> list_devices() = 0;
// Callback called during pad_thread::ThreadFunc
virtual void ThreadProc();
virtual void process();
// Binds a Pad to a device
virtual bool bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id);
virtual void init_config(cfg_pad* cfg) = 0;
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/Io/pad_config_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void fmt_class_string<pad_handler>::format(std::string& out, u64 arg)
#ifdef _WIN32
case pad_handler::xinput: return "XInput";
case pad_handler::mm: return "MMJoystick";
case pad_handler::sdl: return "SDL";
#endif
#ifdef HAVE_LIBEVDEV
case pad_handler::evdev: return "Evdev";
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/Io/pad_config_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum class pad_handler
#ifdef _WIN32
xinput,
mm,
sdl,
#endif
#ifdef HAVE_LIBEVDEV
evdev,
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/Overlays/overlay_controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ namespace rsx
{
if (sinus_modifier >= 0)
{
static const f32 PI = 3.14159265f;
static constexpr f32 PI = 3.14159265f;
const f32 pulse_sinus_x = static_cast<f32>(get_system_time() / 1000) * pulse_speed_modifier;
pulse_sinus_offset = fmod(pulse_sinus_x + sinus_modifier * PI, 2.0f * PI);
}
Expand Down
1 change: 0 additions & 1 deletion rpcs3/Input/evdev_joystick_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ class evdev_joystick_handler final : public PadHandlerBase
std::shared_ptr<EvdevDevice> m_dev;
bool m_is_button_or_trigger;
bool m_is_negative;
bool m_is_init = false;

bool check_button(const EvdevButton& b, const u32 code);
bool check_buttons(const std::array<EvdevButton, 4>& b, const u32 code);
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Input/hid_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ bool hid_pad_handler<Device>::Init()
}

template <class Device>
void hid_pad_handler<Device>::ThreadProc()
void hid_pad_handler<Device>::process()
{
update_devices();

PadHandlerBase::ThreadProc();
PadHandlerBase::process();
}

template <class Device>
Expand Down Expand Up @@ -240,9 +240,9 @@ std::shared_ptr<PadDevice> hid_pad_handler<Device>::get_device(const std::string
}

template <class Device>
u32 hid_pad_handler<Device>::get_battery_color(u8 battery_level, int brightness)
u32 hid_pad_handler<Device>::get_battery_color(u8 battery_level, u32 brightness)
{
static const std::array<u32, 12> battery_level_clr = {0xff00, 0xff33, 0xff66, 0xff99, 0xffcc, 0xffff, 0xccff, 0x99ff, 0x66ff, 0x33ff, 0x00ff, 0x00ff};
static constexpr std::array<u32, 12> battery_level_clr = {0xff00, 0xff33, 0xff66, 0xff99, 0xffcc, 0xffff, 0xccff, 0x99ff, 0x66ff, 0x33ff, 0x00ff, 0x00ff};

const u32 combined_color = battery_level_clr[battery_level < battery_level_clr.size() ? battery_level : 0];

Expand Down
5 changes: 2 additions & 3 deletions rpcs3/Input/hid_pad_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class hid_pad_handler : public PadHandlerBase
~hid_pad_handler();

bool Init() override;
void ThreadProc() override;
void process() override;
std::vector<pad_list_entry> list_devices() override;

protected:
Expand All @@ -77,7 +77,6 @@ class hid_pad_handler : public PadHandlerBase
// pseudo 'controller id' to keep track of unique controllers
std::map<std::string, std::shared_ptr<Device>> m_controllers;

bool m_is_init = false;
std::set<std::string> m_last_enumerated_devices;
std::set<std::string> m_new_enumerated_devices;
std::map<std::string, std::wstring_view> m_enumerated_serials;
Expand Down Expand Up @@ -112,7 +111,7 @@ class hid_pad_handler : public PadHandlerBase
return *static_cast<const u32*>(buf);
}

static u32 get_battery_color(u8 battery_level, int brightness);
static u32 get_battery_color(u8 battery_level, u32 brightness);

private:
std::shared_ptr<PadDevice> get_device(const std::string& device) override;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Input/keyboard_pad_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_i
return true;
}

void keyboard_pad_handler::ThreadProc()
void keyboard_pad_handler::process()
{
static const double stick_interval = 10.0;
static const double button_interval = 10.0;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Input/keyboard_pad_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class keyboard_pad_handler final : public QObject, public PadHandlerBase
std::vector<pad_list_entry> list_devices() override;
void get_next_button_press(const std::string& /*padId*/, const pad_callback& /*callback*/, const pad_fail_callback& /*fail_callback*/, bool /*get_blacklist*/ = false, const std::vector<std::string>& /*buttons*/ = {}) override {}
bool bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id) override;
void ThreadProc() override;
void process() override;

std::string GetMouseName(const QMouseEvent* event) const;
std::string GetMouseName(u32 button) const;
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Input/mm_joystick_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void mm_joystick_handler::init_config(cfg_pad* cfg)

bool mm_joystick_handler::Init()
{
if (is_init)
if (m_is_init)
return true;

m_devices.clear();
Expand All @@ -97,7 +97,7 @@ bool mm_joystick_handler::Init()
m_devices.emplace(i, dev);
}

is_init = true;
m_is_init = true;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Input/mm_joystick_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class mm_joystick_handler final : public PadHandlerBase
int GetIDByName(const std::string& name);
bool GetMMJOYDevice(int index, MMJOYDevice* dev) const;

bool is_init = false;
bool m_is_init = false;

std::vector<u64> m_blacklist;
std::unordered_map<int, MMJOYDevice> m_devices;
Expand Down
10 changes: 8 additions & 2 deletions rpcs3/Input/pad_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifdef _WIN32
#include "xinput_pad_handler.h"
#include "mm_joystick_handler.h"
#include "sdl_pad_handler.h"
#elif HAVE_LIBEVDEV
#include "evdev_joystick_handler.h"
#endif
Expand Down Expand Up @@ -163,6 +164,9 @@ void pad_thread::Init()
case pad_handler::mm:
cur_pad_handler = std::make_shared<mm_joystick_handler>();
break;
case pad_handler::sdl:
cur_pad_handler = std::make_shared<sdl_pad_handler>();
break;
#endif
#ifdef HAVE_LIBEVDEV
case pad_handler::evdev:
Expand Down Expand Up @@ -278,7 +282,7 @@ void pad_thread::operator()()
continue;
}

handler->ThreadProc();
handler->process();

thread_ctrl::wait_for(g_cfg.io.pad_sleep);
}
Expand Down Expand Up @@ -325,7 +329,7 @@ void pad_thread::operator()()
{
for (auto& handler : handlers)
{
handler.second->ThreadProc();
handler.second->process();
connected_devices += handler.second->connected_devices;
}
}
Expand Down Expand Up @@ -452,6 +456,8 @@ std::shared_ptr<PadHandlerBase> pad_thread::GetHandler(pad_handler type)
return std::make_unique<xinput_pad_handler>();
case pad_handler::mm:
return std::make_unique<mm_joystick_handler>();
case pad_handler::sdl:
return std::make_unique<sdl_pad_handler>();
#endif
#ifdef HAVE_LIBEVDEV
case pad_handler::evdev:
Expand Down
Loading

0 comments on commit d9f4070

Please sign in to comment.