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

Implementa mudanças em Input

This commit is contained in:
Danilo 2024-04-19 16:21:45 -03:00
parent c112e25331
commit e73633b88f
13 changed files with 114 additions and 8 deletions

View File

@ -19,6 +19,7 @@ endif()
# Url: https://learn.microsoft.com/pt-br/vcpkg/get_started/get-started?pivots=shell-cmd # 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 # 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, # [!] Atualize o arquivo CMakePresets.json, nos 'presets' necessários,
# para que find_package execute corretamente # para que find_package execute corretamente
@ -29,4 +30,4 @@ endif()
# #
find_package(directxtk CONFIG REQUIRED) 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)

View File

@ -56,6 +56,8 @@ namespace xna {
destinationArray[destinationIndex].X = (source.X * matrix.M11 + source.Y * matrix.M21); destinationArray[destinationIndex].X = (source.X * matrix.M11 + source.Y * matrix.M21);
destinationArray[destinationIndex].Y = (source.X * matrix.M12 + source.Y * matrix.M22); 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) { bool Vector2::Transform(Vector2 const* sourceArray, size_t sourceArrayLength, Quaternion const& rotation, Vector2* destinationArray, size_t destinationArrayLength) {
@ -111,5 +113,7 @@ namespace xna {
++sourceIndex; ++sourceIndex;
++destinationIndex; ++destinationIndex;
} }
return true;
} }
} }

View File

@ -4,6 +4,12 @@
#include "types.hpp" #include "types.hpp"
namespace xna { namespace xna {
//Audio
class SoundEffect;
using PSoundEffect = std::shared_ptr<SoundEffect>;
class AudioEngine;
using PAudioEngine = std::shared_ptr<AudioEngine>;
//CShap //CShap
struct TimeSpan; struct TimeSpan;
using PTimeSpan = std::shared_ptr<TimeSpan>; using PTimeSpan = std::shared_ptr<TimeSpan>;

View File

@ -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<DirectX::AudioEngine> _dxAudioEngine = uNew<DirectX::AudioEngine>();
};
}
#endif

View File

@ -0,0 +1,5 @@
#include "audioengine-dx.hpp"
namespace xna {
}

View File

@ -252,7 +252,7 @@ namespace xna {
private: private:
GamePadCapabilitiesType _type{}; GamePadCapabilitiesType _type{};
bool _connected{ false }; bool _connected{ false };
GamePadId _id{ 0 }; GamePadId _id;
Ushort _vid{ 0 }; Ushort _vid{ 0 };
Ushort _pid{ 0 }; Ushort _pid{ 0 };
}; };
@ -359,10 +359,22 @@ namespace xna {
class GamePad : public IGamePad { class GamePad : public IGamePad {
public: public:
inline static sptr<DirectX::GamePad> _dxGamePad = New<DirectX::GamePad>(); static void Initialize() {
_dxGamePad = uNew<DirectX::GamePad>();
}
inline static uptr<DirectX::GamePad> _dxGamePad = nullptr;
private:
constexpr GamePad() = default;
constexpr GamePad(GamePad&&) = default;
constexpr GamePad(const GamePad&) = default;
}; };
inline GamePadState IGamePad::GetState(PlayerIndex index) { inline GamePadState IGamePad::GetState(PlayerIndex index) {
if (!GamePad::_dxGamePad)
return GamePadState();
const auto state = GamePad::_dxGamePad->GetState( const auto state = GamePad::_dxGamePad->GetState(
static_cast<int>(index) static_cast<int>(index)
); );
@ -370,6 +382,9 @@ namespace xna {
} }
inline GamePadState IGamePad::GetState(PlayerIndex index, GamePadDeadZone deadZone) { inline GamePadState IGamePad::GetState(PlayerIndex index, GamePadDeadZone deadZone) {
if (!GamePad::_dxGamePad)
return GamePadState();
const auto state = GamePad::_dxGamePad->GetState( const auto state = GamePad::_dxGamePad->GetState(
static_cast<int>(index), static_cast<int>(index),
static_cast<DirectX::GamePad::DeadZone>(deadZone) static_cast<DirectX::GamePad::DeadZone>(deadZone)
@ -378,11 +393,17 @@ namespace xna {
} }
inline GamePadCapabilities IGamePad::GetCapabilities(PlayerIndex index) { inline GamePadCapabilities IGamePad::GetCapabilities(PlayerIndex index) {
if (!GamePad::_dxGamePad)
return GamePadCapabilities();
const auto capabilities = GamePad::_dxGamePad->GetCapabilities(static_cast<int>(index)); const auto capabilities = GamePad::_dxGamePad->GetCapabilities(static_cast<int>(index));
return GamePadCapabilities(capabilities); return GamePadCapabilities(capabilities);
} }
inline bool IGamePad::SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger) { 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<int>(index), leftMotor, rightMotor, leftTrigger, rightTrigger); return GamePad::_dxGamePad->SetVibration(static_cast<int>(index), leftMotor, rightMotor, leftTrigger, rightTrigger);
} }
} }

