Improve shutdown again

This commit is contained in:
Daniel Stuart Baxter 2015-05-30 15:21:27 -05:00
parent 326e2f110d
commit 1703988f00
3 changed files with 15 additions and 11 deletions

View File

@ -41,8 +41,7 @@ const Service::HID::PadState ControllerBase::GetPadState() const {
}
void Init(ControllerBackends backend) {
switch(backend)
{
switch(backend) {
//SDL2 backend selected
case SDL2_JOY:
g_user_input = new SDLController();
@ -57,6 +56,12 @@ void Init(ControllerBackends backend) {
break;
}
//Shutdown immediately if backend failed to initialize
if((g_user_input != nullptr) && (!g_user_input->activated)) {
ShutDown();
return;
}
//Setup CoreTiming
frame_ticks = 268123480 / Settings::values.gpu_refresh_rate / 16;
@ -65,9 +70,7 @@ void Init(ControllerBackends backend) {
}
void ShutDown() {
//Delete the current user input plugin
if(g_user_input != nullptr)
{
if((g_user_input != nullptr)
delete g_user_input;
g_user_input = nullptr;
}

View File

@ -38,6 +38,8 @@ public:
///Returns internal pad state
const Service::HID::PadState GetPadState() const;
bool activated;
protected:
///Internal name of currently selected device
std::string device_name;

View File

@ -18,10 +18,7 @@ SDLController::SDLController() {
controller.touch_screen_x = 0;
controller.touch_screen_y = 0;
//Immediately shutdown if initialization fails
if(!Init()) {
ShutDown();
}
activated = Init();
}
SDLController::~SDLController() {
@ -43,6 +40,8 @@ bool SDLController::Init() {
return false;
}
device_name = SDL_JoystickNameForIndex(index);
//If joystick successfully opened, load up keymap from input configuration
//TODO - Make it NOT hardcoded
joypad_id = KeyMap::NewDeviceId();
@ -50,6 +49,8 @@ bool SDLController::Init() {
//TODO - Make it NOT hardcoded
SetDeadZone(8000);
return true;
}
void SDLController::DiscoverDevices() {}
@ -59,8 +60,6 @@ void SDLController::ShutDown() {
if(jpad != nullptr) {
SDL_JoystickClose(jpad);
}
InputCommon::ShutDown();
}
void SDLController::Poll() {