rpcsx/rpcs3/Input/pad_thread.h

70 lines
1.6 KiB
C
Raw Normal View History

#pragma once
#include <map>
#include <thread>
2018-12-17 19:13:35 +01:00
#include <mutex>
2020-02-22 20:42:49 +01:00
#include "stdafx.h"
#include "Emu/Io/pad_types.h"
#include "Emu/Io/pad_config_types.h"
2020-02-22 20:42:49 +01:00
class PadHandlerBase;
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
~pad_thread();
PadInfo& GetInfo() { return m_info; }
auto& GetPads() { return m_pads; }
void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor);
2018-12-17 19:13:35 +01:00
void Init();
2019-09-18 01:44:06 +02:00
void Reset(std::string_view title_id);
void SetEnabled(bool enabled);
2018-12-30 02:34:15 +01:00
void SetIntercepted(bool intercepted);
2019-04-28 23:35:11 +02:00
s32 AddLddPad();
void UnregisterLddPad(u32 handle);
protected:
void InitLddPad(u32 handle);
void ThreadFunc();
2018-10-02 20:27:13 +02:00
// List of all handlers
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> handlers;
2018-10-02 20:27:13 +02:00
// Used for pad_handler::keyboard
void *curthread;
void *curwindow;
PadInfo m_info{ 0, 0, false };
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads;
2018-12-17 19:13:35 +01:00
atomic_t<bool> active{ false };
atomic_t<bool> reset{ false };
atomic_t<bool> is_enabled{ true };
std::shared_ptr<std::thread> thread;
2019-04-28 23:35:11 +02:00
u32 num_ldd_pad = 0;
};
namespace pad
{
extern atomic_t<pad_thread*> g_current;
2018-12-17 19:13:35 +01:00
extern std::recursive_mutex g_pad_mutex;
extern std::string g_title_id;
static inline class pad_thread* get_current_handler()
{
return verify(HERE, g_current.load());
2019-05-12 23:01:28 +02:00
}
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);
}
}