mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-26 01:30:51 +00:00
(SDL*) Properly initialize SDL library/subsystems
This commit is contained in:
parent
e38c826fe1
commit
16e0d24e17
@ -60,7 +60,9 @@ static inline int find_num_frames(int rate, int latency)
|
||||
static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||
{
|
||||
(void)device;
|
||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
|
||||
if (SDL_WasInit(0) == 0 && SDL_Init(SDL_INIT_AUDIO) < 0)
|
||||
return NULL;
|
||||
else if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
|
||||
return NULL;
|
||||
|
||||
sdl_audio_t *sdl = (sdl_audio_t*)calloc(1, sizeof(*sdl));
|
||||
|
@ -385,7 +385,10 @@ static void *sdl2_gfx_init(const video_info_t *video, const input_driver_t **inp
|
||||
|
||||
int i;
|
||||
|
||||
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
||||
if (SDL_WasInit(0) == 0 && SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
return NULL;
|
||||
else if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
||||
return NULL;
|
||||
|
||||
sdl2_video_t *vid = (sdl2_video_t*)calloc(1, sizeof(*vid));
|
||||
if (!vid)
|
||||
|
@ -207,7 +207,10 @@ static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
XInitThreads();
|
||||
#endif
|
||||
|
||||
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
||||
if (SDL_WasInit(0) == 0 && SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
return NULL;
|
||||
else if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
||||
return NULL;
|
||||
|
||||
sdl_video_t *vid = (sdl_video_t*)calloc(1, sizeof(*vid));
|
||||
if (!vid)
|
||||
|
@ -34,7 +34,7 @@ typedef struct _sdl_joypad
|
||||
|
||||
static sdl_joypad_t g_pads[MAX_PLAYERS];
|
||||
#ifdef HAVE_SDL2
|
||||
static bool has_haptic;
|
||||
static bool g_has_haptic;
|
||||
#endif
|
||||
|
||||
static void sdl_joypad_connect(int id)
|
||||
@ -56,9 +56,9 @@ static void sdl_joypad_connect(int id)
|
||||
|
||||
|
||||
#ifdef HAVE_SDL2
|
||||
pad->haptic = has_haptic ? SDL_HapticOpenFromJoystick(pad->joypad) : NULL;
|
||||
pad->haptic = g_has_haptic ? SDL_HapticOpenFromJoystick(pad->joypad) : NULL;
|
||||
|
||||
if (has_haptic && !pad->haptic)
|
||||
if (g_has_haptic && !pad->haptic)
|
||||
RARCH_WARN("[SDL]: Couldn't open haptic device of the joypad #%u: %s\n",
|
||||
id, SDL_GetError());
|
||||
|
||||
@ -124,13 +124,23 @@ static void sdl_joypad_destroy(void)
|
||||
static bool sdl_joypad_init(void)
|
||||
{
|
||||
unsigned i;
|
||||
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
|
||||
if (SDL_WasInit(0) == 0 && SDL_Init(SDL_INIT_JOYSTICK) < 0)
|
||||
return false;
|
||||
else if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
|
||||
return false;
|
||||
|
||||
#if 0 // TODO: Add SDL_GameController support.
|
||||
if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0)
|
||||
RARCH_LOG("[SDL]: Failed to initialize game controller interface: %s\n",
|
||||
SDL_GetError());
|
||||
#if HAS_SDL2
|
||||
// TODO: Add SDL_GameController support.
|
||||
//if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0)
|
||||
// RARCH_LOG("[SDL]: Failed to initialize game controller interface: %s\n",
|
||||
// SDL_GetError());
|
||||
|
||||
g_has_haptic = false;
|
||||
if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0)
|
||||
RARCH_WARN("[SDL]: Failed to initialize haptic device support: %s\n",
|
||||
SDL_GetError());
|
||||
else
|
||||
g_has_haptic = true;
|
||||
#endif
|
||||
|
||||
unsigned num_sticks = SDL_NumJoysticks();
|
||||
@ -140,11 +150,24 @@ static bool sdl_joypad_init(void)
|
||||
for (i = 0; i < num_sticks; i++)
|
||||
sdl_joypad_connect(i);
|
||||
|
||||
#ifndef HAVE_SDL2
|
||||
/* quit if no joypad is detected. */
|
||||
num_sticks = 0;
|
||||
for (i = 0; i < MAX_PLAYERS; i++)
|
||||
if (g_pads[i].joypad)
|
||||
num_sticks++;
|
||||
|
||||
if (num_sticks == 0)
|
||||
goto error;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
|
||||
#ifndef HAVE_SDL2
|
||||
error:
|
||||
sdl_joypad_destroy();
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool sdl_joypad_button(unsigned port, uint16_t joykey)
|
||||
|
Loading…
Reference in New Issue
Block a user