Converting HID API to use be<> auto swapping type.
This commit is contained in:
@@ -9,14 +9,13 @@
|
||||
|
||||
#include <xenia/hid/input_driver.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::hid;
|
||||
InputDriver::InputDriver(InputSystem* input_system)
|
||||
: input_system_(input_system) {}
|
||||
|
||||
InputDriver::~InputDriver() = default;
|
||||
|
||||
InputDriver::InputDriver(InputSystem* input_system) :
|
||||
input_system_(input_system) {
|
||||
}
|
||||
|
||||
InputDriver::~InputDriver() {
|
||||
}
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
@@ -13,38 +13,32 @@
|
||||
#include <xenia/core.h>
|
||||
#include <xenia/xbox.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
|
||||
class InputSystem;
|
||||
|
||||
|
||||
class InputDriver {
|
||||
public:
|
||||
public:
|
||||
virtual ~InputDriver();
|
||||
|
||||
virtual X_STATUS Setup() = 0;
|
||||
|
||||
virtual X_RESULT GetCapabilities(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps) = 0;
|
||||
virtual X_RESULT GetState(
|
||||
uint32_t user_index, X_INPUT_STATE& out_state) = 0;
|
||||
virtual X_RESULT SetState(
|
||||
uint32_t user_index, X_INPUT_VIBRATION& vibration) = 0;
|
||||
virtual X_RESULT GetKeystroke(
|
||||
uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE& out_keystroke) = 0;
|
||||
virtual X_RESULT GetCapabilities(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_CAPABILITIES* out_caps) = 0;
|
||||
virtual X_RESULT GetState(uint32_t user_index, X_INPUT_STATE* out_state) = 0;
|
||||
virtual X_RESULT SetState(uint32_t user_index,
|
||||
X_INPUT_VIBRATION* vibration) = 0;
|
||||
virtual X_RESULT GetKeystroke(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE* out_keystroke) = 0;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
InputDriver(InputSystem* input_system);
|
||||
|
||||
InputSystem* input_system_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_INPUT_DRIVER_H_
|
||||
|
||||
@@ -13,18 +13,14 @@
|
||||
#include <xenia/cpu/processor.h>
|
||||
#include <xenia/hid/input_driver.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::hid;
|
||||
|
||||
|
||||
InputSystem::InputSystem(Emulator* emulator) :
|
||||
emulator_(emulator), memory_(emulator->memory()) {
|
||||
}
|
||||
InputSystem::InputSystem(Emulator* emulator)
|
||||
: emulator_(emulator), memory_(emulator->memory()) {}
|
||||
|
||||
InputSystem::~InputSystem() {
|
||||
for (auto it = drivers_.begin();
|
||||
it != drivers_.end(); ++it) {
|
||||
for (auto it = drivers_.begin(); it != drivers_.end(); ++it) {
|
||||
InputDriver* driver = *it;
|
||||
delete driver;
|
||||
}
|
||||
@@ -36,12 +32,10 @@ X_STATUS InputSystem::Setup() {
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void InputSystem::AddDriver(InputDriver* driver) {
|
||||
drivers_.push_back(driver);
|
||||
}
|
||||
void InputSystem::AddDriver(InputDriver* driver) { drivers_.push_back(driver); }
|
||||
|
||||
X_RESULT InputSystem::GetCapabilities(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps) {
|
||||
X_RESULT InputSystem::GetCapabilities(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_CAPABILITIES* out_caps) {
|
||||
SCOPE_profile_cpu_f("hid");
|
||||
|
||||
for (auto it = drivers_.begin(); it != drivers_.end(); ++it) {
|
||||
@@ -53,7 +47,7 @@ X_RESULT InputSystem::GetCapabilities(
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
X_RESULT InputSystem::GetState(uint32_t user_index, X_INPUT_STATE& out_state) {
|
||||
X_RESULT InputSystem::GetState(uint32_t user_index, X_INPUT_STATE* out_state) {
|
||||
SCOPE_profile_cpu_f("hid");
|
||||
|
||||
for (auto it = drivers_.begin(); it != drivers_.end(); ++it) {
|
||||
@@ -65,8 +59,8 @@ X_RESULT InputSystem::GetState(uint32_t user_index, X_INPUT_STATE& out_state) {
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
X_RESULT InputSystem::SetState(
|
||||
uint32_t user_index, X_INPUT_VIBRATION& vibration) {
|
||||
X_RESULT InputSystem::SetState(uint32_t user_index,
|
||||
X_INPUT_VIBRATION* vibration) {
|
||||
SCOPE_profile_cpu_f("hid");
|
||||
|
||||
for (auto it = drivers_.begin(); it != drivers_.end(); ++it) {
|
||||
@@ -78,8 +72,8 @@ X_RESULT InputSystem::SetState(
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
X_RESULT InputSystem::GetKeystroke(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke) {
|
||||
X_RESULT InputSystem::GetKeystroke(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE* out_keystroke) {
|
||||
SCOPE_profile_cpu_f("hid");
|
||||
|
||||
for (auto it = drivers_.begin(); it != drivers_.end(); ++it) {
|
||||
@@ -89,4 +83,7 @@ X_RESULT InputSystem::GetKeystroke(
|
||||
}
|
||||
}
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
@@ -15,19 +15,16 @@
|
||||
#include <xenia/core.h>
|
||||
#include <xenia/xbox.h>
|
||||
|
||||
|
||||
XEDECLARECLASS1(xe, Emulator);
|
||||
XEDECLARECLASS2(xe, cpu, Processor);
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
|
||||
class InputDriver;
|
||||
|
||||
|
||||
class InputSystem {
|
||||
public:
|
||||
public:
|
||||
InputSystem(Emulator* emulator);
|
||||
~InputSystem();
|
||||
|
||||
@@ -39,24 +36,22 @@ public:
|
||||
|
||||
void AddDriver(InputDriver* driver);
|
||||
|
||||
X_RESULT GetCapabilities(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps);
|
||||
X_RESULT GetState(uint32_t user_index, X_INPUT_STATE& out_state);
|
||||
X_RESULT SetState(uint32_t user_index, X_INPUT_VIBRATION& vibration);
|
||||
X_RESULT GetCapabilities(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_CAPABILITIES* out_caps);
|
||||
X_RESULT GetState(uint32_t user_index, X_INPUT_STATE* out_state);
|
||||
X_RESULT SetState(uint32_t user_index, X_INPUT_VIBRATION* vibration);
|
||||
X_RESULT GetKeystroke(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE& out_keystroke);
|
||||
X_INPUT_KEYSTROKE* out_keystroke);
|
||||
|
||||
private:
|
||||
Emulator* emulator_;
|
||||
Memory* memory_;
|
||||
cpu::Processor* processor_;
|
||||
private:
|
||||
Emulator* emulator_;
|
||||
Memory* memory_;
|
||||
cpu::Processor* processor_;
|
||||
|
||||
std::vector<InputDriver*> drivers_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_INPUT_SYSTEM_H_
|
||||
|
||||
@@ -11,21 +11,16 @@
|
||||
#define XENIA_HID_NOP_NOP_HID_PRIVATE_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
#include <xenia/hid/nop/nop_hid.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace nop {
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
} // namespace nop
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_NOP_NOP_HID_PRIVATE_H_
|
||||
|
||||
@@ -11,34 +11,32 @@
|
||||
|
||||
#include <xenia/hid/nop/nop_input_driver.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace nop {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::hid;
|
||||
using namespace xe::hid::nop;
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
|
||||
namespace {
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
void CleanupOnShutdown() {
|
||||
}
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
}
|
||||
|
||||
void CleanupOnShutdown() {}
|
||||
|
||||
InputDriver* xe::hid::nop::Create(InputSystem* input_system) {
|
||||
InitializeIfNeeded();
|
||||
return new NopInputDriver(input_system);
|
||||
}
|
||||
|
||||
} // namespace nop
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
@@ -12,22 +12,17 @@
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
|
||||
XEDECLARECLASS2(xe, hid, InputDriver);
|
||||
XEDECLARECLASS2(xe, hid, InputSystem);
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace nop {
|
||||
|
||||
|
||||
InputDriver* Create(InputSystem* input_system);
|
||||
|
||||
|
||||
} // namespace nop
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_NOP_NOP_HID_H_
|
||||
|
||||
@@ -11,42 +11,40 @@
|
||||
|
||||
#include <xenia/hid/hid-private.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace nop {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::hid;
|
||||
using namespace xe::hid::nop;
|
||||
NopInputDriver::NopInputDriver(InputSystem* input_system)
|
||||
: InputDriver(input_system) {}
|
||||
|
||||
NopInputDriver::~NopInputDriver() {}
|
||||
|
||||
NopInputDriver::NopInputDriver(InputSystem* input_system) :
|
||||
InputDriver(input_system) {
|
||||
}
|
||||
|
||||
NopInputDriver::~NopInputDriver() {
|
||||
}
|
||||
|
||||
X_STATUS NopInputDriver::Setup() {
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
X_STATUS NopInputDriver::Setup() { return X_STATUS_SUCCESS; }
|
||||
|
||||
// TODO(benvanik): spoof a device so that games don't stop waiting for
|
||||
// a controller to be plugged in.
|
||||
|
||||
X_RESULT NopInputDriver::GetCapabilities(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps) {
|
||||
X_RESULT NopInputDriver::GetCapabilities(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_CAPABILITIES* out_caps) {
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
X_RESULT NopInputDriver::GetState(
|
||||
uint32_t user_index, X_INPUT_STATE& out_state) {
|
||||
X_RESULT NopInputDriver::GetState(uint32_t user_index,
|
||||
X_INPUT_STATE* out_state) {
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
X_RESULT NopInputDriver::SetState(
|
||||
uint32_t user_index, X_INPUT_VIBRATION& vibration) {
|
||||
X_RESULT NopInputDriver::SetState(uint32_t user_index,
|
||||
X_INPUT_VIBRATION* vibration) {
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
X_RESULT NopInputDriver::GetKeystroke(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke) {
|
||||
X_RESULT NopInputDriver::GetKeystroke(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE* out_keystroke) {
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
} // namespace nop
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
@@ -11,39 +11,30 @@
|
||||
#define XENIA_HID_NOP_NOP_INPUT_DRIVER_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
#include <xenia/hid/input_driver.h>
|
||||
#include <xenia/hid/nop/nop_hid-private.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace nop {
|
||||
|
||||
|
||||
class NopInputDriver : public InputDriver {
|
||||
public:
|
||||
public:
|
||||
NopInputDriver(InputSystem* input_system);
|
||||
virtual ~NopInputDriver();
|
||||
~NopInputDriver() override;
|
||||
|
||||
virtual X_STATUS Setup();
|
||||
X_STATUS Setup() override;
|
||||
|
||||
virtual X_RESULT GetCapabilities(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps);
|
||||
virtual X_RESULT GetState(
|
||||
uint32_t user_index, X_INPUT_STATE& out_state);
|
||||
virtual X_RESULT SetState(
|
||||
uint32_t user_index, X_INPUT_VIBRATION& vibration);
|
||||
virtual X_RESULT GetKeystroke(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke);
|
||||
|
||||
protected:
|
||||
X_RESULT GetCapabilities(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_CAPABILITIES* out_caps) override;
|
||||
X_RESULT GetState(uint32_t user_index, X_INPUT_STATE* out_state) override;
|
||||
X_RESULT SetState(uint32_t user_index, X_INPUT_VIBRATION* vibration) override;
|
||||
X_RESULT GetKeystroke(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE* out_keystroke) override;
|
||||
};
|
||||
|
||||
|
||||
} // namespace nop
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_NOP_NOP_INPUT_DRIVER_H_
|
||||
|
||||
@@ -11,21 +11,16 @@
|
||||
#define XENIA_HID_WINKEY_WINKEY_HID_PRIVATE_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
#include <xenia/hid/winkey/winkey_hid.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace winkey {
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
} // namespace winkey
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_WINKEY_WINKEY_HID_PRIVATE_H_
|
||||
|
||||
@@ -11,34 +11,32 @@
|
||||
|
||||
#include <xenia/hid/winkey/winkey_input_driver.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace winkey {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::hid;
|
||||
using namespace xe::hid::winkey;
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
|
||||
namespace {
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
void CleanupOnShutdown() {
|
||||
}
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
}
|
||||
|
||||
void CleanupOnShutdown() {}
|
||||
|
||||
InputDriver* xe::hid::winkey::Create(InputSystem* input_system) {
|
||||
InitializeIfNeeded();
|
||||
return new WinKeyInputDriver(input_system);
|
||||
}
|
||||
|
||||
} // namespace winkey
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
@@ -12,22 +12,17 @@
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
|
||||
XEDECLARECLASS2(xe, hid, InputDriver);
|
||||
XEDECLARECLASS2(xe, hid, InputSystem);
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace winkey {
|
||||
|
||||
|
||||
InputDriver* Create(InputSystem* input_system);
|
||||
|
||||
|
||||
} // namespace winkey
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_WINKEY_WINKEY_HID_H_
|
||||
|
||||
@@ -11,51 +11,44 @@
|
||||
|
||||
#include <xenia/hid/hid-private.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace winkey {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::hid;
|
||||
using namespace xe::hid::winkey;
|
||||
WinKeyInputDriver::WinKeyInputDriver(InputSystem* input_system)
|
||||
: packet_number_(1), InputDriver(input_system) {}
|
||||
|
||||
WinKeyInputDriver::~WinKeyInputDriver() {}
|
||||
|
||||
WinKeyInputDriver::WinKeyInputDriver(InputSystem* input_system) :
|
||||
packet_number_(1),
|
||||
InputDriver(input_system) {
|
||||
}
|
||||
X_STATUS WinKeyInputDriver::Setup() { return X_STATUS_SUCCESS; }
|
||||
|
||||
WinKeyInputDriver::~WinKeyInputDriver() {
|
||||
}
|
||||
|
||||
X_STATUS WinKeyInputDriver::Setup() {
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
X_RESULT WinKeyInputDriver::GetCapabilities(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps) {
|
||||
X_RESULT WinKeyInputDriver::GetCapabilities(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_CAPABILITIES* out_caps) {
|
||||
if (user_index != 0) {
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
// TODO(benvanik): confirm with a real XInput controller.
|
||||
out_caps.type = 0x01; // XINPUT_DEVTYPE_GAMEPAD
|
||||
out_caps.sub_type = 0x01; // XINPUT_DEVSUBTYPE_GAMEPAD
|
||||
out_caps.flags = 0;
|
||||
out_caps.gamepad.buttons = 0xFFFF;
|
||||
out_caps.gamepad.left_trigger = 0xFF;
|
||||
out_caps.gamepad.right_trigger = 0xFF;
|
||||
out_caps.gamepad.thumb_lx = (int16_t)0xFFFF;
|
||||
out_caps.gamepad.thumb_ly = (int16_t)0xFFFF;
|
||||
out_caps.gamepad.thumb_rx = (int16_t)0xFFFF;
|
||||
out_caps.gamepad.thumb_ry = (int16_t)0xFFFF;
|
||||
out_caps.vibration.left_motor_speed = 0;
|
||||
out_caps.vibration.right_motor_speed = 0;
|
||||
out_caps->type = 0x01; // XINPUT_DEVTYPE_GAMEPAD
|
||||
out_caps->sub_type = 0x01; // XINPUT_DEVSUBTYPE_GAMEPAD
|
||||
out_caps->flags = 0;
|
||||
out_caps->gamepad.buttons = 0xFFFF;
|
||||
out_caps->gamepad.left_trigger = 0xFF;
|
||||
out_caps->gamepad.right_trigger = 0xFF;
|
||||
out_caps->gamepad.thumb_lx = (int16_t)0xFFFF;
|
||||
out_caps->gamepad.thumb_ly = (int16_t)0xFFFF;
|
||||
out_caps->gamepad.thumb_rx = (int16_t)0xFFFF;
|
||||
out_caps->gamepad.thumb_ry = (int16_t)0xFFFF;
|
||||
out_caps->vibration.left_motor_speed = 0;
|
||||
out_caps->vibration.right_motor_speed = 0;
|
||||
return X_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
#define IS_KEY_TOGGLED(key) ((GetKeyState(key) & 0x1) == 0x1)
|
||||
#define IS_KEY_DOWN(key) ((GetAsyncKeyState(key) & 0x8000) == 0x8000)
|
||||
|
||||
X_RESULT WinKeyInputDriver::GetState(
|
||||
uint32_t user_index, X_INPUT_STATE& out_state) {
|
||||
X_RESULT WinKeyInputDriver::GetState(uint32_t user_index,
|
||||
X_INPUT_STATE* out_state) {
|
||||
if (user_index != 0) {
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
@@ -74,19 +67,19 @@ X_RESULT WinKeyInputDriver::GetState(
|
||||
// dpad toggled
|
||||
if (IS_KEY_DOWN(0x41)) {
|
||||
// A
|
||||
buttons |= 0x0004; // XINPUT_GAMEPAD_DPAD_LEFT
|
||||
buttons |= 0x0004; // XINPUT_GAMEPAD_DPAD_LEFT
|
||||
}
|
||||
if (IS_KEY_DOWN(0x44)) {
|
||||
// D
|
||||
buttons |= 0x0008; // XINPUT_GAMEPAD_DPAD_RIGHT
|
||||
buttons |= 0x0008; // XINPUT_GAMEPAD_DPAD_RIGHT
|
||||
}
|
||||
if (IS_KEY_DOWN(0x53)) {
|
||||
// S
|
||||
buttons |= 0x0002; // XINPUT_GAMEPAD_DPAD_DOWN
|
||||
buttons |= 0x0002; // XINPUT_GAMEPAD_DPAD_DOWN
|
||||
}
|
||||
if (IS_KEY_DOWN(0x57)) {
|
||||
// W
|
||||
buttons |= 0x0001; // XINPUT_GAMEPAD_DPAD_UP
|
||||
buttons |= 0x0001; // XINPUT_GAMEPAD_DPAD_UP
|
||||
}
|
||||
} else {
|
||||
// left stick
|
||||
@@ -110,44 +103,44 @@ X_RESULT WinKeyInputDriver::GetState(
|
||||
|
||||
if (IS_KEY_DOWN(0x4C)) {
|
||||
// L
|
||||
buttons |= 0x4000; // XINPUT_GAMEPAD_X
|
||||
buttons |= 0x4000; // XINPUT_GAMEPAD_X
|
||||
}
|
||||
if (IS_KEY_DOWN(VK_OEM_7)) {
|
||||
// '
|
||||
buttons |= 0x2000; // XINPUT_GAMEPAD_B
|
||||
buttons |= 0x2000; // XINPUT_GAMEPAD_B
|
||||
}
|
||||
if (IS_KEY_DOWN(VK_OEM_1)) {
|
||||
// ;
|
||||
buttons |= 0x1000; // XINPUT_GAMEPAD_A
|
||||
buttons |= 0x1000; // XINPUT_GAMEPAD_A
|
||||
}
|
||||
if (IS_KEY_DOWN(0x50)) {
|
||||
// P
|
||||
buttons |= 0x8000; // XINPUT_GAMEPAD_Y
|
||||
buttons |= 0x8000; // XINPUT_GAMEPAD_Y
|
||||
}
|
||||
|
||||
if (IS_KEY_DOWN(0x5A)) {
|
||||
// Z
|
||||
buttons |= 0x0020; // XINPUT_GAMEPAD_BACK
|
||||
buttons |= 0x0020; // XINPUT_GAMEPAD_BACK
|
||||
}
|
||||
if (IS_KEY_DOWN(0x58)) {
|
||||
// X
|
||||
buttons |= 0x0010; // XINPUT_GAMEPAD_START
|
||||
buttons |= 0x0010; // XINPUT_GAMEPAD_START
|
||||
}
|
||||
|
||||
out_state.packet_number = packet_number_;
|
||||
out_state.gamepad.buttons = buttons;
|
||||
out_state.gamepad.left_trigger = left_trigger;
|
||||
out_state.gamepad.right_trigger = right_trigger;
|
||||
out_state.gamepad.thumb_lx = thumb_lx;
|
||||
out_state.gamepad.thumb_ly = thumb_ly;
|
||||
out_state.gamepad.thumb_rx = thumb_rx;
|
||||
out_state.gamepad.thumb_ry = thumb_ry;
|
||||
out_state->packet_number = packet_number_;
|
||||
out_state->gamepad.buttons = buttons;
|
||||
out_state->gamepad.left_trigger = left_trigger;
|
||||
out_state->gamepad.right_trigger = right_trigger;
|
||||
out_state->gamepad.thumb_lx = thumb_lx;
|
||||
out_state->gamepad.thumb_ly = thumb_ly;
|
||||
out_state->gamepad.thumb_rx = thumb_rx;
|
||||
out_state->gamepad.thumb_ry = thumb_ry;
|
||||
|
||||
return X_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
X_RESULT WinKeyInputDriver::SetState(
|
||||
uint32_t user_index, X_INPUT_VIBRATION& vibration) {
|
||||
X_RESULT WinKeyInputDriver::SetState(uint32_t user_index,
|
||||
X_INPUT_VIBRATION* vibration) {
|
||||
if (user_index != 0) {
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
@@ -155,8 +148,8 @@ X_RESULT WinKeyInputDriver::SetState(
|
||||
return X_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
X_RESULT WinKeyInputDriver::GetKeystroke(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke) {
|
||||
X_RESULT WinKeyInputDriver::GetKeystroke(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE* out_keystroke) {
|
||||
if (user_index != 0) {
|
||||
return X_ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
@@ -168,14 +161,18 @@ X_RESULT WinKeyInputDriver::GetKeystroke(
|
||||
uint16_t keystroke_flags = 0;
|
||||
uint8_t hid_code = 0;
|
||||
|
||||
out_keystroke.virtual_key = virtual_key;
|
||||
out_keystroke.unicode = unicode;
|
||||
out_keystroke.flags = keystroke_flags;
|
||||
out_keystroke.user_index = 0;
|
||||
out_keystroke.hid_code = hid_code;
|
||||
out_keystroke->virtual_key = virtual_key;
|
||||
out_keystroke->unicode = unicode;
|
||||
out_keystroke->flags = keystroke_flags;
|
||||
out_keystroke->user_index = 0;
|
||||
out_keystroke->hid_code = hid_code;
|
||||
|
||||
// X_ERROR_EMPTY if no new keys
|
||||
// X_ERROR_DEVICE_NOT_CONNECTED if no device
|
||||
// X_ERROR_SUCCESS if key
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace winkey
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
@@ -11,40 +11,33 @@
|
||||
#define XENIA_HID_WINKEY_WINKEY_DRIVER_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
#include <xenia/hid/input_driver.h>
|
||||
#include <xenia/hid/nop/nop_hid-private.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace winkey {
|
||||
|
||||
|
||||
class WinKeyInputDriver : public InputDriver {
|
||||
public:
|
||||
public:
|
||||
WinKeyInputDriver(InputSystem* input_system);
|
||||
virtual ~WinKeyInputDriver();
|
||||
~WinKeyInputDriver() override;
|
||||
|
||||
virtual X_STATUS Setup();
|
||||
X_STATUS Setup() override;
|
||||
|
||||
virtual X_RESULT GetCapabilities(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps);
|
||||
virtual X_RESULT GetState(
|
||||
uint32_t user_index, X_INPUT_STATE& out_state);
|
||||
virtual X_RESULT SetState(
|
||||
uint32_t user_index, X_INPUT_VIBRATION& vibration);
|
||||
virtual X_RESULT GetKeystroke(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke);
|
||||
X_RESULT GetCapabilities(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_CAPABILITIES* out_caps) override;
|
||||
X_RESULT GetState(uint32_t user_index, X_INPUT_STATE* out_state) override;
|
||||
X_RESULT SetState(uint32_t user_index, X_INPUT_VIBRATION* vibration) override;
|
||||
X_RESULT GetKeystroke(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE* out_keystroke) override;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
uint32_t packet_number_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace winkey
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_WINKEY_WINKEY_DRIVER_H_
|
||||
|
||||
@@ -11,21 +11,16 @@
|
||||
#define XENIA_HID_XINPUT_XINPUT_HID_PRIVATE_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
#include <xenia/hid/xinput/xinput_hid.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace xinput {
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
} // namespace xinput
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_XINPUT_XINPUT_HID_PRIVATE_H_
|
||||
|
||||
@@ -11,34 +11,32 @@
|
||||
|
||||
#include <xenia/hid/xinput/xinput_input_driver.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace xinput {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::hid;
|
||||
using namespace xe::hid::xinput;
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
|
||||
namespace {
|
||||
void InitializeIfNeeded();
|
||||
void CleanupOnShutdown();
|
||||
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
void InitializeIfNeeded() {
|
||||
static bool has_initialized = false;
|
||||
if (has_initialized) {
|
||||
return;
|
||||
}
|
||||
has_initialized = true;
|
||||
|
||||
void CleanupOnShutdown() {
|
||||
}
|
||||
//
|
||||
|
||||
atexit(CleanupOnShutdown);
|
||||
}
|
||||
|
||||
void CleanupOnShutdown() {}
|
||||
|
||||
InputDriver* xe::hid::xinput::Create(InputSystem* input_system) {
|
||||
InitializeIfNeeded();
|
||||
return new XInputInputDriver(input_system);
|
||||
}
|
||||
|
||||
} // namespace xinput
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
@@ -12,22 +12,17 @@
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
|
||||
XEDECLARECLASS2(xe, hid, InputDriver);
|
||||
XEDECLARECLASS2(xe, hid, InputSystem);
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace xinput {
|
||||
|
||||
|
||||
InputDriver* Create(InputSystem* input_system);
|
||||
|
||||
|
||||
} // namespace xinput
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_XINPUT_XINPUT_HID_H_
|
||||
|
||||
@@ -13,95 +13,92 @@
|
||||
|
||||
#include <Xinput.h>
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace xinput {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::hid;
|
||||
using namespace xe::hid::xinput;
|
||||
|
||||
|
||||
XInputInputDriver::XInputInputDriver(InputSystem* input_system) :
|
||||
InputDriver(input_system) {
|
||||
XInputInputDriver::XInputInputDriver(InputSystem* input_system)
|
||||
: InputDriver(input_system) {
|
||||
XInputEnable(TRUE);
|
||||
}
|
||||
|
||||
XInputInputDriver::~XInputInputDriver() {
|
||||
XInputEnable(FALSE);
|
||||
}
|
||||
XInputInputDriver::~XInputInputDriver() { XInputEnable(FALSE); }
|
||||
|
||||
X_STATUS XInputInputDriver::Setup() {
|
||||
return X_STATUS_SUCCESS;
|
||||
}
|
||||
X_STATUS XInputInputDriver::Setup() { return X_STATUS_SUCCESS; }
|
||||
|
||||
X_RESULT XInputInputDriver::GetCapabilities(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps) {
|
||||
X_RESULT XInputInputDriver::GetCapabilities(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_CAPABILITIES* out_caps) {
|
||||
XINPUT_CAPABILITIES native_caps;
|
||||
DWORD result = XInputGetCapabilities(user_index, flags, &native_caps);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
out_caps.type = native_caps.Type;
|
||||
out_caps.sub_type = native_caps.SubType;
|
||||
out_caps.flags = native_caps.Flags;
|
||||
out_caps.gamepad.buttons = native_caps.Gamepad.wButtons;
|
||||
out_caps.gamepad.left_trigger = native_caps.Gamepad.bLeftTrigger;
|
||||
out_caps.gamepad.right_trigger = native_caps.Gamepad.bRightTrigger;
|
||||
out_caps.gamepad.thumb_lx = native_caps.Gamepad.sThumbLX;
|
||||
out_caps.gamepad.thumb_ly = native_caps.Gamepad.sThumbLY;
|
||||
out_caps.gamepad.thumb_rx = native_caps.Gamepad.sThumbRX;
|
||||
out_caps.gamepad.thumb_ry = native_caps.Gamepad.sThumbRY;
|
||||
out_caps.vibration.left_motor_speed =
|
||||
native_caps.Vibration.wLeftMotorSpeed;
|
||||
out_caps.vibration.right_motor_speed =
|
||||
out_caps->type = native_caps.Type;
|
||||
out_caps->sub_type = native_caps.SubType;
|
||||
out_caps->flags = native_caps.Flags;
|
||||
out_caps->gamepad.buttons = native_caps.Gamepad.wButtons;
|
||||
out_caps->gamepad.left_trigger = native_caps.Gamepad.bLeftTrigger;
|
||||
out_caps->gamepad.right_trigger = native_caps.Gamepad.bRightTrigger;
|
||||
out_caps->gamepad.thumb_lx = native_caps.Gamepad.sThumbLX;
|
||||
out_caps->gamepad.thumb_ly = native_caps.Gamepad.sThumbLY;
|
||||
out_caps->gamepad.thumb_rx = native_caps.Gamepad.sThumbRX;
|
||||
out_caps->gamepad.thumb_ry = native_caps.Gamepad.sThumbRY;
|
||||
out_caps->vibration.left_motor_speed = native_caps.Vibration.wLeftMotorSpeed;
|
||||
out_caps->vibration.right_motor_speed =
|
||||
native_caps.Vibration.wRightMotorSpeed;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
X_RESULT XInputInputDriver::GetState(
|
||||
uint32_t user_index, X_INPUT_STATE& out_state) {
|
||||
X_RESULT XInputInputDriver::GetState(uint32_t user_index,
|
||||
X_INPUT_STATE* out_state) {
|
||||
XINPUT_STATE native_state;
|
||||
DWORD result = XInputGetState(user_index, &native_state);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
out_state.packet_number = native_state.dwPacketNumber;
|
||||
out_state.gamepad.buttons = native_state.Gamepad.wButtons;
|
||||
out_state.gamepad.left_trigger = native_state.Gamepad.bLeftTrigger;
|
||||
out_state.gamepad.right_trigger = native_state.Gamepad.bRightTrigger;
|
||||
out_state.gamepad.thumb_lx = native_state.Gamepad.sThumbLX;
|
||||
out_state.gamepad.thumb_ly = native_state.Gamepad.sThumbLY;
|
||||
out_state.gamepad.thumb_rx = native_state.Gamepad.sThumbRX;
|
||||
out_state.gamepad.thumb_ry = native_state.Gamepad.sThumbRY;
|
||||
out_state->packet_number = native_state.dwPacketNumber;
|
||||
out_state->gamepad.buttons = native_state.Gamepad.wButtons;
|
||||
out_state->gamepad.left_trigger = native_state.Gamepad.bLeftTrigger;
|
||||
out_state->gamepad.right_trigger = native_state.Gamepad.bRightTrigger;
|
||||
out_state->gamepad.thumb_lx = native_state.Gamepad.sThumbLX;
|
||||
out_state->gamepad.thumb_ly = native_state.Gamepad.sThumbLY;
|
||||
out_state->gamepad.thumb_rx = native_state.Gamepad.sThumbRX;
|
||||
out_state->gamepad.thumb_ry = native_state.Gamepad.sThumbRY;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
X_RESULT XInputInputDriver::SetState(
|
||||
uint32_t user_index, X_INPUT_VIBRATION& vibration) {
|
||||
X_RESULT XInputInputDriver::SetState(uint32_t user_index,
|
||||
X_INPUT_VIBRATION* vibration) {
|
||||
XINPUT_VIBRATION native_vibration;
|
||||
native_vibration.wLeftMotorSpeed = vibration.left_motor_speed;
|
||||
native_vibration.wRightMotorSpeed= vibration.right_motor_speed;
|
||||
native_vibration.wLeftMotorSpeed = vibration->left_motor_speed;
|
||||
native_vibration.wRightMotorSpeed = vibration->right_motor_speed;
|
||||
DWORD result = XInputSetState(user_index, &native_vibration);
|
||||
return result;
|
||||
}
|
||||
|
||||
X_RESULT XInputInputDriver::GetKeystroke(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke) {
|
||||
X_RESULT XInputInputDriver::GetKeystroke(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE* out_keystroke) {
|
||||
// We may want to filter flags/user_index before sending to native.
|
||||
// flags is reserved on desktop.
|
||||
XINPUT_KEYSTROKE native_keystroke;
|
||||
DWORD result = XInputGetKeystroke(user_index, flags, &native_keystroke);
|
||||
if (result == ERROR_SUCCESS) {
|
||||
out_keystroke.virtual_key = native_keystroke.VirtualKey;
|
||||
out_keystroke.unicode = native_keystroke.Unicode;
|
||||
out_keystroke.flags = native_keystroke.Flags;
|
||||
out_keystroke.user_index = native_keystroke.UserIndex;
|
||||
out_keystroke.hid_code = native_keystroke.HidCode;
|
||||
out_keystroke->virtual_key = native_keystroke.VirtualKey;
|
||||
out_keystroke->unicode = native_keystroke.Unicode;
|
||||
out_keystroke->flags = native_keystroke.Flags;
|
||||
out_keystroke->user_index = native_keystroke.UserIndex;
|
||||
out_keystroke->hid_code = native_keystroke.HidCode;
|
||||
}
|
||||
// X_ERROR_EMPTY if no new keys
|
||||
// X_ERROR_DEVICE_NOT_CONNECTED if no device
|
||||
// X_ERROR_SUCCESS if key
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace xinput
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
@@ -11,39 +11,32 @@
|
||||
#define XENIA_HID_XINPUT_XINPUT_DRIVER_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
#include <xenia/hid/input_driver.h>
|
||||
#include <xenia/hid/nop/nop_hid-private.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace hid {
|
||||
namespace xinput {
|
||||
|
||||
|
||||
class XInputInputDriver : public InputDriver {
|
||||
public:
|
||||
public:
|
||||
XInputInputDriver(InputSystem* input_system);
|
||||
virtual ~XInputInputDriver();
|
||||
~XInputInputDriver() override;
|
||||
|
||||
virtual X_STATUS Setup();
|
||||
X_STATUS Setup() override;
|
||||
|
||||
virtual X_RESULT GetCapabilities(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps);
|
||||
virtual X_RESULT GetState(
|
||||
uint32_t user_index, X_INPUT_STATE& out_state);
|
||||
virtual X_RESULT SetState(
|
||||
uint32_t user_index, X_INPUT_VIBRATION& vibration);
|
||||
virtual X_RESULT GetKeystroke(
|
||||
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke);
|
||||
X_RESULT GetCapabilities(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_CAPABILITIES* out_caps) override;
|
||||
X_RESULT GetState(uint32_t user_index, X_INPUT_STATE* out_state) override;
|
||||
X_RESULT SetState(uint32_t user_index, X_INPUT_VIBRATION* vibration) override;
|
||||
X_RESULT GetKeystroke(uint32_t user_index, uint32_t flags,
|
||||
X_INPUT_KEYSTROKE* out_keystroke) override;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
} // namespace xinput
|
||||
} // namespace hid
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_HID_XINPUT_XINPUT_DRIVER_H_
|
||||
|
||||
Reference in New Issue
Block a user