SDL/include/SDL3
Ryan C. Gordon 9c664b0062
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:

First:

    int SDL_AppInit(int argc, char **argv);

This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.

Then:

     int SDL_AppIterate(void);

This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).

Next:

    int SDL_AppEvent(const SDL_Event *event);

This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.

Finally:

    void SDL_AppQuit(void);

This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.

The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.

In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.

On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).

Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.

The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.

Fixes #6785.
Reference PR #8247.
2023-11-01 18:40:41 -04:00
..
SDL.h Added SDL properties API 2023-10-11 22:38:00 -07:00
SDL_assert.h SDL_TriggerBreakppoint for riscv arch (both 32/64) version. 2023-08-13 11:36:49 -04:00
SDL_atomic.h SDL_atomic.h: __ARM_ARCH is not always defined for an arm platform 2023-07-22 15:55:48 -04:00
SDL_audio.h Sync SDL3 wiki -> header 2023-10-19 14:03:06 +00:00
SDL_begin_code.h MSVC has __declspec(deprecated) 2023-08-09 02:54:18 +02:00
SDL_bits.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_blendmode.h Simplify SDL_BLENDMODE_MUL 2023-03-16 20:25:59 +01:00
SDL_clipboard.h Add 'return' comment to SDL_ClearClipboardData 2023-07-07 10:25:06 +02:00
SDL_close_code.h
SDL_copying.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_cpuinfo.h cpuinfo: update \sa's of SDL_HasXXX functions 2023-03-27 06:12:49 +00:00
SDL_egl.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_endian.h byteswap: Don't use intrinsic byteswap functions with Intel C compiler 2023-03-27 06:12:49 +00:00
SDL_error.h Sync wiki -> headers. 2023-02-24 11:49:41 -05:00
SDL_events.h Renamed display added/removed events for consistency with the rest of the API 2023-10-23 09:14:54 -07:00
SDL_filesystem.h Sync SDL3 wiki -> header 2023-07-31 23:40:15 +00:00
SDL_gamepad.h Sync wiki -> headers 2023-10-12 15:20:53 -04:00
SDL_guid.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_haptic.h
SDL_hidapi.h Fixed pedantic warning: comma at end of enumerator list 2023-06-27 21:52:33 -07:00
SDL_hints.h main: Added _optional_ callback entry points. 2023-11-01 18:40:41 -04:00
SDL_init.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_intrin.h Use #ifdef/#ifndef instead of #if defined/#if \!defined 2023-03-30 21:35:01 +00:00
SDL_joystick.h Sync wiki -> headers 2023-10-12 15:20:53 -04:00
SDL_keyboard.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_keycode.h Don't map the top keyboard row to numbers when using the one-handed DVORAK layouts (thanks @tormol!) 2023-05-22 11:33:47 -07:00
SDL_loadso.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_locale.h Sync wiki -> headers. 2023-02-24 11:49:41 -05:00
SDL_log.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_main.h main: Added _optional_ callback entry points. 2023-11-01 18:40:41 -04:00
SDL_main_impl.h main: Added _optional_ callback entry points. 2023-11-01 18:40:41 -04:00
SDL_messagebox.h
SDL_metal.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_misc.h Update `\returns` to the generic form 2023-02-12 08:21:02 -08:00
SDL_mouse.h Fixed the documentation for SDL_SetRelativeMouseMode() 2023-03-08 22:32:54 -08:00
SDL_mutex.h Sync SDL3 wiki -> header 2023-10-26 18:23:13 +00:00
SDL_oldnames.h Renamed display added/removed events for consistency with the rest of the API 2023-10-23 09:14:54 -07:00
SDL_opengl.h Use #ifdef/#ifndef instead of #if defined/#if \!defined 2023-03-30 21:35:01 +00:00
SDL_opengl_glext.h replaced line comments in public header. 2023-02-04 10:02:10 +03:00
SDL_opengles.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_opengles2.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_opengles2_gl2.h
SDL_opengles2_gl2ext.h
SDL_opengles2_gl2platform.h
SDL_opengles2_khrplatform.h
SDL_pixels.h pixels: Document the naming convention 2023-10-10 03:24:43 -07:00
SDL_platform.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_platform_defines.h Implement visionOS support 2023-08-08 22:25:04 -07:00
SDL_power.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_properties.h Removed redundant thread-safety information 2023-10-18 22:19:50 -07:00
SDL_quit.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_rect.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_render.h Sync wiki -> headers 2023-10-12 15:20:53 -04:00
SDL_revision.h SDL_revision.h: added missing newline at end of file. 2023-02-23 23:55:56 +03:00
SDL_rwops.h Sync wiki -> headers 2023-10-12 15:20:53 -04:00
SDL_scancode.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_sensor.h Sync wiki -> headers 2023-10-12 15:20:53 -04:00
SDL_shape.h SDL_CreateWindow() has been simplified and no longer takes a window position. 2023-03-06 09:50:12 -08:00
SDL_stdinc.h Use SDL_DISABLE_ALLOCA instead of HAVE_ALLOCA in SDL_stdinc.h 2023-10-28 18:54:12 +02:00
SDL_surface.h Sync wiki -> headers 2023-10-12 15:20:53 -04:00
SDL_system.h Sync SDL3 wiki -> header 2023-10-19 17:13:15 +00:00
SDL_syswm.h gdk: Fix the project 2023-05-26 14:53:17 -07:00
SDL_test.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_test_assert.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_test_common.h main: Added _optional_ callback entry points. 2023-11-01 18:40:41 -04:00
SDL_test_compare.h test: Extract SDLTest_ReadSurfacePixel 2023-10-10 03:23:20 -07:00
SDL_test_crc32.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_test_font.h Improved testaudiostreamdynamicresample 2023-09-01 14:38:45 -04:00
SDL_test_fuzzer.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_test_harness.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_test_log.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_test_md5.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_test_memory.h Added --randmem test parameter 2023-08-27 13:08:15 -07:00
SDL_test_random.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_thread.h SDL_thread.h: do not conflict with sdl2-compat::sdl3_include_wrapper.h 2023-08-06 14:11:02 +03:00
SDL_timer.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_touch.h Sync wiki -> headers. 2023-02-24 11:49:41 -05:00
SDL_version.h include: add \brief to includes 2023-02-19 10:01:33 -08:00
SDL_video.h Sync wiki -> headers 2023-10-12 15:20:53 -04:00
SDL_vulkan.h include: add \brief to includes 2023-02-19 10:01:33 -08:00