rpcsx/rpcs3/pad_thread.h

68 lines
1.5 KiB
C
Raw Normal View History

#pragma once
#include <map>
#include <thread>
2018-12-17 19:13:35 +01:00
#include <mutex>
#include "../Utilities/types.h"
#include "Emu/Io/PadHandler.h"
struct PadInfo
{
u32 now_connect;
u32 system_info;
};
class pad_thread
{
public:
pad_thread(void* _curthread, void* _curwindow, const std::string& 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();
void Reset(const std::string& title_id = "");
void SetEnabled(bool enabled);
2018-12-30 02:34:15 +01:00
void SetIntercepted(bool intercepted);
protected:
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;
2018-12-30 02:34:15 +01:00
PadInfo m_info{ 0, 0 };
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 };
atomic_t<bool> m_is_intercepted{ false };
std::shared_ptr<std::thread> thread;
};
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);
}
}