Skip to content

The Action Set API #7558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_SRC_FILES := \
$(subst $(LOCAL_PATH)/,, \
$(wildcard $(LOCAL_PATH)/src/*.c) \
$(wildcard $(LOCAL_PATH)/src/actionset/*.c) \
$(wildcard $(LOCAL_PATH)/src/actionset/sdlinput/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/audio/dummy/*.c) \
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ endif()
set(LONGESTOPTIONNAME 0) # set_option and friends will change this.

set(SDL_SUBSYSTEMS
Atomic Audio Video Render Events Joystick Haptic Hidapi Power Threads Timers
File Loadso CPUinfo Filesystem Sensor Locale Misc)
ActionSet Atomic Audio Video Render Events Joystick Haptic Hidapi Power
Threads Timers File Loadso CPUinfo Filesystem Sensor Locale Misc)
foreach(_SUB ${SDL_SUBSYSTEMS})
string(TOUPPER ${_SUB} _OPT)
if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
Expand Down Expand Up @@ -483,6 +483,9 @@ endif()
# General source files
file(GLOB SOURCE_FILES
${SDL3_SOURCE_DIR}/src/*.c
${SDL3_SOURCE_DIR}/src/actionset/*.c
${SDL3_SOURCE_DIR}/src/actionset/sdlinput/*.c
${SDL3_SOURCE_DIR}/src/actionset/steaminput/*.c # FIXME: Windows/macOS/Linux only
${SDL3_SOURCE_DIR}/src/atomic/*.c
${SDL3_SOURCE_DIR}/src/audio/*.c
${SDL3_SOURCE_DIR}/src/core/*.c
Expand Down
5 changes: 5 additions & 0 deletions VisualC-GDK/SDL/SDL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
<ClInclude Include="..\..\include\SDL3\SDL_begin_code.h" />
<ClInclude Include="..\..\include\SDL3\SDL_close_code.h" />
<ClInclude Include="..\..\include\SDL3\SDL.h" />
<ClInclude Include="..\..\include\SDL3\SDL_actionset.h" />
<ClInclude Include="..\..\include\SDL3\SDL_assert.h" />
<ClInclude Include="..\..\include\SDL3\SDL_atomic.h" />
<ClInclude Include="..\..\include\SDL3\SDL_audio.h" />
Expand Down Expand Up @@ -364,6 +365,8 @@
<ClInclude Include="..\..\include\SDL3\SDL_version.h" />
<ClInclude Include="..\..\include\SDL3\SDL_video.h" />
<ClInclude Include="..\..\include\SDL3\SDL_vulkan.h" />
<ClInclude Include="..\..\src\actionset\SDL_actionset_c.h" />
<ClInclude Include="..\..\src\actionset\sdlinput\SDL_sdlinput.h" />
<ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" />
<ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
Expand Down Expand Up @@ -538,6 +541,8 @@
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb_std_func.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\actionset\SDL_actionset.c" />
<ClCompile Include="..\..\src\actionset\sdlinput\SDL_sdlinput.c" />
<ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
<ClCompile Include="..\..\src\atomic\SDL_spinlock.c" />
<ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" />
Expand Down
7 changes: 7 additions & 0 deletions VisualC-GDK/SDL/SDL.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
<ClInclude Include="..\..\include\SDL3\SDL.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_actionset.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_assert.h">
<Filter>API Headers</Filter>
</ClInclude>
Expand Down Expand Up @@ -405,6 +408,8 @@
<ClInclude Include="..\..\include\SDL3\SDL_test_memory.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\src\actionset\SDL_actionset_c.h" />
<ClInclude Include="..\..\src\actionset\sdlinput\SDL_sdlinput.h" />
<ClInclude Include="..\..\src\audio\SDL_audio_c.h">
<Filter>audio</Filter>
</ClInclude>
Expand Down Expand Up @@ -832,6 +837,8 @@
<ClCompile Include="..\..\src\SDL_hints.c" />
<ClCompile Include="..\..\src\SDL_list.c" />
<ClCompile Include="..\..\src\SDL_utils.c" />
<ClCompile Include="..\..\src\actionset\SDL_actionset.c" />
<ClCompile Include="..\..\src\actionset\sdlinput\SDL_sdlinput.c" />
<ClCompile Include="..\..\src\audio\SDL_audio.c">
<Filter>audio</Filter>
</ClCompile>
Expand Down
5 changes: 5 additions & 0 deletions VisualC-WinRT/SDL-UWP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<ClInclude Include="..\include\SDL3\SDL_begin_code.h" />
<ClInclude Include="..\include\SDL3\SDL_close_code.h" />
<ClInclude Include="..\include\SDL3\SDL.h" />
<ClInclude Include="..\include\SDL3\SDL_actionset.h" />
<ClInclude Include="..\include\SDL3\SDL_assert.h" />
<ClInclude Include="..\include\SDL3\SDL_atomic.h" />
<ClInclude Include="..\include\SDL3\SDL_audio.h" />
Expand Down Expand Up @@ -89,6 +90,8 @@
<ClInclude Include="..\include\SDL3\SDL_types.h" />
<ClInclude Include="..\include\SDL3\SDL_version.h" />
<ClInclude Include="..\include\SDL3\SDL_video.h" />
<ClInclude Include="..\src\actionset\SDL_actionset_c.h" />
<ClInclude Include="..\src\actionset\sdlinput\SDL_sdlinput.h" />
<ClInclude Include="..\src\audio\disk\SDL_diskaudio.h" />
<ClInclude Include="..\src\audio\dummy\SDL_dummyaudio.h" />
<ClInclude Include="..\src\audio\SDL_audiodev_c.h" />
Expand Down Expand Up @@ -185,6 +188,8 @@
<ClInclude Include="..\src\video\yuv2rgb\yuv_rgb.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\actionset\SDL_actionset.c" />
<ClCompile Include="..\src\actionset\sdlinput\SDL_sdlinput.c" />
<ClCompile Include="..\src\atomic\SDL_atomic.c" />
<ClCompile Include="..\src\atomic\SDL_spinlock.c" />
<ClCompile Include="..\src\audio\disk\SDL_diskaudio.c" />
Expand Down
15 changes: 15 additions & 0 deletions VisualC-WinRT/SDL-UWP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<ClInclude Include="..\include\SDL3\SDL.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SDL3\SDL_actionset.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SDL3\SDL_assert.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -168,6 +171,12 @@
<ClInclude Include="..\src\joystick\SDL_gamepad_db.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\actionset\SDL_actionset_c.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\src\actionset\sdlinput\SDL_sdlinput.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\src\audio\disk\SDL_diskaudio.h">
<Filter>Source Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -447,6 +456,12 @@
<ClInclude Include="..\include\SDL3\SDL_misc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClCompile Include="..\src\actionset\SDL_actionset.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\actionset\sdlinput\SDL_sdlinput.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\atomic\SDL_atomic.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
7 changes: 7 additions & 0 deletions VisualC/SDL/SDL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
<ClInclude Include="..\..\include\SDL3\SDL_begin_code.h" />
<ClInclude Include="..\..\include\SDL3\SDL_close_code.h" />
<ClInclude Include="..\..\include\SDL3\SDL.h" />
<ClInclude Include="..\..\include\SDL3\SDL_actionset.h" />
<ClInclude Include="..\..\include\SDL3\SDL_assert.h" />
<ClInclude Include="..\..\include\SDL3\SDL_atomic.h" />
<ClInclude Include="..\..\include\SDL3\SDL_audio.h" />
Expand Down Expand Up @@ -309,6 +310,9 @@
<ClInclude Include="..\..\include\SDL3\SDL_version.h" />
<ClInclude Include="..\..\include\SDL3\SDL_video.h" />
<ClInclude Include="..\..\include\SDL3\SDL_vulkan.h" />
<ClInclude Include="..\..\src\actionset\SDL_actionset_c.h" />
<ClInclude Include="..\..\src\actionset\sdlinput\SDL_sdlinput.h" />
<ClInclude Include="..\..\src\actionset\steaminput\SDL_steaminput.h" />
<ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" />
<ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
Expand Down Expand Up @@ -461,6 +465,9 @@
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb_std_func.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\actionset\SDL_actionset.c" />
<ClCompile Include="..\..\src\actionset\sdlinput\SDL_sdlinput.c" />
<ClCompile Include="..\..\src\actionset\steaminput\SDL_steaminput.c" />
<ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
<ClCompile Include="..\..\src\atomic\SDL_spinlock.c" />
<ClCompile Include="..\..\src\audio\directsound\SDL_directsound.c" />
Expand Down
9 changes: 9 additions & 0 deletions VisualC/SDL/SDL.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
<ClInclude Include="..\..\include\SDL3\SDL.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_actionset.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_assert.h">
<Filter>API Headers</Filter>
</ClInclude>
Expand Down Expand Up @@ -399,6 +402,9 @@
<ClInclude Include="..\..\include\SDL3\SDL_test_memory.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\src\actionset\SDL_actionset_c.h" />
<ClInclude Include="..\..\src\actionset\sdlinput\SDL_sdlinput.h" />
<ClInclude Include="..\..\src\actionset\steaminput\SDL_steaminput.h" />
<ClInclude Include="..\..\src\audio\SDL_audio_c.h">
<Filter>audio</Filter>
</ClInclude>
Expand Down Expand Up @@ -820,6 +826,9 @@
<ClCompile Include="..\..\src\SDL_hints.c" />
<ClCompile Include="..\..\src\SDL_list.c" />
<ClCompile Include="..\..\src\SDL_utils.c" />
<ClCompile Include="..\..\src\actionset\SDL_actionset.c" />
<ClCompile Include="..\..\src\actionset\sdlinput\SDL_sdlinput.c" />
<ClCompile Include="..\..\src\actionset\steaminput\SDL_steaminput.c" />
<ClCompile Include="..\..\src\audio\SDL_audio.c">
<Filter>audio</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions include/SDL3/SDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define SDL_h_

#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_actionset.h>
#include <SDL3/SDL_assert.h>
#include <SDL3/SDL_atomic.h>
#include <SDL3/SDL_audio.h>
Expand Down
47 changes: 47 additions & 0 deletions include/SDL3/SDL_actionset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <[email protected]>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

/**
* \file SDL_actionset.h
*
* \brief Access to the "action set" interface for the SDL library.
*/

#ifndef SDL_actionset_h_
#define SDL_actionset_h_

#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif

/* TODO: Copy over from Codename GigaBrain */

extern DECLSPEC void SDLCALL SDL_UpdateActionSet(void);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>

#endif /* SDL_actionset_h_ */
12 changes: 12 additions & 0 deletions include/SDL3/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ extern "C" {
*/
#define SDL_HINT_AUTO_UPDATE_SENSORS "SDL_AUTO_UPDATE_SENSORS"

/**
* \brief A variable controlling whether SDL updates action set state when getting action events
*
* This variable can be set to the following values:
*
* "0" - You'll call SDL_UpdateActionSet() manually
* "1" - SDL will automatically call SDL_UpdateActionSet() (default)
*
* This hint can be toggled on and off at runtime.
*/
#define SDL_HINT_AUTO_UPDATE_ACTIONSET "SDL_AUTO_UPDATE_ACTIONSET"

/**
* \brief Prevent SDL from using version 4 of the bitmap header when saving BMPs.
*
Expand Down
8 changes: 6 additions & 2 deletions include/SDL3/SDL_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ typedef enum
SDL_INIT_HAPTIC = 0x00001000,
SDL_INIT_GAMEPAD = 0x00002000, /**< `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK` */
SDL_INIT_EVENTS = 0x00004000,
SDL_INIT_SENSOR = 0x00008000
SDL_INIT_SENSOR = 0x00008000,
SDL_INIT_ACTIONSET = 0x00010000, /**< `SDL_INIT_ACTIONSET` implies `SDL_INIT_GAMEPAD | SDL_INIT_SENSOR | SDL_INIT_HAPTIC` */
} SDL_InitFlags;
#define SDL_INIT_EVERYTHING ( \
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMEPAD | SDL_INIT_SENSOR \
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMEPAD | SDL_INIT_SENSOR | \
SDL_INIT_ACTIONSET \
)

/**
Expand Down Expand Up @@ -94,6 +96,8 @@ typedef enum
* - `SDL_INIT_GAMEPAD`: gamepad subsystem; automatically initializes the
* joystick subsystem
* - `SDL_INIT_EVENTS`: events subsystem
* - `SDL_INIT_ACTIONSET`: actionset subsystem, automatically initializes the
* gamepad, sensor, haptic, and events subsystems
* - `SDL_INIT_EVERYTHING`: all of the above subsystems
*
* Subsystem initialization is ref-counted, you must call SDL_QuitSubSystem()
Expand Down
33 changes: 33 additions & 0 deletions src/SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "joystick/SDL_gamepad_c.h"
#include "joystick/SDL_joystick_c.h"
#include "sensor/SDL_sensor_c.h"
#include "actionset/SDL_actionset_c.h"

/* Initialization/Cleanup routines */
#ifndef SDL_TIMERS_DISABLED
Expand Down Expand Up @@ -175,6 +176,11 @@ int SDL_InitSubSystem(Uint32 flags)
SDL_DBus_Init();
#endif

if (flags & SDL_INIT_ACTIONSET) {
/* action set implies gamepad, sensor, and haptic */
flags |= SDL_INIT_GAMEPAD | SDL_INIT_SENSOR | SDL_INIT_HAPTIC;
}

if (flags & SDL_INIT_GAMEPAD) {
/* game controller implies joystick */
flags |= SDL_INIT_JOYSTICK;
Expand Down Expand Up @@ -348,6 +354,24 @@ int SDL_InitSubSystem(Uint32 flags)
#endif
}

if (flags & SDL_INIT_ACTIONSET) {
#ifndef SDL_ACTIONSET_DISABLED
if (SDL_ShouldInitSubsystem(SDL_INIT_ACTIONSET)) {
SDL_IncrementSubsystemRefCount(SDL_INIT_ACTIONSET);
if (SDL_InitActionSet() < 0) {
SDL_DecrementSubsystemRefCount(SDL_INIT_ACTIONSET);
goto quit_and_error;
}
} else {
SDL_IncrementSubsystemRefCount(SDL_INIT_ACTIONSET);
}
flags_initialized |= SDL_INIT_ACTIONSET;
#else
SDL_SetError("SDL not built with actionset support");
goto quit_and_error;
#endif
}

(void)flags_initialized; /* make static analysis happy, since this only gets used in error cases. */

return 0;
Expand All @@ -365,6 +389,15 @@ int SDL_Init(Uint32 flags)
void SDL_QuitSubSystem(Uint32 flags)
{
/* Shut down requested initialized subsystems */
#ifndef SDL_ACTIONSET_DISABLED
if (flags & SDL_INIT_ACTIONSET) {
if (SDL_ShouldQuitSubsystem(SDL_INIT_ACTIONSET)) {
SDL_QuitActionSet();
}
SDL_DecrementSubsystemRefCount(SDL_INIT_ACTIONSET);
}
#endif

#ifndef SDL_SENSOR_DISABLED
if (flags & SDL_INIT_SENSOR) {
if (SDL_ShouldQuitSubsystem(SDL_INIT_SENSOR)) {
Expand Down
Loading