mirror of https://github.com/mgba-emu/mgba.git
SDL: Clean up initialization functions
This commit is contained in:
parent
d09d0e505f
commit
f8fd3ae2cc
1
CHANGES
1
CHANGES
|
@ -67,6 +67,7 @@ Misc:
|
||||||
- Qt: Add application icon and XDG desktop files
|
- Qt: Add application icon and XDG desktop files
|
||||||
- GBA Thread: Split GBASync into a separate file
|
- GBA Thread: Split GBASync into a separate file
|
||||||
- SDL: Properly check for initialization
|
- SDL: Properly check for initialization
|
||||||
|
- SDL: Clean up initialization functions
|
||||||
|
|
||||||
0.2.1: (2015-05-13)
|
0.2.1: (2015-05-13)
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
|
@ -18,7 +18,7 @@ static void _GBASDLAudioCallback(void* context, Uint8* data, int len);
|
||||||
|
|
||||||
bool GBASDLInitAudio(struct GBASDLAudio* context, struct GBAThread* threadContext) {
|
bool GBASDLInitAudio(struct GBASDLAudio* context, struct GBAThread* threadContext) {
|
||||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,19 +33,23 @@ static int32_t _GBASDLReadGyroZ(struct GBARotationSource* rumble);
|
||||||
static void _GBASDLRotationSample(struct GBARotationSource* source);
|
static void _GBASDLRotationSample(struct GBARotationSource* source);
|
||||||
|
|
||||||
bool GBASDLInitEvents(struct GBASDLEvents* context) {
|
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)
|
#if SDL_VERSION_ATLEAST(2, 0, 4)
|
||||||
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
|
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
|
||||||
#endif
|
#endif
|
||||||
if (SDL_InitSubSystem(subsystem) < 0) {
|
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {
|
||||||
return false;
|
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);
|
SDL_JoystickEventState(SDL_ENABLE);
|
||||||
int nJoysticks = SDL_NumJoysticks();
|
int nJoysticks = SDL_NumJoysticks();
|
||||||
if (nJoysticks > 0) {
|
if (nJoysticks > 0) {
|
||||||
|
@ -158,6 +162,10 @@ bool GBASDLAttachPlayer(struct GBASDLEvents* events, struct GBASDLPlayer* player
|
||||||
player->joystick = 0;
|
player->joystick = 0;
|
||||||
player->joystickIndex = SIZE_MAX;
|
player->joystickIndex = SIZE_MAX;
|
||||||
|
|
||||||
|
if (events->playersAttached >= MAX_PLAYERS) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
player->rumble.d.setRumble = _GBASDLSetRumble;
|
player->rumble.d.setRumble = _GBASDLSetRumble;
|
||||||
CircleBufferInit(&player->rumble.history, RUMBLE_PWM);
|
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);
|
CircleBufferInit(&player->rotation.zHistory, sizeof(float) * GYRO_STEPS);
|
||||||
player->rotation.p = player;
|
player->rotation.p = player;
|
||||||
|
|
||||||
if (events->playersAttached >= MAX_PLAYERS) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
player->playerId = events->playersAttached;
|
player->playerId = events->playersAttached;
|
||||||
size_t firstUnclaimed = SIZE_MAX;
|
size_t firstUnclaimed = SIZE_MAX;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue