Skip to content

Commit f7439a2

Browse files
authored
Merge branch 'main' into progress-bar
2 parents 18b727e + 18185e3 commit f7439a2

File tree

182 files changed

+21547
-17557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+21547
-17557
lines changed

VisualC-GDK/tests/testgdk/src/testgdk.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ static struct
5656
static SDL_AudioStream *stream;
5757

5858
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
59-
static void
60-
quit(int rc)
59+
static void quit(int rc)
6160
{
6261
SDL_free(sprites);
6362
SDL_DestroyAudioStream(stream);
@@ -80,8 +79,7 @@ static int fillerup(void)
8079
return 0;
8180
}
8281

83-
void
84-
UserLoggedIn(XUserHandle user)
82+
static void UserLoggedIn(XUserHandle user)
8583
{
8684
HRESULT hr;
8785
char gamertag[128];
@@ -96,8 +94,7 @@ UserLoggedIn(XUserHandle user)
9694
XUserCloseHandle(user);
9795
}
9896

99-
void
100-
AddUserUICallback(XAsyncBlock *asyncBlock)
97+
static void AddUserUICallback(XAsyncBlock *asyncBlock)
10198
{
10299
HRESULT hr;
103100
XUserHandle user = NULL;
@@ -123,8 +120,7 @@ AddUserUICallback(XAsyncBlock *asyncBlock)
123120
delete asyncBlock;
124121
}
125122

126-
void
127-
AddUserUI()
123+
static void AddUserUI()
128124
{
129125
HRESULT hr;
130126
XAsyncBlock *asyncBlock = new XAsyncBlock;
@@ -141,8 +137,7 @@ AddUserUI()
141137
}
142138
}
143139

144-
void
145-
AddUserSilentCallback(XAsyncBlock *asyncBlock)
140+
static void AddUserSilentCallback(XAsyncBlock *asyncBlock)
146141
{
147142
HRESULT hr;
148143
XUserHandle user = NULL;
@@ -168,8 +163,7 @@ AddUserSilentCallback(XAsyncBlock *asyncBlock)
168163
delete asyncBlock;
169164
}
170165

171-
void
172-
AddUserSilent()
166+
static void AddUserSilent()
173167
{
174168
HRESULT hr;
175169
XAsyncBlock *asyncBlock = new XAsyncBlock;
@@ -186,30 +180,27 @@ AddUserSilent()
186180
}
187181
}
188182

189-
int
190-
LoadSprite(const char *file)
183+
static bool LoadSprite(const char *file)
191184
{
192185
int i;
193186

194187
for (i = 0; i < state->num_windows; ++i) {
195188
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
196-
sprites[i] = LoadTexture(state->renderers[i], file, true, &sprite_w, &sprite_h);
189+
sprites[i] = LoadTexture(state->renderers[i], file, true);
197190
if (!sprites[i]) {
198-
return -1;
199-
}
200-
if (!SDL_SetTextureBlendMode(sprites[i], blendMode)) {
201-
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s", SDL_GetError());
202-
SDL_DestroyTexture(sprites[i]);
203-
return -1;
191+
return false;
204192
}
193+
sprite_w = sprites[i]->w;
194+
sprite_h = sprites[i]->h;
195+
196+
SDL_SetTextureBlendMode(sprites[i], blendMode);
205197
}
206198

207199
/* We're ready to roll. :) */
208-
return 0;
200+
return true;
209201
}
210202

211-
void
212-
DrawSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
203+
static void DrawSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
213204
{
214205
SDL_Rect viewport;
215206
SDL_FRect temp;
@@ -300,8 +291,7 @@ DrawSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
300291
SDL_RenderPresent(renderer);
301292
}
302293

303-
void
304-
loop()
294+
static void loop()
305295
{
306296
int i;
307297
SDL_Event event;
@@ -329,8 +319,7 @@ loop()
329319
fillerup();
330320
}
331321

