mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
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:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user