Remove an assumption in SDL.

We can compile with haptic support, and then not initialize due to haptics not being available.
So if we are compiling with haptics, test initializing with haptics and if that fails attempt to initialize without haptics before bailing out.
This commit is contained in:
Ryan Houdek 2015-01-19 16:05:21 -06:00
parent 7376956c92
commit 817abdd579
2 changed files with 23 additions and 16 deletions

View File

@ -38,21 +38,31 @@ void Init( std::vector<Core::Device*>& devices )
// multiple joysticks with the same name shall get unique ids starting at 0 // multiple joysticks with the same name shall get unique ids starting at 0
std::map<std::string, int> name_counts; std::map<std::string, int> name_counts;
if (SDL_Init( SDL_INIT_FLAGS ) >= 0) #ifdef USE_SDL_HAPTIC
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) >= 0)
{ {
// joysticks // Correctly initialized
for (int i = 0; i < SDL_NumJoysticks(); ++i) }
else
#endif
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
{
// Failed to initialize
return;
}
// joysticks
for (int i = 0; i < SDL_NumJoysticks(); ++i)
{
SDL_Joystick* dev = SDL_JoystickOpen(i);
if (dev)
{ {
SDL_Joystick* dev = SDL_JoystickOpen(i); Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++);
if (dev) // only add if it has some inputs/outputs
{ if (js->Inputs().size() || js->Outputs().size())
Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++); devices.push_back( js );
// only add if it has some inputs/outputs else
if (js->Inputs().size() || js->Outputs().size()) delete js;
devices.push_back( js );
else
delete js;
}
} }
} }
} }

View File

@ -17,9 +17,6 @@
#ifdef USE_SDL_HAPTIC #ifdef USE_SDL_HAPTIC
#include <SDL_haptic.h> #include <SDL_haptic.h>
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC
#else
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK
#endif #endif
namespace ciface namespace ciface