Commit Graph

13814 Commits (23db9716814bfad469227a5d7069dc1898310d96)

Author SHA1 Message Date
SDL Wiki Bot 3ab6670cb1 Sync SDL3 wiki -> header 2023-11-04 05:36:15 +00:00
Sam Lantinga f439ccfc1a Updated return values for SDL event functions
SDL_PollEvent(), SDL_WaitEvent(), and SDL_WaitEventTimeout() all return SDL_bool.
SDL_AddEventWatch() returns an int result code.

Also improved timeout accuracy in SDL_WaitEventTimeout()
2023-11-03 22:31:42 -07:00
Sam Lantinga e0379c3b37 Grab events in large chunks in SDL_IterateMainCallbacks()
This is more efficient, especially since we're just going to discard them.
2023-11-03 21:47:44 -07:00
Sam Lantinga ad5264e54f Don't run SDL_IterateMainCallbacks() if the init call returns an exit code
This fixes a crash in testsprite if you pass invalid command line parameters.
2023-11-03 21:35:42 -07:00
Sam Lantinga dad1a84be4 Fixed building Vivante video driver 2023-11-03 14:56:15 -07:00
Sam Lantinga fe175d025f Fixed building Vivante video driver 2023-11-03 14:54:11 -07:00
Sam Lantinga 0b460f34ba The HP HyperX controllers have a share button 2023-11-03 14:47:20 -07:00
Sam Lantinga f3261fedcc Code cleanup now that SDL_bool is equivalent to a C boolean expression 2023-11-03 09:54:04 -07:00
Sam Lantinga a76d8e39aa Changed SDL_bool from an enum to unsigned int
Fixes https://github.com/libsdl-org/SDL/issues/7957
2023-11-03 09:54:04 -07:00
SDL Wiki Bot cf7e5bd0e8 Sync SDL3 wiki -> header 2023-11-03 15:41:14 +00:00
Ryan C. Gordon 853c28e624
docs: Added first draft of README-main-functions.md
Reference PR #8247.
2023-11-03 11:39:53 -04:00
Ryan C. Gordon 70d75b4a23
Sync wiki -> headers 2023-11-03 10:13:46 -04:00
Sam Lantinga ea02630143 More audio migration clarification 2023-11-03 00:28:05 -07:00
Sam Lantinga 14980b25a8 Clarify documentation for audio callback migration 2023-11-02 22:32:25 -07:00
Anonymous Maarten 6cf84e2c5b cmake: fold HAVE_INPUT_EVENTS into HAVE_LINUX_INPUT_H 2023-11-02 21:31:37 +01:00
Ozkan Sezer 5e869d1b35 fix Cocoa_Vulkan_GetInstanceExtensions prototype for Mac 2023-11-02 22:12:56 +03:00
Ryan C. Gordon 07a776f255
include: Fixed documentation for SDL_Vulkan_GetInstanceExtensions. 2023-11-02 15:12:24 -04:00
Ryan C. Gordon 5b3a2c6df6
docs: Updated SDL_Vulkan_GetInstanceExtensions info in README-migration.md.
Reference PR #8457.
2023-11-02 14:57:13 -04:00
ilyas-taouaou 9224a0a2d8 Fix emscripten, android, uikit and windows 2023-11-02 14:27:36 -04:00
ilyas-taouaou d0d8b28df1 Change SDL_Vulkan_GetInstanceExtensions 2023-11-02 14:27:36 -04:00
Ozkan Sezer 338974bb29 SDL_test_memory.c: fix build against older windows SDKs. 2023-11-02 21:00:02 +03:00
Sam Lantinga 618d15bce6 Fixed typo 2023-11-02 10:33:44 -07:00
Sam Lantinga ad0af48883 Check to make sure the Windows joystick device has buttons and axes
This reverts commit e5a15f94e2.

It turns out removing this check allows mice like the ROG PUGIO II to show up as game controllers. We need to find a different way to differentiate between gaming mice and pedals.

Since these mice show up as controllers, and potentially causing games to use them instead of real controllers, we'll go ahead revert this change for now.

Reopens https://github.com/libsdl-org/SDL/issues/8227
2023-11-02 08:33:15 -07:00
Ryan C. Gordon ac6b32bb02
gendynapi.py: Discard SDLMAIN_DECLSPEC functions.
Otherwise SDL_main and SDL_App* functions look like exported symbols instead
of functions the app is meant to implement.

