Skip to content

Commit 2b0845e

Browse files
committed
Introduce ActionSet subsystem
1 parent a67d410 commit 2b0845e

File tree

9 files changed

+209
-4
lines changed

9 files changed

+209
-4
lines changed

CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ endif()
353353
set(LONGESTOPTIONNAME 0) # set_option and friends will change this.
354354

355355
set(SDL_SUBSYSTEMS
356-
Atomic Audio Video Render Events Joystick Haptic Hidapi Power Threads Timers
357-
File Loadso CPUinfo Filesystem Sensor Locale Misc)
356+
ActionSet Atomic Audio Video Render Events Joystick Haptic Hidapi Power
357+
Threads Timers File Loadso CPUinfo Filesystem Sensor Locale Misc)
358358
foreach(_SUB ${SDL_SUBSYSTEMS})
359359
string(TOUPPER ${_SUB} _OPT)
360360
if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
@@ -483,6 +483,7 @@ endif()
483483
# General source files
484484
file(GLOB SOURCE_FILES
485485
${SDL3_SOURCE_DIR}/src/*.c
486+
${SDL3_SOURCE_DIR}/src/actionset/*.c
486487
${SDL3_SOURCE_DIR}/src/atomic/*.c
487488
${SDL3_SOURCE_DIR}/src/audio/*.c
488489
${SDL3_SOURCE_DIR}/src/core/*.c

include/SDL3/SDL.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define SDL_h_
3131

3232
#include <SDL3/SDL_stdinc.h>
33+
#include <SDL3/SDL_actionset.h>
3334
#include <SDL3/SDL_assert.h>
3435
#include <SDL3/SDL_atomic.h>
3536
#include <SDL3/SDL_audio.h>

include/SDL3/SDL_actionset.h

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
/**
23+
* \file SDL_actionset.h
24+
*
25+
* \brief Access to the "action set" interface for the SDL library.
26+
*/
27+
28+
#ifndef SDL_actionset_h_
29+
#define SDL_actionset_h_
30+
31+
#include <SDL3/SDL_begin_code.h>
32+
/* Set up for C function definitions, even when using C++ */
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
37+
/* TODO: Copy over from Codename GigaBrain */
38+
39+
extern DECLSPEC void SDLCALL SDL_UpdateActionSet(void);
40+
41+
/* Ends C function definitions when using C++ */
42+
#ifdef __cplusplus
43+
}
44+
#endif
45+
#include <SDL3/SDL_close_code.h>
46+
47+
#endif /* SDL_actionset_h_ */

include/SDL3/SDL_hints.h

+12
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,18 @@ extern "C" {
315315
*/
316316
#define SDL_HINT_AUTO_UPDATE_SENSORS "SDL_AUTO_UPDATE_SENSORS"
317317

318+
/**
319+
* \brief A variable controlling whether SDL updates action set state when getting action events
320+
*
321+
* This variable can be set to the following values:
322+
*
323+
* "0" - You'll call SDL_UpdateActionSet() manually
324+
* "1" - SDL will automatically call SDL_UpdateActionSet() (default)
325+
*
326+
* This hint can be toggled on and off at runtime.
327+
*/
328+
#define SDL_HINT_AUTO_UPDATE_ACTIONSET "SDL_AUTO_UPDATE_ACTIONSET"
329+
318330
/**
319331
* \brief Prevent SDL from using version 4 of the bitmap header when saving BMPs.
320332
*

include/SDL3/SDL_init.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ typedef enum
5959
SDL_INIT_HAPTIC = 0x00001000,
6060
SDL_INIT_GAMEPAD = 0x00002000, /**< `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK` */
6161
SDL_INIT_EVENTS = 0x00004000,
62-
SDL_INIT_SENSOR = 0x00008000
62+
SDL_INIT_SENSOR = 0x00008000,
63+
SDL_INIT_ACTIONSET = 0x00010000, /**< `SDL_INIT_ACTIONSET` implies `SDL_INIT_GAMEPAD | SDL_INIT_SENSOR | SDL_INIT_HAPTIC` */
6364
} SDL_InitFlags;
6465
#define SDL_INIT_EVERYTHING ( \
6566
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
66-
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMEPAD | SDL_INIT_SENSOR \
67+
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMEPAD | SDL_INIT_SENSOR | \
68+
SDL_INIT_ACTIONSET \
6769
)
6870

