Commit graph

183 commits

Author SHA1 Message Date
Sylvain Becker cb6b8b0132
Simplify flags testing (#7220) 2023-02-03 13:08:42 -08:00
Anonymous Maarten 4af93990a9 Remove disabled self test main functions 2023-02-01 20:13:34 +01:00
Sam Lantinga 2aa9569b3e Replaced SDL_SIMDAlloc(), SDL_SIMDRealloc(), and SDL_SIMDFree() with SDL_aligned_alloc() and SDL_aligned_free()
Fixes https://github.com/libsdl-org/SDL/issues/5641
2023-01-09 18:01:59 -08:00
Sam Lantinga fde78d12f2 Updated copyright for 2023 2023-01-09 09:41:41 -08:00
Sam Lantinga 38b138cd0a Fixed rounding of floating point values in snprintf 2023-01-03 06:35:25 -08:00
Sam Lantinga 7f23d71b6a Added SDL_modf() and SDL_modff()
This function is useful for accumulating relative mouse motion if you want to only handle whole pixel movement.
e.g.
static float dx_frac, dy_frac;
float dx, dy;

/* Accumulate new motion with previous sub-pixel motion */
dx = event.motion.xrel + dx_frac;
dy = event.motion.yrel + dy_frac;

/* Split the integral and fractional motion, dx and dy will contain whole pixel deltas */
dx_frac = SDL_modff(dx, &dx);
dy_frac = SDL_modff(dy, &dy);
if (dx != 0.0f || dy != 0.0f) {
    ...
}
2022-12-29 23:12:19 -08:00
Sam Lantinga ead4f122e4 Added basic support for %g snprintf format specifier 2022-12-29 23:12:19 -08:00
Sam Lantinga 36d4395c97 SDL API renaming: internal functions 2022-12-27 15:05:51 -08:00
Sylvain 25336d053a Remove underscore for _SDL_iconv_t
And change the name, not to have the same for pointer and data
2022-12-27 12:41:09 -08:00
Sam Lantinga 63724c113b Removed the vi format comments from the source
Vim users can use the [editorconfig plugin](https://github.com/editorconfig/editorconfig-vim) to automatically set tab spacing for the SDL coding style.

Fixes https://github.com/libsdl-org/SDL/issues/6903
2022-12-26 11:17:23 -08:00
Pierre Wendling 3c501b963d
Clang-Tidy fixes (#6725) 2022-12-01 13:07:03 -08:00
Ozkan Sezer 45025799b7 restore SDL_malloc.c original formatting. 2022-11-30 17:28:26 -08:00
Sam Lantinga 5750bcb174
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594
2022-11-30 12:51:59 -08:00
Sam Lantinga c5790359fd
Added precompiled header support for Visual Studio and Xcode (#6710)
Fixes https://github.com/libsdl-org/SDL/issues/6704
2022-11-29 18:34:15 -08:00
Sylvain Becker 6a2200823c
Cleanup add brace (#6545)
* Add braces after if conditions

* More add braces after if conditions

* Add braces after while() conditions

* Fix compilation because of macro being modified

* Add braces to for loop

* Add braces after if/goto

* Move comments up

* Remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements

* More remove extra () in the 'return ...;' statements after merge

* Fix inconsistent patterns are xxx == NULL vs !xxx

* More "{}" for "if() break;"  and "if() continue;"

* More "{}" after if() short statement

* More "{}" after "if () return;" statement

* More fix inconsistent patterns are xxx == NULL vs !xxx

* Revert some modificaion on SDL_RLEaccel.c

* SDL_RLEaccel: no short statement

* Cleanup 'if' where the bracket is in a new line

* Cleanup 'while' where the bracket is in a new line

* Cleanup 'for' where the bracket is in a new line

* Cleanup 'else' where the bracket is in a new line
2022-11-27 08:38:43 -08:00
Sam Lantinga 0a48abc860 Switch header convention from #include "SDL.h" to #include <SDL3/SDLh>
I ran this script in the include directory:
```sh
sed -i '' -e 's,#include "\(SDL.*\)",#include <SDL3/\1>,' *.h
```

I ran this script in the src directory:
```sh
for i in ../include/SDL3/SDL*.h
do hdr=$(basename $i)
   if [ x"$(echo $hdr | egrep 'SDL_main|SDL_name|SDL_test|SDL_syswm|SDL_opengl|SDL_egl|SDL_vulkan')" != x ]; then
        find . -type f -exec sed -i '' -e 's,#include "\('$hdr'\)",#include <SDL3/\1>,' {} \;
    else
        find . -type f -exec sed -i '' -e '/#include "'$hdr'"/d' {} \;
    fi
done
```

Fixes https://github.com/libsdl-org/SDL/issues/6575
2022-11-26 22:15:18 -08:00
Sam Lantinga ce9f3173cd Only use memset_pattern4() if we have string.h on Apple platforms 2022-11-26 05:25:57 -08:00
Sam Lantinga 63f307fe1f Remove SDL_config.h from the public headers
The SDL headers are no longer dependent on the build configuration.

Fixes https://github.com/libsdl-org/SDL/issues/6643 and https://github.com/libsdl-org/SDL/issues/6641
2022-11-26 04:48:36 -08:00
Ozkan Sezer 0b8309da0c renamed SDL PI constants to SDL_PI_D and SDL_PI_F. 2022-11-25 22:35:24 +03:00
Sam Lantinga 670f1df469 Removed SDL_stdinc.h dependency on HAVE_M_PI, added SDL_M_PIl (double) and SDL_M_PIf (float) instead 2022-11-25 10:33:37 -08:00
Sam Lantinga 2c4159b99a First pass at changing SDL 2.0 to SDL 3.0 2022-11-21 20:28:58 -08:00
Sylvain cd0d5a5fc5
Don't compare pointer against '0', but NULL 2022-11-17 11:23:15 +01:00
Sylvain ce5da5d579
Don't compare pointer against '0', but NULL 2022-11-16 21:47:43 +01:00
ulatekh ec58a817ef Fixes made in response to running a static code analyzer under MS Windows.
Most of these are probably harmless, but the changes to SDL_immdevice.c and SDL_pixels.c appear to have fixed genuine bugs.

SDL_audiocvt.c: By separating the calculation of the divisor, I got rid of the suspicion that dividing a double by an integer led to loss of precision.
SDL_immdevice.c: Added a missing test, one that could have otherwise led to dereferencing a null pointer.
SDL_events.c, SDL_gamecontroller.c, SDL_joystick.c, SDL_malloc.c, SDL_video.c: Made it clear the return values weren't used.
SDL_hidapi_shield.c: The size is zero, so nothing bad would have happened, but the SDL_memset() was still being given an address outside of the array's range.
SDL_dinputjoystick.c: Initialize local data, just in case IDirectInputDevice8_GetProperty() isn't guaranteed to write to it.
SDL_render_sw.c: drawstate.viewport could be null (as seen on line 691).
SDL.c: SDL_MostSignificantBitIndex32() could return -1, though I don't know if you want to cope with that (what I did) or SDL_assert() that it can't happen.
SDL_hints.c: Replaced boolean tests on pointer values with comparisons to NULL.
SDL_pixels.c: Looks like the switch is genuinely missing a break!
SDL_rect_impl.h: The MacOS static checker pointed out issues with the X comparisons that were handled by assertions; I added assertions for the Y comparisons.
SDL_yuv.c, SDL_windowskeyboard.c, SDL_windowswindow.c: Checked error-result returns.
2022-11-16 12:43:20 -05:00
Sam Lantinga 02ab7f3745 Fixed release build using clang on Windows 2022-11-15 12:57:07 -08:00
Sam Lantinga 297ecb706d Added SDL_strcasestr() for a case insensitive version of SDL_strstr() 2022-11-05 15:58:30 -07:00
Anonymous Maarten c3b13346e0 On x86, pass -nodefaultlib to linker when wanting to avoid the C library 2022-10-22 09:28:00 -07:00
Anonymous Maarten b51a88a95c SDL_malloc.c: fix variable 'used' set but not used
Emitted by clang-cl
2022-10-08 23:41:07 +02:00
Anonymous Maarten 5c150ddc2f SDL_mslibc.c: fix unknown pragma ignored [-Wunknown-pragmas]
Emitted by clang-cl
2022-10-08 23:41:07 +02:00
Sam Lantinga dc2a682a82 Use the right kind of 0 2022-09-20 09:22:43 -07:00
Sam Lantinga 2461930601 Fixed build on RISC OS 2022-09-20 09:16:10 -07:00
Ozkan Sezer 887ae0c6eb fix build failure after commit 2a8d00634d if strtod isn't available. 2022-09-20 18:20:00 +03:00
Sam Lantinga 2a8d00634d Fixed scanning a negative number as an unsigned value
e.g. sscanf("-1", "%zu", &v)

Thanks to @sezero for the test case
2022-09-20 07:25:49 -07:00
Ozkan Sezer 3f5c46663e SDL_vsscanf: fix an uninitialized warning 2022-09-20 11:56:40 +03:00
Sam Lantinga 216e3f10bb Implemented size_t format specifiers for SDL_snprintf() and SDL_sscanf()
Fixes https://github.com/libsdl-org/SDL/issues/6264
2022-09-19 15:42:11 -07:00
Ivan Epifanov 7115ceb775 Vita: restore sceClibMemcmp 2022-09-17 10:12:46 -07:00
Sam Lantinga 67cb3874ef Fixed potential uninitialized variable usage 2022-08-12 20:51:28 -07:00
Sam Lantinga 9f30d4981e Added note about CRC algorithm compatibility 2022-08-11 14:27:08 -07:00
Sam Lantinga b4c4dd84c2 Added SDL_crc16() to be used in joystick GUIDs after 2.24.0 2022-08-11 09:53:25 -07:00
Sam Lantinga 7f42fb54ad Applied DragonFly BSD patch
https://github.com/DragonFlyBSD/DeltaPorts/blob/master/ports/devel/sdl20/dragonfly/patch-src_stdlib_SDL__malloc.c
2022-07-30 16:34:40 -07:00
Anonymous Maarten 36dfbe5d66 stdlib: exclude mslibc functions using SDL_STATIC_LIB macro 2022-07-29 15:05:19 +02:00
Anonymous Maarten 5da85376b9 stdlib: move all mslibc functions to SDL_mslibc.c
This allows disabling LTO on them by only specifying a single file.
2022-07-27 09:07:56 -07:00
Dav999-v 51f75b8b30 Fix fallback implementations of SDL_strchr and SDL_strrchr for '\0'
strchr and strrchr return a pointer to the first/last occurrence of a
character in a string, or NULL if the character is not found. According
to the C standard, the final null terminator is part of the string, and
it should thus be possible to get a pointer to the final null with
these functions. The fallback implementations of SDL_strchr and
SDL_strrchr would always return NULL if trying to find '\0', and this
commit fixes that.
2022-07-04 11:10:26 -04:00
chalonverse f317d619cc
Xbox GDKX support (#5869)
* Xbox GDK support (14 squashed commits)

* Added basic keyboard testing

* Update readme

* Code review fixes

* Fixed issue where controller add/removal wasn't working (since the device notification events don't work on Xbox, have to use the joystick thread to poll XInput)
2022-07-01 13:59:14 -07:00
Sam Lantinga cbd0187475 Removed the limit on the size of the SDL error message
Also added SDL_GetOriginalMemoryFunctions()

Fixes https://github.com/libsdl-org/SDL/issues/5795
2022-06-27 16:59:50 -07:00
chalonverse 3b191580c3
Windows GDK Support (#5830)
* Added GDK

* Simplfied checks in SDL_config_wingdk.h

* Added testgdk sample

* Added GDK readme

* Fixed error in merge of SDL_windows.h

* Additional GDK fixes

* OpenWatcom should not export _SDL_GDKGetTaskQueue

* Formatting fixes

* Moved initialization code into SDL_GDKRunApp
2022-06-27 10:19:39 -07:00
Sam Lantinga 12f14bdbeb Fixed digit count in sscanf, e.g. "%1x" 2022-06-18 07:02:38 -07:00
Anonymous Maarten ae7446a959 stlib: Extract SDL_memcpy and SDL_memset to its own file respectively
This is done such that we can disable LTO for these 2 functions when
building with MSVC.

This is due to a limitation of Link Time Code Generation (LTCG).
Code generation might generate a new reference to memset after linking
has started. The LTCG must make assumptions about where memset is
defined which is normally the C runtime.
2022-06-15 14:17:35 -07:00
Guldoman 74bcc5a0a3 stdlib: Add SDL_utf8strnlen 2022-06-09 15:18:50 -07:00
Pierre Wendling 501a499180 Add clang-format on/off comments where necessary.
Comments were added in places where INDENT-ON/OFF comments are. Places
like stdlib's asm don't need it as clang-format doesn't try to indent it.
2022-05-19 01:31:29 -07:00