Simplify code to include SDL_main_impl.h in SDL_main.h

Basically all platforms where SDL_main.h renames main() to SDL_main()
use the platform-specific main() (or WinMain() or whatever)
implementations in SDL_main_impl.h - and that renaming is enabled with:
  #if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) \
      || defined(SDL_MAIN_USE_CALLBACKS)
    #define main SDL_main
  #endif

The only exception is Android, where main() *is* renamed, but
SDL_main_impl.h isn't used, because SDL_main() is called from Java.

So I think it's cleaner and less error-prone (for adding additional
platforms that need SDL_main() in the future), to use the same check
for including SDL_main_impl.h as is used for `#define main SDL_main`
and only list the exceptions (currently Android) there explicitly.

If new platforms like Android turn up, they can easily be added there
by inserting "|| defined(SDL_PLATFORM_WEIRDPLATFORM)" right next
to the Android check.

See also https://github.com/libsdl-org/SDL/issues/11068#issuecomment-2399907535
This commit is contained in:
Daniel Gibson
2024-10-08 18:03:16 +02:00
committed by Sam Lantinga
parent cba77834f2
commit 823b218051

View File

@@ -562,11 +562,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendComplete(void);
#include <SDL3/SDL_close_code.h>
#if !defined(SDL_MAIN_HANDLED) && !defined(SDL_MAIN_NOIMPL)
/* include header-only SDL_main implementations */
#if defined(SDL_MAIN_USE_CALLBACKS) \
|| defined(SDL_PLATFORM_WINDOWS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS) \
|| defined(SDL_PLATFORM_3DS) || defined(SDL_PLATFORM_NGAGE) || defined(SDL_PLATFORM_PS2) || defined(SDL_PLATFORM_PSP) \
|| defined(SDL_PLATFORM_EMSCRIPTEN)
/* include header-only SDL_main implementations
* Note: currently Android is the only platform where we rename main() to SDL_main()
* but do *not* use SDL_main_impl.h (because SDL_main() is called from external Java code)
*/
#if ( defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) ) && \
!defined(SDL_PLATFORM_ANDROID)
/* platforms which main (-equivalent) can be implemented in plain C */
#include <SDL3/SDL_main_impl.h>