Files

115 lines
2.8 KiB
C++
Raw Permalink Normal View History

2020-12-05 13:08:24 +01:00
#pragma once
2017-08-15 14:03:07 +02:00
2020-12-22 11:42:57 +03:00
#include "util/types.hpp"
#include "util/atomic.hpp"
#include "Emu/Io/pad_types.h"
#include "Emu/Io/pad_config.h"
2020-12-22 11:42:57 +03:00
#include "Emu/Io/pad_config_types.h"
2026-02-02 11:21:02 +03:00
#include "Input/mouse_gyro_handler.h"
2021-05-28 12:35:03 +03:00
#include "Utilities/mutex.h"
2020-12-22 11:42:57 +03:00
2017-08-15 14:03:07 +02:00
#include <map>
2018-12-17 19:13:35 +01:00
#include <mutex>
2020-12-22 11:42:57 +03:00
#include <string_view>
#include <string>
2017-08-15 14:03:07 +02:00
2020-02-22 20:42:49 +01:00
class PadHandlerBase;
2017-08-15 14:03:07 +02:00
class pad_thread
{
public:
2022-08-05 14:49:32 +02:00
pad_thread(void* curthread, void* curwindow, std::string_view title_id); // void * instead of QThread * and QWindow * because of include in emucore
2021-03-02 19:22:39 +03:00
pad_thread(const pad_thread&) = delete;
pad_thread& operator=(const pad_thread&) = delete;
2017-08-15 14:03:07 +02:00
~pad_thread();
2021-09-07 21:56:49 +02:00
void operator()();
2017-08-15 14:03:07 +02:00
PadInfo& GetInfo() { return m_info; }
2024-11-27 22:16:04 +01:00
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM>& GetPads() { return m_pads; }
void SetRumble(u32 pad, u8 large_motor, u8 small_motor);
2018-12-30 02:34:15 +01:00
void SetIntercepted(bool intercepted);
2017-08-15 14:03:07 +02:00
2019-04-28 23:35:11 +02:00
s32 AddLddPad();
void UnregisterLddPad(u32 handle);
2023-01-14 00:07:07 +01:00
void open_home_menu();
std::map<pad_handler, std::shared_ptr<PadHandlerBase>>& get_handlers() { return m_handlers; }
static std::shared_ptr<PadHandlerBase> GetHandler(pad_handler type);
static void InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr<PadHandlerBase>& handler);
2021-09-07 21:56:49 +02:00
static auto constexpr thread_name = "Pad Thread"sv;
2026-02-02 11:21:02 +03:00
mouse_gyro_handler& get_mouse_gyro() { return m_mouse_gyro; }
2017-08-15 14:03:07 +02:00
protected:
2021-09-07 21:56:49 +02:00
void Init();
void InitLddPad(u32 handle, const u32* port_status);
2017-08-15 14:03:07 +02:00
2018-10-02 20:27:13 +02:00
// List of all handlers
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> m_handlers;
2017-08-15 14:03:07 +02:00
2018-10-02 20:27:13 +02:00
// Used for pad_handler::keyboard
2022-08-05 14:49:32 +02:00
void* m_curthread = nullptr;
void* m_curwindow = nullptr;
2017-08-15 14:03:07 +02:00
PadInfo m_info{ 0, 0, false };
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads{};
std::array<bool, CELL_PAD_MAX_PORT_NUM> m_pads_connected{};
2017-08-15 14:03:07 +02:00
2019-04-28 23:35:11 +02:00
u32 num_ldd_pad = 0;
private:
2025-06-02 00:52:05 +02:00
void apply_copilots();
void update_pad_states();
2023-01-14 00:07:07 +01:00
u32 m_mask_start_press_to_resume = 0;
u64 m_track_start_press_begin_timestamp = 0;
bool m_resume_emulation_flag = false;
bool m_ps_button_pressed = false;
2023-01-14 00:07:07 +01:00
atomic_t<bool> m_home_menu_open = false;
2026-02-02 11:21:02 +03:00
mouse_gyro_handler m_mouse_gyro;
2017-08-15 14:03:07 +02:00
};
2018-12-13 07:24:17 +02:00
namespace pad
{
2025-01-20 22:55:21 +01:00
extern atomic_t<pad_thread*> g_pad_thread;
2021-05-28 12:35:03 +03:00
extern shared_mutex g_pad_mutex;
2018-11-20 16:35:06 +01:00
extern std::string g_title_id;
extern atomic_t<bool> g_enabled;
extern atomic_t<bool> g_reset;
2022-08-05 14:49:32 +02:00
extern atomic_t<bool> g_started;
extern atomic_t<bool> g_home_menu_requested;
2018-12-13 07:24:17 +02:00
2025-01-20 22:55:21 +01:00
static inline class pad_thread* get_pad_thread(bool relaxed = false)
2018-12-13 07:24:17 +02:00
{
if (relaxed)
{
2025-01-20 22:55:21 +01:00
return g_pad_thread.observe();
}
2025-01-20 22:55:21 +01:00
return ensure(g_pad_thread.load());
2019-05-12 23:01:28 +02:00
}
2018-12-30 02:34:15 +01:00
static inline void set_enabled(bool enabled)
{
g_enabled = enabled;
}
static inline void reset(std::string_view title_id)
{
g_title_id = title_id;
2021-09-07 21:56:49 +02:00
g_reset = true;
}
2018-12-30 02:34:15 +01:00
static inline void SetIntercepted(bool intercepted)
{
std::lock_guard lock(g_pad_mutex);
2025-01-20 22:55:21 +01:00
const auto handler = get_pad_thread();
2018-12-30 02:34:15 +01:00
handler->SetIntercepted(intercepted);
}
2018-12-13 07:24:17 +02:00
}