Skip to content

Commit 8a57c83

Browse files
committed
Updated to GameInput v1.1
The biggest change is that the C API is no longer available. Here are more details: https://www.nuget.org/packages/Microsoft.GameInput Fixes #12802
1 parent f35a273 commit 8a57c83

File tree

12 files changed

+201
-132
lines changed

12 files changed

+201
-132
lines changed

.github/workflows/create-test-plan.py

+2
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,11 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool) -> JobDeta
381381
match spec.msvc_arch:
382382
case MsvcArch.X86:
383383
job.cflags.append("/clang:-m32")
384+
job.cxxflags.append("/clang:-m32")
384385
job.ldflags.append("/MACHINE:X86")
385386
case MsvcArch.X64:
386387
job.cflags.append("/clang:-m64")
388+
job.cxxflags.append("/clang:-m64")
387389
job.ldflags.append("/MACHINE:X64")
388390
case _:
389391
raise ValueError(f"Unsupported clang-cl architecture (arch={spec.msvc_arch})")

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1893,11 +1893,13 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
18931893
set (USE_POSIX_SPAWN 1)
18941894
endif()
18951895
elseif(WINDOWS)
1896+
enable_language(CXX)
18961897
check_c_source_compiles("
18971898
#include <windows.h>
18981899
int main(int argc, char **argv) { return 0; }" HAVE_WIN32_CC)
18991900

19001901
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/windows/*.c")
1902+
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/windows/*.cpp")
19011903
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/main/windows/*.c")
19021904
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/io/windows/*.c")
19031905

@@ -2008,6 +2010,7 @@ elseif(WINDOWS)
20082010
if(SDL_VIDEO)
20092011
set(SDL_VIDEO_DRIVER_WINDOWS 1)
20102012
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/windows/*.c")
2013+
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/windows/*.cpp")
20112014

20122015
CheckOpenVR()
20132016

@@ -2135,7 +2138,7 @@ elseif(WINDOWS)
21352138
set(SDL_JOYSTICK_WGI 1)
21362139
endif()
21372140
if(HAVE_GAMEINPUT_H)
2138-
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/gdk/*.c")
2141+
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/gdk/*.cpp")
21392142
set(SDL_JOYSTICK_GAMEINPUT 1)
21402143
endif()
21412144
set(HAVE_SDL_JOYSTICK TRUE)

VisualC-GDK/SDL/SDL.vcxproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@
645645
<ClCompile Include="..\..\src\audio\SDL_wave.c" />
646646
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi.c" />
647647
<ClCompile Include="..\..\src\core\SDL_core_unsupported.c" />
648-
<ClCompile Include="..\..\src\core\windows\SDL_gameinput.c"/>
648+
<ClCompile Include="..\..\src\core\windows\SDL_gameinput.cpp"/>
649649
<ClCompile Include="..\..\src\core\windows\SDL_hid.c" />
650650
<ClCompile Include="..\..\src\core\windows\SDL_immdevice.c" />
651651
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
@@ -710,7 +710,7 @@
710710
<ClCompile Include="..\..\src\hidapi\SDL_hidapi.c" />
711711
<ClCompile Include="..\..\src\joystick\controller_type.c" />
712712
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
713-
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.c" />
713+
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.cpp" />
714714
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapijoystick.c" />
715715
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_8bitdo.c" />
716716
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_combined.c" />
@@ -891,7 +891,7 @@
891891
<ClCompile Include="..\..\src\video\windows\SDL_windowsevents.c" />
892892
<ClCompile Include="..\..\src\video\windows\SDL_windowsframebuffer.c" />
893893
<ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c" />
894-
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.c" />
894+
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.cpp" />
895895
<ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c" />
896896
<ClCompile Include="..\..\src\video\windows\SDL_windowsmodes.c" />
897897
<ClCompile Include="..\..\src\video\windows\SDL_windowsmouse.c" />

VisualC-GDK/SDL/SDL.vcxproj.filters

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<ClCompile Include="..\..\src\audio\SDL_wave.c" />
2828
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi.c" />
2929
<ClCompile Include="..\..\src\core\SDL_core_unsupported.c" />
30-
<ClCompile Include="..\..\src\core\windows\SDL_gameinput.c" />
30+
<ClCompile Include="..\..\src\core\windows\SDL_gameinput.cpp" />
3131
<ClCompile Include="..\..\src\core\windows\SDL_hid.c" />
3232
<ClCompile Include="..\..\src\core\windows\SDL_immdevice.c" />
3333
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
@@ -61,7 +61,7 @@
6161
<ClCompile Include="..\..\src\hidapi\SDL_hidapi.c" />
6262
<ClCompile Include="..\..\src\joystick\controller_type.c" />
6363
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
64-
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.c" />
64+
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.cpp" />
6565
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapijoystick.c" />
6666
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_8bitdo.c" />
6767
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_combined.c" />
@@ -193,7 +193,7 @@
193193
<ClCompile Include="..\..\src\video\windows\SDL_windowsevents.c" />
194194
<ClCompile Include="..\..\src\video\windows\SDL_windowsframebuffer.c" />
195195
<ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c" />
196-
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.c" />
196+
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.cpp" />
197197
<ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c" />
198198
<ClCompile Include="..\..\src\video\windows\SDL_windowsmodes.c" />
199199
<ClCompile Include="..\..\src\video\windows\SDL_windowsmouse.c" />

VisualC/SDL/SDL.vcxproj

+28-3
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,16 @@
424424
<ClCompile Include="..\..\src\camera\dummy\SDL_camera_dummy.c" />
425425
<ClCompile Include="..\..\src\camera\mediafoundation\SDL_camera_mediafoundation.c" />
426426
<ClCompile Include="..\..\src\camera\SDL_camera.c" />
427+
<ClCompile Include="..\..\src\core\windows\pch_cpp.cpp">
428+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
429+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
430+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
431+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
432+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
433+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
434+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
435+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
436+
</ClCompile>
427437
<ClCompile Include="..\..\src\dialog\SDL_dialog.c" />
428438
<ClCompile Include="..\..\src\dialog\SDL_dialog_utils.c" />
429439
<ClCompile Include="..\..\src\filesystem\SDL_filesystem.c" />
@@ -543,7 +553,12 @@
543553
<ClCompile Include="..\..\src\audio\SDL_wave.c" />
544554
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi.c" />
545555
<ClCompile Include="..\..\src\core\SDL_core_unsupported.c" />
546-
<ClCompile Include="..\..\src\core\windows\SDL_gameinput.c" />
556+
<ClCompile Include="..\..\src\core\windows\SDL_gameinput.cpp">
557+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
558+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
559+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
560+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
561+
</ClCompile>
547562
<ClCompile Include="..\..\src\core\windows\SDL_hid.c" />
548563
<ClCompile Include="..\..\src\core\windows\SDL_immdevice.c" />
549564
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
@@ -580,7 +595,12 @@
580595
<ClCompile Include="..\..\src\hidapi\SDL_hidapi.c" />
581596
<ClCompile Include="..\..\src\joystick\controller_type.c" />
582597
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
583-
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.c" />
598+
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.cpp">
599+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
600+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
601+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
602+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
603+
</ClCompile>
584604
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapijoystick.c" />
585605
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_8bitdo.c" />
586606
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_combined.c" />
@@ -726,7 +746,12 @@
726746
<ClCompile Include="..\..\src\video\windows\SDL_windowsevents.c" />
727747
<ClCompile Include="..\..\src\video\windows\SDL_windowsframebuffer.c" />
728748
<ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c" />
729-
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.c" />
749+
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.cpp">
750+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
751+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
752+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
753+
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
754+
</ClCompile>
730755
<ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c" />
731756
<ClCompile Include="..\..\src\video\windows\SDL_windowsmodes.c" />
732757
<ClCompile Include="..\..\src\video\windows\SDL_windowsmouse.c" />

VisualC/SDL/SDL.vcxproj.filters

+8-12
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,6 @@
537537
<ClInclude Include="..\..\src\events\SDL_events_c.h">
538538
<Filter>events</Filter>
539539
</ClInclude>
540-
<ClInclude Include="..\..\src\events\SDL_eventfilter_c.h">
541-
<Filter>events</Filter>
542-
</ClInclude>
543540
<ClInclude Include="..\..\src\events\SDL_keyboard_c.h">
544541
<Filter>events</Filter>
545542
</ClInclude>
@@ -962,6 +959,7 @@
962959
<ClInclude Include="..\..\include\SDL3\SDL_storage.h" />
963960
<ClInclude Include="..\..\include\SDL3\SDL_time.h" />
964961
<ClInclude Include="..\..\src\events\SDL_categories_c.h" />
962+
<ClInclude Include="..\..\src\events\SDL_eventwatch_c.h" />
965963
</ItemGroup>
966964
<ItemGroup>
967965
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi.c" />
@@ -1049,7 +1047,7 @@
10491047
<ClCompile Include="..\..\src\core\SDL_core_unsupported.c">
10501048
<Filter>core</Filter>
10511049
</ClCompile>
1052-
<ClCompile Include="..\..\src\core\windows\SDL_gameinput.c">
1050+
<ClCompile Include="..\..\src\core\windows\SDL_gameinput.cpp">
10531051
<Filter>core\windows</Filter>
10541052
</ClCompile>
10551053
<ClCompile Include="..\..\src\core\windows\SDL_hid.c">
@@ -1088,9 +1086,6 @@
10881086
<ClCompile Include="..\..\src\events\SDL_events.c">
10891087
<Filter>events</Filter>
10901088
</ClCompile>
1091-
<ClCompile Include="..\..\src\events\SDL_eventfilter.c">
1092-
<Filter>events</Filter>
1093-
</ClCompile>
10941089
<ClCompile Include="..\..\src\events\SDL_keyboard.c">
10951090
<Filter>events</Filter>
10961091
</ClCompile>
@@ -1184,7 +1179,7 @@
11841179
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c">
11851180
<Filter>joystick\dummy</Filter>
11861181
</ClCompile>
1187-
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.c">
1182+
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.cpp">
11881183
<Filter>joystick\gdk</Filter>
11891184
</ClCompile>
11901185
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_8bitdo.c">
@@ -1367,7 +1362,7 @@
13671362
<ClCompile Include="..\..\src\video\windows\SDL_windowskeyboard.c">
13681363
<Filter>video\windows</Filter>
13691364
</ClCompile>
1370-
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.c">
1365+
<ClCompile Include="..\..\src\video\windows\SDL_windowsgameinput.cpp">
13711366
<Filter>video\windows</Filter>
13721367
</ClCompile>
13731368
<ClCompile Include="..\..\src\video\windows\SDL_windowsmessagebox.c">
@@ -1606,11 +1601,12 @@
16061601
<ClCompile Include="..\..\src\storage\generic\SDL_genericstorage.c" />
16071602
<ClCompile Include="..\..\src\storage\steam\SDL_steamstorage.c" />
16081603
<ClCompile Include="..\..\src\storage\SDL_storage.c" />
1604+
<ClCompile Include="..\..\src\events\SDL_eventwatch.c" />
1605+
<ClCompile Include="..\..\src\core\windows\pch_cpp.cpp">
1606+
<Filter>core\windows</Filter>
1607+
</ClCompile>
16091608
</ItemGroup>
16101609
<ItemGroup>
16111610
<ResourceCompile Include="..\..\src\core\windows\version.rc" />
16121611
</ItemGroup>
1613-
<ItemGroup>
1614-
<MASM Include="..\..\src\stdlib\SDL_mslibc_x64.masm" />
1615-
</ItemGroup>
16161612
</Project>

src/core/windows/SDL_gameinput.c renamed to src/core/windows/SDL_gameinput.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@
2525
#include "SDL_windows.h"
2626
#include "SDL_gameinput.h"
2727

28-
#ifdef SDL_PLATFORM_WIN32
29-
#include <initguid.h>
30-
// {11BE2A7E-4254-445A-9C09-FFC40F006918}
31-
DEFINE_GUID(SDL_IID_GameInput, 0x11BE2A7E, 0x4254, 0x445A, 0x9C, 0x09, 0xFF, 0xC4, 0x0F, 0x00, 0x69, 0x18);
32-
#endif
33-
3428
static SDL_SharedObject *g_hGameInputDLL;
3529
static IGameInput *g_pGameInput;
3630
static int g_nGameInputRefCount;
3731

32+
3833
bool SDL_InitGameInput(IGameInput **ppGameInput)
3934
{
4035
if (g_nGameInputRefCount == 0) {
@@ -43,7 +38,7 @@ bool SDL_InitGameInput(IGameInput **ppGameInput)
4338
return false;
4439
}
4540

46-
typedef HRESULT (WINAPI *GameInputCreate_t)(IGameInput * *gameInput);
41+
typedef HRESULT (WINAPI *GameInputCreate_t)(IGameInput **gameInput);
4742
GameInputCreate_t GameInputCreateFunc = (GameInputCreate_t)SDL_LoadFunction(g_hGameInputDLL, "GameInputCreate");
4843
if (!GameInputCreateFunc) {
4944
SDL_UnloadObject(g_hGameInputDLL);
@@ -58,15 +53,19 @@ bool SDL_InitGameInput(IGameInput **ppGameInput)
5853
}
5954

6055
#ifdef SDL_PLATFORM_WIN32
61-
hr = IGameInput_QueryInterface(pGameInput, &SDL_IID_GameInput, (void **)&g_pGameInput);
62-
IGameInput_Release(pGameInput);
56+
#if GAMEINPUT_API_VERSION >= 1
57+
hr = pGameInput->QueryInterface(IID_IGameInput, (void **)&g_pGameInput);
58+
#else
59+
// We require GameInput v1.1 or newer
60+
hr = E_NOINTERFACE;
61+
#endif
62+
pGameInput->Release();
6363
if (FAILED(hr)) {
6464
SDL_UnloadObject(g_hGameInputDLL);
6565
return WIN_SetErrorFromHRESULT("GameInput QueryInterface failed", hr);
6666
}
6767
#else
6868
// Assume that the version we get is compatible with the current SDK
69-
// If that isn't the case, define the correct GUID for SDL_IID_GameInput above
7069
g_pGameInput = pGameInput;
7170
#endif
7271
}
@@ -85,7 +84,7 @@ void SDL_QuitGameInput(void)
8584
--g_nGameInputRefCount;
8685
if (g_nGameInputRefCount == 0) {
8786
if (g_pGameInput) {
88-
IGameInput_Release(g_pGameInput);
87+
g_pGameInput->Release();
8988
g_pGameInput = NULL;
9089
}
9190
if (g_hGameInputDLL) {

src/core/windows/SDL_gameinput.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@
2525

2626
#ifdef HAVE_GAMEINPUT_H
2727

28-
#define COBJMACROS
2928
#include <gameinput.h>
3029

30+
#ifndef GAMEINPUT_API_VERSION
31+
#define GAMEINPUT_API_VERSION 0
32+
#endif
33+
34+
#if GAMEINPUT_API_VERSION == 1
35+
using namespace GameInput::v1;
36+
#endif
37+
3138
extern bool SDL_InitGameInput(IGameInput **ppGameInput);
3239
extern void SDL_QuitGameInput(void);
3340

0 commit comments

Comments
 (0)