add basic gamepad support

This commit is contained in:
Sigrid Solveig Haflínudóttir 2021-12-27 15:25:33 +01:00
parent 8e04040958
commit f6e48c482c
1 changed files with 10 additions and 2 deletions

View File

@ -145,8 +145,15 @@ init(void)
as.callback = audio_callback;
as.samples = 512;
as.userdata = NULL;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
return error("sdl", SDL_GetError());
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) {
error("sdl", SDL_GetError());
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
return error("sdl", SDL_GetError());
} else {
audio_id = SDL_OpenAudioDevice(NULL, 0, &as, NULL, 0);
if(!audio_id)
error("sdl_audio", SDL_GetError());
}
gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (WIDTH + PAD * 2) * zoom, (HEIGHT + PAD * 2) * zoom, SDL_WINDOW_SHOWN);
if(gWindow == NULL)
return error("sdl_window", SDL_GetError());
@ -164,6 +171,7 @@ init(void)
SDL_StartTextInput();
SDL_ShowCursor(SDL_DISABLE);
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
SDL_GameControllerEventState(SDL_ENABLE);
return 1;
}