From dd43ea7dbc975179fc512948fd28092f83a0dfbf Mon Sep 17 00:00:00 2001 From: Danilo Date: Sat, 22 Jun 2024 16:24:11 -0300 Subject: [PATCH] =?UTF-8?q?Coment=C3=A1rios=20em=20Input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/platform-dx/gamepad.cpp | 3 +-- framework/platform-dx/keyboard.cpp | 1 - framework/platform-dx/mouse.cpp | 1 - inc/xna/input/gamepad.hpp | 26 ++++++++++++++++++++------ inc/xna/input/keyboard.hpp | 20 ++++++++++++++++---- inc/xna/input/mouse.hpp | 13 +++++++++++-- inc/xna/platform-dx/dx.hpp | 15 ++++++++------- 7 files changed, 56 insertions(+), 23 deletions(-) diff --git a/framework/platform-dx/gamepad.cpp b/framework/platform-dx/gamepad.cpp index c62a8c1..16035f8 100644 --- a/framework/platform-dx/gamepad.cpp +++ b/framework/platform-dx/gamepad.cpp @@ -3,8 +3,7 @@ namespace xna { void GamePad::Initialize() { - impl = unew(); - impl->_dxGamePad = unew(); + impl = unew(); } GamePadState GamePad::GetState(PlayerIndex index) { diff --git a/framework/platform-dx/keyboard.cpp b/framework/platform-dx/keyboard.cpp index b8968cb..d373fe5 100644 --- a/framework/platform-dx/keyboard.cpp +++ b/framework/platform-dx/keyboard.cpp @@ -15,7 +15,6 @@ namespace xna { void Keyboard::Initialize() { impl = unew(); - impl->_dxKeyboard = unew(); } bool Keyboard::IsConnected() { diff --git a/framework/platform-dx/mouse.cpp b/framework/platform-dx/mouse.cpp index 53dc95a..87614c8 100644 --- a/framework/platform-dx/mouse.cpp +++ b/framework/platform-dx/mouse.cpp @@ -50,6 +50,5 @@ namespace xna { void Mouse::Initialize() { impl = unew(); - impl->_dxMouse = unew(); } } \ No newline at end of file diff --git a/inc/xna/input/gamepad.hpp b/inc/xna/input/gamepad.hpp index f77ca95..9e52515 100644 --- a/inc/xna/input/gamepad.hpp +++ b/inc/xna/input/gamepad.hpp @@ -5,6 +5,7 @@ #include "../common/numerics.hpp" namespace xna { + //Structure that defines the position of the left and right triggers on an Xbox Controller. struct GamePadTriggers { constexpr GamePadTriggers() = default; @@ -37,6 +38,7 @@ namespace xna { } }; + //Structure that represents the position of left and right sticks (thumbsticks) on an Xbox Controller. struct GamePadThumbSticks { constexpr GamePadThumbSticks() = default; @@ -69,6 +71,7 @@ namespace xna { } }; + //Identifies which directions on the directional pad of an Xbox Controller are being pressed. struct GamePadDPad { constexpr GamePadDPad() = default; @@ -83,6 +86,7 @@ namespace xna { ButtonState Left{}; }; + //Identifies whether buttons on an Xbox Controller are pressed or released. struct GamePadButtons { constexpr GamePadButtons() = default; @@ -146,6 +150,7 @@ namespace xna { using GamePadId = uint64_t; #endif + //Describes the capabilities of an Xbox Controller, including controller type, and identifies if the controller supports voice. struct GamePadCapabilities { constexpr GamePadCapabilities() = default; @@ -156,6 +161,7 @@ namespace xna { GamePadId Id{}; }; + //Represents specific information about the state of an Xbox Controller, including the current state of buttons and sticks. struct GamePadState { constexpr GamePadState() = default; @@ -229,22 +235,30 @@ namespace xna { GamePadTriggers Triggers{}; }; + //Allows retrieval of user interaction with an Xbox Controller and setting of controller vibration motors. class GamePad { public: + //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); + //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. static GamePadCapabilities GetCapabilities(PlayerIndex index); + //Sets the vibration motor speeds on an Xbox 360 Controller. static bool SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger = 0, float rightTrigger = 0); + + GamePad() = delete; + GamePad(GamePad&) = delete; + GamePad(GamePad&&) = delete; + + private: + friend class Game; static void Initialize(); public: struct PlatformImplementation; - inline static uptr impl = nullptr; - - private: - GamePad(); - GamePad(GamePad&&); - GamePad(GamePad&); + inline static uptr impl = nullptr; }; } diff --git a/inc/xna/input/keyboard.hpp b/inc/xna/input/keyboard.hpp index 152c1ed..7957664 100644 --- a/inc/xna/input/keyboard.hpp +++ b/inc/xna/input/keyboard.hpp @@ -4,9 +4,13 @@ #include "../default.hpp" namespace xna { + //Represents a state of keystrokes recorded by a keyboard input device. struct KeyboardState { + // + //same implementation of the DirectX::Keyboard::State structure + // public: - bool IsKeyDown(Keys key) const { + constexpr bool IsKeyDown(Keys key) const { const auto k = static_cast(key); if (k <= 0xfe) @@ -18,7 +22,7 @@ namespace xna { return false; } - bool IsKeyUp(Keys key) const { + constexpr bool IsKeyUp(Keys key) const { return !IsKeyDown(key); } @@ -210,13 +214,21 @@ namespace xna { bool Reserved26 : 1; }; + //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(); - static void Initialize(); static bool IsConnected(); + Keyboard() = delete; + Keyboard(Keyboard&) = delete; + Keyboard(Keyboard&&) = delete; + + private: + friend class Game; + static void Initialize(); + public: struct PlatformImplementation; inline static uptr impl = nullptr; diff --git a/inc/xna/input/mouse.hpp b/inc/xna/input/mouse.hpp index 940969d..2f8277f 100644 --- a/inc/xna/input/mouse.hpp +++ b/inc/xna/input/mouse.hpp @@ -15,19 +15,28 @@ namespace xna { int ScroolWheelValue{ 0 }; }; + //Allows retrieval of position and button clicks from a mouse input device. class Mouse { public: + //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(); + static void ResetScrollWheel(); + Mouse() = delete; + Mouse(Mouse&) = delete; + Mouse(Mouse&&) = delete; + + private: + friend class Game; static void Initialize(); public: struct PlatformImplementation; - inline static uptr impl = nullptr; + inline static uptr impl = nullptr; }; } diff --git a/inc/xna/platform-dx/dx.hpp b/inc/xna/platform-dx/dx.hpp index 7ad64d6..bd19353 100644 --- a/inc/xna/platform-dx/dx.hpp +++ b/inc/xna/platform-dx/dx.hpp @@ -59,6 +59,7 @@ using comptr = Microsoft::WRL::ComPtr; // OTHERS INCLUDES //--------------------------------// +#include "../default.hpp" #include "../exception.hpp" #include "../graphics/blendstate.hpp" #include "../graphics/adapter.hpp" @@ -586,14 +587,14 @@ namespace xna { }; struct GamePad::PlatformImplementation { - inline static uptr _dxGamePad = nullptr; + uptr _dxGamePad = unew(); - void Suspend() { + void Suspend() const { if (_dxGamePad) _dxGamePad->Suspend(); } - void Resume() { + void Resume() const { if (_dxGamePad) _dxGamePad->Resume(); } @@ -611,18 +612,18 @@ namespace xna { }; struct Keyboard::PlatformImplementation { - inline static uptr _dxKeyboard = nullptr; + uptr _dxKeyboard = unew(); - void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) { + void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const { if (_dxKeyboard) _dxKeyboard->ProcessMessage(message, wParam, lParam); } }; struct Mouse::PlatformImplementation { - inline static uptr _dxMouse = nullptr; + uptr _dxMouse = unew(); - void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) { + void ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam) const { if (_dxMouse) _dxMouse->ProcessMessage(message, wParam, lParam); }