2020-12-05 13:08:24 +01:00
|
|
|
#pragma once
|
2017-08-15 14:03:07 +02:00
|
|
|
|
2020-12-22 09:42:57 +01:00
|
|
|
#include "util/types.hpp"
|
|
|
|
|
#include "util/atomic.hpp"
|
|
|
|
|
#include "Emu/Io/pad_types.h"
|
|
|
|
|
#include "Emu/Io/pad_config_types.h"
|
|
|
|
|
|
2017-08-15 14:03:07 +02:00
|
|
|
#include <map>
|
|
|
|
|
#include <thread>
|
2018-12-17 19:13:35 +01:00
|
|
|
#include <mutex>
|
2020-12-22 09:42:57 +01: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:
|
2019-09-18 01:44:06 +02:00
|
|
|
pad_thread(void* _curthread, void* _curwindow, std::string_view title_id); // void * instead of QThread * and QWindow * because of include in emucore
|
2017-08-15 14:03:07 +02:00
|
|
|
~pad_thread();
|
|
|
|
|
|
|
|
|
|
PadInfo& GetInfo() { return m_info; }
|
2019-03-11 08:30:00 +01:00
|
|
|
auto& GetPads() { return m_pads; }
|
2017-08-15 14:03:07 +02:00
|
|
|
void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor);
|
2018-12-17 19:13:35 +01:00
|
|
|
void Init();
|
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);
|
|
|
|
|
|
2017-08-15 14:03:07 +02:00
|
|
|
protected:
|
2020-05-08 21:41:05 +02:00
|
|
|
void InitLddPad(u32 handle);
|
2017-08-15 14:03:07 +02:00
|
|
|
void ThreadFunc();
|
|
|
|
|
|
2018-10-02 20:27:13 +02:00
|
|
|
// List of all handlers
|
2017-08-15 14:03:07 +02:00
|
|
|
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> handlers;
|
|
|
|
|
|
2018-10-02 20:27:13 +02:00
|
|
|
// Used for pad_handler::keyboard
|
2017-08-15 14:03:07 +02:00
|
|
|
void *curthread;
|
|
|
|
|
void *curwindow;
|
|
|
|
|
|
2019-09-20 10:12:01 +02:00
|
|
|
PadInfo m_info{ 0, 0, false };
|
2019-03-11 08:30:00 +01:00
|
|
|
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads;
|
2017-08-15 14:03:07 +02:00
|
|
|
|
|
|
|
|
std::shared_ptr<std::thread> thread;
|
2019-04-28 23:35:11 +02:00
|
|
|
|
|
|
|
|
u32 num_ldd_pad = 0;
|
2017-08-15 14:03:07 +02:00
|
|
|
};
|
2018-12-13 06:24:17 +01:00
|
|
|
|
|
|
|
|
namespace pad
|
|
|
|
|
{
|
|
|
|
|
extern atomic_t<pad_thread*> g_current;
|
2018-12-17 19:13:35 +01:00
|
|
|
extern std::recursive_mutex g_pad_mutex;
|
2018-11-20 16:35:06 +01:00
|
|
|
extern std::string g_title_id;
|
2020-06-24 17:01:48 +02:00
|
|
|
extern atomic_t<bool> g_enabled;
|
|
|
|
|
extern atomic_t<bool> g_reset;
|
|
|
|
|
extern atomic_t<bool> g_active;
|
2018-12-13 06:24:17 +01:00
|
|
|
|
2020-06-24 17:01:48 +02:00
|
|
|
static inline class pad_thread* get_current_handler(bool relaxed = false)
|
2018-12-13 06:24:17 +01:00
|
|
|
{
|
2020-06-24 17:01:48 +02:00
|
|
|
if (relaxed)
|
|
|
|
|
{
|
2020-12-09 08:47:45 +01:00
|
|
|
return g_current.observe();
|
2020-06-24 17:01:48 +02:00
|
|
|
}
|
|
|
|
|
|
2020-12-09 08:47:45 +01:00
|
|
|
return ensure(g_current.load());
|
2019-05-12 23:01:28 +02:00
|
|
|
}
|
2018-12-30 02:34:15 +01:00
|
|
|
|
2020-06-24 17:01:48 +02: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;
|
|
|
|
|
g_reset = g_active.load();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-30 02:34:15 +01:00
|
|
|
static inline void SetIntercepted(bool intercepted)
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard lock(g_pad_mutex);
|
|
|
|
|
const auto handler = get_current_handler();
|
|
|
|
|
handler->SetIntercepted(intercepted);
|
|
|
|
|
}
|
2018-12-13 06:24:17 +01:00
|
|
|
}
|