diff --git a/src/common/EventHandlerSDL2.cxx b/src/common/EventHandlerSDL2.cxx index abec5b3da..5cb3dee58 100644 --- a/src/common/EventHandlerSDL2.cxx +++ b/src/common/EventHandlerSDL2.cxx @@ -36,12 +36,21 @@ void EventHandlerSDL2::initializeJoysticks() { #ifdef JOYSTICK_SUPPORT // Initialize the joystick subsystem - if((SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0) && (SDL_NumJoysticks() > 0)) + if(SDL_WasInit(SDL_INIT_JOYSTICK) != 0) { - int numSticks = SDL_NumJoysticks(); - for(int i = 0; i < numSticks; ++i) - addJoystick(new JoystickSDL2(i), i); + if(SDL_NumJoysticks() > 0) + { + int numSticks = SDL_NumJoysticks(); + for(int i = 0; i < numSticks; ++i) + addJoystick(new JoystickSDL2(i), i); + + myOSystem.logMessage("EventHandlerSDL2::initializeJoysticks() +sticks", 2); + } + else + myOSystem.logMessage("EventHandlerSDL2::initializeJoysticks() -sticks", 2); } + else + myOSystem.logMessage("EventHandlerSDL2::initializeJoysticks() failed!", 2); #endif } @@ -198,16 +207,16 @@ void EventHandlerSDL2::pollEvent() handleSystemEvent(EVENT_WINDOW_FOCUS_LOST); break; } - break; + break; // SDL_WINDOWEVENT } } } -#ifdef JOYSTICK_SUPPORT // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - EventHandlerSDL2::JoystickSDL2::JoystickSDL2(int idx) : myStick(NULL) { +#ifdef JOYSTICK_SUPPORT myStick = SDL_JoystickOpen(idx); if(myStick) { @@ -215,13 +224,15 @@ EventHandlerSDL2::JoystickSDL2::JoystickSDL2(int idx) SDL_JoystickNumAxes(myStick), SDL_JoystickNumButtons(myStick), SDL_JoystickNumHats(myStick), SDL_JoystickNumBalls(myStick)); } +#endif } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - EventHandlerSDL2::JoystickSDL2::~JoystickSDL2() { +#ifdef JOYSTICK_SUPPORT if(myStick) SDL_JoystickClose(myStick); myStick = NULL; -} #endif +} diff --git a/src/common/EventHandlerSDL2.hxx b/src/common/EventHandlerSDL2.hxx index 3670b3acc..a16ea4dc8 100644 --- a/src/common/EventHandlerSDL2.hxx +++ b/src/common/EventHandlerSDL2.hxx @@ -68,7 +68,6 @@ class EventHandlerSDL2 : public EventHandler private: SDL_Event myEvent; - #ifdef JOYSTICK_SUPPORT // A thin wrapper around a basic StellaJoystick, holding the pointer to // the underlying SDL stick. class JoystickSDL2 : public StellaJoystick @@ -80,7 +79,6 @@ class EventHandlerSDL2 : public EventHandler private: SDL_Joystick* myStick; }; - #endif }; #endif diff --git a/src/common/FrameBufferSDL2.cxx b/src/common/FrameBufferSDL2.cxx index 5130e7dd5..3b3779a84 100644 --- a/src/common/FrameBufferSDL2.cxx +++ b/src/common/FrameBufferSDL2.cxx @@ -42,13 +42,14 @@ FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem) myDblBufferedFlag(true) { // Initialize SDL2 context - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) < 0) { ostringstream buf; buf << "ERROR: Couldn't initialize SDL: " << SDL_GetError() << endl; myOSystem.logMessage(buf.str(), 0); return; } + myOSystem.logMessage("FrameBufferSDL2::FrameBufferSDL2 SDL_Init()", 2); // We need a pixel format for palette value calculations // It's done this way (vs directly accessing a FBSurfaceSDL2 object) diff --git a/src/emucore/MediaFactory.hxx b/src/emucore/MediaFactory.hxx index 9e7f429f6..f65027286 100644 --- a/src/emucore/MediaFactory.hxx +++ b/src/emucore/MediaFactory.hxx @@ -105,7 +105,6 @@ class MediaFactory { return new EventHandlerSDL2(osystem); } - }; #endif