1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-12-01 15:35:47 +00:00

Proper ~Joystick() dtor. Make haptics optional. Hopefully fixes #50.

This commit is contained in:
fgenesis 2017-06-25 15:56:45 +02:00
parent 1af3b0f220
commit 6f170de929
3 changed files with 18 additions and 2 deletions

View file

@ -712,7 +712,8 @@ void Core::init()
SDL_putenv((char *) "SDL_MOUSE_RELATIVE=0"); SDL_putenv((char *) "SDL_MOUSE_RELATIVE=0");
#endif #endif
if((SDL_Init(SDL_INIT_EVERYTHING))==-1) // Haptic is inited separately, in Jostick.cpp, when a joystick is actually plugged in
if((SDL_Init(SDL_INIT_EVERYTHING & ~SDL_INIT_HAPTIC))==-1)
{ {
std::string msg("Failed to init SDL: "); std::string msg("Failed to init SDL: ");
msg.append(SDL_GetError()); msg.append(SDL_GetError());
@ -2849,7 +2850,6 @@ void Core::onJoystickRemoved(int instanceID)
if(Joystick *j = joysticks[i]) if(Joystick *j = joysticks[i])
if(j->getInstanceID() == instanceID) if(j->getInstanceID() == instanceID)
{ {
j->shutdown();
delete j; delete j;
joysticks[i] = NULL; joysticks[i] = NULL;
} }

View file

@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Joystick.h" #include "Joystick.h"
#include "Core.h" #include "Core.h"
#include "SDL.h"
unsigned Joystick::GetNumJoysticks() unsigned Joystick::GetNumJoysticks()
{ {
@ -33,6 +34,9 @@ Joystick::Joystick()
# ifdef BBGE_BUILD_SDL2 # ifdef BBGE_BUILD_SDL2
sdl_controller = NULL; sdl_controller = NULL;
sdl_haptic = NULL; sdl_haptic = NULL;
if(!SDL_WasInit(SDL_INIT_HAPTIC))
if(SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0)
debugLog("Failed to init haptic subsystem");
# endif # endif
sdl_joy = NULL; sdl_joy = NULL;
buttonBitmask = 0; buttonBitmask = 0;
@ -51,6 +55,16 @@ Joystick::Joystick()
enabled = false; enabled = false;
} }
Joystick::~Joystick()
{
shutdown();
#ifdef BBGE_BUILD_SDL2
if(SDL_WasInit(SDL_INIT_HAPTIC))
SDL_QuitSubSystem(SDL_INIT_HAPTIC);
#endif
}
const char *Joystick::getName() const const char *Joystick::getName() const
{ {
return name.c_str(); return name.c_str();

View file

@ -22,6 +22,8 @@ public:
static unsigned GetNumJoysticks(); static unsigned GetNumJoysticks();
Joystick(); Joystick();
~Joystick();
bool init(int stick=0); bool init(int stick=0);
void shutdown(); void shutdown();
//Ranges from 0 to 1 (full speed). //Ranges from 0 to 1 (full speed).