332-
int
333-
main(int argc, char *argv[])
322+
int main(int argc, char *argv[])
334323
{
335324
int i;
336325
const char *icon = "icon.bmp";
@@ -413,7 +402,7 @@ main(int argc, char *argv[])
413402
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
414403
SDL_RenderClear(renderer);
415404
}
416-
if (LoadSprite(icon) < 0) {
405+
if (!LoadSprite(icon)) {
417406
quit(2);
418407
}
419408

docs/INTRO-mingw.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-ninja mingw-w64-ucrt-x
1616

1717
## Create the file CMakeLists.txt
1818
```cmake
19-
project(sdl_test C CXX)
2019
cmake_minimum_required(VERSION 3.26)
20+
project(hello C CXX)
2121
2222
find_package(SDL3 REQUIRED)
2323
24-
add_executable(sdl_test)
24+
add_executable(hello)
2525
26-
target_sources(sdl_test
26+
target_sources(hello
2727
PRIVATE
2828
hello.c
2929
)
3030
31-
target_link_libraries(sdl_test SDL3::SDL3)
31+
target_link_libraries(hello SDL3::SDL3)
3232
```
3333

3434
## Configure and Build:

examples/demo/01-snake/snake.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#define THREE_BITS 0x7U /* ~CHAR_MAX >> (CHAR_BIT - SNAKE_CELL_MAX_BITS) */
2222
#define SHIFT(x, y) (((x) + ((y) * SNAKE_GAME_WIDTH)) * SNAKE_CELL_MAX_BITS)
2323

24+
static SDL_Joystick *joystick = NULL;
25+
2426
typedef enum
2527
{
2628
SNAKE_CELL_NOTHING = 0U,
@@ -186,6 +188,8 @@ void snake_step(SnakeContext *ctx)
186188
case SNAKE_DIR_DOWN:
187189
++ctx->head_ypos;
188190
break;
191+
default:
192+
break;
189193
}
190194
wrap_around_(&ctx->head_xpos, SNAKE_GAME_WIDTH);
191195
wrap_around_(&ctx->head_ypos, SNAKE_GAME_HEIGHT);
@@ -238,6 +242,26 @@ static SDL_AppResult handle_key_event_(SnakeContext *ctx, SDL_Scancode key_code)
238242
return SDL_APP_CONTINUE;
239243
}
240244

245+
static SDL_AppResult handle_hat_event_(SnakeContext *ctx, Uint8 hat) {
246+
switch (hat) {
247+
case SDL_HAT_RIGHT:
248+
snake_redir(ctx, SNAKE_DIR_RIGHT);
249+
break;
250+
case SDL_HAT_UP:
251+
snake_redir(ctx, SNAKE_DIR_UP);
252+
break;
253+
case SDL_HAT_LEFT:
254+
snake_redir(ctx, SNAKE_DIR_LEFT);
255+
break;
256+
case SDL_HAT_DOWN:
257+
snake_redir(ctx, SNAKE_DIR_DOWN);
258+
break;
259+
default:
260+
break;
261+
}
262+
return SDL_APP_CONTINUE;
263+
}
264+
241265
SDL_AppResult SDL_AppIterate(void *appstate)
242266
{
243267
AppState *as = (AppState *)appstate;
@@ -305,7 +329,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
305329
}
306330
}
307331

308-
if (!SDL_Init(SDL_INIT_VIDEO)) {
332+
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK)) {
333+
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
309334
return SDL_APP_FAILURE;
310335
}
311336

@@ -333,14 +358,35 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
333358
switch (event->type) {
334359
case SDL_EVENT_QUIT:
335360
return SDL_APP_SUCCESS;
361+
case SDL_EVENT_JOYSTICK_ADDED:
362+
if (joystick == NULL) {
363+
joystick = SDL_OpenJoystick(event->jdevice.which);
364+
if (!joystick) {
365+
SDL_Log("Failed to open joystick ID %u: %s", (unsigned int) event->jdevice.which, SDL_GetError());
366+
}
367+
}
368+
break;
369+
case SDL_EVENT_JOYSTICK_REMOVED:
370+
if (joystick && (SDL_GetJoystickID(joystick) == event->jdevice.which)) {
371+
SDL_CloseJoystick(joystick);
372+
joystick = NULL;
373+
}
374+
break;
375+
case SDL_EVENT_JOYSTICK_HAT_MOTION:
376+
return handle_hat_event_(ctx, event->jhat.value);
336377
case SDL_EVENT_KEY_DOWN:
337378
return handle_key_event_(ctx, event->key.scancode);
379+
default:
380+
break;
338381
}
339382
return SDL_APP_CONTINUE;
340383
}
341384

