From 5e0cd7694806e4a2c8f68d0385f8480d321ab8f2 Mon Sep 17 00:00:00 2001 From: Dominic Szablewski Date: Mon, 21 Aug 2023 13:07:39 +0200 Subject: [PATCH] Initialize joysticks and support loading gamecontrollerdb.txt; see #26 --- .gitignore | 1 + README.md | 2 ++ src/platform_sdl.c | 10 +++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b36a8e5..245a9a4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /wipegame /save.dat .DS_STORE +gamecontrollerdb.txt diff --git a/README.md b/README.md index 16953d5..45295db 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,8 @@ The directory structure is assumed to be as follows Note that the blog post announcing this project may or may not provide a link to a ZIP containing all files needed. Who knows! +Optionally, if you want to use a game controller that may not be supported by SDL directly, you can place the [gamecontrollerdb.txt](https://github.com/gabomdq/SDL_GameControllerDB) in the root directory of this project (along the compiled `wipegame`). + ## Ideas for improvements diff --git a/src/platform_sdl.c b/src/platform_sdl.c index 5750c05..4d45c46 100755 --- a/src/platform_sdl.c +++ b/src/platform_sdl.c @@ -302,7 +302,15 @@ void platform_set_audio_mix_cb(void (*cb)(float *buffer, uint32_t len)) { int main(int argc, char *argv[]) { - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMECONTROLLER); + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); + + int gcdb_res = SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt"); + if (gcdb_res < 0) { + printf("Failed to load gamecontrollerdb.txt\n"); + } + else { + printf("load gamecontrollerdb.txt\n"); + } audio_device = SDL_OpenAudioDevice(NULL, 0, &(SDL_AudioSpec){ .freq = 44100,