Skip to content

Commit

Permalink
Initialize joysticks and support loading gamecontrollerdb.txt; see #26
Browse files Browse the repository at this point in the history
  • Loading branch information
phoboslab committed Aug 21, 2023
1 parent 4c1e509 commit 5e0cd76
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/wipegame
/save.dat
.DS_STORE
gamecontrollerdb.txt
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/platform_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5e0cd76

Please sign in to comment.