342385
void SDL_AppQuit(void *appstate, SDL_AppResult result)
343386
{
387+
if (joystick) {
388+
SDL_CloseJoystick(joystick);
389+
}
344390
if (appstate != NULL) {
345391
AppState *as = (AppState *)appstate;
346392
SDL_DestroyRenderer(as->renderer);

include/SDL3/SDL_gpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4151,7 +4151,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GPUTextureSupportsFormat(
41514151
* \param device a GPU context.
41524152
* \param format the texture format to check.
41534153
* \param sample_count the sample count to check.
4154-
* \returns a hardware-specific version of min(preferred, possible).
4154+
* \returns whether the sample count is supported for this texture format.
41554155
*
41564156
* \since This function is available since SDL 3.2.0.
41574157
*/

include/SDL3/SDL_hints.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,6 @@ extern "C" {
711711
*
712712
* This hint only applies to the emscripten platform.
713713
*
714-
* The default value is "#canvas"
715-
*
716714
* This hint should be set before creating a window.
717715
*
718716
* \since This hint is available since SDL 3.2.0.
@@ -726,7 +724,7 @@ extern "C" {
726724
*
727725
* The variable can be one of:
728726
*
729-
* - "#window": the javascript window object (default)
727+
* - "#window": the javascript window object
730728
* - "#document": the javascript document object
731729
* - "#screen": the javascript window.screen object
732730
* - "#canvas": the WebGL canvas element
@@ -3407,6 +3405,26 @@ extern "C" {
34073405
*/
34083406
#define SDL_HINT_VIDEO_MAC_FULLSCREEN_MENU_VISIBILITY "SDL_VIDEO_MAC_FULLSCREEN_MENU_VISIBILITY"
34093407

3408+
/**
3409+
* A variable controlling whether SDL will attempt to automatically set the
3410+
* destination display to a mode most closely matching that of the previous
3411+
* display if an exclusive fullscreen window is moved onto it.
3412+
*
3413+
* The variable can be set to the following values:
3414+
*
3415+
* - "0": SDL will not attempt to automatically set a matching mode on the
3416+
* destination display. If an exclusive fullscreen window is moved to a new
3417+
* display, the window will become fullscreen desktop.
3418+
* - "1": SDL will attempt to automatically set a mode on the destination
3419+
* display that most closely matches the mode of the display that the
3420+
* exclusive fullscreen window was previously on. (default)
3421+
*
3422+
* This hint can be set anytime.
3423+
*
3424+
* \since This hint is available since SDL 3.4.0.
3425+
*/
3426+
#define SDL_HINT_VIDEO_MATCH_EXCLUSIVE_MODE_ON_MOVE "SDL_VIDEO_MATCH_EXCLUSIVE_MODE_ON_MOVE"
3427+
34103428
/**
34113429
* A variable controlling whether fullscreen windows are minimized when they
34123430
* lose focus.

include/SDL3/SDL_joystick.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ typedef Uint32 SDL_JoystickID;
107107
* This is by no means a complete list of everything that can be plugged into
108108
* a computer.
109109
*
110+
* You may refer to
111+
* [XInput Controller Types](https://learn.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes)
112+
* table for a general understanding of each joystick type.
113+
*
110114
* \since This enum is available since SDL 3.2.0.
111115
*/
112116
typedef enum SDL_JoystickType

include/SDL3/SDL_main.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppInit(void **appstate, int a
347347
* Apps implement this function when using SDL_MAIN_USE_CALLBACKS. If using a
348348
* standard "main" function, you should not supply this.
349349
*
350-
* This function is called repeatedly by SDL after SDL_AppInit returns 0. The
351-
* function should operate as a single iteration the program's primary loop;
352-
* it should update whatever state it needs and draw a new frame of video,
353-
* usually.
350+
* This function is called repeatedly by SDL after SDL_AppInit returns
351+
* SDL_APP_CONTINUE. The function should operate as a single iteration the
352+
* program's primary loop; it should update whatever state it needs and draw a
353+
* new frame of video, usually.
354354
*
355355
* On some platforms, this function will be called at the refresh rate of the
356356
* display (which might change during the life of your app!). There are no

include/SDL3/SDL_mutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ typedef enum SDL_InitStatus
942942
* Here is an example of using this:
943943
*
944944
* ```c
945-
* static SDL_AtomicInitState init;
945+
* static SDL_InitState init;
946946
*
947947
* bool InitSystem(void)
948948
* {

0 commit comments

Comments
 (0)