//Joystick bool ZL_InitJoystickSubSystem() { #ifndef ZL_USE_EXTERNAL_SDL return (SDL_JoystickInit() ? true : false); #else return (SDL_Init(SDL_INIT_JOYSTICK) ? true : false); #endif }
MediaWidget::JoystickIniter::JoystickIniter() { SDL_JoystickInit(); SDL_SetEventFilter(SDL_JOYAXISMOTION | SDL_JOYBUTTONCHANGE | SDL_JOYHATMOTION); for (int i = 0, n = SDL_NumJoysticks(); i < n; ++i) { if (SDL_Joystick *joy = SDL_JoystickOpen(i)) joysticks_.push_back(joy); } SDL_JoystickUpdate(); SDL_ClearEvents(); }
int SDL_InitSubSystem(Uint32 flags) { #if !SDL_VIDEO_DISABLED /* Initialize the video/event subsystem */ if ((flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO)) { if (SDL_VideoInit(NULL) < 0) { return (-1); } SDL_initialized |= SDL_INIT_VIDEO; } #else if (flags & SDL_INIT_VIDEO) { SDL_SetError("SDL not built with video support"); return (-1); } #endif #if !SDL_AUDIO_DISABLED /* Initialize the audio subsystem */ if ((flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO)) { if (SDL_AudioInit(NULL) < 0) { return (-1); } SDL_initialized |= SDL_INIT_AUDIO; } #else if (flags & SDL_INIT_AUDIO) { SDL_SetError("SDL not built with audio support"); return (-1); } #endif #if !SDL_TIMERS_DISABLED /* Initialize the timer subsystem */ if (!ticks_started) { SDL_StartTicks(); ticks_started = 1; } if ((flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER)) { if (SDL_TimerInit() < 0) { return (-1); } SDL_initialized |= SDL_INIT_TIMER; } #else if (flags & SDL_INIT_TIMER) { SDL_SetError("SDL not built with timer support"); return (-1); } #endif #if !SDL_JOYSTICK_DISABLED /* Initialize the joystick subsystem */ if ((flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK)) { if (SDL_JoystickInit() < 0) { return (-1); } SDL_initialized |= SDL_INIT_JOYSTICK; } #else if (flags & SDL_INIT_JOYSTICK) { SDL_SetError("SDL not built with joystick support"); return (-1); } #endif #if !SDL_HAPTIC_DISABLED /* Initialize the haptic subsystem */ if ((flags & SDL_INIT_HAPTIC) && !(SDL_initialized & SDL_INIT_HAPTIC)) { if (SDL_HapticInit() < 0) { return (-1); } SDL_initialized |= SDL_INIT_HAPTIC; } #else if (flags & SDL_INIT_HAPTIC) { SDL_SetError("SDL not built with haptic (force feedback) support"); return (-1); } #endif return (0); }
int SDL_InitSubSystem(Uint32 flags) { if (!SDL_MainIsReady) { SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?"); return -1; } /* Clear the error message */ SDL_ClearError(); if ((flags & SDL_INIT_GAMECONTROLLER)) { /* game controller implies joystick */ flags |= SDL_INIT_JOYSTICK; } if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) { /* video or joystick implies events */ flags |= SDL_INIT_EVENTS; } #if SDL_VIDEO_DRIVER_WINDOWS if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) { if (SDL_HelperWindowCreate() < 0) { return -1; } } #endif #if !SDL_TIMERS_DISABLED SDL_TicksInit(); #endif /* Initialize the event subsystem */ if ((flags & SDL_INIT_EVENTS)) { #if !SDL_EVENTS_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) { if (SDL_StartEventLoop() < 0) { return (-1); } SDL_QuitInit(); } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS); #else return SDL_SetError("SDL not built with events support"); #endif } /* Initialize the timer subsystem */ if ((flags & SDL_INIT_TIMER)){ #if !SDL_TIMERS_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) { if (SDL_TimerInit() < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER); #else return SDL_SetError("SDL not built with timer support"); #endif } /* Initialize the video subsystem */ if ((flags & SDL_INIT_VIDEO)){ #if !SDL_VIDEO_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) { if (SDL_VideoInit(NULL) < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO); #else return SDL_SetError("SDL not built with video support"); #endif } /* Initialize the audio subsystem */ if ((flags & SDL_INIT_AUDIO)){ #if !SDL_AUDIO_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) { if (SDL_AudioInit(NULL) < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO); #else return SDL_SetError("SDL not built with audio support"); #endif } /* Initialize the joystick subsystem */ if ((flags & SDL_INIT_JOYSTICK)){ #if !SDL_JOYSTICK_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) { if (SDL_JoystickInit() < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK); #else return SDL_SetError("SDL not built with joystick support"); #endif } if ((flags & SDL_INIT_GAMECONTROLLER)){ #if !SDL_JOYSTICK_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) { if (SDL_GameControllerInit() < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER); #else return SDL_SetError("SDL not built with joystick support"); #endif } /* Initialize the haptic subsystem */ if ((flags & SDL_INIT_HAPTIC)){ #if !SDL_HAPTIC_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) { if (SDL_HapticInit() < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC); #else return SDL_SetError("SDL not built with haptic (force feedback) support"); #endif } return (0); }
int SDL_InitSubSystem(Uint32 flags) { #ifndef DISABLE_VIDEO /* Initialize the video/event subsystem */ if ( (flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO) ) { if ( SDL_VideoInit(getenv("SDL_VIDEODRIVER"), (flags&SDL_INIT_EVENTTHREAD)) < 0 ) { return(-1); } SDL_initialized |= SDL_INIT_VIDEO; } #else if ( flags & SDL_INIT_VIDEO ) { SDL_SetError("SDL not built with video support"); return(-1); } #endif #ifndef DISABLE_AUDIO /* Initialize the audio subsystem */ if ( (flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO) ) { if ( SDL_AudioInit(getenv("SDL_AUDIODRIVER")) < 0 ) { return(-1); } SDL_initialized |= SDL_INIT_AUDIO; } #else if ( flags & SDL_INIT_AUDIO ) { SDL_SetError("SDL not built with audio support"); return(-1); } #endif #ifndef DISABLE_TIMERS /* Initialize the timer subsystem */ if ( ! ticks_started ) { SDL_StartTicks(); ticks_started = 1; } if ( (flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER) ) { if ( SDL_TimerInit() < 0 ) { return(-1); } SDL_initialized |= SDL_INIT_TIMER; } #else if ( flags & SDL_INIT_TIMER ) { SDL_SetError("SDL not built with timer support"); return(-1); } #endif #ifndef DISABLE_JOYSTICK /* Initialize the joystick subsystem */ if ( (flags & SDL_INIT_JOYSTICK) && !(SDL_initialized & SDL_INIT_JOYSTICK) ) { if ( SDL_JoystickInit() < 0 ) { return(-1); } SDL_initialized |= SDL_INIT_JOYSTICK; } #else if ( flags & SDL_INIT_JOYSTICK ) { SDL_SetError("SDL not built with joystick support"); return(-1); } #endif #ifndef DISABLE_CDROM /* Initialize the CD-ROM subsystem */ if ( (flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM) ) { if ( SDL_CDROMInit() < 0 ) { return(-1); } SDL_initialized |= SDL_INIT_CDROM; } #else if ( flags & SDL_INIT_CDROM ) { SDL_SetError("SDL not built with cdrom support"); return(-1); } #endif return(0); }
int SDL_InitSubSystem(Uint32 flags) { #if !SDL_TIMERS_DISABLED if (!ticks_started) { SDL_StartTicks(); ticks_started = 1; } #endif /* Initialize the timer subsystem */ if ((flags & SDL_INIT_TIMER) ){ #if !SDL_TIMERS_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) { if (SDL_TimerInit() < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER); #else SDL_SetError("SDL not built with timer support"); return (-1); #endif } /* Initialize the video/event subsystem */ if ((flags & SDL_INIT_VIDEO) ){ #if !SDL_VIDEO_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) { if (SDL_VideoInit(NULL) < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO); #else SDL_SetError("SDL not built with video support"); return (-1); #endif } /* Initialize the audio subsystem */ if ((flags & SDL_INIT_AUDIO) ){ #if !SDL_AUDIO_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) { if (SDL_AudioInit(NULL) < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO); #else SDL_SetError("SDL not built with audio support"); return (-1); #endif } if ((flags & SDL_INIT_GAMECONTROLLER)) { // Game controller implies Joystick. flags |= SDL_INIT_JOYSTICK; } /* Initialize the joystick subsystem */ if ((flags & SDL_INIT_JOYSTICK) ){ #if !SDL_JOYSTICK_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) { if (SDL_JoystickInit() < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK); #else SDL_SetError("SDL not built with joystick support"); return (-1); #endif } if ((flags & SDL_INIT_GAMECONTROLLER) ){ #if !SDL_JOYSTICK_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) { if (SDL_GameControllerInit() < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER); #else SDL_SetError("SDL not built with joystick support"); return (-1); #endif } /* Initialize the haptic subsystem */ if ((flags & SDL_INIT_HAPTIC) ){ #if !SDL_HAPTIC_DISABLED if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) { if (SDL_HapticInit() < 0) { return (-1); } } SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC); #else SDL_SetError("SDL not built with haptic (force feedback) support"); return (-1); #endif } return (0); }