Skip to content

Commit ba22d4e

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

14 files changed

+328
-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

+25
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,37 @@
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+
ActionSetDeviceMask current_mask = ACTIONSET_DEVICE_NONE;
41+
for (i = 0; i < SDL_arraysize(providers); i += 1) {
42+
current_mask |= providers[i]->Init(current_mask);
43+
}
2844
return 0;
2945
}
3046

3147
void SDL_QuitActionSet(void)
3248
{
49+
int i;
50+
/* TODO: Close ActionSetDevice array here */
51+
for (i = 0; i < SDL_arraysize(providers); i += 1) {
52+
providers[i]->Quit();
53+
}
3354
}
3455

3556
SDL_bool SDL_ActionSetsOpened(void)
@@ -39,4 +60,8 @@ SDL_bool SDL_ActionSetsOpened(void)
3960

4061
void SDL_UpdateActionSet(void)
4162
{
63+
int i;
64+
for (i = 0; i < SDL_arraysize(providers); i += 1) {
65+
providers[i]->Update();
66+
}
4267
}

src/actionset/SDL_sysactionset.h

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
/* Only one provider can read each device at a time.
29+
* For example, if Steam Input is running, SDL Input doesn't need to read any
30+
* events for SDL_GameController devices.
31+
*/
32+
typedef enum
33+
{
34+
ACTIONSET_DEVICE_NONE = 0x0000,
35+
ACTIONSET_DEVICE_KEYBOARDMOUSE = 0x0001,
36+
ACTIONSET_DEVICE_CONTROLLER = 0x0002,
37+
ACTIONSET_DEVICE_TOUCH = 0x0004,
38+
ACTIONSET_DEVICE_ALL = 0xFFFF
39+
} ActionSetDeviceMask;
40+
41+
typedef struct SDL_ActionSetProvider
42+
{
43+
ActionSetDeviceMask (*Init)(ActionSetDeviceMask current_mask);
44+
void (*Quit)(void);
45+
void (*Update)(void);
46+
} SDL_ActionSetProvider;
47+
48+
/* Not all of these are available in a given build. Use #ifdefs, etc. */
49+
extern SDL_ActionSetProvider STEAMINPUT_provider;
50+
extern SDL_ActionSetProvider SDLINPUT_provider;
51+
52+
#if defined(__WINDOWS__) || defined(__MACOS__) || defined(__LINUX__)
53+
#define SDL_ACTIONSET_STEAMINPUT
54+
#endif
55+
56+
#endif /* SDL_sysactionset_h_ */

src/actionset/sdlinput/SDL_sdlinput.c

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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_internal.h"
23+
#include "../SDL_sysactionset.h"
24+
#include "SDL_sdlinput.h"
25+
26+
static ActionSetDeviceMask sdlinput_mask = ACTIONSET_DEVICE_NONE;
27+
28+
static int SDLINPUT_EventWatch(void *userdata, SDL_Event *event)
29+
{
30+
/* TODO: Handle keyboard, mouse, and controller events, based on mask */
31+
/* FIXME: Can we get keyboard/mouse hotplugging? */
32+
return 0;
33+
}
34+
35+
static ActionSetDeviceMask SDLINPUT_Init(ActionSetDeviceMask current_mask)
36+
{
37+
if (!(current_mask & ACTIONSET_DEVICE_KEYBOARDMOUSE)) {
38+
sdlinput_mask |= ACTIONSET_DEVICE_KEYBOARDMOUSE;
39+
}
40+
if (!(current_mask & ACTIONSET_DEVICE_CONTROLLER)) {
41+
sdlinput_mask |= ACTIONSET_DEVICE_CONTROLLER;
42+
}
43+
if (!(current_mask & ACTIONSET_DEVICE_TOUCH)) {
44+
sdlinput_mask |= ACTIONSET_DEVICE_TOUCH;
45+
}
46+
47+
if (sdlinput_mask == ACTIONSET_DEVICE_NONE) {
48+
return current_mask;
49+
}
50+
51+
/* Do NOT open devices here! Let the event watcher do that! */
52+
SDL_AddEventWatch(SDLINPUT_EventWatch, NULL);
53+
54+
return current_mask
55+
| ACTIONSET_DEVICE_KEYBOARDMOUSE
56+
| ACTIONSET_DEVICE_CONTROLLER
57+
| ACTIONSET_DEVICE_TOUCH;
58+
}
59+
60+
static void SDLINPUT_Quit(void)
61+
{
62+
SDL_DelEventWatch(SDLINPUT_EventWatch, NULL);
63+
sdlinput_mask = ACTIONSET_DEVICE_NONE;
64+
}
65+
66+
static void SDLINPUT_Update(void)
67+
{
68+
/* Nothing to do, the event watch handles everything for us */
69+
}
70+
71+
SDL_ActionSetProvider SDLINPUT_provider = {
72+
SDLINPUT_Init,
73+
SDLINPUT_Quit,
74+
SDLINPUT_Update
75+
};

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_ */

0 commit comments

Comments
 (0)