1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Merge pull request #14 from borgesdan/develop

Implementações em Input
This commit is contained in:
Danilo Borges 2024-08-01 14:32:55 -03:00 committed by GitHub
commit ebeb77c0b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 542 additions and 441 deletions

View File

@ -18,10 +18,6 @@ namespace xna {
_gameComponents = snew<GameComponentCollection>();
}
Game::~Game() {
impl = nullptr;
}
void Game::Exit() {
_gameWindow->impl->Close();
}
@ -85,8 +81,8 @@ namespace xna {
}
void Game::Initialize() {
Keyboard::Initialize();
Mouse::Initialize();
Keyboard::Initialize();
Mouse::Initialize(_gameWindow->Handle());
GamePad::Initialize();
AudioEngine::Initialize();
@ -147,4 +143,19 @@ namespace xna {
sptr<GameServiceContainer> Game::Services() { return services; }
sptr<ContentManager> Game::Content() { return _contentManager; }
void Game::EnableGameComponents(bool value) { _enabledGameComponents = value; }
void Game::AttachGraphicsDevice(sptr<GraphicsDevice> const& device) {
graphicsDevice = device;
}
void Game::ResizeWindow(int width, int heigth) {
const auto windowBounds = _gameWindow->ClientBounds();
if (windowBounds.Width != width || windowBounds.Height != heigth) {
_gameWindow->impl->Size(
width,
heigth);
_gameWindow->impl->Update();
}
}
}

View File

@ -14,20 +14,7 @@ namespace xna {
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.ThumbSticks = 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(
const auto buttons = GamePadButtons(
static_cast<ButtonState>(state.buttons.a),
static_cast<ButtonState>(state.buttons.b),
static_cast<ButtonState>(state.buttons.x),
@ -39,7 +26,21 @@ namespace xna {
static_cast<ButtonState>(state.buttons.back),
static_cast<ButtonState>(state.buttons.start),
static_cast<ButtonState>(state.buttons.view));
const auto 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));
const auto isConnected = state.connected;
const auto thumbSticks = GamePadThumbSticks(
Vector2(state.thumbSticks.leftX, state.thumbSticks.leftY),
Vector2(state.thumbSticks.rightX, state.thumbSticks.rightY));
const auto triggers = GamePadTriggers(state.triggers.left, state.triggers.right);
const auto pad = GamePadState(thumbSticks, triggers, buttons, dpad, isConnected);
return pad;
}
@ -51,21 +52,34 @@ namespace xna {
static_cast<int>(index),
static_cast<DirectX::GamePad::DeadZone>(deadZone)
);
const auto 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));
GamePadState pad;
pad.Dpad = GamePadDPad(
const auto 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.ThumbSticks = GamePadThumbSticks(
const auto isConnected = state.connected;
const auto thumbSticks = GamePadThumbSticks(
Vector2(state.thumbSticks.leftX, state.thumbSticks.leftY),
Vector2(state.thumbSticks.rightX, state.thumbSticks.rightY));
pad.Triggers = GamePadTriggers(state.triggers.left, state.triggers.right);
const auto triggers = GamePadTriggers(state.triggers.left, state.triggers.right);
const auto pad = GamePadState(thumbSticks, triggers, buttons, dpad, isConnected);
return pad;
}
@ -74,12 +88,11 @@ namespace xna {
return GamePadCapabilities();
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;
const auto gamePadType = static_cast<GamePadCapabilitiesType>(capabilities.gamepadType);
const auto cap = GamePadCapabilities(
capabilities.connected,
gamePadType);
return cap;
}

View File

@ -107,19 +107,12 @@ namespace xna {
MassagePresentParameters(*newInfo.PresentParameters);
ValidateGraphicsDeviceInformation(newInfo);
const auto windowBounds = game->Window()->ClientBounds();
if (windowBounds.Width != newInfo.PresentParameters->BackBufferWidth || windowBounds.Height != newInfo.PresentParameters->BackBufferHeight) {
game->Window()->impl->Size(
newInfo.PresentParameters->BackBufferWidth,
newInfo.PresentParameters->BackBufferHeight);
game->Window()->impl->Update();
}
game->ResizeWindow(newInfo.PresentParameters->BackBufferWidth, newInfo.PresentParameters->BackBufferHeight);
device = snew<GraphicsDevice>(newInfo.Adapter, newInfo.Profile, newInfo.PresentParameters);
device->Initialize();
game->graphicsDevice = this->device;
game->AttachGraphicsDevice(device);
//device.DeviceResetting += new EventHandler<EventArgs>(this.HandleDeviceResetting);
//device.DeviceReset += new EventHandler<EventArgs>(this.HandleDeviceReset);

View File

@ -1,4 +1,3 @@
#include "xna/input/keyboard.hpp"
#include "xna/xna-dx.hpp"
namespace xna {
@ -15,12 +14,5 @@ namespace xna {
void Keyboard::Initialize() {
impl = unew<PlatformImplementation>();
}
bool Keyboard::IsConnected() {
if (!impl || !impl->_dxKeyboard)
return false;
return impl->_dxKeyboard->IsConnected();
}
}
}

View File

@ -2,9 +2,6 @@
namespace xna {
MouseState Mouse::GetState() {
if (!impl || !impl->_dxMouse)
return MouseState();
const auto state = impl->_dxMouse->GetState();
MouseState mstate;
mstate.LeftButton = static_cast<ButtonState>(state.leftButton);
@ -17,37 +14,22 @@ namespace xna {
mstate.ScroolWheelValue = state.scrollWheelValue;
return mstate;
}
}
bool Mouse::IsConnected() {
if (!impl || !impl->_dxMouse)
return false;
return impl->_dxMouse->IsConnected();
}
bool Mouse::IsVisible() {
if (!impl || !impl->_dxMouse)
return false;
return impl->_dxMouse->IsVisible();
}
void Mouse::IsVisible(bool value) {
if (!impl || !impl->_dxMouse)
return;
impl->_dxMouse->SetVisible(value);
}
void Mouse::ResetScrollWheel() {
if (!impl || !impl->_dxMouse)
return;
impl->_dxMouse->ResetScrollWheelValue();
}
void Mouse::Initialize() {
void Mouse::Initialize(intptr_t handle) {
impl = unew<PlatformImplementation>();
windowHandle = handle;
}
void Mouse::WindowHandle(intptr_t value) {
auto hwnd = reinterpret_cast<HWND>(value);
if (!hwnd) return;
impl->_dxMouse->SetWindow(hwnd);
}
void Mouse::SetPosition(Int x, Int y) {
SetCursorPos(x, y);
}
}

View File

@ -80,40 +80,6 @@ namespace xna {
Static,
};
enum class Buttons {
A = 4096, // 0x00001000
B = 8192, // 0x00002000
X = 16384, // 0x00004000
Y = 32768, // 0x00008000
Back = 32, // 0x00000020
Start = 16, // 0x00000010
DPadUp = 1,
DPadDown = 2,
DPadLeft = 4,
DPadRight = 8,
LeftShoulder = 256, // 0x00000100
RightShoulder = 512, // 0x00000200
LeftStick = 64, // 0x00000040
RightStick = 128, // 0x00000080
BigButton = 2048, // 0x00000800
LeftThumbstickLeft = 2097152, // 0x00200000
LeftThumbstickRight = 1073741824, // 0x40000000
LeftThumbstickDown = 536870912, // 0x20000000
LeftThumbstickUp = 268435456, // 0x10000000
RightThumbstickLeft = 134217728, // 0x08000000
RightThumbstickRight = 67108864, // 0x04000000
RightThumbstickDown = 33554432, // 0x02000000
RightThumbstickUp = 16777216, // 0x01000000
LeftTrigger = 8388608, // 0x00800000
RightTrigger = 4194304, // 0x00400000
};
enum class ButtonState
{
Released,
Pressed,
};
enum class ClearOptions {
DepthBuffer,
Stencil,
@ -234,27 +200,6 @@ namespace xna {
Drawable,
};
enum class GamePadCapabilitiesType
{
Unknown = 0,
Gamepad,
Wheel,
ArdaceStick,
FlightStick,
DancePAd,
Guitar,
GuitarAlternate,
DrumKit,
GuitarBass = 11,
ArcadePad = 19,
};
enum class GamePadDeadZone {
IndependentAxes,
Circular,
None,
};
//Identifies the set of supported devices for the game based on device capabilities.
enum class GraphicsProfile {
//Use a limited set of graphic features and capabilities, allowing the game to support the widest variety of devices, including all Windows-based computers.
@ -264,192 +209,6 @@ namespace xna {
HiDef
};
enum class Keys : unsigned char {
None = 0,
Back = 0x8,
Tab = 0x9,
Enter = 0xd,
Pause = 0x13,
CapsLock = 0x14,
Kana = 0x15,
ImeOn = 0x16,
Kanji = 0x19,
ImeOff = 0x1a,
Escape = 0x1b,
ImeConvert = 0x1c,
ImeNoConvert = 0x1d,
Space = 0x20,
PageUp = 0x21,
PageDown = 0x22,
End = 0x23,
Home = 0x24,
Left = 0x25,
Up = 0x26,
Right = 0x27,
Down = 0x28,
Select = 0x29,
Print = 0x2a,
Execute = 0x2b,
PrintScreen = 0x2c,
Insert = 0x2d,
Delete = 0x2e,
Help = 0x2f,
D0 = 0x30,
D1 = 0x31,
D2 = 0x32,
D3 = 0x33,
D4 = 0x34,
D5 = 0x35,
D6 = 0x36,
D7 = 0x37,
D8 = 0x38,
D9 = 0x39,
A = 0x41,
B = 0x42,
C = 0x43,
D = 0x44,
E = 0x45,
F = 0x46,
G = 0x47,
H = 0x48,
I = 0x49,
J = 0x4a,
K = 0x4b,
L = 0x4c,
M = 0x4d,
N = 0x4e,
O = 0x4f,
P = 0x50,
Q = 0x51,
R = 0x52,
S = 0x53,
T = 0x54,
U = 0x55,
V = 0x56,
W = 0x57,
X = 0x58,
Y = 0x59,
Z = 0x5a,
LeftWindows = 0x5b,
RightWindows = 0x5c,
Apps = 0x5d,
Sleep = 0x5f,
NumPad0 = 0x60,
NumPad1 = 0x61,
NumPad2 = 0x62,
NumPad3 = 0x63,
NumPad4 = 0x64,
NumPad5 = 0x65,
NumPad6 = 0x66,
NumPad7 = 0x67,
NumPad8 = 0x68,
NumPad9 = 0x69,
Multiply = 0x6a,
Add = 0x6b,
Separator = 0x6c,
Subtract = 0x6d,
Decimal = 0x6e,
Divide = 0x6f,
F1 = 0x70,
F2 = 0x71,
F3 = 0x72,
F4 = 0x73,
F5 = 0x74,
F6 = 0x75,
F7 = 0x76,
F8 = 0x77,
F9 = 0x78,
F10 = 0x79,
F11 = 0x7a,
F12 = 0x7b,
F13 = 0x7c,
F14 = 0x7d,
F15 = 0x7e,
F16 = 0x7f,
F17 = 0x80,
F18 = 0x81,
F19 = 0x82,
F20 = 0x83,
F21 = 0x84,
F22 = 0x85,
F23 = 0x86,
F24 = 0x87,
NumLock = 0x90,
Scroll = 0x91,
LeftShift = 0xa0,
RightShift = 0xa1,
LeftControl = 0xa2,
RightControl = 0xa3,
LeftAlt = 0xa4,
RightAlt = 0xa5,
BrowserBack = 0xa6,
BrowserForward = 0xa7,
BrowserRefresh = 0xa8,
BrowserStop = 0xa9,
BrowserSearch = 0xaa,
BrowserFavorites = 0xab,
BrowserHome = 0xac,
VolumeMute = 0xad,
VolumeDown = 0xae,
VolumeUp = 0xaf,
MediaNextTrack = 0xb0,
MediaPreviousTrack = 0xb1,
MediaStop = 0xb2,
MediaPlayPause = 0xb3,
LaunchMail = 0xb4,
SelectMedia = 0xb5,
LaunchApplication1 = 0xb6,
LaunchApplication2 = 0xb7,
OemSemicolon = 0xba,
OemPlus = 0xbb,
OemComma = 0xbc,
OemMinus = 0xbd,
OemPeriod = 0xbe,
OemQuestion = 0xbf,
OemTilde = 0xc0,
OemOpenBrackets = 0xdb,
OemPipe = 0xdc,
OemCloseBrackets = 0xdd,
OemQuotes = 0xde,
Oem8 = 0xdf,
OemBackslash = 0xe2,
ProcessKey = 0xe5,
OemCopy = 0xf2,
OemAuto = 0xf3,
OemEnlW = 0xf4,
Attn = 0xf6,
Crsel = 0xf7,
Exsel = 0xf8,
EraseEof = 0xf9,
Play = 0xfa,
Zoom = 0xfb,
Pa1 = 0xfd,
OemClear = 0xfe,
};
enum class KeyState {
Up,
Down,
};
enum class PlaneIntersectionType {
Front,
Back,
@ -483,9 +242,7 @@ namespace xna {
DiscardContents,
PreserveContents,
PlatformContents
};
};
enum class SpriteEffects {
None = 0,

View File

@ -8,7 +8,6 @@ namespace xna {
class Game : public std::enable_shared_from_this<Game> {
public:
Game();
~Game();
void Exit();
int Run();
sptr<GameWindow> Window();
@ -18,6 +17,9 @@ namespace xna {
sptr<ContentManager> Content();
void EnableGameComponents(bool value);
void AttachGraphicsDevice(sptr<GraphicsDevice> const& graphicsDevice);
void ResizeWindow(int width, int heigth);
protected:
virtual void Draw(GameTime const& gameTime);
virtual void Initialize();

View File

@ -1,9 +1,9 @@
#ifndef XNA_GAME_GRAPHICSDEVICEMANAGER_HPP
#define XNA_GAME_GRAPHICSDEVICEMANAGER_HPP
#include "../csharp/eventhandler.hpp"
#include "../default.hpp"
#include "gdeviceinfo.hpp"
#include "../csharp/eventhandler.hpp"
namespace xna {
struct IGraphicsDeviceService {
@ -21,6 +21,7 @@ namespace xna {
//virtual void EndDraw() = 0;
};
//Handles the configuration and management of the graphics device.
class GraphicsDeviceManager : public IGraphicsDeviceService, public IGraphicsDeviceManager {
public:
//Creates a new GraphicsDeviceManager and registers it to handle the configuration and management of the graphics device for the specified Game.

View File

@ -2,6 +2,7 @@
#define XNA_INPUT_GAMEPAD_HPP
#include "../default.hpp"
#include "input-enums.hpp"
#include "../common/numerics.hpp"
namespace xna {
@ -9,14 +10,17 @@ namespace xna {
struct GamePadTriggers {
constexpr GamePadTriggers() = default;
constexpr GamePadTriggers(float left, float right) : _left(left), _right(right) {
constexpr GamePadTriggers(float left, float right)
: _left(left), _right(right) {
clamp();
}
//Identifies the position of the left trigger on the Xbox Controller.
constexpr float Left() const {
return _left;
}
//Identifies the position of the right trigger on the Xbox Controller.
constexpr float Right() const {
return _right;
}
@ -25,7 +29,7 @@ namespace xna {
return _left == other._left && _right == other._right;
}
public:
private:
float _left{ 0 };
float _right{ 0 };
@ -46,10 +50,12 @@ namespace xna {
clamp();
}
//Returns the position of the left Xbox Controller stick (thumbstick) as a 2D vector.
constexpr Vector2 Left() const {
return _left;
}
//Returns the position of the right Xbox Controller stick (thumbstick) as a 2D vector.
constexpr Vector2 Right() const {
return _right;
}
@ -76,14 +82,22 @@ namespace xna {
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{};
const ButtonState& left, const ButtonState& right) : up(up), down(down), left(left), right(right) {}
//Identifies whether the Up direction on the Xbox Controller directional pad is pressed.
constexpr ButtonState Up() const { return up; }
//Identifies whether the Right direction on the Xbox Controller directional pad is pressed.
constexpr ButtonState Right() const { return right; }
//Identifies whether the Down direction on the Xbox Controller directional pad is pressed.
constexpr ButtonState Down() const { return down; }
//Identifies whether the Left direction on the Xbox Controller directional pad is pressed.
constexpr ButtonState Left() const { return left; }
private:
ButtonState up{};
ButtonState right{};
ButtonState down{};
ButtonState left{};
};
//Identifies whether buttons on an Xbox Controller are pressed or released.
@ -102,137 +116,178 @@ namespace xna {
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;
this->a = a;
this->b = b;
this->x = x;
this->y = y;
this->leftStick = leftStick;
this->rightStick = rightStick;
this->leftShoulder = leftShoulder;
this->rightShoulder = rightShoulder;
this->back = back;
this->start = start;
this->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;
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{};
};
//Identifies if the A button on the Xbox Controller is pressed.
constexpr ButtonState A() const { return a; }
//Identifies if the B button on the Xbox Controller is pressed.
constexpr ButtonState B() const { return b; }
//Identifies if the X button on the Xbox Controller is pressed.
constexpr ButtonState X() const { return x; }
//Identifies if the Y button on the Xbox Controller is pressed.
constexpr ButtonState Y() const { return y; }
//Identifies if the left stick button on the Xbox Controller is pressed (the stick is "clicked" in
constexpr ButtonState LeftStick() const { return leftStick; }
//Identifies if the right stick button on the Xbox Controller is pressed (the stick is "clicked" in).
constexpr ButtonState RightStick() const { return rightStick; }
//Identifies if the left shoulder (bumper) button on the Xbox Controller is pressed.
constexpr ButtonState LeftShoulder() const { return leftShoulder; }
//Identifies if the right shoulder (bumper) button on the Xbox Controller is pressed.
constexpr ButtonState RightShoulder() const { return rightShoulder; }
//Identifies if the BACK button on the Xbox Controller is pressed.
constexpr ButtonState Back() const { return back; }
//Identifies if the START button on the Xbox Controller is pressed.
constexpr ButtonState Start() const { return start; }
//Identifies if the BigButton button is pressed.
constexpr ButtonState BigButton() const { return bigButton; }
#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
private:
ButtonState a{};
ButtonState b{};
ButtonState x{};
ButtonState y{};
ButtonState leftStick{};
ButtonState rightStick{};
ButtonState leftShoulder{};
ButtonState rightShoulder{};
ButtonState back{};
ButtonState start{};
ButtonState bigButton{};
};
//Describes the capabilities of an Xbox Controller, including controller type, and identifies if the controller supports voice.
struct GamePadCapabilities {
constexpr GamePadCapabilities() = default;
constexpr GamePadCapabilities() = default;
constexpr GamePadCapabilities(bool isConnected, GamePadCapabilitiesType type) : isConnected(isConnected), type(type){}
GamePadCapabilitiesType Type{};
bool Connected{ false };
Ushort Vid{ 0 };
Ushort Pid{ 0 };
GamePadId Id{};
//Indicates whether the Xbox Controller is connected.
constexpr bool IsConnected() const { return isConnected; }
//Gets the type of controller.
constexpr GamePadCapabilitiesType GamePadType() const { return type; }
private:
GamePadCapabilitiesType type{};
bool isConnected{ false };
};
//Represents specific information about the state of an Xbox Controller, including the current state of buttons and sticks.
struct GamePadState {
constexpr GamePadState() = default;
constexpr GamePadState() = default;
constexpr GamePadState(
GamePadThumbSticks sticks,
GamePadTriggers triggers,
GamePadButtons buttons,
GamePadDPad dpad, bool isConnected
) : buttons(buttons), dpad(dpad), triggers(triggers), thumbSticks(sticks), isConnected(isConnected){}
//Determines whether specified input device buttons are pressed in this GamePadState.
constexpr bool IsButtonDown(xna::Buttons button) const {
switch (button)
{
case xna::Buttons::A:
return this->Buttons.A == ButtonState::Pressed;
return this->Buttons().A() == ButtonState::Pressed;
case xna::Buttons::B:
return this->Buttons.B == ButtonState::Pressed;
return this->Buttons().B() == ButtonState::Pressed;
case xna::Buttons::X:
return this->Buttons.X == ButtonState::Pressed;
return this->Buttons().X() == ButtonState::Pressed;
case xna::Buttons::Y:
return this->Buttons.Y == ButtonState::Pressed;
return this->Buttons().Y() == ButtonState::Pressed;
case xna::Buttons::Back:
return this->Buttons.Back == ButtonState::Pressed;
return this->Buttons().Back() == ButtonState::Pressed;
case xna::Buttons::Start:
return this->Buttons.Start == ButtonState::Pressed;
return this->Buttons().Start() == ButtonState::Pressed;
case xna::Buttons::DPadUp:
return this->Dpad.Up == ButtonState::Pressed;
return this->Dpad().Up() == ButtonState::Pressed;
case xna::Buttons::DPadDown:
return this->Dpad.Down == ButtonState::Pressed;
return this->Dpad().Down() == ButtonState::Pressed;
case xna::Buttons::DPadLeft:
return this->Dpad.Left == ButtonState::Pressed;
return this->Dpad().Left() == ButtonState::Pressed;
case xna::Buttons::DPadRight:
return this->Dpad.Right == ButtonState::Pressed;
return this->Dpad().Right() == ButtonState::Pressed;
case xna::Buttons::LeftShoulder:
return this->Buttons.LeftShoulder == ButtonState::Pressed;
return this->Buttons().LeftShoulder() == ButtonState::Pressed;
case xna::Buttons::RightShoulder:
return this->Buttons.RightShoulder == ButtonState::Pressed;
return this->Buttons().RightShoulder() == ButtonState::Pressed;
case xna::Buttons::LeftStick:
return this->Buttons.LeftStick == ButtonState::Pressed;
return this->Buttons().LeftStick() == ButtonState::Pressed;
case xna::Buttons::RightStick:
return this->Buttons.RightStick == ButtonState::Pressed;
return this->Buttons().RightStick() == ButtonState::Pressed;
case xna::Buttons::BigButton:
return this->Buttons.BigButton == ButtonState::Pressed;
return this->Buttons().BigButton() == ButtonState::Pressed;
case xna::Buttons::LeftThumbstickLeft:
return this->ThumbSticks.Left().X < 0.5F;
return this->ThumbSticks().Left().X < 0.5F;
case xna::Buttons::LeftThumbstickRight:
return this->ThumbSticks.Left().X > 0.5F;
return this->ThumbSticks().Left().X > 0.5F;
case xna::Buttons::LeftThumbstickDown:
return this->ThumbSticks.Left().Y > 0.5F;
return this->ThumbSticks().Left().Y > 0.5F;
case xna::Buttons::LeftThumbstickUp:
return this->ThumbSticks.Left().Y < 0.5F;
return this->ThumbSticks().Left().Y < 0.5F;
case xna::Buttons::RightThumbstickLeft:
return this->ThumbSticks.Right().X < 0.5F;
return this->ThumbSticks().Right().X < 0.5F;
case xna::Buttons::RightThumbstickRight:
return this->ThumbSticks.Right().X > 0.5F;
return this->ThumbSticks().Right().X > 0.5F;
case xna::Buttons::RightThumbstickDown:
return this->ThumbSticks.Right().Y > 0.5F;
return this->ThumbSticks().Right().Y > 0.5F;
case xna::Buttons::RightThumbstickUp:
return this->ThumbSticks.Right().Y < 0.5F;
return this->ThumbSticks().Right().Y < 0.5F;
case xna::Buttons::LeftTrigger:
return this->Triggers.Left() > 0.5F;
return this->Triggers().Left() > 0.5F;
case xna::Buttons::RightTrigger:
return this->Triggers.Right() > 0.5F;
return this->Triggers().Right() > 0.5F;
default:
return false;
}
}
//Determines whether specified input device buttons are up (not pressed) in this GamePadState.
constexpr bool IsButtonUp(xna::Buttons button) const {
return !IsButtonDown(button);
}
GamePadButtons Buttons{};
GamePadDPad Dpad{};
bool IsConnected{false};
Ulong PackedNumber{0};
GamePadThumbSticks ThumbSticks{};
GamePadTriggers Triggers{};
//Returns a structure that identifies what buttons on the Xbox controller are pressed.
constexpr GamePadButtons Buttons() const { return buttons; }
//Returns a structure that identifies what directions of the directional pad on the Xbox Controller are pressed.
constexpr GamePadDPad Dpad() const { return dpad; }
//Indicates whether the Xbox Controller is connected.
constexpr bool IsConnected() const { return isConnected; }
//Returns a structure that indicates the position of the Xbox Controller sticks (thumbsticks).
constexpr GamePadThumbSticks ThumbSticks() const { return thumbSticks; }
//Returns a structure that identifies the position of triggers on the Xbox controller.
constexpr GamePadTriggers Triggers() const { return triggers; }
private:
GamePadButtons buttons{};
GamePadDPad dpad{};
bool isConnected{ false };
GamePadThumbSticks thumbSticks{};
GamePadTriggers triggers{};
};
//Allows retrieval of user interaction with an Xbox Controller and setting of controller vibration motors.
@ -243,9 +298,9 @@ namespace xna {
//Gets the current state of a game pad controller. As an option, it specifies a dead zone processing method for the analog sticks.
static GamePadState GetState(PlayerIndex index, GamePadDeadZone deadZone);
//Retrieves the capabilities of an Xbox 360 Controller.
//Retrieves the capabilities of an Xbox Controller.
static GamePadCapabilities GetCapabilities(PlayerIndex index);
//Sets the vibration motor speeds on an Xbox 360 Controller.
//Sets the vibration motor speeds on an Xbox Controller.
static bool SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger = 0, float rightTrigger = 0);
private:

View File

@ -0,0 +1,256 @@
#ifndef XNA_INPUT_ENUMS_HPP
#define XNA_INPUT_ENUMS_HPP
namespace xna {
//Identifies the state of a keyboard key.
enum class KeyState {
Up,
Down,
};
//Enumerates input device buttons.
enum class Buttons {
A = 4096, // 0x00001000
B = 8192, // 0x00002000
X = 16384, // 0x00004000
Y = 32768, // 0x00008000
Back = 32, // 0x00000020
Start = 16, // 0x00000010
DPadUp = 1,
DPadDown = 2,
DPadLeft = 4,
DPadRight = 8,
LeftShoulder = 256, // 0x00000100
RightShoulder = 512, // 0x00000200
LeftStick = 64, // 0x00000040
RightStick = 128, // 0x00000080
BigButton = 2048, // 0x00000800
LeftThumbstickLeft = 2097152, // 0x00200000
LeftThumbstickRight = 1073741824, // 0x40000000
LeftThumbstickDown = 536870912, // 0x20000000
LeftThumbstickUp = 268435456, // 0x10000000
RightThumbstickLeft = 134217728, // 0x08000000
RightThumbstickRight = 67108864, // 0x04000000
RightThumbstickDown = 33554432, // 0x02000000
RightThumbstickUp = 16777216, // 0x01000000
LeftTrigger = 8388608, // 0x00800000
RightTrigger = 4194304, // 0x00400000
};
//Identifies the state of a controller button.
enum class ButtonState
{
Released,
Pressed,
};
//Describes the type of a specified Xbox Controller.
enum class GamePadCapabilitiesType
{
Unknown = 0,
Gamepad,
Wheel,
ArdaceStick,
FlightStick,
DancePAd,
Guitar,
GuitarAlternate,
DrumKit,
GuitarBass = 11,
ArcadePad = 19,
};
//Specifies a type of dead zone processing to apply to Xbox Controller analog sticks when calling GetState.
enum class GamePadDeadZone {
//The X and Y positions of each stick are compared against the dead zone independently. This setting is the default when calling GetState.
IndependentAxes,
//The combined X and Y position of each stick is compared to the dead zone.
//This provides better control than IndependentAxes when the stick is used as a two-dimensional control surface, such as when controlling a character's view in a first-person game.
Circular,
//The values of each stick are not processed and are returned by GetState as "raw" values. This is best if you intend to implement your own dead zone processing.
None,
};
enum class Keys : unsigned char {
None = 0,
Back = 0x8,
Tab = 0x9,
Enter = 0xd,
Pause = 0x13,
CapsLock = 0x14,
Kana = 0x15,
ImeOn = 0x16,
Kanji = 0x19,
ImeOff = 0x1a,
Escape = 0x1b,
ImeConvert = 0x1c,
ImeNoConvert = 0x1d,
Space = 0x20,
PageUp = 0x21,
PageDown = 0x22,
End = 0x23,
Home = 0x24,
Left = 0x25,
Up = 0x26,
Right = 0x27,
Down = 0x28,
Select = 0x29,
Print = 0x2a,
Execute = 0x2b,
PrintScreen = 0x2c,
Insert = 0x2d,
Delete = 0x2e,
Help = 0x2f,
D0 = 0x30,
D1 = 0x31,
D2 = 0x32,
D3 = 0x33,
D4 = 0x34,
D5 = 0x35,
D6 = 0x36,
D7 = 0x37,
D8 = 0x38,
D9 = 0x39,
A = 0x41,
B = 0x42,
C = 0x43,
D = 0x44,
E = 0x45,
F = 0x46,
G = 0x47,
H = 0x48,
I = 0x49,
J = 0x4a,
K = 0x4b,
L = 0x4c,
M = 0x4d,
N = 0x4e,
O = 0x4f,
P = 0x50,
Q = 0x51,
R = 0x52,
S = 0x53,
T = 0x54,
U = 0x55,
V = 0x56,
W = 0x57,
X = 0x58,
Y = 0x59,
Z = 0x5a,
LeftWindows = 0x5b,
RightWindows = 0x5c,
Apps = 0x5d,
Sleep = 0x5f,
NumPad0 = 0x60,
NumPad1 = 0x61,
NumPad2 = 0x62,
NumPad3 = 0x63,
NumPad4 = 0x64,
NumPad5 = 0x65,
NumPad6 = 0x66,
NumPad7 = 0x67,
NumPad8 = 0x68,
NumPad9 = 0x69,
Multiply = 0x6a,
Add = 0x6b,
Separator = 0x6c,
Subtract = 0x6d,
Decimal = 0x6e,
Divide = 0x6f,
F1 = 0x70,
F2 = 0x71,
F3 = 0x72,
F4 = 0x73,
F5 = 0x74,
F6 = 0x75,
F7 = 0x76,
F8 = 0x77,
F9 = 0x78,
F10 = 0x79,
F11 = 0x7a,
F12 = 0x7b,
F13 = 0x7c,
F14 = 0x7d,
F15 = 0x7e,
F16 = 0x7f,
F17 = 0x80,
F18 = 0x81,
F19 = 0x82,
F20 = 0x83,
F21 = 0x84,
F22 = 0x85,
F23 = 0x86,
F24 = 0x87,
NumLock = 0x90,
Scroll = 0x91,
LeftShift = 0xa0,
RightShift = 0xa1,
LeftControl = 0xa2,
RightControl = 0xa3,
LeftAlt = 0xa4,
RightAlt = 0xa5,
BrowserBack = 0xa6,
BrowserForward = 0xa7,
BrowserRefresh = 0xa8,
BrowserStop = 0xa9,
BrowserSearch = 0xaa,
BrowserFavorites = 0xab,
BrowserHome = 0xac,
VolumeMute = 0xad,
VolumeDown = 0xae,
VolumeUp = 0xaf,
MediaNextTrack = 0xb0,
MediaPreviousTrack = 0xb1,
MediaStop = 0xb2,
MediaPlayPause = 0xb3,
LaunchMail = 0xb4,
SelectMedia = 0xb5,
LaunchApplication1 = 0xb6,
LaunchApplication2 = 0xb7,
OemSemicolon = 0xba,
OemPlus = 0xbb,
OemComma = 0xbc,
OemMinus = 0xbd,
OemPeriod = 0xbe,
OemQuestion = 0xbf,
OemTilde = 0xc0,
OemOpenBrackets = 0xdb,
OemPipe = 0xdc,
OemCloseBrackets = 0xdd,
OemQuotes = 0xde,
Oem8 = 0xdf,
OemBackslash = 0xe2,
ProcessKey = 0xe5,
OemCopy = 0xf2,
OemAuto = 0xf3,
OemEnlW = 0xf4,
Attn = 0xf6,
Crsel = 0xf7,
Exsel = 0xf8,
EraseEof = 0xf9,
Play = 0xfa,
Zoom = 0xfb,
Pa1 = 0xfd,
OemClear = 0xfe,
};
}
#endif

View File

@ -2,6 +2,7 @@
#define XNA_INPUT_KEYBOARD_HPP
#include "../default.hpp"
#include "input-enums.hpp"
namespace xna {
//Represents a state of keystrokes recorded by a keyboard input device.
@ -10,6 +11,8 @@ namespace xna {
//same implementation of the DirectX::Keyboard::State structure
//
public:
//Returns whether a specified key is currently being pressed.
constexpr bool IsKeyDown(Keys key) const {
const auto k = static_cast<unsigned char>(key);
@ -22,10 +25,19 @@ namespace xna {
return false;
}
//Returns whether a specified key is currently not pressed.
constexpr bool IsKeyUp(Keys key) const {
return !IsKeyDown(key);
}
//Returns the state of a particular key.
KeyState operator[](Keys key) {
const auto isDown = IsKeyDown(key);
const auto state = static_cast<KeyState>(static_cast<int>(isDown));
return state;
}
private:
bool Reserved0 : 8;
bool Back : 1; // VK_BACK, 0x8
@ -217,9 +229,8 @@ namespace xna {
//Allows retrieval of keystrokes from a keyboard input device.
class Keyboard {
public:
//Returns the current keyboard or Chatpad state.
static KeyboardState GetState();
static bool IsConnected();
//Returns the current keyboard.
static KeyboardState GetState();
private:
friend class Game;

View File

@ -2,17 +2,27 @@
#define XNA_INPUT_MOUSE_HPP
#include "../default.hpp"
#include "input-enums.hpp"
namespace xna {
//Represents the state of a mouse input device, including mouse cursor position and buttons pressed.
struct MouseState {
//Returns the state of the left mouse button.
ButtonState LeftButton{ ButtonState::Released };
ButtonState RightButton{ ButtonState::Released };
//Returns the state of the middle mouse button.
ButtonState MiddleButton{ ButtonState::Released };
ButtonState XButton1{ ButtonState::Released };
ButtonState XButton2{ ButtonState::Released };
int X{ 0 };
int Y{ 0 };
//Returns the state of the right mouse button.
ButtonState RightButton{ ButtonState::Released };
//Gets the cumulative mouse scroll wheel value since the game was started.
int ScroolWheelValue{ 0 };
//Specifies the horizontal position of the mouse cursor.
int X{ 0 };
//Returns the state of XBUTTON1.
ButtonState XButton1{ ButtonState::Released };
//Returns the state of XBUTTON2.
ButtonState XButton2{ ButtonState::Released };
//Specifies the vertical position of the mouse cursor.
int Y{ 0 };
};
//Allows retrieval of position and button clicks from a mouse input device.
@ -21,19 +31,29 @@ namespace xna {
//Gets the current state of the mouse, including mouse position and buttons pressed.
static MouseState GetState();
static bool IsConnected();
static bool IsVisible();
static void IsVisible(bool value);
static void ResetScrollWheel();
//Gets or sets the window used for mouse processing.
//Mouse coordinates returned by GetState are relative to the upper-left corner of this window.
constexpr static intptr_t WindowHandle() {
return windowHandle;
}
//Gets or sets the window used for mouse processing.
//Mouse coordinates returned by GetState are relative to the upper-left corner of this window.
static void WindowHandle(intptr_t value);
//Sets the position of the mouse cursor relative to the upper-left corner of the window.
static void SetPosition(Int x, Int y);
private:
friend class Game;
static void Initialize();
static void Initialize(intptr_t windowHandle);
Mouse() = default;
Mouse(Mouse&) = default;
Mouse(Mouse&&) = default;
inline static intptr_t windowHandle = 0;
public:
struct PlatformImplementation;
inline static uptr<PlatformImplementation> impl = nullptr;

View File

@ -635,21 +635,29 @@ namespace xna {
};
struct Keyboard::PlatformImplementation {
uptr<DirectX::Keyboard> _dxKeyboard = unew<DirectX::Keyboard>();
PlatformImplementation() {
_dxKeyboard = unew<DirectX::Keyboard>();
}
void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const {
uptr<DirectX::Keyboard> _dxKeyboard = nullptr;
inline void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const {
if (_dxKeyboard)
_dxKeyboard->ProcessMessage(message, wParam, lParam);
}
};
struct Mouse::PlatformImplementation {
uptr<DirectX::Mouse> _dxMouse = unew<DirectX::Mouse>();
PlatformImplementation() {
_dxMouse = unew<DirectX::Mouse>();
}
void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const {
inline void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const {
if (_dxMouse)
_dxMouse->ProcessMessage(message, wParam, lParam);
}
}
uptr<DirectX::Mouse> _dxMouse = nullptr;
};
struct RasterizerState::PlatformImplementation {

View File

@ -4,4 +4,4 @@
# Add source to this project's executable.
add_subdirectory ("01_blank")
add_subdirectory ("02_PlatfformerStarterKit")
#add_subdirectory ("02_PlatfformerStarterKit")