Skip to content

Commit a0f922f

Browse files
authored
GameInput implementation updates for for GAMEINPUT_API_VERSION = 1 (#541)
1 parent 9ea36a2 commit a0f922f

8 files changed

Lines changed: 109 additions & 19 deletions

File tree

.github/workflows/vcpkg.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,78 @@ jobs:
3030
build_type: [x64-Debug-VCPKG]
3131
arch: [amd64]
3232
shared: [OFF]
33+
gameinput: [OFF]
3334
include:
35+
- os: windows-2022
36+
build_type: x64-Debug-VCPKG
37+
arch: amd64
38+
shared: OFF
39+
gameinput: ON
40+
- os: windows-2022
41+
build_type: x64-Debug-Clang-VCPKG
42+
arch: amd64
43+
shared: OFF
44+
gameinput: OFF
3445
- os: windows-2022
3546
build_type: x64-Debug-Clang-VCPKG
3647
arch: amd64
3748
shared: OFF
49+
gameinput: ON
3850
- os: windows-2022
3951
build_type: x86-Debug-VCPKG
4052
arch: amd64_x86
4153
shared: OFF
54+
gameinput: OFF
4255
- os: windows-2022
4356
build_type: x64-Debug-Redist
4457
arch: amd64
4558
shared: OFF
59+
gameinput: OFF
4660
- os: windows-2022
4761
build_type: x64-Release-Redist
4862
arch: amd64
4963
shared: OFF
64+
gameinput: OFF
5065
- os: windows-2022
5166
build_type: arm64-Debug-VCPKG
5267
arch: amd64_arm64
5368
shared: OFF
69+
gameinput: OFF
5470
- os: windows-2022
5571
build_type: arm64ec-Debug-VCPKG
5672
arch: amd64_arm64
5773
shared: OFF
74+
gameinput: OFF
5875
- os: windows-2022
5976
build_type: x64-Debug-MinGW
6077
arch: amd64
6178
shared: OFF
79+
gameinput: OFF
6280
- os: windows-2022
6381
build_type: x64-Release-MinGW
6482
arch: amd64
6583
shared: OFF
84+
gameinput: OFF
85+
- os: windows-2022
86+
build_type: x64-Debug-MinGW
87+
arch: amd64
88+
shared: OFF
89+
gameinput: ON
90+
- os: windows-2022
91+
build_type: x64-Debug-VCPKG
92+
arch: amd64
93+
shared: ON
94+
gameinput: ON
6695
- os: windows-2022
6796
build_type: x64-Debug-MinGW
6897
arch: amd64
6998
shared: ON
99+
gameinput: OFF
70100
- os: windows-2022
71101
build_type: x64-Release-MinGW
72102
arch: amd64
73103
shared: ON
104+
gameinput: OFF
74105

75106
steps:
76107
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -85,6 +116,7 @@ jobs:
85116
- name: 'Set triplet'
86117
shell: pwsh
87118
run: |
119+
echo "VCPKG_INSTALLED_DIR=${{ github.workspace }}/build/vcpkg_installed" >> $env:GITHUB_ENV
88120
if ("${{ matrix.arch }}" -eq "amd64")
89121
{
90122
if ("${{ matrix.build_type }}" -match "MinGW")
@@ -142,8 +174,8 @@ jobs:
142174
- name: 'Configure CMake'
143175
working-directory: ${{ github.workspace }}
144176
run: >
145-
cmake --preset=${{ matrix.build_type }} -DBUILD_TESTING=OFF -DBUILD_XAUDIO_WIN10=OFF -DBUILD_XAUDIO_WIN8=OFF -DBUILD_XAUDIO_REDIST=ON
146-
-DBUILD_SHARED_LIBS=${{ matrix.shared }}
177+
cmake --preset=${{ matrix.build_type }} -DBUILD_TESTING=OFF
178+
-DBUILD_SHARED_LIBS=${{ matrix.shared }} -DBUILD_GAMEINPUT=${{ matrix.gameinput }}
147179
-DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_MANIFEST_DIR="${{ github.workspace }}/build"
148180
-DVCPKG_TARGET_TRIPLET="${env:VCPKG_DEFAULT_TRIPLET}"
149181

CMakePresets.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@
158158
{
159159
"name": "Durango",
160160
"cacheVariables": {
161-
"XBOX_CONSOLE_TARGET": "durango",
162-
"BUILD_TESTING": false
161+
"XBOX_CONSOLE_TARGET": "durango"
163162
},
164163
"hidden": true
165164
},
@@ -321,10 +320,10 @@
321320
{ "name": "x64-Debug-GDK-Clang" , "description": "Clang/LLVM for x64 (Debug) with Microsoft GDK", "inherits": [ "base", "x64", "Debug", "Clang", "GDK" ] },
322321
{ "name": "x64-Release-GDK-Clang" , "description": "Clang/LLVM for x64 (Release) with Microsoft GDK", "inherits": [ "base", "x64", "Release", "Clang", "GDK" ] },
323322

324-
{ "name": "x64-Debug-MinGW" , "description": "MinG-W64 (Debug)", "inherits": [ "base", "x64", "Debug", "GNUC", "VCPKG", "MinGW64", "XAudio2Redist" ] },
325-
{ "name": "x64-Release-MinGW", "description": "MinG-W64 (Release)", "inherits": [ "base", "x64", "Release", "GNUC", "VCPKG", "MinGW64", "XAudio2Redist" ] },
326-
{ "name": "x86-Debug-MinGW" , "description": "MinG-W32 (Debug)", "inherits": [ "base", "x86", "Debug", "GNUC", "VCPKG", "MinGW32", "XAudio2Redist" ] },
327-
{ "name": "x86-Release-MinGW", "description": "MinG-W32 (Release)", "inherits": [ "base", "x86", "Release", "GNUC", "VCPKG", "MinGW32", "XAudio2Redist" ] },
323+
{ "name": "x64-Debug-MinGW" , "description": "MinG-W64 (Debug)", "inherits": [ "base", "x64", "Debug", "GNUC", "VCPKG", "XAudio2Redist", "MinGW64" ] },
324+
{ "name": "x64-Release-MinGW", "description": "MinG-W64 (Release)", "inherits": [ "base", "x64", "Release", "GNUC", "VCPKG", "XAudio2Redist", "MinGW64" ] },
325+
{ "name": "x86-Debug-MinGW" , "description": "MinG-W32 (Debug)", "inherits": [ "base", "x86", "Debug", "GNUC", "VCPKG", "XAudio2Redist", "MinGW32" ] },
326+
{ "name": "x86-Release-MinGW", "description": "MinG-W32 (Release)", "inherits": [ "base", "x86", "Release", "GNUC", "VCPKG", "XAudio2Redist", "MinGW32" ] },
328327

329328
{ "name": "x64-Debug-ICC" , "description": "Intel Classic Compiler (Debug) for Windows 8", "inherits": [ "base", "x64", "Debug", "Intel" ] },
330329
{ "name": "x64-Release-ICC" , "description": "Intel Classic Compiler (Release) for Windows 8", "inherits": [ "base", "x64", "Release", "Intel" ] },
@@ -354,6 +353,9 @@
354353
{ "name": "x86-Debug-Redist" , "configurePreset": "x86-Debug-Redist" },
355354
{ "name": "x86-Release-Redist" , "configurePreset": "x86-Release-Redist" },
356355

356+
{ "name": "x64-Debug-VCPKG" , "configurePreset": "x64-Debug-VCPKG" },
357+
{ "name": "x64-Release-VCPKG" , "configurePreset": "x64-Release-VCPKG" },
358+
357359
{ "name": "x64-Debug-Clang" , "configurePreset": "x64-Debug-Clang" },
358360
{ "name": "x64-Release-Clang" , "configurePreset": "x64-Release-Clang" },
359361
{ "name": "x86-Debug-Clang" , "configurePreset": "x86-Debug-Clang" },

Inc/GamePad.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,13 @@ namespace DirectX
325325
// Underlying device access
326326
_Success_(return)
327327
DIRECTX_TOOLKIT_API
328-
bool __cdecl GetDevice(int player, _Outptr_ IGameInputDevice * *device) noexcept;
328+
bool __cdecl GetDevice(int player,
329+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
330+
_Outptr_ GameInput::v1::IGameInputDevice * *device
331+
#else
332+
_Outptr_ IGameInputDevice * *device
333+
#endif
334+
) noexcept;
329335
#elif defined(USING_WINDOWS_GAMING_INPUT) || defined(_XBOX_ONE)
330336
DIRECTX_TOOLKIT_API void __cdecl RegisterEvents(void* ctrlChanged, void* userChanged) noexcept;
331337
#endif

Src/GamePad.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ namespace
8484
#pragma region Implementations
8585
#ifdef USING_GAMEINPUT
8686

87+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
88+
using namespace GameInput::v1;
89+
#endif
90+
8791
//======================================================================================
8892
// GameInput
8993
//======================================================================================
@@ -141,7 +145,11 @@ class GamePad::Impl
141145
{
142146
if (mGameInput)
143147
{
148+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
149+
if (!mGameInput->UnregisterCallback(mDeviceToken))
150+
#else
144151
if (!mGameInput->UnregisterCallback(mDeviceToken, UINT64_MAX))
152+
#endif
145153
{
146154
DebugTrace("ERROR: GameInput::UnregisterCallback [gamepad] failed");
147155
}
@@ -189,7 +197,11 @@ class GamePad::Impl
189197
if (reading->GetGamepadState(&pad))
190198
{
191199
state.connected = true;
200+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
201+
state.packet = reading->GetTimestamp();
202+
#else
192203
state.packet = reading->GetSequenceNumber(GameInputKindGamepad);
204+
#endif
193205

194206
state.buttons.a = (pad.buttons & GameInputGamepadA) != 0;
195207
state.buttons.b = (pad.buttons & GameInputGamepadB) != 0;
@@ -233,7 +245,12 @@ class GamePad::Impl
233245
{
234246
if (device->GetDeviceStatus() & GameInputDeviceConnected)
235247
{
248+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
249+
const GameInputDeviceInfo* deviceInfo = nullptr;
250+
device->GetDeviceInfo(&deviceInfo);
251+
#else
236252
auto deviceInfo = device->GetDeviceInfo();
253+
#endif
237254
caps.connected = true;
238255
caps.gamepadType = Capabilities::GAMEPAD;
239256
caps.id = deviceInfo->deviceId;

Src/Keyboard.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ namespace
5353

5454
#include <GameInput.h>
5555

56+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
57+
using namespace GameInput::v1;
58+
#endif
59+
60+
5661
//======================================================================================
5762
// GameInput
5863
//======================================================================================
@@ -111,7 +116,11 @@ class Keyboard::Impl
111116
{
112117
if (mGameInput)
113118
{
119+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
120+
if (!mGameInput->UnregisterCallback(mDeviceToken))
121+
#else
114122
if (!mGameInput->UnregisterCallback(mDeviceToken, UINT64_MAX))
123+
#endif
115124
{
116125
DebugTrace("ERROR: GameInput::UnregisterCallback [keyboard] failed");
117126
}

Src/Mouse.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ using Microsoft::WRL::ComPtr;
2121

2222
#include <GameInput.h>
2323

24+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
25+
using namespace GameInput::v1;
26+
#endif
27+
2428
//======================================================================================
2529
// Win32 + GameInput implementation
2630
//======================================================================================
@@ -121,7 +125,11 @@ class Mouse::Impl
121125
{
122126
if (mGameInput)
123127
{
128+
#if defined(GAMEINPUT_API_VERSION) && (GAMEINPUT_API_VERSION == 1)
129+
if (!mGameInput->UnregisterCallback(mDeviceToken))
130+
#else
124131
if (!mGameInput->UnregisterCallback(mDeviceToken, UINT64_MAX))
132+
#endif
125133
{
126134
DebugTrace("ERROR: GameInput::UnregisterCallback [mouse] failed");
127135
}

Src/pch.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@
188188
#include <OCIdl.h>
189189
#endif
190190

191+
#if defined(USING_GAMEINPUT) && defined(__MINGW32__)
192+
namespace GameInput { namespace v1 { interface IGameInput; } }
193+
template<> inline auto __mingw_uuidof<GameInput::v1::IGameInput>() -> GUID const&
194+
{
195+
static constexpr GUID the_uuid = { 0x40ffb7e4,0x6150,0x407a,0xb4,0x39,0x13,0x2b,0xad,0xc0,0x8d,0x2d };
196+
return the_uuid;
197+
}
198+
#endif
199+
191200
#if (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)) || (defined(_XBOX_ONE) && defined(_TITLE))
192201
#pragma warning(push)
193202
#pragma warning(disable: 4471 5204 5256)

build/vcpkg.json

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
3-
"dependencies": [
4-
"directxmath",
5-
"directx-headers",
6-
{
7-
"name": "xaudio2redist",
8-
"platform": "windows & !arm"
9-
}
10-
]
11-
}
2+
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
3+
"dependencies": [
4+
{
5+
"name": "directx-headers",
6+
"platform": "windows & mingw"
7+
},
8+
"directxmath",
9+
{
10+
"name": "gameinput",
11+
"platform": "windows & x64"
12+
},
13+
{
14+
"name": "xaudio2redist",
15+
"platform": "windows & !arm"
16+
}
17+
]
18+
}

0 commit comments

Comments
 (0)