From e73633b88f812a6d17caf7d8db461224840aaf50 Mon Sep 17 00:00:00 2001 From: Danilo Date: Fri, 19 Apr 2024 16:21:45 -0300 Subject: [PATCH] =?UTF-8?q?Implementa=20mudan=C3=A7as=20em=20Input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/CMakeLists.txt | 3 ++- framework/common/vectors.cpp | 4 ++++ framework/forward.hpp | 6 ++++++ framework/platform/audioengine-dx.hpp | 19 +++++++++++++++++++ framework/platform/audioengine.dx.cpp | 5 +++++ framework/platform/gamepad-dx.hpp | 25 +++++++++++++++++++++++-- framework/platform/keyboard-dx.hpp | 15 +++++++++++---- framework/platform/mouse-dx.hpp | 7 ++++++- framework/platform/window-dx.cpp | 3 +++ framework/sound/audioengine.hpp | 17 +++++++++++++++++ framework/sound/soundeffect.hpp | 10 ++++++++++ framework/types.hpp | 7 +++++++ framework/xna.cpp | 1 + 13 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 framework/platform/audioengine-dx.hpp create mode 100644 framework/platform/audioengine.dx.cpp create mode 100644 framework/sound/audioengine.hpp create mode 100644 framework/sound/soundeffect.hpp diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 4d881ea..9becb06 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -19,6 +19,7 @@ endif() # Url: https://learn.microsoft.com/pt-br/vcpkg/get_started/get-started?pivots=shell-cmd # # Siga os procedimentos da página oficial do DirectxTK para instalação via vcpkg +# $- vcpkg install directxtk[tools,spectre,xaudio2-9] # # [!] Atualize o arquivo CMakePresets.json, nos 'presets' necessários, # para que find_package execute corretamente @@ -29,4 +30,4 @@ endif() # find_package(directxtk CONFIG REQUIRED) -target_link_libraries(${PROJECT_NAME} D3d11.lib dxgi.lib d3dcompiler.lib Microsoft::DirectXTK) +target_link_libraries(${PROJECT_NAME} D3d11.lib dxgi.lib dxguid.lib d3dcompiler.lib Microsoft::DirectXTK) diff --git a/framework/common/vectors.cpp b/framework/common/vectors.cpp index d4a7272..34ced99 100644 --- a/framework/common/vectors.cpp +++ b/framework/common/vectors.cpp @@ -56,6 +56,8 @@ namespace xna { destinationArray[destinationIndex].X = (source.X * matrix.M11 + source.Y * matrix.M21); destinationArray[destinationIndex].Y = (source.X * matrix.M12 + source.Y * matrix.M22); } + + return true; } bool Vector2::Transform(Vector2 const* sourceArray, size_t sourceArrayLength, Quaternion const& rotation, Vector2* destinationArray, size_t destinationArrayLength) { @@ -111,5 +113,7 @@ namespace xna { ++sourceIndex; ++destinationIndex; } + + return true; } } \ No newline at end of file diff --git a/framework/forward.hpp b/framework/forward.hpp index b6ec522..53b334e 100644 --- a/framework/forward.hpp +++ b/framework/forward.hpp @@ -4,6 +4,12 @@ #include "types.hpp" namespace xna { + //Audio + class SoundEffect; + using PSoundEffect = std::shared_ptr; + class AudioEngine; + using PAudioEngine = std::shared_ptr; + //CShap struct TimeSpan; using PTimeSpan = std::shared_ptr; diff --git a/framework/platform/audioengine-dx.hpp b/framework/platform/audioengine-dx.hpp new file mode 100644 index 0000000..a88ef46 --- /dev/null +++ b/framework/platform/audioengine-dx.hpp @@ -0,0 +1,19 @@ +#ifndef XNA_PLATFORM_SOUNDENGINE_DX_HPP +#define XNA_PLATFORM_SOUNDENGINE_DX_HPP + +#include "../sound/audioengine.hpp" + + +namespace xna { + class AudioEngine : public IAudioEngine { + public: + AudioEngine() { + + } + + public: + //static inline uptr _dxAudioEngine = uNew(); + }; +} + +#endif \ No newline at end of file diff --git a/framework/platform/audioengine.dx.cpp b/framework/platform/audioengine.dx.cpp new file mode 100644 index 0000000..865c570 --- /dev/null +++ b/framework/platform/audioengine.dx.cpp @@ -0,0 +1,5 @@ +#include "audioengine-dx.hpp" + +namespace xna { + +} \ No newline at end of file diff --git a/framework/platform/gamepad-dx.hpp b/framework/platform/gamepad-dx.hpp index 422216e..5775ad6 100644 --- a/framework/platform/gamepad-dx.hpp +++ b/framework/platform/gamepad-dx.hpp @@ -252,7 +252,7 @@ namespace xna { private: GamePadCapabilitiesType _type{}; bool _connected{ false }; - GamePadId _id{ 0 }; + GamePadId _id; Ushort _vid{ 0 }; Ushort _pid{ 0 }; }; @@ -359,10 +359,22 @@ namespace xna { class GamePad : public IGamePad { public: - inline static sptr _dxGamePad = New(); + static void Initialize() { + _dxGamePad = uNew(); + } + + inline static uptr _dxGamePad = nullptr; + + private: + constexpr GamePad() = default; + constexpr GamePad(GamePad&&) = default; + constexpr GamePad(const GamePad&) = default; }; inline GamePadState IGamePad::GetState(PlayerIndex index) { + if (!GamePad::_dxGamePad) + return GamePadState(); + const auto state = GamePad::_dxGamePad->GetState( static_cast(index) ); @@ -370,6 +382,9 @@ namespace xna { } inline GamePadState IGamePad::GetState(PlayerIndex index, GamePadDeadZone deadZone) { + if (!GamePad::_dxGamePad) + return GamePadState(); + const auto state = GamePad::_dxGamePad->GetState( static_cast(index), static_cast(deadZone) @@ -378,11 +393,17 @@ namespace xna { } inline GamePadCapabilities IGamePad::GetCapabilities(PlayerIndex index) { + if (!GamePad::_dxGamePad) + return GamePadCapabilities(); + const auto capabilities = GamePad::_dxGamePad->GetCapabilities(static_cast(index)); return GamePadCapabilities(capabilities); } inline bool IGamePad::SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger) { + if (!GamePad::_dxGamePad) + return false; + return GamePad::_dxGamePad->SetVibration(static_cast(index), leftMotor, rightMotor, leftTrigger, rightTrigger); } } diff --git a/framework/platform/keyboard-dx.hpp b/framework/platform/keyboard-dx.hpp index 902334b..af5ad26 100644 --- a/framework/platform/keyboard-dx.hpp +++ b/framework/platform/keyboard-dx.hpp @@ -25,20 +25,27 @@ namespace xna { }; class Keyboard : public IKeyboard { - public: - Keyboard() = default; + private: + constexpr Keyboard() = default; + constexpr Keyboard(Keyboard&&) = default; + constexpr Keyboard(const Keyboard&) = default; public: - inline static sptr _dxKeyboard = New(); + inline static uptr _dxKeyboard = nullptr; }; inline KeyboardState IKeyboard::GetState() { - + if (!Keyboard::_dxKeyboard) + return KeyboardState(); + const auto state = Keyboard::_dxKeyboard->GetState(); return KeyboardState(state); } inline bool IKeyboard::IsConnected() { + if (!Keyboard::_dxKeyboard) + return false; + return Keyboard::_dxKeyboard->IsConnected(); } } diff --git a/framework/platform/mouse-dx.hpp b/framework/platform/mouse-dx.hpp index 9ad5d93..9ffdd28 100644 --- a/framework/platform/mouse-dx.hpp +++ b/framework/platform/mouse-dx.hpp @@ -22,7 +22,12 @@ namespace xna { struct Mouse : public IMouse { public: - inline static sptr _dxMouse = New(); + inline static uptr _dxMouse = nullptr; + + private: + constexpr Mouse() = default; + constexpr Mouse(Mouse&&) = default; + constexpr Mouse(const Mouse&) = default; }; inline MouseState IMouse::GetState() { diff --git a/framework/platform/window-dx.cpp b/framework/platform/window-dx.cpp index 5352cda..67fa7d3 100644 --- a/framework/platform/window-dx.cpp +++ b/framework/platform/window-dx.cpp @@ -134,6 +134,9 @@ namespace xna { LRESULT GameWindow::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { + if (!Keyboard::_dxKeyboard) Keyboard::_dxKeyboard = uNew(); + if (!Mouse::_dxMouse) Mouse::_dxMouse = uNew(); + switch (msg) { case WM_DESTROY: PostQuitMessage(0); diff --git a/framework/sound/audioengine.hpp b/framework/sound/audioengine.hpp new file mode 100644 index 0000000..269cd0c --- /dev/null +++ b/framework/sound/audioengine.hpp @@ -0,0 +1,17 @@ +#ifndef XNA_SOUND_SOUNDENGINE_HPP +#define XNA_SOUND_SOUNDENGINE_HPP + +#include "../default.hpp" +//#include + +namespace xna { + class IAudioEngine { + public: + virtual ~IAudioEngine(){} + + public: + //uptr _dxAudioEngine = nullptr; + }; +} + +#endif \ No newline at end of file diff --git a/framework/sound/soundeffect.hpp b/framework/sound/soundeffect.hpp new file mode 100644 index 0000000..b1cf0d0 --- /dev/null +++ b/framework/sound/soundeffect.hpp @@ -0,0 +1,10 @@ +#ifndef XNA_SOUND_SOUNDEFFECT_HPP +#define XNA_SOUND_SOUNDEFFECT_HPP + +#include "../default.hpp" + +namespace xna { + +} + +#endif \ No newline at end of file diff --git a/framework/types.hpp b/framework/types.hpp index 8adac56..f162b5e 100644 --- a/framework/types.hpp +++ b/framework/types.hpp @@ -47,12 +47,19 @@ namespace xna { template using sptr = std::shared_ptr; + template + using uptr = std::unique_ptr; template inline std::shared_ptr<_Ty> New(_Types&&... _Args) { return std::make_shared<_Ty>(std::forward<_Types>(_Args)...); } + template + inline std::unique_ptr<_Ty> uNew(_Types&&... _Args) { + return std::make_unique<_Ty>(std::forward<_Types>(_Args)...); + } + #define PLATFORM_DEVELOPMENT //See ref: https://en.cppreference.com/w/cpp/error/assert diff --git a/framework/xna.cpp b/framework/xna.cpp index ea10de7..150565d 100644 --- a/framework/xna.cpp +++ b/framework/xna.cpp @@ -23,6 +23,7 @@ public: graphics->Initialize(); Game::Initialize(); + GamePad::Initialize(); } void LoadContent() override {