View File

@ -25,20 +25,27 @@ namespace xna {
}; };
class Keyboard : public IKeyboard { class Keyboard : public IKeyboard {
public: private:
Keyboard() = default; constexpr Keyboard() = default;
constexpr Keyboard(Keyboard&&) = default;
constexpr Keyboard(const Keyboard&) = default;
public: public:
inline static sptr<DirectX::Keyboard> _dxKeyboard = New<DirectX::Keyboard>(); inline static uptr<DirectX::Keyboard> _dxKeyboard = nullptr;
}; };
inline KeyboardState IKeyboard::GetState() { inline KeyboardState IKeyboard::GetState() {
if (!Keyboard::_dxKeyboard)
return KeyboardState();
const auto state = Keyboard::_dxKeyboard->GetState(); const auto state = Keyboard::_dxKeyboard->GetState();
return KeyboardState(state); return KeyboardState(state);
} }
inline bool IKeyboard::IsConnected() { inline bool IKeyboard::IsConnected() {
if (!Keyboard::_dxKeyboard)
return false;
return Keyboard::_dxKeyboard->IsConnected(); return Keyboard::_dxKeyboard->IsConnected();
} }
} }

View File

@ -22,7 +22,12 @@ namespace xna {
struct Mouse : public IMouse { struct Mouse : public IMouse {
public: public:
inline static sptr<DirectX::Mouse> _dxMouse = New<DirectX::Mouse>(); inline static uptr<DirectX::Mouse> _dxMouse = nullptr;
private:
constexpr Mouse() = default;
constexpr Mouse(Mouse&&) = default;
constexpr Mouse(const Mouse&) = default;
}; };
inline MouseState IMouse::GetState() { inline MouseState IMouse::GetState() {

View File

@ -134,6 +134,9 @@ namespace xna {
LRESULT GameWindow::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT GameWindow::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
if (!Keyboard::_dxKeyboard) Keyboard::_dxKeyboard = uNew<DirectX::Keyboard>();
if (!Mouse::_dxMouse) Mouse::_dxMouse = uNew<DirectX::Mouse>();
switch (msg) { switch (msg) {
case WM_DESTROY: case WM_DESTROY:
PostQuitMessage(0); PostQuitMessage(0);

View File

@ -0,0 +1,17 @@
#ifndef XNA_SOUND_SOUNDENGINE_HPP
#define XNA_SOUND_SOUNDENGINE_HPP
#include "../default.hpp"
//#include <Audio.h>
namespace xna {
class IAudioEngine {
public:
virtual ~IAudioEngine(){}
public:
//uptr<DirectX::AudioEngine> _dxAudioEngine = nullptr;
};
}
#endif

View File

@ -0,0 +1,10 @@
#ifndef XNA_SOUND_SOUNDEFFECT_HPP
#define XNA_SOUND_SOUNDEFFECT_HPP
#include "../default.hpp"
namespace xna {
}
#endif

View File

@ -47,12 +47,19 @@ namespace xna {
template <typename T> template <typename T>
using sptr = std::shared_ptr<T>; using sptr = std::shared_ptr<T>;
template <typename T>
using uptr = std::unique_ptr<T>;
template <class _Ty, class... _Types> template <class _Ty, class... _Types>
inline std::shared_ptr<_Ty> New(_Types&&... _Args) { inline std::shared_ptr<_Ty> New(_Types&&... _Args) {
return std::make_shared<_Ty>(std::forward<_Types>(_Args)...); return std::make_shared<_Ty>(std::forward<_Types>(_Args)...);
} }
template <class _Ty, class... _Types>
inline std::unique_ptr<_Ty> uNew(_Types&&... _Args) {
return std::make_unique<_Ty>(std::forward<_Types>(_Args)...);
}
#define PLATFORM_DEVELOPMENT #define PLATFORM_DEVELOPMENT
//See ref: https://en.cppreference.com/w/cpp/error/assert //See ref: https://en.cppreference.com/w/cpp/error/assert

View File

@ -23,6 +23,7 @@ public:
graphics->Initialize(); graphics->Initialize();
Game::Initialize(); Game::Initialize();
GamePad::Initialize();
} }
void LoadContent() override { void LoadContent() override {