mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige GamePad
This commit is contained in:
parent
6dada4f616
commit
9bcce79410
@ -3,10 +3,11 @@
|
||||
#include "platform-dx/audioengine-dx.hpp"
|
||||
#include "platform-dx/device-dx.hpp"
|
||||
#include "platform-dx/game-dx.hpp"
|
||||
#include "platform-dx/gamepad-dx.hpp"
|
||||
#include "input/gamepad.hpp"
|
||||
#include "platform-dx/gdevicemanager-dx.hpp"
|
||||
#include "platform-dx/keyboard-dx.hpp"
|
||||
#include "platform-dx/mouse-dx.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "platform-dx/window-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
@ -42,6 +43,7 @@ namespace xna {
|
||||
void Game::Initialize() {
|
||||
Keyboard::Initialize();
|
||||
Mouse::Initialize();
|
||||
GamePad::Initialize();
|
||||
|
||||
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
|
||||
Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
|
||||
|
@ -1,39 +1,94 @@
|
||||
#include "platform-dx/gamepad-dx.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
#include "input/gamepad.hpp"
|
||||
|
||||
namespace xna {
|
||||
GamePadState _GamePad::GetState(PlayerIndex index) {
|
||||
if (!_dxGamePad)
|
||||
return GamePadState();
|
||||
|
||||
const auto state = _dxGamePad->GetState(
|
||||
static_cast<int>(index)
|
||||
);
|
||||
return GamePadState(state);
|
||||
|
||||
void GamePad::Initialize() {
|
||||
impl = uNew<PlatformImplementation>();
|
||||
}
|
||||
|
||||
GamePadState _GamePad::GetState(PlayerIndex index, GamePadDeadZone deadZone) {
|
||||
if (!_dxGamePad)
|
||||
GamePadState GamePad::GetState(PlayerIndex index) {
|
||||
if (!impl || !impl->_dxGamePad)
|
||||
return GamePadState();
|
||||
|
||||
const auto state = _dxGamePad->GetState(
|
||||
const auto state = impl->_dxGamePad->GetState(
|
||||
static_cast<int>(index)
|
||||
);
|
||||
|
||||
GamePadState pad;
|
||||
pad.Dpad = GamePadDPad(
|
||||
static_cast<ButtonState>(state.dpad.up),
|
||||
static_cast<ButtonState>(state.dpad.right),
|
||||
static_cast<ButtonState>(state.dpad.down),
|
||||
static_cast<ButtonState>(state.dpad.left));
|
||||
|
||||
pad.IsConnected = state.connected;
|
||||
pad.PackedNumber = state.packet;
|
||||
pad.Sticks = GamePadThumbSticks(
|
||||
Vector2(state.thumbSticks.leftX, state.thumbSticks.leftY),
|
||||
Vector2(state.thumbSticks.rightX, state.thumbSticks.rightY));
|
||||
pad.Triggers = GamePadTriggers(state.triggers.left, state.triggers.right);
|
||||
pad.Buttons = GamePadButtons(
|
||||
static_cast<ButtonState>(state.buttons.a),
|
||||
static_cast<ButtonState>(state.buttons.b),
|
||||
static_cast<ButtonState>(state.buttons.x),
|
||||
static_cast<ButtonState>(state.buttons.y),
|
||||
static_cast<ButtonState>(state.buttons.leftStick),
|
||||
static_cast<ButtonState>(state.buttons.rightStick),
|
||||
static_cast<ButtonState>(state.buttons.leftShoulder),
|
||||
static_cast<ButtonState>(state.buttons.rightShoulder),
|
||||
static_cast<ButtonState>(state.buttons.back),
|
||||
static_cast<ButtonState>(state.buttons.start),
|
||||
static_cast<ButtonState>(state.buttons.view));
|
||||
|
||||
return pad;
|
||||
}
|
||||
|
||||
GamePadState GamePad::GetState(PlayerIndex index, GamePadDeadZone deadZone) {
|
||||
if (!impl || !impl->_dxGamePad)
|
||||
return GamePadState();
|
||||
|
||||
const auto state = impl->_dxGamePad->GetState(
|
||||
static_cast<int>(index),
|
||||
static_cast<DirectX::GamePad::DeadZone>(deadZone)
|
||||
);
|
||||
return GamePadState(state);
|
||||
|
||||
GamePadState pad;
|
||||
pad.Dpad = GamePadDPad(
|
||||
static_cast<ButtonState>(state.dpad.up),
|
||||
static_cast<ButtonState>(state.dpad.right),
|
||||
static_cast<ButtonState>(state.dpad.down),
|
||||
static_cast<ButtonState>(state.dpad.left));
|
||||
|
||||
pad.IsConnected = state.connected;
|
||||
pad.PackedNumber = state.packet;
|
||||
pad.Sticks = GamePadThumbSticks(
|
||||
Vector2(state.thumbSticks.leftX, state.thumbSticks.leftY),
|
||||
Vector2(state.thumbSticks.rightX, state.thumbSticks.rightY));
|
||||
pad.Triggers = GamePadTriggers(state.triggers.left, state.triggers.right);
|
||||
|
||||
return pad;
|
||||
}
|
||||
|
||||
GamePadCapabilities _GamePad::GetCapabilities(PlayerIndex index) {
|
||||
if (!_dxGamePad)
|
||||
GamePadCapabilities GamePad::GetCapabilities(PlayerIndex index) {
|
||||
if (!impl || !impl->_dxGamePad)
|
||||
return GamePadCapabilities();
|
||||
|
||||
const auto capabilities = _dxGamePad->GetCapabilities(static_cast<int>(index));
|
||||
return GamePadCapabilities(capabilities);
|
||||
const auto capabilities = impl->_dxGamePad->GetCapabilities(static_cast<int>(index));
|
||||
GamePadCapabilities cap;
|
||||
cap.Connected = capabilities.connected;
|
||||
cap.Id = capabilities.id;
|
||||
cap.Pid = capabilities.pid;
|
||||
cap.Type = static_cast<GamePadCapabilitiesType>(capabilities.gamepadType);
|
||||
cap.Vid = capabilities.vid;
|
||||
return cap;
|
||||
}
|
||||
|
||||
bool _GamePad::SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger) {
|
||||
if (!_dxGamePad)
|
||||
bool GamePad::SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger) {
|
||||
if (!impl || !impl->_dxGamePad)
|
||||
return false;
|
||||
|
||||
return _dxGamePad->SetVibration(static_cast<int>(index), leftMotor, rightMotor, leftTrigger, rightTrigger);
|
||||
return impl->_dxGamePad->SetVibration(static_cast<int>(index), leftMotor, rightMotor, leftTrigger, rightTrigger);
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
#include "platform-dx/window-dx.hpp"
|
||||
#include "platform-dx/keyboard-dx.hpp"
|
||||
#include "platform-dx/mouse-dx.hpp"
|
||||
#include "platform-dx/gamepad-dx.hpp"
|
||||
#include "input/gamepad.hpp"
|
||||
#include "platform-dx/implementations.hpp"
|
||||
|
||||
namespace xna {
|
||||
GameWindow::GameWindow() {
|
||||
@ -170,10 +171,12 @@ namespace xna {
|
||||
Mouse::_dxMouse->ProcessMessage(msg, wParam, lParam);
|
||||
break;
|
||||
case WM_KILLFOCUS:
|
||||
if(GamePad._dxGamePad) GamePad._dxGamePad->Suspend();
|
||||
if(GamePad::impl->_dxGamePad)
|
||||
GamePad::impl->_dxGamePad->Suspend();
|
||||
break;
|
||||
case WM_SETFOCUS:
|
||||
if (GamePad._dxGamePad) GamePad._dxGamePad->Resume();
|
||||
if (GamePad::impl->_dxGamePad)
|
||||
GamePad::impl->_dxGamePad->Resume();
|
||||
break;
|
||||
}
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
|
@ -34,7 +34,7 @@ namespace xna {
|
||||
}
|
||||
|
||||
void Update(GameTime const& gameTime) override {
|
||||
if (Keyboard::GetState().IsKeyDown(Keys::Escape) || GamePad.GetState(PlayerIndex::One).IsButtonDown(Buttons::Back))
|
||||
if (Keyboard::GetState().IsKeyDown(Keys::Escape) || GamePad::GetState(PlayerIndex::One).IsButtonDown(Buttons::Back))
|
||||
Exit();
|
||||
|
||||
Game::Update(gameTime);
|
||||
|
@ -5,68 +5,246 @@
|
||||
#include "../common/numerics.hpp"
|
||||
|
||||
namespace xna {
|
||||
struct IGamePadTriggers {
|
||||
struct GamePadTriggers {
|
||||
constexpr GamePadTriggers() = default;
|
||||
|
||||
constexpr GamePadTriggers(float left, float right) : _left(left), _right(right) {
|
||||
clamp();
|
||||
}
|
||||
|
||||
constexpr float Left() const {
|
||||
return _left;
|
||||
}
|
||||
|
||||
constexpr float Right() const {
|
||||
return _right;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const GamePadTriggers& other) const {
|
||||
return _left == other._left && _right == other._right;
|
||||
}
|
||||
|
||||
public:
|
||||
virtual float Left() const = 0;
|
||||
virtual float Right() const = 0;
|
||||
float _left{ 0 };
|
||||
float _right{ 0 };
|
||||
|
||||
private:
|
||||
void constexpr clamp() {
|
||||
_left = _left < 1.0F ? _left : 1.0F;
|
||||
_left = _left > 0.0F ? _left : 0.0F;
|
||||
_right = _right < 1.0F ? _right : 1.0F;
|
||||
_right = _right > 0.0F ? _right : 0.0F;
|
||||
}
|
||||
};
|
||||
|
||||
struct IGamePadThumbSticks {
|
||||
public:
|
||||
virtual Vector2 Left() const = 0;
|
||||
virtual Vector2 Right() const = 0;
|
||||
struct GamePadThumbSticks {
|
||||
constexpr GamePadThumbSticks() = default;
|
||||
|
||||
constexpr GamePadThumbSticks(Vector2 left, Vector2 right) : _left(left), _right(right) {
|
||||
clamp();
|
||||
}
|
||||
|
||||
constexpr Vector2 Left() const {
|
||||
return _left;
|
||||
}
|
||||
|
||||
constexpr Vector2 Right() const {
|
||||
return _right;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const GamePadThumbSticks& other) const {
|
||||
return _left == other._left && _right == other._right;
|
||||
}
|
||||
|
||||
private:
|
||||
Vector2 _left{};
|
||||
Vector2 _right{};
|
||||
|
||||
private:
|
||||
constexpr void clamp() {
|
||||
_left = Vector2::Min(_left, Vector2::One());
|
||||
_left = Vector2::Max(_left, -Vector2::One());
|
||||
_right = Vector2::Min(_right, Vector2::One());
|
||||
_right = Vector2::Max(_right, -Vector2::One());
|
||||
}
|
||||
};
|
||||
|
||||
struct IGamePadDPad {
|
||||
virtual ButtonState Up() const = 0;
|
||||
virtual ButtonState Down() const = 0;
|
||||
virtual ButtonState Right() const = 0;
|
||||
virtual ButtonState Left() const = 0;
|
||||
struct GamePadDPad {
|
||||
constexpr GamePadDPad() = default;
|
||||
|
||||
constexpr GamePadDPad(const ButtonState& up, const ButtonState& down,
|
||||
const ButtonState& left, const ButtonState& right)
|
||||
: Up(up), Right(right), Down(down), Left(left) {
|
||||
}
|
||||
|
||||
ButtonState Up{};
|
||||
ButtonState Right{};
|
||||
ButtonState Down{};
|
||||
ButtonState Left{};
|
||||
};
|
||||
|
||||
struct IGamePadButtons {
|
||||
virtual ButtonState A() const = 0;
|
||||
virtual ButtonState B() const = 0;
|
||||
virtual ButtonState Back() const = 0;
|
||||
virtual ButtonState X() const = 0;
|
||||
virtual ButtonState Y() const = 0;
|
||||
virtual ButtonState Start() const = 0;
|
||||
virtual ButtonState LeftShoulder() const = 0;
|
||||
virtual ButtonState LeftStick() const = 0;
|
||||
virtual ButtonState RightShoulder() const = 0;
|
||||
virtual ButtonState RightStick() const = 0;
|
||||
virtual ButtonState BigButton() const = 0;
|
||||
struct GamePadButtons {
|
||||
constexpr GamePadButtons() = default;
|
||||
|
||||
constexpr GamePadButtons(
|
||||
ButtonState a,
|
||||
ButtonState b,
|
||||
ButtonState x,
|
||||
ButtonState y,
|
||||
ButtonState leftStick,
|
||||
ButtonState rightStick,
|
||||
ButtonState leftShoulder,
|
||||
ButtonState rightShoulder,
|
||||
ButtonState back,
|
||||
ButtonState start,
|
||||
ButtonState bigButton) {
|
||||
A = a;
|
||||
B = b;
|
||||
X = x;
|
||||
Y = y;
|
||||
LeftStick = leftStick;
|
||||
RightStick = rightStick;
|
||||
LeftShoulder = leftShoulder;
|
||||
RightShoulder = rightShoulder;
|
||||
Back = back;
|
||||
Start = start;
|
||||
BigButton = bigButton;
|
||||
}
|
||||
|
||||
constexpr GamePadButtons(Buttons buttons) {
|
||||
A = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::A))) == Buttons::A ? ButtonState::Pressed : ButtonState::Released;
|
||||
B = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::B))) == Buttons::B ? ButtonState::Pressed : ButtonState::Released;
|
||||
X = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::X))) == Buttons::X ? ButtonState::Pressed : ButtonState::Released;
|
||||
Y = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::Y))) == Buttons::Y ? ButtonState::Pressed : ButtonState::Released;
|
||||
Start = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::Start))) == Buttons::Start ? ButtonState::Pressed : ButtonState::Released;
|
||||
Back = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::Back))) == Buttons::Back ? ButtonState::Pressed : ButtonState::Released;
|
||||
LeftStick = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::LeftStick))) == Buttons::LeftStick ? ButtonState::Pressed : ButtonState::Released;
|
||||
RightStick = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::RightStick))) == Buttons::RightStick ? ButtonState::Pressed : ButtonState::Released;
|
||||
LeftShoulder = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::LeftShoulder))) == Buttons::LeftShoulder ? ButtonState::Pressed : ButtonState::Released;
|
||||
RightShoulder = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::RightShoulder))) == Buttons::RightShoulder ? ButtonState::Pressed : ButtonState::Released;
|
||||
BigButton = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::BigButton))) == Buttons::BigButton ? ButtonState::Pressed : ButtonState::Released;
|
||||
}
|
||||
|
||||
ButtonState A{};
|
||||
ButtonState B{};
|
||||
ButtonState X{};
|
||||
ButtonState Y{};
|
||||
ButtonState LeftStick{};
|
||||
ButtonState RightStick{};
|
||||
ButtonState LeftShoulder{};
|
||||
ButtonState RightShoulder{};
|
||||
ButtonState Back{};
|
||||
ButtonState Start{};
|
||||
ButtonState BigButton{};
|
||||
};
|
||||
|
||||
struct GamePadId;
|
||||
#ifdef USING_GAMEINPUT
|
||||
using GamePadId = APP_LOCAL_DEVICE_ID;
|
||||
#elif defined(USING_WINDOWS_GAMING_INPUT)
|
||||
using GamePadId = std::wstring;
|
||||
#else
|
||||
using GamePadId = uint64_t;
|
||||
#endif
|
||||
|
||||
struct IGamePadCapabilities {
|
||||
virtual GamePadCapabilitiesType GamePadType() const = 0;
|
||||
virtual bool IsConnected() const = 0;
|
||||
virtual GamePadId Id() const = 0;
|
||||
virtual Ushort Vid() const = 0;
|
||||
virtual Ushort Pid() const = 0;
|
||||
struct GamePadCapabilities {
|
||||
constexpr GamePadCapabilities() = default;
|
||||
|
||||
GamePadCapabilitiesType Type{};
|
||||
bool Connected{ false };
|
||||
Ushort Vid{ 0 };
|
||||
Ushort Pid{ 0 };
|
||||
GamePadId Id;
|
||||
};
|
||||
|
||||
struct IGamePadState {
|
||||
virtual GamePadButtons Buttons() const = 0;
|
||||
virtual GamePadDPad DPad() const = 0;
|
||||
virtual bool IsConnected() const = 0;
|
||||
virtual Ulong PacketNumber() const = 0;
|
||||
virtual GamePadThumbSticks ThumbSticks() = 0;
|
||||
virtual GamePadTriggers Triggers() = 0;
|
||||
virtual bool IsButtonDown(xna::Buttons button) = 0;
|
||||
virtual bool IsButtonUp(xna::Buttons button) = 0;
|
||||
struct GamePadState {
|
||||
GamePadState() = default;
|
||||
|
||||
constexpr bool IsButtonDown(xna::Buttons button) const {
|
||||
switch (button)
|
||||
{
|
||||
case xna::Buttons::A:
|
||||
return this->Buttons.A == ButtonState::Pressed;
|
||||
case xna::Buttons::B:
|
||||
return this->Buttons.B == ButtonState::Pressed;
|
||||
case xna::Buttons::X:
|
||||
return this->Buttons.X == ButtonState::Pressed;
|
||||
case xna::Buttons::Y:
|
||||
return this->Buttons.Y == ButtonState::Pressed;
|
||||
case xna::Buttons::Back:
|
||||
return this->Buttons.Back == ButtonState::Pressed;
|
||||
case xna::Buttons::Start:
|
||||
return this->Buttons.Start == ButtonState::Pressed;
|
||||
case xna::Buttons::DPadUp:
|
||||
return this->Dpad.Up == ButtonState::Pressed;
|
||||
case xna::Buttons::DPadDown:
|
||||
return this->Dpad.Down == ButtonState::Pressed;
|
||||
case xna::Buttons::DPadLeft:
|
||||
return this->Dpad.Left == ButtonState::Pressed;
|
||||
case xna::Buttons::DPadRight:
|
||||
return this->Dpad.Right == ButtonState::Pressed;
|
||||
case xna::Buttons::LeftShoulder:
|
||||
return this->Buttons.LeftShoulder == ButtonState::Pressed;
|
||||
case xna::Buttons::RightShoulder:
|
||||
return this->Buttons.RightShoulder == ButtonState::Pressed;
|
||||
case xna::Buttons::LeftStick:
|
||||
return this->Buttons.LeftStick == ButtonState::Pressed;
|
||||
case xna::Buttons::RightStick:
|
||||
return this->Buttons.RightStick == ButtonState::Pressed;
|
||||
case xna::Buttons::BigButton:
|
||||
return this->Buttons.BigButton == ButtonState::Pressed;
|
||||
case xna::Buttons::LeftThumbstickLeft:
|
||||
return this->Sticks.Left().X < 0.5F;
|
||||
case xna::Buttons::LeftThumbstickRight:
|
||||
return this->Sticks.Left().X > 0.5F;
|
||||
case xna::Buttons::LeftThumbstickDown:
|
||||
return this->Sticks.Left().Y > 0.5F;
|
||||
case xna::Buttons::LeftThumbstickUp:
|
||||
return this->Sticks.Left().Y < 0.5F;
|
||||
case xna::Buttons::RightThumbstickLeft:
|
||||
return this->Sticks.Right().X < 0.5F;
|
||||
case xna::Buttons::RightThumbstickRight:
|
||||
return this->Sticks.Right().X > 0.5F;
|
||||
case xna::Buttons::RightThumbstickDown:
|
||||
return this->Sticks.Right().Y > 0.5F;
|
||||
case xna::Buttons::RightThumbstickUp:
|
||||
return this->Sticks.Right().Y < 0.5F;
|
||||
case xna::Buttons::LeftTrigger:
|
||||
return this->Triggers.Left() > 0.5F;
|
||||
case xna::Buttons::RightTrigger:
|
||||
return this->Triggers.Right() > 0.5F;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr bool IsButtonUp(xna::Buttons button) const {
|
||||
return !IsButtonDown(button);
|
||||
}
|
||||
|
||||
GamePadButtons Buttons;
|
||||
GamePadDPad Dpad;
|
||||
bool IsConnected;
|
||||
Ulong PackedNumber;
|
||||
GamePadThumbSticks Sticks;
|
||||
GamePadTriggers Triggers;
|
||||
};
|
||||
|
||||
class IGamePad {
|
||||
class GamePad {
|
||||
public:
|
||||
static GamePadState GetState(PlayerIndex index);
|
||||
static GamePadState GetState(PlayerIndex index, GamePadDeadZone deadZone);
|
||||
static GamePadCapabilities GetCapabilities(PlayerIndex index);
|
||||
static bool SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger = 0, float rightTrigger = 0);
|
||||
static void Initialize();
|
||||
|
||||
public:
|
||||
virtual ~IGamePad(){}
|
||||
struct PlatformImplementation;
|
||||
inline static uptr<PlatformImplementation> impl = nullptr;
|
||||
|
||||
virtual GamePadState GetState(PlayerIndex index) = 0;
|
||||
virtual GamePadState GetState(PlayerIndex index, GamePadDeadZone deadZone) = 0;
|
||||
virtual GamePadCapabilities GetCapabilities(PlayerIndex index) = 0;
|
||||
virtual bool SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger = 0, float rightTrigger = 0) = 0;
|
||||
private:
|
||||
GamePad();
|
||||
GamePad(GamePad&&);
|
||||
GamePad(GamePad&);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,390 +0,0 @@
|
||||
#ifndef XNA_PLATFORM_GAMEPAD_DX_HPP
|
||||
#define XNA_PLATFORM_GAMEPAD_DX_HPP
|
||||
|
||||
#include "../input/gamepad.hpp"
|
||||
#include <GamePad.h>
|
||||
|
||||
namespace xna {
|
||||
struct GamePadTriggers: public IGamePadTriggers {
|
||||
constexpr GamePadTriggers() = default;
|
||||
|
||||
constexpr GamePadTriggers(float left, float right) : _left(left), _right(right) {
|
||||
clamp();
|
||||
}
|
||||
|
||||
constexpr GamePadTriggers(DirectX::GamePad::Triggers const& trigger) {
|
||||
_left = trigger.left;
|
||||
_right = trigger.right;
|
||||
clamp();
|
||||
}
|
||||
|
||||
virtual constexpr float Left() const override {
|
||||
return _left;
|
||||
}
|
||||
|
||||
virtual constexpr float Right() const override {
|
||||
return _right;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const GamePadTriggers& other) const {
|
||||
return _left == other._left && _right == other._right;
|
||||
}
|
||||
|
||||
public:
|
||||
float _left{ 0 };
|
||||
float _right{ 0 };
|
||||
|
||||
private:
|
||||
void constexpr clamp() {
|
||||
_left = _left < 1.0F ? _left : 1.0F;
|
||||
_left = _left > 0.0F ? _left : 0.0F;
|
||||
_right = _right < 1.0F ? _right : 1.0F;
|
||||
_right = _right > 0.0F ? _right : 0.0F;
|
||||
}
|
||||
};
|
||||
|
||||
struct GamePadThumbSticks : public IGamePadThumbSticks {
|
||||
constexpr GamePadThumbSticks() = default;
|
||||
|
||||
constexpr GamePadThumbSticks(Vector2 left, Vector2 right) : _left(left), _right(right) {
|
||||
clamp();
|
||||
}
|
||||
|
||||
constexpr GamePadThumbSticks(DirectX::GamePad::ThumbSticks const& sticks) {
|
||||
_left = Vector2(sticks.leftX, sticks.leftY);
|
||||
_right = Vector2(sticks.rightX, sticks.rightY);
|
||||
clamp();
|
||||
}
|
||||
|
||||
virtual constexpr Vector2 Left() const override {
|
||||
return _left;
|
||||
}
|
||||
|
||||
virtual constexpr Vector2 Right() const override {
|
||||
return _right;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const GamePadThumbSticks& other) const {
|
||||
return _left == other._left && _right == other._right;
|
||||
}
|
||||
|
||||
private:
|
||||
Vector2 _left{};
|
||||
Vector2 _right{};
|
||||
|
||||
private:
|
||||
constexpr void clamp() {
|
||||
_left = Vector2::Min(_left, Vector2::One());
|
||||
_left = Vector2::Max(_left, -Vector2::One());
|
||||
_right = Vector2::Min(_right, Vector2::One());
|
||||
_right = Vector2::Max(_right, -Vector2::One());
|
||||
}
|
||||
};
|
||||
|
||||
struct GamePadDPad : public IGamePadDPad {
|
||||
constexpr GamePadDPad() = default;
|
||||
|
||||
constexpr GamePadDPad(const ButtonState& up, const ButtonState& down,
|
||||
const ButtonState& left, const ButtonState& right)
|
||||
: _up(up), _right(right), _down(down), _left(left) {
|
||||
}
|
||||
|
||||
constexpr GamePadDPad(DirectX::GamePad::DPad dpad) {
|
||||
_up = static_cast<ButtonState>(dpad.up);
|
||||
_right = static_cast<ButtonState>(dpad.right);
|
||||
_down = static_cast<ButtonState>(dpad.down);
|
||||
_left = static_cast<ButtonState>(dpad.left);
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState Up() const override {
|
||||
return _up;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState Down() const override {
|
||||
return _down;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState Right() const override {
|
||||
return _right;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState Left() const override {
|
||||
return _left;
|
||||
}
|
||||
|
||||
private:
|
||||
ButtonState _up{};
|
||||
ButtonState _right{};
|
||||
ButtonState _down{};
|
||||
ButtonState _left{};
|
||||
};
|
||||
|
||||
struct GamePadButtons : public IGamePadButtons {
|
||||
constexpr GamePadButtons() = default;
|
||||
|
||||
constexpr GamePadButtons(Buttons buttons) {
|
||||
_a = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::A))) == Buttons::A ? ButtonState::Pressed : ButtonState::Released;
|
||||
_b = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::B))) == Buttons::B ? ButtonState::Pressed : ButtonState::Released;
|
||||
_x = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::X))) == Buttons::X ? ButtonState::Pressed : ButtonState::Released;
|
||||
_y = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::Y))) == Buttons::Y ? ButtonState::Pressed : ButtonState::Released;
|
||||
_start = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::Start))) == Buttons::Start ? ButtonState::Pressed : ButtonState::Released;
|
||||
_back = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::Back))) == Buttons::Back ? ButtonState::Pressed : ButtonState::Released;
|
||||
_leftStick = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::LeftStick))) == Buttons::LeftStick ? ButtonState::Pressed : ButtonState::Released;
|
||||
_rightStick = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::RightStick))) == Buttons::RightStick ? ButtonState::Pressed : ButtonState::Released;
|
||||
_leftShoulder = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::LeftShoulder))) == Buttons::LeftShoulder ? ButtonState::Pressed : ButtonState::Released;
|
||||
_rightShoulder = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::RightShoulder))) == Buttons::RightShoulder ? ButtonState::Pressed : ButtonState::Released;
|
||||
_bigButton = static_cast<Buttons>((static_cast<int>(buttons) & static_cast<int>(Buttons::BigButton))) == Buttons::BigButton ? ButtonState::Pressed : ButtonState::Released;
|
||||
}
|
||||
|
||||
constexpr GamePadButtons(DirectX::GamePad::Buttons const& buttons) {
|
||||
_a = static_cast<ButtonState>(buttons.a);
|
||||
_b = static_cast<ButtonState>(buttons.b);
|
||||
_x = static_cast<ButtonState>(buttons.x);
|
||||
_y = static_cast<ButtonState>(buttons.y);
|
||||
_leftStick = static_cast<ButtonState>(buttons.leftStick);
|
||||
_rightStick = static_cast<ButtonState>(buttons.rightStick);
|
||||
_leftShoulder = static_cast<ButtonState>(buttons.leftShoulder);
|
||||
_rightShoulder = static_cast<ButtonState>(buttons.rightShoulder);
|
||||
_back = static_cast<ButtonState>(buttons.back);
|
||||
_start = static_cast<ButtonState>(buttons.start);
|
||||
_bigButton = static_cast<ButtonState>(buttons.view);
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState A() const override {
|
||||
return _a;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState B() const override {
|
||||
return _b;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState Back() const override{
|
||||
return _back;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState X() const override {
|
||||
return _x;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState Y() const override {
|
||||
return _y;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState Start() const override {
|
||||
return _start;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState LeftShoulder() const override {
|
||||
return _leftShoulder;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState LeftStick() const override {
|
||||
return _leftStick;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState RightShoulder() const override {
|
||||
return _rightShoulder;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState RightStick() const override {
|
||||
return _rightStick;
|
||||
}
|
||||
|
||||
virtual constexpr ButtonState BigButton() const override {
|
||||
return _bigButton;
|
||||
}
|
||||
|
||||
private:
|
||||
ButtonState _a{};
|
||||
ButtonState _b{};
|
||||
ButtonState _x{};
|
||||
ButtonState _y{};
|
||||
ButtonState _leftStick{};
|
||||
ButtonState _rightStick{};
|
||||
ButtonState _leftShoulder{};
|
||||
ButtonState _rightShoulder{};
|
||||
ButtonState _back{};
|
||||
ButtonState _start{};
|
||||
ButtonState _bigButton{};
|
||||
};
|
||||
|
||||
struct GamePadId {
|
||||
#ifdef USING_GAMEINPUT
|
||||
APP_LOCAL_DEVICE_ID id;
|
||||
#elif defined(USING_WINDOWS_GAMING_INPUT)
|
||||
std::wstring id;
|
||||
#else
|
||||
uint64_t id;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct GamePadCapabilities : public IGamePadCapabilities {
|
||||
constexpr GamePadCapabilities() = default;
|
||||
|
||||
constexpr GamePadCapabilities(DirectX::GamePad::Capabilities const& capabilities) {
|
||||
_type = static_cast<GamePadCapabilitiesType>(capabilities.gamepadType);
|
||||
_connected = capabilities.connected;
|
||||
_id.id = capabilities.id;
|
||||
_vid = capabilities.vid;
|
||||
_pid = capabilities.pid;
|
||||
}
|
||||
|
||||
virtual constexpr GamePadCapabilitiesType GamePadType() const override {
|
||||
return _type;
|
||||
}
|
||||
|
||||
virtual constexpr bool IsConnected() const override {
|
||||
return _connected;
|
||||
}
|
||||
|
||||
virtual GamePadId Id() const override {
|
||||
return _id;
|
||||
}
|
||||
|
||||
virtual constexpr Ushort Vid() const override {
|
||||
return _vid;
|
||||
}
|
||||
|
||||
virtual constexpr Ushort Pid() const override {
|
||||
return _pid;
|
||||
}
|
||||
|
||||
private:
|
||||
GamePadCapabilitiesType _type{};
|
||||
bool _connected{ false };
|
||||
GamePadId _id{};
|
||||
Ushort _vid{ 0 };
|
||||
Ushort _pid{ 0 };
|
||||
};
|
||||
|
||||
struct GamePadState : public IGamePadState {
|
||||
constexpr GamePadState() = default;
|
||||
|
||||
constexpr GamePadState(DirectX::GamePad::State const& state) : _dxState(state){
|
||||
}
|
||||
|
||||
virtual constexpr GamePadButtons Buttons() const override {
|
||||
const auto buttons = _dxState.buttons;
|
||||
return GamePadButtons(buttons);
|
||||
};
|
||||
|
||||
virtual constexpr GamePadDPad DPad() const override {
|
||||
const auto dpad = _dxState.dpad;
|
||||
return GamePadDPad(dpad);
|
||||
};
|
||||
|
||||
inline virtual bool IsConnected() const override{
|
||||
return _dxState.IsConnected();
|
||||
};
|
||||
|
||||
virtual constexpr Ulong PacketNumber() const override {
|
||||
return _dxState.packet;
|
||||
};
|
||||
|
||||
virtual constexpr GamePadThumbSticks ThumbSticks() override{
|
||||
const auto thumbs = _dxState.thumbSticks;
|
||||
return GamePadThumbSticks(thumbs);
|
||||
};
|
||||
|
||||
virtual GamePadTriggers Triggers() override {
|
||||
const auto triggers = _dxState.triggers;
|
||||
return GamePadTriggers(triggers);
|
||||
};
|
||||
|
||||
virtual bool IsButtonDown(xna::Buttons button) override {
|
||||
switch (button)
|
||||
{
|
||||
case xna::Buttons::A:
|
||||
return _dxState.IsAPressed();
|
||||
case xna::Buttons::B:
|
||||
return _dxState.IsBPressed();
|
||||
case xna::Buttons::X:
|
||||
return _dxState.IsXPressed();
|
||||
case xna::Buttons::Y:
|
||||
return _dxState.IsYPressed();
|
||||
case xna::Buttons::Back:
|
||||
return _dxState.IsBackPressed();
|
||||
case xna::Buttons::Start:
|
||||
return _dxState.IsStartPressed();
|
||||
case xna::Buttons::DPadUp:
|
||||
return _dxState.IsDPadUpPressed();
|
||||
case xna::Buttons::DPadDown:
|
||||
return _dxState.IsDPadDownPressed();
|
||||
case xna::Buttons::DPadLeft:
|
||||
return _dxState.IsDPadLeftPressed();
|
||||
case xna::Buttons::DPadRight:
|
||||
return _dxState.IsDPadRightPressed();
|
||||
case xna::Buttons::LeftShoulder:
|
||||
return _dxState.IsLeftShoulderPressed();
|
||||
case xna::Buttons::RightShoulder:
|
||||
return _dxState.IsRightShoulderPressed();
|
||||
case xna::Buttons::LeftStick:
|
||||
return _dxState.IsLeftStickPressed();
|
||||
case xna::Buttons::RightStick:
|
||||
return _dxState.IsRightStickPressed();
|
||||
case xna::Buttons::BigButton:
|
||||
return _dxState.IsViewPressed();
|
||||
case xna::Buttons::LeftThumbstickLeft:
|
||||
return _dxState.IsLeftThumbStickLeft();
|
||||
case xna::Buttons::LeftThumbstickRight:
|
||||
return _dxState.IsLeftThumbStickRight();
|
||||
case xna::Buttons::LeftThumbstickDown:
|
||||
return _dxState.IsLeftThumbStickDown();
|
||||
case xna::Buttons::LeftThumbstickUp:
|
||||
return _dxState.IsLeftThumbStickUp();
|
||||
case xna::Buttons::RightThumbstickLeft:
|
||||
return _dxState.IsRightThumbStickLeft();
|
||||
case xna::Buttons::RightThumbstickRight:
|
||||
return _dxState.IsLeftThumbStickRight();
|
||||
case xna::Buttons::RightThumbstickDown:
|
||||
return _dxState.IsRightThumbStickDown();
|
||||
case xna::Buttons::RightThumbstickUp:
|
||||
return _dxState.IsRightThumbStickUp();
|
||||
case xna::Buttons::LeftTrigger:
|
||||
return _dxState.IsLeftTriggerPressed();
|
||||
case xna::Buttons::RightTrigger:
|
||||
return _dxState.IsRightTriggerPressed();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
virtual bool IsButtonUp(xna::Buttons button) override {
|
||||
return !IsButtonDown(button);
|
||||
};
|
||||
|
||||
public:
|
||||
DirectX::GamePad::State _dxState{};
|
||||
};
|
||||
|
||||
class _GamePad : public IGamePad {
|
||||
public:
|
||||
constexpr _GamePad() = default;
|
||||
|
||||
virtual ~_GamePad() override {
|
||||
if (_dxGamePad) {
|
||||
_dxGamePad->Suspend();
|
||||
_dxGamePad = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize() {
|
||||
_dxGamePad = uNew<DirectX::GamePad>();
|
||||
}
|
||||
|
||||
virtual GamePadState GetState(PlayerIndex index) override;
|
||||
virtual GamePadState GetState(PlayerIndex index, GamePadDeadZone deadZone) override;
|
||||
virtual GamePadCapabilities GetCapabilities(PlayerIndex index) override;
|
||||
virtual bool SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger) override;
|
||||
|
||||
public:
|
||||
uptr<DirectX::GamePad> _dxGamePad = nullptr;
|
||||
|
||||
private:
|
||||
constexpr _GamePad(_GamePad&&) = default;
|
||||
};
|
||||
|
||||
inline static _GamePad GamePad = _GamePad();
|
||||
}
|
||||
|
||||
#endif
|
@ -1,14 +1,15 @@
|
||||
#include "graphics/sprite.hpp"
|
||||
#include "graphics/device.hpp"
|
||||
#include "graphics/adapter.hpp"
|
||||
#include "graphics/buffer.hpp"
|
||||
#include "platform-dx/presentparameters-dx.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
#include "platform-dx/swapchain-dx.hpp"
|
||||
#include "platform-dx/rendertarget-dx.hpp"
|
||||
#include "graphics/adapter.hpp"
|
||||
#include "graphics/blendstate.hpp"
|
||||
#include "graphics/buffer.hpp"
|
||||
#include "graphics/depthstencilstate.hpp"
|
||||
#include "graphics/device.hpp"
|
||||
#include "graphics/displaymode.hpp"
|
||||
#include "graphics/sprite.hpp"
|
||||
#include "input/gamepad.hpp"
|
||||
#include "platform-dx/presentparameters-dx.hpp"
|
||||
#include "platform-dx/rendertarget-dx.hpp"
|
||||
#include "platform-dx/swapchain-dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
struct SpriteFont::PlatformImplementation {
|
||||
@ -138,4 +139,15 @@ namespace xna {
|
||||
struct DisplayMode::PlatformImplementation {
|
||||
std::vector<DisplayModeDescription> Descriptions;
|
||||
};
|
||||
|
||||
struct GamePad::PlatformImplementation {
|
||||
~PlatformImplementation() {
|
||||
if (_dxGamePad) {
|
||||
_dxGamePad->Suspend();
|
||||
_dxGamePad = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
inline static uptr<DirectX::GamePad> _dxGamePad = uNew<DirectX::GamePad>();
|
||||
};
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
#include "audioengine-dx.hpp"
|
||||
#include "content-readers/texture2Dreader-dx.hpp"
|
||||
#include "device-dx.hpp"
|
||||
#include "dx/StepTimer.hpp"
|
||||
#include "dxheaders.hpp"
|
||||
#include "game-dx.hpp"
|
||||
#include "gamepad-dx.hpp"
|
||||
#include "gdeviceinfo-dx.hpp"
|
||||
#include "gdevicemanager-dx.hpp"
|
||||
#include "indexbuffer-dx.hpp"
|
||||
@ -20,5 +21,4 @@
|
||||
#include "vertexbuffer-dx.hpp"
|
||||
#include "vertexinput-dx.hpp"
|
||||
#include "window-dx.hpp"
|
||||
#include "content-readers/texture2Dreader-dx.hpp"
|
||||
#include "dx/StepTimer.hpp"
|
||||
#include "implementations.hpp"
|
@ -20,28 +20,28 @@ namespace xna {
|
||||
using Ulong = uint64_t;
|
||||
using Char = char16_t;
|
||||
|
||||
constexpr Sbyte SbyteMaxValue = std::numeric_limits<Sbyte>::max();
|
||||
constexpr Sbyte SbyteMinValue = std::numeric_limits<Sbyte>::min();
|
||||
constexpr Byte ByteMaxValue = std::numeric_limits<Byte>::max();
|
||||
constexpr Byte ByteMinValue = std::numeric_limits<Byte>::min();
|
||||
constexpr Short ShortMaxValue = std::numeric_limits<Short>::max();
|
||||
constexpr Short ShortMinValue = std::numeric_limits<Short>::min();
|
||||
constexpr Ushort UshortMaxValue = std::numeric_limits<Ushort>::max();
|
||||
constexpr Ushort UshortMinValue = std::numeric_limits<Ushort>::min();
|
||||
constexpr Int IntMaxValue = std::numeric_limits<Int>::max();
|
||||
constexpr Int IntMinValue = std::numeric_limits<Int>::min();
|
||||
constexpr Uint UintMaxValue = std::numeric_limits<Uint>::max();
|
||||
constexpr Uint UintMinValue = std::numeric_limits<Uint>::min();
|
||||
constexpr Long LongMaxValue = std::numeric_limits<Long>::max();
|
||||
constexpr Long LongMinValue = std::numeric_limits<Long>::min();
|
||||
constexpr Ulong UlongMaxValue = std::numeric_limits<Ulong>::max();
|
||||
constexpr Ulong UlongMinValue = std::numeric_limits<Ulong>::min();
|
||||
constexpr Char CharMaxValue = std::numeric_limits<Char>::max();
|
||||
constexpr Char CharMinValue = std::numeric_limits<Char>::min();
|
||||
constexpr float FloatMaxValue = std::numeric_limits<float>::max();
|
||||
constexpr float FloatMinValue = std::numeric_limits<float>::min();
|
||||
constexpr double DoubleMaxValue = std::numeric_limits<double>::max();
|
||||
constexpr double DoubleMinValue = std::numeric_limits<double>::min();
|
||||
constexpr Sbyte SbyteMaxValue = (std::numeric_limits<Sbyte>::max)();
|
||||
constexpr Sbyte SbyteMinValue = (std::numeric_limits<Sbyte>::min)();
|
||||
constexpr Byte ByteMaxValue = (std::numeric_limits<Byte>::max)();
|
||||
constexpr Byte ByteMinValue = (std::numeric_limits<Byte>::min)();
|
||||
constexpr Short ShortMaxValue = (std::numeric_limits<Short>::max)();
|
||||
constexpr Short ShortMinValue = (std::numeric_limits<Short>::min)();
|
||||
constexpr Ushort UshortMaxValue = (std::numeric_limits<Ushort>::max)();
|
||||
constexpr Ushort UshortMinValue = (std::numeric_limits<Ushort>::min)();
|
||||
constexpr Int IntMaxValue = (std::numeric_limits<Int>::max)();
|
||||
constexpr Int IntMinValue = (std::numeric_limits<Int>::min)();
|
||||
constexpr Uint UintMaxValue = (std::numeric_limits<Uint>::max)();
|
||||
constexpr Uint UintMinValue = (std::numeric_limits<Uint>::min)();
|
||||
constexpr Long LongMaxValue = (std::numeric_limits<Long>::max)();
|
||||
constexpr Long LongMinValue = (std::numeric_limits<Long>::min)();
|
||||
constexpr Ulong UlongMaxValue = (std::numeric_limits<Ulong>::max)();
|
||||
constexpr Ulong UlongMinValue = (std::numeric_limits<Ulong>::min)();
|
||||
constexpr Char CharMaxValue = (std::numeric_limits<Char>::max)();
|
||||
constexpr Char CharMinValue = (std::numeric_limits<Char>::min)();
|
||||
constexpr float FloatMaxValue = (std::numeric_limits<float>::max)();
|
||||
constexpr float FloatMinValue = (std::numeric_limits<float>::min)();
|
||||
constexpr double DoubleMaxValue = (std::numeric_limits<double>::max)();
|
||||
constexpr double DoubleMinValue = (std::numeric_limits<double>::min)();
|
||||
|
||||
using String = std::string;
|
||||
using WString = std::wstring;
|
||||
|
Loading…
x
Reference in New Issue
Block a user