mirror of https://github.com/sm64pc/sm64pc.git
controller_sdl: init haptics separately in case it's not available
This commit is contained in:
parent
6686a2d7d9
commit
5abf1baf6a
|
@ -37,6 +37,7 @@ extern u8 newcam_mouse;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool init_ok;
|
static bool init_ok;
|
||||||
|
static bool haptics_enabled;
|
||||||
static SDL_GameController *sdl_cntrl;
|
static SDL_GameController *sdl_cntrl;
|
||||||
static SDL_Haptic *sdl_haptic;
|
static SDL_Haptic *sdl_haptic;
|
||||||
|
|
||||||
|
@ -89,11 +90,13 @@ static void controller_sdl_bind(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void controller_sdl_init(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());
|
fprintf(stderr, "SDL init error: %s\n", SDL_GetError());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
haptics_enabled = (SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0);
|
||||||
|
|
||||||
// try loading an external gamecontroller mapping file
|
// try loading an external gamecontroller mapping file
|
||||||
uint64_t gcsize = 0;
|
uint64_t gcsize = 0;
|
||||||
void *gcdata = fs_load_file("gamecontrollerdb.txt", &gcsize);
|
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) {
|
static SDL_Haptic *controller_sdl_init_haptics(const int joy) {
|
||||||
|
if (!haptics_enabled) return NULL;
|
||||||
|
|
||||||
SDL_Haptic *hap = SDL_HapticOpen(joy);
|
SDL_Haptic *hap = SDL_HapticOpen(joy);
|
||||||
if (!hap) return NULL;
|
if (!hap) return NULL;
|
||||||
|
|
||||||
|
@ -279,12 +284,18 @@ static void controller_sdl_shutdown(void) {
|
||||||
SDL_GameControllerClose(sdl_cntrl);
|
SDL_GameControllerClose(sdl_cntrl);
|
||||||
sdl_cntrl = NULL;
|
sdl_cntrl = NULL;
|
||||||
}
|
}
|
||||||
|
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDL_WasInit(SDL_INIT_HAPTIC)) {
|
||||||
if (sdl_haptic) {
|
if (sdl_haptic) {
|
||||||
SDL_HapticClose(sdl_haptic);
|
SDL_HapticClose(sdl_haptic);
|
||||||
sdl_haptic = NULL;
|
sdl_haptic = NULL;
|
||||||
}
|
}
|
||||||
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
SDL_QuitSubSystem(SDL_INIT_HAPTIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
haptics_enabled = false;
|
||||||
init_ok = false;
|
init_ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue