Skip to content

Commit 09508a6

Browse files
authored
GameInput implementation updates for for GAMEINPUT_API_VERSION = 2 (#336)
1 parent f3316f0 commit 09508a6

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

Inc/GamePad.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,16 @@ namespace DirectX
331331
DIRECTX_TOOLKIT_API void __cdecl RegisterEvents(void* ctrlChanged) noexcept;
332332

333333
// Underlying device access
334+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
335+
using GameInputDevice_t = GameInput::v1::IGameInputDevice;
336+
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 2)
337+
using GameInputDevice_t = GameInput::v2::IGameInputDevice;
338+
#else
339+
using GameInputDevice_t = ::IGameInputDevice;
340+
#endif
341+
334342
_Success_(return)
335-
DIRECTX_TOOLKIT_API
336-
bool __cdecl GetDevice(int player,
337-
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
338-
_Outptr_ GameInput::v1::IGameInputDevice * *device
339-
#else
340-
_Outptr_ IGameInputDevice * *device
341-
#endif
342-
) noexcept;
343+
DIRECTX_TOOLKIT_API bool __cdecl GetDevice(int player, _Outptr_ GameInputDevice_t * *device) noexcept;
343344
#elif defined(USING_WINDOWS_GAMING_INPUT) || defined(_XBOX_ONE)
344345
DIRECTX_TOOLKIT_API void __cdecl RegisterEvents(void* ctrlChanged, void* userChanged) noexcept;
345346
#endif

Src/GamePad.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ namespace
8686

8787
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
8888
using namespace GameInput::v1;
89+
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 2)
90+
using namespace GameInput::v2;
8991
#endif
9092

9193
//======================================================================================
@@ -145,11 +147,11 @@ class GamePad::Impl
145147
{
146148
if (mGameInput)
147149
{
148-
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
150+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION >= 1)
149151
if (!mGameInput->UnregisterCallback(mDeviceToken))
150-
#else
152+
#else
151153
if (!mGameInput->UnregisterCallback(mDeviceToken, UINT64_MAX))
152-
#endif
154+
#endif
153155
{
154156
DebugTrace("ERROR: GameInput::UnregisterCallback [gamepad] failed");
155157
}
@@ -197,7 +199,7 @@ class GamePad::Impl
197199
if (reading->GetGamepadState(&pad))
198200
{
199201
state.connected = true;
200-
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
202+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION >= 1)
201203
state.packet = reading->GetTimestamp();
202204
#else
203205
state.packet = reading->GetSequenceNumber(GameInputKindGamepad);
@@ -245,7 +247,7 @@ class GamePad::Impl
245247
{
246248
if (device->GetDeviceStatus() & GameInputDeviceConnected)
247249
{
248-
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
250+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION >= 1)
249251
const GameInputDeviceInfo* deviceInfo = nullptr;
250252
device->GetDeviceInfo(&deviceInfo);
251253
#else
@@ -425,7 +427,7 @@ void GamePad::RegisterEvents(HANDLE ctrlChanged) noexcept
425427
}
426428

427429
_Success_(return)
428-
bool GamePad::GetDevice(int player, _Outptr_ IGameInputDevice * *device) noexcept
430+
bool GamePad::GetDevice(int player, _Outptr_ GameInputDevice_t * *device) noexcept
429431
{
430432
return pImpl->GetDevice(player, device);
431433
}

Src/Keyboard.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ namespace
5555

5656
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
5757
using namespace GameInput::v1;
58+
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 2)
59+
using namespace GameInput::v2;
5860
#endif
5961

6062

@@ -116,11 +118,11 @@ class Keyboard::Impl
116118
{
117119
if (mGameInput)
118120
{
119-
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
121+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION >= 1)
120122
if (!mGameInput->UnregisterCallback(mDeviceToken))
121-
#else
123+
#else
122124
if (!mGameInput->UnregisterCallback(mDeviceToken, UINT64_MAX))
123-
#endif
125+
#endif
124126
{
125127
DebugTrace("ERROR: GameInput::UnregisterCallback [keyboard] failed");
126128
}

Src/Mouse.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ using Microsoft::WRL::ComPtr;
2323

2424
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
2525
using namespace GameInput::v1;
26+
#elif defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 2)
27+
using namespace GameInput::v2;
2628
#endif
2729

2830
//======================================================================================
@@ -125,11 +127,11 @@ class Mouse::Impl
125127
{
126128
if (mGameInput)
127129
{
128-
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
130+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION >= 1)
129131
if (!mGameInput->UnregisterCallback(mDeviceToken))
130-
#else
132+
#else
131133
if (!mGameInput->UnregisterCallback(mDeviceToken, UINT64_MAX))
132-
#endif
134+
#endif
133135
{
134136
DebugTrace("ERROR: GameInput::UnregisterCallback [mouse] failed");
135137
}

0 commit comments

Comments
 (0)