Skip to content

Commit

Permalink
ioasync: Added async i/o APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Sep 5, 2024
1 parent c5c3651 commit d735ed8
Show file tree
Hide file tree
Showing 24 changed files with 1,889 additions and 3 deletions.
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ LOCAL_SRC_FILES := \
$(wildcard $(LOCAL_PATH)/src/dynapi/*.c) \
$(wildcard $(LOCAL_PATH)/src/events/*.c) \
$(wildcard $(LOCAL_PATH)/src/file/*.c) \
$(wildcard $(LOCAL_PATH)/src/file/generic/*.c) \
$(wildcard $(LOCAL_PATH)/src/gpu/*.c) \
$(wildcard $(LOCAL_PATH)/src/gpu/vulkan/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/*.c) \
Expand Down
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@ sdl_glob_sources(
"${SDL3_SOURCE_DIR}/src/dynapi/*.c"
"${SDL3_SOURCE_DIR}/src/events/*.c"
"${SDL3_SOURCE_DIR}/src/file/*.c"
"${SDL3_SOURCE_DIR}/src/file/generic/*.c"
"${SDL3_SOURCE_DIR}/src/filesystem/*.c"
"${SDL3_SOURCE_DIR}/src/gpu/*.c"
"${SDL3_SOURCE_DIR}/src/joystick/*.c"
Expand Down Expand Up @@ -2177,8 +2178,6 @@ elseif(APPLE)
set(HAVE_SDL_MAIN_CALLBACKS TRUE)
endif()

sdl_glob_sources("${SDL3_SOURCE_DIR}/src/file/cocoa/*.m")

if(SDL_CAMERA)
if(MACOS OR IOS)
set(SDL_CAMERA_DRIVER_COREMEDIA 1)
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 @@ -339,6 +339,7 @@
<ClInclude Include="..\..\include\SDL3\SDL_haptic.h" />
<ClInclude Include="..\..\include\SDL3\SDL_hints.h" />
<ClInclude Include="..\..\include\SDL3\SDL_hidapi.h" />
<ClInclude Include="..\..\include\SDL3\SDL_ioasync.h" />
<ClInclude Include="..\..\include\SDL3\SDL_joystick.h" />
<ClInclude Include="..\..\include\SDL3\SDL_keyboard.h" />
<ClInclude Include="..\..\include\SDL3\SDL_keycode.h" />
Expand Down Expand Up @@ -430,6 +431,8 @@
<ClInclude Include="..\..\src\events\SDL_windowevents_c.h" />
<ClInclude Include="..\..\src\filesystem\SDL_sysfilesystem.h" />
<ClInclude Include="..\..\src\gpu\SDL_sysgpu.h" />
<ClInclude Include="..\..\src\file\SDL_ioasync_c.h" />
<ClInclude Include="..\..\src\file\SDL_sysioasync.h" />
<ClInclude Include="..\..\src\haptic\SDL_haptic_c.h" />
<ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
<ClInclude Include="..\..\src\haptic\windows\SDL_dinputhaptic_c.h" />
Expand Down Expand Up @@ -515,6 +518,8 @@
<ClCompile Include="..\..\src\dialog\SDL_dialog_utils.c" />
<ClCompile Include="..\..\src\filesystem\SDL_filesystem.c" />
<ClCompile Include="..\..\src\filesystem\windows\SDL_sysfsops.c" />
<ClCompile Include="..\..\src\file\generic\SDL_ioasync_generic.c" />
<ClCompile Include="..\..\src\file\SDL_ioasync.c" />
<ClCompile Include="..\..\src\main\gdk\SDL_sysmain_runapp.cpp" />
<ClCompile Include="..\..\src\main\generic\SDL_sysmain_callbacks.c" />
<ClCompile Include="..\..\src\main\SDL_main_callbacks.c" />
Expand Down
15 changes: 15 additions & 0 deletions VisualC-GDK/SDL/SDL.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<ClCompile Include="..\..\src\filesystem\windows\SDL_sysfsops.c">
<Filter>filesystem\windows</Filter>
</ClCompile>
<ClCompile Include="..\..\src\file\generic\SDL_ioasync_generic.c">
<Filter>file\generic</Filter>
</ClCompile>
<ClCompile Include="..\..\src\file\SDL_ioasync.c">
<Filter>file</Filter>
</ClCompile>
<ClCompile Include="..\..\src\render\direct3d12\SDL_render_d3d12_xbox.cpp" />
<ClCompile Include="..\..\src\render\direct3d12\SDL_shaders_d3d12_xboxone.cpp" />
<ClCompile Include="..\..\src\render\direct3d12\SDL_shaders_d3d12_xboxseries.cpp" />
Expand Down Expand Up @@ -258,6 +264,9 @@
<ClInclude Include="..\..\include\SDL3\SDL_haptic.h" />
<ClInclude Include="..\..\include\SDL3\SDL_hints.h" />
<ClInclude Include="..\..\include\SDL3\SDL_hidapi.h" />
<ClInclude Include="..\..\include\SDL3\SDL_ioasync.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_joystick.h" />
<ClInclude Include="..\..\include\SDL3\SDL_keyboard.h" />
<ClInclude Include="..\..\include\SDL3\SDL_keycode.h" />
Expand Down Expand Up @@ -347,6 +356,12 @@
<Filter>filesystem</Filter>
</ClInclude>
<ClInclude Include="..\..\src\gpu\SDL_sysgpu.h" />
<ClInclude Include="..\..\src\file\SDL_ioasync_c.h">
<Filter>file</Filter>
</ClInclude>
<ClInclude Include="..\..\src\file\SDL_sysioasync.h">
<Filter>file</Filter>
</ClInclude>
<ClInclude Include="..\..\src\haptic\SDL_haptic_c.h" />
<ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
<ClInclude Include="..\..\src\haptic\windows\SDL_dinputhaptic_c.h" />
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 @@ -56,6 +56,7 @@
<ClInclude Include="..\include\SDL3\SDL_hints.h" />
<ClInclude Include="..\include\SDL3\SDL_hidapi.h" />
<ClInclude Include="..\include\SDL3\SDL_input.h" />
<ClInclude Include="..\include\SDL3\SDL_ioasync.h" />
<ClInclude Include="..\include\SDL3\SDL_joystick.h" />
<ClInclude Include="..\include\SDL3\SDL_keyboard.h" />
<ClInclude Include="..\include\SDL3\SDL_keycode.h" />
Expand Down Expand Up @@ -126,6 +127,8 @@
<ClInclude Include="..\src\events\SDL_windowevents_c.h" />
<ClInclude Include="..\src\filesystem\SDL_sysfilesystem.h" />
<ClInclude Include="..\src\gpu\SDL_sysgpu.h" />
<ClInclude Include="..\src\file\SDL_ioasync_c.h" />
<ClInclude Include="..\src\file\SDL_sysioasync.h" />
<ClInclude Include="..\src\haptic\SDL_haptic_c.h" />
<ClInclude Include="..\src\haptic\SDL_syshaptic.h" />
<ClInclude Include="..\src\haptic\windows\SDL_dinputhaptic_c.h" />
Expand Down Expand Up @@ -341,6 +344,8 @@
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)$(TargetName)_cpp.pch</PrecompiledHeaderOutputFile>
</ClCompile>
<ClCompile Include="..\src\file\generic\SDL_ioasync_generic.c" />
<ClCompile Include="..\src\file\SDL_ioasync.c" />
<ClCompile Include="..\src\file\SDL_iostream.c" />
<ClCompile Include="..\src\filesystem\SDL_filesystem.c" />
<ClCompile Include="..\src\filesystem\windows\SDL_sysfsops.c" />
Expand Down
21 changes: 21 additions & 0 deletions VisualC-WinRT/SDL-UWP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
<Filter Include="main\winrt">
<UniqueIdentifier>{00006680a11742e2b280c6453be80000}</UniqueIdentifier>
</Filter>
<Filter Include="file">
<UniqueIdentifier>{0000681aa625874d5ebeea7ef7640000}</UniqueIdentifier>
</Filter>
<Filter Include="file\generic">
<UniqueIdentifier>{00007fb7319480de96547d4a9b610000}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\SDL3\SDL_begin_code.h">
Expand Down Expand Up @@ -102,6 +108,9 @@
<ClInclude Include="..\include\SDL3\SDL_input.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SDL3\SDL_ioasync.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\include\SDL3\SDL_joystick.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -198,6 +207,12 @@
<ClInclude Include="..\src\filesystem\SDL_sysfilesystem.h">
<Filter>filesystem</Filter>
</ClInclude>
<ClInclude Include="..\src\file\SDL_ioasync_c.h">
<Filter>file</Filter>
</ClInclude>
<ClInclude Include="..\src\file\SDL_sysioasync.h">
<Filter>file</Filter>
</ClInclude>
<ClInclude Include="..\src\joystick\SDL_gamepad_c.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -615,6 +630,12 @@
<ClCompile Include="..\src\filesystem\winrt\SDL_sysfilesystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\file\generic\SDL_ioasync_generic.c">
<Filter>file\generic</Filter>
</ClCompile>
<ClCompile Include="..\src\file\SDL_ioasync.c">
<Filter>file</Filter>
</ClCompile>
<ClCompile Include="..\src\file\SDL_iostream.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
5 changes: 5 additions & 0 deletions VisualC/SDL/SDL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
<ClInclude Include="..\..\include\SDL3\SDL_haptic.h" />
<ClInclude Include="..\..\include\SDL3\SDL_hints.h" />
<ClInclude Include="..\..\include\SDL3\SDL_hidapi.h" />
<ClInclude Include="..\..\include\SDL3\SDL_ioasync.h" />
<ClInclude Include="..\..\include\SDL3\SDL_joystick.h" />
<ClInclude Include="..\..\include\SDL3\SDL_keyboard.h" />
<ClInclude Include="..\..\include\SDL3\SDL_keycode.h" />
Expand Down Expand Up @@ -351,6 +352,8 @@
<ClInclude Include="..\..\src\filesystem\SDL_sysfilesystem.h" />
<ClInclude Include="..\..\src\gpu\SDL_sysgpu.h" />
<ClInclude Include="..\..\src\gpu\vulkan\SDL_gpu_vulkan_vkfuncs.h" />
<ClInclude Include="..\..\src\file\SDL_ioasync_c.h" />
<ClInclude Include="..\..\src\file\SDL_sysioasync.h" />
<ClInclude Include="..\..\src\haptic\SDL_haptic_c.h" />
<ClInclude Include="..\..\src\haptic\SDL_syshaptic.h" />
<ClInclude Include="..\..\src\haptic\windows\SDL_dinputhaptic_c.h" />
Expand Down Expand Up @@ -415,6 +418,8 @@
<ClCompile Include="..\..\src\gpu\d3d11\SDL_gpu_d3d11.c" />
<ClCompile Include="..\..\src\gpu\d3d12\SDL_gpu_d3d12.c" />
<ClCompile Include="..\..\src\gpu\vulkan\SDL_gpu_vulkan.c" />
<ClCompile Include="..\..\src\file\generic\SDL_ioasync_generic.c" />
<ClCompile Include="..\..\src\file\SDL_ioasync.c" />
<ClCompile Include="..\..\src\main\generic\SDL_sysmain_callbacks.c" />
<ClCompile Include="..\..\src\main\SDL_main_callbacks.c" />
<ClCompile Include="..\..\src\main\SDL_runapp.c" />
Expand Down
18 changes: 18 additions & 0 deletions VisualC/SDL/SDL.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@
<Filter Include="main\windows">
<UniqueIdentifier>{00009d5ded166cc6c6680ec771a30000}</UniqueIdentifier>
</Filter>
<Filter Include="file\generic">
<UniqueIdentifier>{00004d6806b6238cae0ed62db5440000}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\SDL3\SDL_begin_code.h">
Expand Down Expand Up @@ -278,6 +281,9 @@
<ClInclude Include="..\..\include\SDL3\SDL_hidapi.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_ioasync.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_joystick.h">
<Filter>API Headers</Filter>
</ClInclude>
Expand Down Expand Up @@ -434,6 +440,12 @@
<ClInclude Include="..\..\src\filesystem\SDL_sysfilesystem.h">
<Filter>filesystem</Filter>
</ClInclude>
<ClInclude Include="..\..\src\file\SDL_ioasync_c.h">
<Filter>file</Filter>
</ClInclude>
<ClInclude Include="..\..\src\file\SDL_sysioasync.h">
<Filter>file</Filter>
</ClInclude>
<ClInclude Include="..\..\src\main\SDL_main_callbacks.h">
<Filter>main</Filter>
</ClInclude>
Expand Down Expand Up @@ -939,6 +951,12 @@
<ClCompile Include="..\..\src\filesystem\windows\SDL_sysfsops.c">
<Filter>filesystem\windows</Filter>
</ClCompile>
<ClCompile Include="..\..\src\file\generic\SDL_ioasync_generic.c">
<Filter>file\generic</Filter>
</ClCompile>
<ClCompile Include="..\..\src\file\SDL_ioasync.c">
<Filter>file</Filter>
</ClCompile>
<ClCompile Include="..\..\src\main\generic\SDL_sysmain_callbacks.c">
<Filter>main\generic</Filter>
</ClCompile>
Expand Down
25 changes: 25 additions & 0 deletions Xcode/SDL/SDL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@
FA73671D19A540EF004122E4 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA73671C19A540EF004122E4 /* CoreVideo.framework */; platformFilters = (ios, maccatalyst, macos, tvos, watchos, ); };
0000E5D7110DFF81FF660000 /* SDL_cocoapen.h in Headers */ = {isa = PBXBuildFile; fileRef = 00002F2F5496FA184A0F0000 /* SDL_cocoapen.h */; };
0000D5B526B85DE7AB1C0000 /* SDL_cocoapen.m in Sources */ = {isa = PBXBuildFile; fileRef = 0000CCA310B73A7B59910000 /* SDL_cocoapen.m */; };
0000AEB9AE90228CA2D60000 /* SDL_ioasync.c in Sources */ = {isa = PBXBuildFile; fileRef = 00003928A612EC33D42C0000 /* SDL_ioasync.c */; };
000062F9C843687F50F70000 /* SDL_ioasync_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 0000919399B1A908267F0000 /* SDL_ioasync_c.h */; };
00005081394CCF8322BE0000 /* SDL_sysioasync.h in Headers */ = {isa = PBXBuildFile; fileRef = 0000585B2CAB450B40540000 /* SDL_sysioasync.h */; };
000018AF97C08F2DAFFD0000 /* SDL_ioasync.h in Headers */ = {isa = PBXBuildFile; fileRef = 00004945A946DF5B1AED0000 /* SDL_ioasync.h */; settings = {ATTRIBUTES = (Public, ); }; };
00004D0B73767647AD550000 /* SDL_ioasync_generic.c in Sources */ = {isa = PBXBuildFile; fileRef = 0000FB02CDE4BE34A87E0000 /* SDL_ioasync_generic.c */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -1098,6 +1103,11 @@
FA73671C19A540EF004122E4 /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; };
00002F2F5496FA184A0F0000 /* SDL_cocoapen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_cocoapen.h; path = SDL_cocoapen.h; sourceTree = "<group>"; };
0000CCA310B73A7B59910000 /* SDL_cocoapen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_cocoapen.m; path = SDL_cocoapen.m; sourceTree = "<group>"; };
00003928A612EC33D42C0000 /* SDL_ioasync.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_ioasync.c; path = SDL_ioasync.c; sourceTree = "<group>"; };
0000919399B1A908267F0000 /* SDL_ioasync_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_ioasync_c.h; path = SDL_ioasync_c.h; sourceTree = "<group>"; };
0000585B2CAB450B40540000 /* SDL_sysioasync.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_sysioasync.h; path = SDL_sysioasync.h; sourceTree = "<group>"; };
00004945A946DF5B1AED0000 /* SDL_ioasync.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_ioasync.h; path = SDL3/SDL_ioasync.h; sourceTree = "<group>"; };
0000FB02CDE4BE34A87E0000 /* SDL_ioasync_generic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_ioasync_generic.c; path = SDL_ioasync_generic.c; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1272,6 +1282,7 @@
F3F7D8C52933074B00816151 /* SDL_video.h */,
F3F7D8D42933074C00816151 /* SDL_vulkan.h */,
F3F7D8CF2933074C00816151 /* SDL.h */,
00004945A946DF5B1AED0000 /* SDL_ioasync.h */,
);
name = "Public Headers";
path = ../../include;
Expand Down Expand Up @@ -1911,6 +1922,10 @@
isa = PBXGroup;
children = (
A7D8A7DB23E2513F00DCD162 /* SDL_iostream.c */,
00003928A612EC33D42C0000 /* SDL_ioasync.c */,
0000919399B1A908267F0000 /* SDL_ioasync_c.h */,
0000585B2CAB450B40540000 /* SDL_sysioasync.h */,
000013C0F2EADC24ADC10000 /* generic */,
);
path = file;
sourceTree = "<group>";
Expand Down Expand Up @@ -2362,6 +2377,14 @@
path = resources;
sourceTree = "<group>";
};
000013C0F2EADC24ADC10000 /* generic */ = {
isa = PBXGroup;
children = (
0000FB02CDE4BE34A87E0000 /* SDL_ioasync_generic.c */,
);
path = generic;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -2975,6 +2998,8 @@
000095FA1BDE436CF3AF0000 /* SDL_time.c in Sources */,
0000140640E77F73F1DF0000 /* SDL_dialog_utils.c in Sources */,
0000D5B526B85DE7AB1C0000 /* SDL_cocoapen.m in Sources */,
0000AEB9AE90228CA2D60000 /* SDL_ioasync.c in Sources */,
00004D0B73767647AD550000 /* SDL_ioasync_generic.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ add_sdl_example_executable(audio-load-wav SOURCES audio/03-load-wav/load-wav.c D
add_sdl_example_executable(camera-read-and-draw SOURCES camera/01-read-and-draw/read-and-draw.c)
add_sdl_example_executable(pen-drawing-lines SOURCES pen/01-drawing-lines/drawing-lines.c)
add_sdl_example_executable(game-snake SOURCES game/01-snake/snake.c)

add_sdl_example_executable(asyncio-load-bitmaps SOURCES asyncio/01-load-bitmaps/load-bitmaps.c DATAFILES ${CMAKE_CURRENT_SOURCE_DIR}/../test/sample.bmp ${CMAKE_CURRENT_SOURCE_DIR}/../test/gamepad_front.bmp ${CMAKE_CURRENT_SOURCE_DIR}/../test/speaker.bmp ${CMAKE_CURRENT_SOURCE_DIR}/../test/icon2x.bmp)

if(PSP)
# Build EBOOT files if building for PSP
Expand Down
6 changes: 6 additions & 0 deletions examples/asyncio/01-load-bitmaps/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This example code loads a few bitmap files from disk using the asynchronous
i/o, and then draws it to the window. It uses a task group to watch multiple
reads and deal with them in whatever order they finish.

Note that for a single tiny file like this, you'd probably not want to bother
with async i/o in real life, but this is just an example of how to do it.
Loading

0 comments on commit d735ed8

Please sign in to comment.