Skip to content

Commit e0ef7c0

Browse files
committed
ActionSet: Fill in basic driver layout, add Steam and SDL drivers
1 parent b879a86 commit e0ef7c0

14 files changed

+279
-0
lines changed

Android.mk

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ LOCAL_SRC_FILES := \
1818
$(subst $(LOCAL_PATH)/,, \
1919
$(wildcard $(LOCAL_PATH)/src/*.c) \
2020
$(wildcard $(LOCAL_PATH)/src/actionset/*.c) \
21+
$(wildcard $(LOCAL_PATH)/src/actionset/sdlinput/*.c) \
2122
$(wildcard $(LOCAL_PATH)/src/audio/*.c) \
2223
$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \
2324
$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ endif()
484484
file(GLOB SOURCE_FILES
485485
${SDL3_SOURCE_DIR}/src/*.c
486486
${SDL3_SOURCE_DIR}/src/actionset/*.c
487+
${SDL3_SOURCE_DIR}/src/actionset/sdlinput/*.c
488+
${SDL3_SOURCE_DIR}/src/actionset/steaminput/*.c # FIXME: Windows/macOS/Linux only
487489
${SDL3_SOURCE_DIR}/src/atomic/*.c
488490
${SDL3_SOURCE_DIR}/src/audio/*.c
489491
${SDL3_SOURCE_DIR}/src/core/*.c

VisualC-GDK/SDL/SDL.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@
366366
<ClInclude Include="..\..\include\SDL3\SDL_video.h" />
367367
<ClInclude Include="..\..\include\SDL3\SDL_vulkan.h" />
368368
<ClInclude Include="..\..\src\actionset\SDL_actionset_c.h" />
369+
<ClInclude Include="..\..\src\actionset\sdlinput\SDL_sdlinput.h" />
369370
<ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" />
370371
<ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
371372
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
@@ -541,6 +542,7 @@
541542
</ItemGroup>
542543
<ItemGroup>
543544
<ClCompile Include="..\..\src\actionset\SDL_actionset.c" />
545+
<ClCompile Include="..\..\src\actionset\sdlinput\SDL_sdlinput.c" />
544546
<ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
545547
<ClCompile Include="..\..\src\atomic\SDL_spinlock.c" />
546548
<ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" />

VisualC-GDK/SDL/SDL.vcxproj.filters

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@
409409
<Filter>API Headers</Filter>
410410
</ClInclude>
411411
<ClInclude Include="..\..\src\actionset\SDL_actionset_c.h" />
412+
<ClInclude Include="..\..\src\actionset\sdlinput\SDL_sdlinput.h" />
412413
<ClInclude Include="..\..\src\audio\SDL_audio_c.h">
413414
<Filter>audio</Filter>
414415
</ClInclude>
@@ -837,6 +838,7 @@
837838
<ClCompile Include="..\..\src\SDL_list.c" />
838839
<ClCompile Include="..\..\src\SDL_utils.c" />
839840
<ClCompile Include="..\..\src\actionset\SDL_actionset.c" />
841+
<ClCompile Include="..\..\src\actionset\sdlinput\SDL_sdlinput.c" />
840842
<ClCompile Include="..\..\src\audio\SDL_audio.c">
841843
<Filter>audio</Filter>
842844
</ClCompile>

VisualC-WinRT/SDL-UWP.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<ClInclude Include="..\include\SDL3\SDL_version.h" />
9292
<ClInclude Include="..\include\SDL3\SDL_video.h" />
9393
<ClInclude Include="..\src\actionset\SDL_actionset_c.h" />
94+
<ClInclude Include="..\src\actionset\sdlinput\SDL_sdlinput.h" />
9495
<ClInclude Include="..\src\audio\disk\SDL_diskaudio.h" />
9596
<ClInclude Include="..\src\audio\dummy\SDL_dummyaudio.h" />
9697
<ClInclude Include="..\src\audio\SDL_audiodev_c.h" />
@@ -188,6 +189,7 @@
188189
</ItemGroup>
189190
<ItemGroup>
190191
<ClCompile Include="..\src\actionset\SDL_actionset.c" />
192+
<ClCompile Include="..\src\actionset\sdlinput\SDL_sdlinput.c" />
191193
<ClCompile Include="..\src\atomic\SDL_atomic.c" />
192194
<ClCompile Include="..\src\atomic\SDL_spinlock.c" />
193195
<ClCompile Include="..\src\audio\disk\SDL_diskaudio.c" />

VisualC-WinRT/SDL-UWP.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@
174174
<ClInclude Include="..\src\actionset\SDL_actionset_c.h">
175175
<Filter>Source Files</Filter>
176176
</ClInclude>
177+
<ClInclude Include="..\src\actionset\sdlinput\SDL_sdlinput.h">
178+
<Filter>Source Files</Filter>
179+
</ClInclude>
177180
<ClInclude Include="..\src\audio\disk\SDL_diskaudio.h">
178181
<Filter>Source Files</Filter>
179182
</ClInclude>
@@ -456,6 +459,9 @@
456459
<ClCompile Include="..\src\actionset\SDL_actionset.c">
457460
<Filter>Source Files</Filter>
458461
</ClCompile>
462+
<ClCompile Include="..\src\actionset\sdlinput\SDL_sdlinput.c">
463+
<Filter>Source Files</Filter>
464+
</ClCompile>
459465
<ClCompile Include="..\src\atomic\SDL_atomic.c">
460466
<Filter>Source Files</Filter>
461467
</ClCompile>

VisualC/SDL/SDL.vcxproj

+4
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@
311311
<ClInclude Include="..\..\include\SDL3\SDL_video.h" />
312312
<ClInclude Include="..\..\include\SDL3\SDL_vulkan.h" />
313313
<ClInclude Include="..\..\src\actionset\SDL_actionset_c.h" />
314+
<ClInclude Include="..\..\src\actionset\sdlinput\SDL_sdlinput.h" />
315+
<ClInclude Include="..\..\src\actionset\steaminput\SDL_steaminput.h" />
314316
<ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" />
315317
<ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
316318
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
@@ -464,6 +466,8 @@
464466
</ItemGroup>
465467
<ItemGroup>
466468
<ClCompile Include="..\..\src\actionset\SDL_actionset.c" />
469+
<ClCompile Include="..\..\src\actionset\sdlinput\SDL_sdlinput.c" />
470+
<ClCompile Include="..\..\src\actionset\steaminput\SDL_steaminput.c" />
467471
<ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
468472
<ClCompile Include="..\..\src\atomic\SDL_spinlock.c" />
469473
<ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" />

VisualC/SDL/SDL.vcxproj.filters

+4
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@
403403
<Filter>API Headers</Filter>
404404
</ClInclude>
405405
<ClInclude Include="..\..\src\actionset\SDL_actionset_c.h" />
406+
<ClInclude Include="..\..\src\actionset\sdlinput\SDL_sdlinput.h" />
407+
<ClInclude Include="..\..\src\actionset\steaminput\SDL_steaminput.h" />
406408
<ClInclude Include="..\..\src\audio\SDL_audio_c.h">
407409
<Filter>audio</Filter>
408410
</ClInclude>
@@ -825,6 +827,8 @@
825827
<ClCompile Include="..\..\src\SDL_list.c" />
826828
<ClCompile Include="..\..\src\SDL_utils.c" />
827829
<ClCompile Include="..\..\src\actionset\SDL_actionset.c" />
830+
<ClCompile Include="..\..\src\actionset\sdlinput\SDL_sdlinput.c" />
831+
<ClCompile Include="..\..\src\actionset\steaminput\SDL_steaminput.c" />
828832
<ClCompile Include="..\..\src\audio\SDL_audio.c">
829833
<Filter>audio</Filter>
830834
</ClCompile>

src/actionset/SDL_actionset.c

+24
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,36 @@
2020
*/
2121
#include "SDL_internal.h"
2222
#include "SDL_actionset_c.h"
23+
#include "SDL_sysactionset.h"
2324

2425
/* TODO: Copy over from Codename GigaBrain */
2526

27+
/* Providers should be prioritized as follows:
28+
* Private Launchers (i.e. EA) > Shared Stores (i.e. Steam, Itch) > OS > SDL
29+
*/
30+
static const SDL_ActionSetProvider *const providers[] = {
31+
#ifdef SDL_ACTIONSET_STEAMINPUT
32+
&STEAMINPUT_provider,
33+
#endif
34+
&SDLINPUT_provider /* Unlike other subsystems, SDL is always available, no dummy drivers needed */
35+
};
36+
2637
int SDL_InitActionSet(void)
2738
{
39+
int i;
40+
for (i = 0; i < SDL_arraysize(providers); i += 1) {
41+
providers[i]->Init();
42+
}
2843
return 0;
2944
}
3045

3146
void SDL_QuitActionSet(void)
3247
{
48+
int i;
49+
/* TODO: Close ActionSetDevice array here */
50+
for (i = 0; i < SDL_arraysize(providers); i += 1) {
51+
providers[i]->Quit();
52+
}
3353
}
3454

3555
SDL_bool SDL_ActionSetsOpened(void)
@@ -39,4 +59,8 @@ SDL_bool SDL_ActionSetsOpened(void)
3959

4060
void SDL_UpdateActionSet(void)
4161
{
62+
int i;
63+
for (i = 0; i < SDL_arraysize(providers); i += 1) {
64+
providers[i]->Update();
65+
}
4266
}

src/actionset/SDL_sysactionset.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
#include "SDL_internal.h"
22+
23+
#ifndef SDL_sysactionset_h_
24+
#define SDL_sysactionset_h_
25+
26+
#include "./SDL_actionset_c.h"
27+
28+
typedef struct SDL_ActionSetProvider
29+
{
30+
void (*Init)(void);
31+
void (*Quit)(void);
32+
void (*Update)(void);
33+
} SDL_ActionSetProvider;
34+
35+
/* Not all of these are available in a given build. Use #ifdefs, etc. */
36+
extern SDL_ActionSetProvider STEAMINPUT_provider;
37+
extern SDL_ActionSetProvider SDLINPUT_provider;
38+
39+
#if defined(__WINDOWS__) || defined(__MACOS__) || defined(__LINUX__)
40+
#define SDL_ACTIONSET_STEAMINPUT
41+
#endif
42+
43+
#endif /* SDL_sysactionset_h_ */

src/actionset/sdlinput/SDL_sdlinput.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
22+
#include "../SDL_sysactionset.h"
23+
#include "SDL_sdlinput.h"
24+
25+
static int SDLINPUT_EventWatch(void *userdata, SDL_Event *event)
26+
{
27+
/* TODO: Handle keyboard, mouse, and controller events */
28+
/* FIXME: Can we get keyboard/mouse hotplugging? */
29+
return 0;
30+
}
31+
32+
static void SDLINPUT_Init(void)
33+
{
34+
/* Do NOT open devices here! Let the event watcher do that! */
35+
SDL_AddEventWatch(SDLINPUT_EventWatch, NULL);
36+
}
37+
38+
static void SDLINPUT_Quit(void)
39+
{
40+
SDL_DelEventWatch(SDLINPUT_EventWatch, NULL);
41+
}
42+
43+
static void SDLINPUT_Update(void)
44+
{
45+
/* Nothing to do, the event watch handles everything for us */
46+
}
47+
48+
SDL_ActionSetProvider SDLINPUT_provider = {
49+
SDLINPUT_Init,
50+
SDLINPUT_Quit,
51+
SDLINPUT_Update
52+
};

src/actionset/sdlinput/SDL_sdlinput.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
#include "SDL_internal.h"
22+
23+
#ifndef SDL_sdlinput_h_
24+
#define SDL_sdlinput_h_
25+
26+
/* TODO: Device-specific data struct */
27+
28+
#endif /* SDL_sdlinput_h_ */
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
22+
#include "../SDL_sysactionset.h"
23+
#include "SDL_steaminput.h"
24+
#include "SDL_loadso.h"
25+
26+
#ifdef __WINDOWS__
27+
#ifdef _WIN64
28+
#define STEAM_DLL "steam_api64.dll"
29+
#else
30+
#define STEAM_DLL "steam_api.dll"
31+
#endif
32+
#elif defined(__MACOS__)
33+
#define STEAM_DLL "libsteam_api.dylib"
34+
#else
35+
#define STEAM_DLL "libsteam_api.so"
36+
#endif
37+
38+
static void *steam_dll = NULL;
39+
40+
static void STEAMINPUT_Init(void)
41+
{
42+
steam_dll = SDL_LoadObject(STEAM_DLL);
43+
if (steam_dll == NULL) {
44+
SDL_SetError("Steamworks library was not found");
45+
return;
46+
}
47+
/* TODO: Load entry points, unload if any are missing */
48+
/* TODO: if (!SteamAPI_WasInit()) unload and bail */
49+
/* TODO: Call ISteamInput_Init(true) */
50+
/* TODO: Subscribe to SteamInputConfigurationLoaded_t */
51+
/* TODO: Subscribe to SteamInputDeviceConnected_t */
52+
/* TODO: Subscribe to SteamInputDeviceDisconnected_t */
53+
}
54+
55+
static void STEAMINPUT_Quit(void)
56+
{
57+
if (steam_dll == NULL) {
58+
return;
59+
}
60+
61+
/* TODO: Call ISteamInput_Shutdown(), clear entry points */
62+
SDL_UnloadObject(steam_dll);
63+
steam_dll = NULL;
64+
}
65+
66+
static void STEAMINPUT_Update(void)
67+
{
68+
if (steam_dll == NULL) {
69+
return;
70+
}
71+
72+
/* TODO: SteamAPI_ISteamInput_RunFrame() */
73+
/* TODO: if (!BNewDataAvailable()) return; */
74+
/* TODO: Poll all actions for active set. FIXME: Can we get events...? */
75+
}
76+
77+
SDL_ActionSetProvider STEAMINPUT_provider = {
78+
STEAMINPUT_Init,
79+
STEAMINPUT_Quit,
80+
STEAMINPUT_Update
81+
};

0 commit comments

Comments
 (0)