Converting HID API to use be<> auto swapping type.

This commit is contained in:
Ben Vanik
2014-08-19 22:50:21 -07:00
parent 48a0e5c601
commit fb98683ed3
24 changed files with 325 additions and 518 deletions

View File

@@ -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_

View File

@@ -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

View File

@@ -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_

View File

@@ -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

View File

@@ -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_