Add love.joystick.reload, remove love.joystick.open and friends. (issue #392)

Reload originates from love-experiments, as noted in the ticket.
This commit is contained in:
Bart van Strien
2012-05-18 19:42:46 +02:00
parent fb6ffded14
commit 8211b8f93f
4 changed files with 40 additions and 28 deletions
+24 -1
View File
@@ -34,7 +34,7 @@ namespace sdl
{
// Init the SDL joystick system.
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
throw Exception(SDL_GetError());
throw love::Exception("%s", SDL_GetError());
// Start joystick event watching.
SDL_JoystickEventState(SDL_ENABLE);
@@ -61,6 +61,29 @@ namespace sdl
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
}
void Joystick::reload()
{
// Closes any open joysticks.
for (int i = 0; i != getNumJoysticks(); i++)
{
if (isOpen(i))
close(i);
}
free(joysticks);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
throw love::Exception("%s", SDL_GetError());
int numjoysticks = this->getNumJoysticks();
this->joysticks = (SDL_Joystick **)calloc(numjoysticks, sizeof(SDL_Joystick*));
for (int i = 0;i<numjoysticks;i++)
this->open(i);
}
const char * Joystick::getName() const
{
return "love.joystick.sdl";