6971
/**
@@ -94,6 +96,8 @@ typedef enum
9496
* - `SDL_INIT_GAMEPAD`: gamepad subsystem; automatically initializes the
9597
* joystick subsystem
9698
* - `SDL_INIT_EVENTS`: events subsystem
99+
* - `SDL_INIT_ACTIONSET`: actionset subsystem, automatically initializes the
100+
* gamepad, sensor, haptic, and events subsystems
97101
* - `SDL_INIT_EVERYTHING`: all of the above subsystems
98102
*
99103
* Subsystem initialization is ref-counted, you must call SDL_QuitSubSystem()

src/SDL.c

+33
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "joystick/SDL_gamepad_c.h"
4646
#include "joystick/SDL_joystick_c.h"
4747
#include "sensor/SDL_sensor_c.h"
48+
#include "actionset/SDL_actionset_c.h"
4849

4950
/* Initialization/Cleanup routines */
5051
#ifndef SDL_TIMERS_DISABLED
@@ -175,6 +176,11 @@ int SDL_InitSubSystem(Uint32 flags)
175176
SDL_DBus_Init();
176177
#endif
177178

179+
if (flags & SDL_INIT_ACTIONSET) {
180+
/* action set implies gamepad, sensor, and haptic */
181+
flags |= SDL_INIT_GAMEPAD | SDL_INIT_SENSOR | SDL_INIT_HAPTIC;
182+
}
183+
178184
if (flags & SDL_INIT_GAMEPAD) {
179185
/* game controller implies joystick */
180186
flags |= SDL_INIT_JOYSTICK;
@@ -348,6 +354,24 @@ int SDL_InitSubSystem(Uint32 flags)
348354
#endif
349355
}
350356

357+
if (flags & SDL_INIT_ACTIONSET) {
358+
#ifndef SDL_ACTIONSET_DISABLED
359+
if (SDL_ShouldInitSubsystem(SDL_INIT_ACTIONSET)) {
360+
SDL_IncrementSubsystemRefCount(SDL_INIT_ACTIONSET);
361+
if (SDL_InitActionSet() < 0) {
362+
SDL_DecrementSubsystemRefCount(SDL_INIT_ACTIONSET);
363+
goto quit_and_error;
364+
}
365+
} else {
366+
SDL_IncrementSubsystemRefCount(SDL_INIT_ACTIONSET);
367+
}
368+
flags_initialized |= SDL_INIT_ACTIONSET;
369+
#else
370+
SDL_SetError("SDL not built with actionset support");
371+
goto quit_and_error;
372+
#endif
373+
}
374+
351375
(void)flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
352376