Reference PR #8247.
2023-11-01 21:47:42 -04:00
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
Sam Lantinga 9323417e9c Fixed gendyapi.py parsing of SDL_RELEASE_GENERIC 2023-11-01 08:36:51 -07:00
Ryan C. Gordon 759cdf6159
audio: Fixed GetFirstAudioDeviceAdded().
It forgot to check for the type of device needed.
2023-11-01 00:39:51 -04:00
Ryan C. Gordon 0e614d9179
audio: Massive reworking on thread locking.
This cleans up a ton of race conditions, and starts moving towards something
we can use with Clang's -Wthread-safety (but that has a ways to go still).
2023-11-01 00:10:25 -04:00
Ryan C. Gordon 40fb76196c
audio: Don't let simplified audio streams bind to new devices.
This can happen if you close the stream's underlying device directly, which
removes the binding but doesn't destroy the object.

In this case, the stream remains valid until destroyed, but still should not
be able to be bound to a new device.
2023-10-31 10:52:50 -04:00
Ryan C. Gordon 24e3328cca
audio: Don't reset device ID counter on subsystem init/quit.
Otherwise you risk a buggy app holding an obsolete device ID that now refers
to a different device after reinit.
2023-10-31 10:50:37 -04:00
Anonymous Maarten 5d95cbde37 cmake: reset check state before testing -fobjc-arc 2023-10-30 21:14:39 +01:00
Anonymous Maarten f18120c83c cmake: check -fobjc-arc compiler flag on Apple platforms 2023-10-30 19:59:28 +01:00
Anonymous Maarten 4aacc4b92e cmake: file(RELATIVE_PATH) needs 2 absolute paths 2023-10-30 19:50:35 +01:00
Ryan C. Gordon dcc8805c21
testaudio: Fixed compiler warning on Visual Studio. 2023-10-30 13:09:56 -04:00
Ryan C. Gordon 9cb259e865
audio: Never SDL_PushEvent from anywhere but SDL_UpdateAudio().
Fixes some corner-case deadlocks.
2023-10-30 13:08:10 -04:00
Frank Praznik 875e45e70b wayland: Sanity check pointers and protocols before confining 2023-10-29 14:24:47 -04:00
Frank Praznik 0e87b71d08 wayland: Check the relative pointer handle before destroying
If the relative protocol is unsupported, this will always be null and the destroy function won't be called.
2023-10-29 14:15:23 -04:00
Anonymous Maarten 6127ac0871 Use SDL_DISABLE_ALLOCA instead of HAVE_ALLOCA in SDL_stdinc.h 2023-10-28 18:54:12 +02:00
Sam Lantinga 552bee47cb Clear any previous errors if we successfully show a message box 2023-10-27 10:11:23 -07:00
Sam Lantinga 343da852a6 Don't try to use the Wayland messagebox if we're not in Wayland
Also cleaned up some potential file handle leaks when querying the zenity version
2023-10-27 10:11:23 -07:00
Ryan C. Gordon f63e9a8a3f
wasapi: Handle disconnected devices that get reconnected.
The device ID strings don't change between connects, so we need to move the
old device object out of the way if it still exists as a zombie, and let
the reconnected device get itself a fresh object.
2023-10-27 01:30:27 -04:00
Ryan C. Gordon 5fa7b291d4
wasapi: Fixed memory leak if new audio devices fail to add. 2023-10-27 01:30:13 -04:00
Ryan C. Gordon 468c386686
wasapi: Handle disconnect notifications from the management thread, too.
These are also pretty heavyweight, don't do them from the notification
thread, which can deadlock everything.
2023-10-27 01:28:51 -04:00
Ryan C. Gordon ce3be02b48
wasapi: If device is marked as a zombie, don't try to resuscitate it. 2023-10-27 01:27:22 -04:00
Ryan C. Gordon 85923049a6
wasapi: Patched to compile. 2023-10-26 23:09:11 -04:00
Ryan C. Gordon 9bec57309c
wasapi: Proxy default device change handling to management thread.
This does a ton of work that can deadlock, because several crucial WASAPI
things that we want to do in response to this will block until the
notification callback has returned, so we can't call them from the handler
directly, or we'll be waiting until the thing that called us returns.
2023-10-26 23:03:27 -04:00
Ryan C. Gordon c45b5121ce
audio: Fixed potential race condition.
We need to check if the device is ready to close before releasing the lock,
in case other things are messing with the list of logical devices.
2023-10-26 23:03:27 -04:00
Sam Lantinga 8b6da3c701 Fixed making the EGL context current when resuming on Android
Make sure that we don't have the context cached as current on the current thread.
2023-10-26 17:07:40 -07:00
SDL Wiki Bot 2e9eb1073d Sync SDL3 wiki -> header 2023-10-26 18:23:13 +00:00
Ryan C. Gordon e6116d399a
mutex: Removed SDL_MUTEX_MAXWAIT.
Fixes #8436.
2023-10-26 14:21:53 -04:00