Cleanup of SDL_PrivateShouldInitSubsystem.

Also fixes a build error if a module was disabled.
This commit is contained in:
Jørgen P. Tjernø 2013-02-25 16:52:54 -08:00
parent 05631f0599
commit e02925eca9

View file

@ -68,14 +68,9 @@ SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
/* Private helper to check if a system needs init. */ /* Private helper to check if a system needs init. */
static SDL_bool static SDL_bool
SDL_PrivateShouldInitSubsystem(Uint32 flags, Uint32 subsystem) SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
{ {
int subsystem_index; int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
if ((flags & subsystem) == 0) {
return SDL_FALSE;
}
subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255); SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
return (SDL_SubsystemRefCount[subsystem_index] == 0); return (SDL_SubsystemRefCount[subsystem_index] == 0);
} }
@ -106,8 +101,8 @@ SDL_InitSubSystem(Uint32 flags)
/* Initialize the timer subsystem */ /* Initialize the timer subsystem */
if ((flags & SDL_INIT_TIMER) ){ if ((flags & SDL_INIT_TIMER) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_TIMER)) {
#if !SDL_TIMERS_DISABLED #if !SDL_TIMERS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) { if (SDL_TimerInit() < 0) {
return (-1); return (-1);
} }
@ -121,8 +116,8 @@ SDL_InitSubSystem(Uint32 flags)
/* Initialize the video/event subsystem */ /* Initialize the video/event subsystem */
if ((flags & SDL_INIT_VIDEO) ){ if ((flags & SDL_INIT_VIDEO) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_VIDEO)) {
#if !SDL_VIDEO_DISABLED #if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL) < 0) { if (SDL_VideoInit(NULL) < 0) {
return (-1); return (-1);
} }
@ -136,8 +131,8 @@ SDL_InitSubSystem(Uint32 flags)
/* Initialize the audio subsystem */ /* Initialize the audio subsystem */
if ((flags & SDL_INIT_AUDIO) ){ if ((flags & SDL_INIT_AUDIO) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_AUDIO)) {
#if !SDL_AUDIO_DISABLED #if !SDL_AUDIO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
if (SDL_AudioInit(NULL) < 0) { if (SDL_AudioInit(NULL) < 0) {
return (-1); return (-1);
} }
@ -156,8 +151,8 @@ SDL_InitSubSystem(Uint32 flags)
/* Initialize the joystick subsystem */ /* Initialize the joystick subsystem */
if ((flags & SDL_INIT_JOYSTICK) ){ if ((flags & SDL_INIT_JOYSTICK) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_JOYSTICK)) {
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) { if (SDL_JoystickInit() < 0) {
return (-1); return (-1);
} }
@ -170,8 +165,8 @@ SDL_InitSubSystem(Uint32 flags)
} }
if ((flags & SDL_INIT_GAMECONTROLLER) ){ if ((flags & SDL_INIT_GAMECONTROLLER) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_GAMECONTROLLER)) {
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
if (SDL_GameControllerInit() < 0) { if (SDL_GameControllerInit() < 0) {
return (-1); return (-1);
} }
@ -185,11 +180,11 @@ SDL_InitSubSystem(Uint32 flags)
/* Initialize the haptic subsystem */ /* Initialize the haptic subsystem */
if ((flags & SDL_INIT_HAPTIC) ){ if ((flags & SDL_INIT_HAPTIC) ){
if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_HAPTIC)) {
#if !SDL_HAPTIC_DISABLED #if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) { if (SDL_HapticInit() < 0) {
return (-1); return (-1);
} }
} }
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC); SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
#else #else
@ -441,4 +436,4 @@ _DllMainCRTStartup(HANDLE hModule,
#endif /* __WIN32__ */ #endif /* __WIN32__ */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set sts=4 ts=4 sw=4 expandtab: */