353377
return 0;
@@ -365,6 +389,15 @@ int SDL_Init(Uint32 flags)
365389
void SDL_QuitSubSystem(Uint32 flags)
366390
{
367391
/* Shut down requested initialized subsystems */
392+
#ifndef SDL_ACTIONSET_DISABLED
393+
if (flags & SDL_INIT_ACTIONSET) {
394+
if (SDL_ShouldQuitSubsystem(SDL_INIT_ACTIONSET)) {
395+
SDL_QuitActionSet();
396+
}
397+
SDL_DecrementSubsystemRefCount(SDL_INIT_ACTIONSET);
398+
}
399+
#endif
400+
368401
#ifndef SDL_SENSOR_DISABLED
369402
if (flags & SDL_INIT_SENSOR) {
370403
if (SDL_ShouldQuitSubsystem(SDL_INIT_SENSOR)) {

src/actionset/SDL_actionset.c

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
#include "SDL_actionset_c.h"
23+
24+
/* TODO: Copy over from Codename GigaBrain */
25+
26+
int SDL_InitActionSet(void)
27+
{
28+
return 0;
29+
}
30+
31+
void SDL_QuitActionSet(void)
32+
{
33+
}
34+
35+
SDL_bool SDL_ActionSetsOpened(void)
36+
{
37+
return SDL_FALSE;
38+
}
39+
40+
void SDL_UpdateActionSet(void)
41+
{
42+
}

src/actionset/SDL_actionset_c.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
#ifndef SDL_actionset_c_h_
23+
#define SDL_actionset_c_h_
24+
25+
#include "SDL_internal.h"
26+
27+
extern int SDL_InitActionSet(void);
28+
29+
extern void SDL_QuitActionSet(void);
30+
31+
extern SDL_bool SDL_ActionSetsOpened(void);
32+
33+
#endif /* SDL_actionset_c_h_ */

src/events/SDL_events.c

+32
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#ifndef SDL_SENSOR_DISABLED
3232
#include "../sensor/SDL_sensor_c.h"
3333
#endif
34+
#ifndef SDL_ACTIONSET_DISABLED
35+
#include "../actionset/SDL_actionset_c.h"
36+
#endif
3437
#include "../video/SDL_sysvideo.h"
3538
#include <SDL3/SDL_syswm.h>
3639

@@ -120,6 +123,17 @@ static void SDLCALL SDL_AutoUpdateSensorsChanged(void *userdata, const char *nam
120123

121124
#endif /* !SDL_SENSOR_DISABLED */
122125

126+
#ifndef SDL_ACTIONSET_DISABLED
127+
128+
static SDL_bool SDL_update_actionset = SDL_TRUE;
129+
130+
static void SDLCALL SDL_AutoUpdateActionSetChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
131+
{
132+
SDL_update_actionset = SDL_GetStringBoolean(hint, SDL_TRUE);
133+
}
134+
135+
#endif /* !SDL_ACTIONSET_DISABLED */
136+
123137
static void SDLCALL SDL_PollSentinelChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
124138
{
125139
SDL_SetEventEnabled(SDL_EVENT_POLL_SENTINEL, SDL_GetStringBoolean(hint, SDL_TRUE));
@@ -866,6 +880,13 @@ static void SDL_PumpEventsInternal(SDL_bool push_sentinel)
866880
}
867881
#endif
868882

883+
#ifndef SDL_ACTIONSET_DISABLED
884+
/* Check for action set changes */
885+
if (SDL_update_actionset) {
886+
SDL_UpdateActionSet();
887+
}
888+
#endif
889+
869890
SDL_SendPendingSignalEvents(); /* in case we had a signal handler fire, etc. */
870891

871892
if (push_sentinel && SDL_EventEnabled(SDL_EVENT_POLL_SENTINEL)) {
@@ -985,6 +1006,11 @@ static SDL_bool SDL_events_need_polling(void)
9851006
(SDL_WasInit(SDL_INIT_SENSOR) && SDL_update_sensors && SDL_SensorsOpened());
9861007
#endif
9871008

1009+
#ifndef SDL_ACTIONSET_DISABLED
1010+
need_polling = need_polling ||
1011+
(SDL_WasInit(SDL_INIT_ACTIONSET) && SDL_update_actionset && SDL_ActionSetsOpened());
1012+
#endif
1013+
9881014
return need_polling;
9891015
}
9901016

@@ -1360,6 +1386,9 @@ int SDL_InitEvents(void)
13601386
#endif
13611387
#ifndef SDL_SENSOR_DISABLED
13621388
SDL_AddHintCallback(SDL_HINT_AUTO_UPDATE_SENSORS, SDL_AutoUpdateSensorsChanged, NULL);
1389+
#endif
1390+
#ifndef SDL_ACTIONSET_DISABLED
1391+
SDL_AddHintCallback(SDL_HINT_AUTO_UPDATE_ACTIONSET, SDL_AutoUpdateActionSetChanged, NULL);
13631392
#endif
13641393
SDL_AddHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL);
13651394
SDL_AddHintCallback(SDL_HINT_POLL_SENTINEL, SDL_PollSentinelChanged, NULL);
@@ -1379,6 +1408,9 @@ void SDL_QuitEvents(void)
13791408
SDL_StopEventLoop();
13801409
SDL_DelHintCallback(SDL_HINT_POLL_SENTINEL, SDL_PollSentinelChanged, NULL);
13811410
SDL_DelHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL);
1411+
#ifndef SDL_ACTIONSET_DISABLED
1412+
SDL_DelHintCallback(SDL_HINT_AUTO_UPDATE_ACTIONSET, SDL_AutoUpdateActionSetChanged, NULL);
1413+
#endif
13821414
#ifndef SDL_JOYSTICK_DISABLED
13831415
SDL_DelHintCallback(SDL_HINT_AUTO_UPDATE_JOYSTICKS, SDL_AutoUpdateJoysticksChanged, NULL);
13841416
#endif

0 commit comments

Comments
 (0)