controller_sdl: init haptics separately in case it's not available

This commit is contained in:
fgsfds 2020-06-17 03:11:50 +03:00
parent 6686a2d7d9
commit 5abf1baf6a
1 changed files with 13 additions and 2 deletions

View File

@ -37,6 +37,7 @@ extern u8 newcam_mouse;
#endif
static bool init_ok;
static bool haptics_enabled;
static SDL_GameController *sdl_cntrl;
static SDL_Haptic *sdl_haptic;
@ -89,11 +90,13 @@ static void controller_sdl_bind(void) {
}
static void controller_sdl_init(void) {
if (SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_HAPTIC) != 0) {
if (SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS) != 0) {
fprintf(stderr, "SDL init error: %s\n", SDL_GetError());
return;
}
haptics_enabled = (SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0);
// try loading an external gamecontroller mapping file
uint64_t gcsize = 0;
void *gcdata = fs_load_file("gamecontrollerdb.txt", &gcsize);
@ -119,6 +122,8 @@ static void controller_sdl_init(void) {
}
static SDL_Haptic *controller_sdl_init_haptics(const int joy) {
if (!haptics_enabled) return NULL;
SDL_Haptic *hap = SDL_HapticOpen(joy);
if (!hap) return NULL;
@ -279,12 +284,18 @@ static void controller_sdl_shutdown(void) {
SDL_GameControllerClose(sdl_cntrl);
sdl_cntrl = NULL;
}
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
}
if (SDL_WasInit(SDL_INIT_HAPTIC)) {
if (sdl_haptic) {
SDL_HapticClose(sdl_haptic);
sdl_haptic = NULL;
}
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
SDL_QuitSubSystem(SDL_INIT_HAPTIC);
}
haptics_enabled = false;
init_ok = false;
}