mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-12 12:58:34 +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)
|
static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||||
{
|
{
|
||||||
(void)device;
|
(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;
|
return NULL;
|
||||||
|
|
||||||
sdl_audio_t *sdl = (sdl_audio_t*)calloc(1, sizeof(*sdl));
|
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;
|
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));
|
sdl2_video_t *vid = (sdl2_video_t*)calloc(1, sizeof(*vid));
|
||||||
if (!vid)
|
if (!vid)
|
||||||
|
@ -207,7 +207,10 @@ static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
|||||||
XInitThreads();
|
XInitThreads();
|
||||||
#endif
|
#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));
|
sdl_video_t *vid = (sdl_video_t*)calloc(1, sizeof(*vid));
|
||||||
if (!vid)
|
if (!vid)
|
||||||
|
@ -34,7 +34,7 @@ typedef struct _sdl_joypad
|
|||||||
|
|
||||||
static sdl_joypad_t g_pads[MAX_PLAYERS];
|
static sdl_joypad_t g_pads[MAX_PLAYERS];
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
static bool has_haptic;
|
static bool g_has_haptic;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void sdl_joypad_connect(int id)
|
static void sdl_joypad_connect(int id)
|
||||||
@ -56,9 +56,9 @@ static void sdl_joypad_connect(int id)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_SDL2
|
#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",
|
RARCH_WARN("[SDL]: Couldn't open haptic device of the joypad #%u: %s\n",
|
||||||
id, SDL_GetError());
|
id, SDL_GetError());
|
||||||
|
|
||||||
@ -124,13 +124,23 @@ static void sdl_joypad_destroy(void)
|
|||||||
static bool sdl_joypad_init(void)
|
static bool sdl_joypad_init(void)
|
||||||
{
|
{
|
||||||
unsigned i;
|
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;
|
return false;
|
||||||
|
|
||||||
#if 0 // TODO: Add SDL_GameController support.
|
#if HAS_SDL2
|
||||||
if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0)
|
// TODO: Add SDL_GameController support.
|
||||||
RARCH_LOG("[SDL]: Failed to initialize game controller interface: %s\n",
|
//if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0)
|
||||||
SDL_GetError());
|
// 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
|
#endif
|
||||||
|
|
||||||
unsigned num_sticks = SDL_NumJoysticks();
|
unsigned num_sticks = SDL_NumJoysticks();
|
||||||
@ -140,11 +150,24 @@ static bool sdl_joypad_init(void)
|
|||||||
for (i = 0; i < num_sticks; i++)
|
for (i = 0; i < num_sticks; i++)
|
||||||
sdl_joypad_connect(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;
|
return true;
|
||||||
|
|
||||||
|
#ifndef HAVE_SDL2
|
||||||
error:
|
error:
|
||||||
sdl_joypad_destroy();
|
sdl_joypad_destroy();
|
||||||
return false;
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sdl_joypad_button(unsigned port, uint16_t joykey)
|
static bool sdl_joypad_button(unsigned port, uint16_t joykey)
|
||||||
|
Loading…
Reference in New Issue
Block a user