SDL: Clean up initialization functions

This commit is contained in:
Jeffrey Pfau 2015-06-12 00:54:16 -07:00
parent d09d0e505f
commit f8fd3ae2cc
3 changed files with 18 additions and 13 deletions

View File

@ -67,6 +67,7 @@ Misc:
- Qt: Add application icon and XDG desktop files
- GBA Thread: Split GBASync into a separate file
- SDL: Properly check for initialization
- SDL: Clean up initialization functions
0.2.1: (2015-05-13)
Bugfixes:

View File

@ -18,7 +18,7 @@ static void _GBASDLAudioCallback(void* context, Uint8* data, int len);
bool GBASDLInitAudio(struct GBASDLAudio* context, struct GBAThread* threadContext) {
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
GBALog(0, GBA_LOG_ERROR, "Could not initialize SDL sound system");
GBALog(0, GBA_LOG_ERROR, "Could not initialize SDL sound system: %s", SDL_GetError());
return false;
}

View File

@ -33,19 +33,23 @@ static int32_t _GBASDLReadGyroZ(struct GBARotationSource* rumble);
static void _GBASDLRotationSample(struct GBARotationSource* source);
bool GBASDLInitEvents(struct GBASDLEvents* context) {
int subsystem = SDL_INIT_JOYSTICK;
#if SDL_VERSION_ATLEAST(2, 0, 0)
subsystem |= SDL_INIT_HAPTIC | SDL_INIT_VIDEO;
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
#endif
#if SDL_VERSION_ATLEAST(2, 0, 4)
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
#endif
if (SDL_InitSubSystem(subsystem) < 0) {
return false;
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {
GBALog(0, GBA_LOG_ERROR, "SDL joystick initialization failed: %s", SDL_GetError());
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) {
GBALog(0, GBA_LOG_ERROR, "SDL haptic initialization failed: %s", SDL_GetError());
}
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
GBALog(0, GBA_LOG_ERROR, "SDL video initialization failed: %s", SDL_GetError());
}
#endif
SDL_JoystickEventState(SDL_ENABLE);
int nJoysticks = SDL_NumJoysticks();
if (nJoysticks > 0) {
@ -158,6 +162,10 @@ bool GBASDLAttachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player
player->joystick = 0;
player->joystickIndex = SIZE_MAX;
if (events->playersAttached >= MAX_PLAYERS) {
return false;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
player->rumble.d.setRumble = _GBASDLSetRumble;
CircleBufferInit(&player->rumble.history, RUMBLE_PWM);
@ -178,10 +186,6 @@ bool GBASDLAttachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player
CircleBufferInit(&player->rotation.zHistory, sizeof(float) * GYRO_STEPS);
player->rotation.p = player;
if (events->playersAttached >= MAX_PLAYERS) {
return false;
}
player->playerId = events->playersAttached;
size_t firstUnclaimed = SIZE_MAX;