Improve shutdown again
This commit is contained in:
parent
326e2f110d
commit
1703988f00
3 changed files with 15 additions and 11 deletions
|
@ -41,8 +41,7 @@ const Service::HID::PadState ControllerBase::GetPadState() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init(ControllerBackends backend) {
|
void Init(ControllerBackends backend) {
|
||||||
switch(backend)
|
switch(backend) {
|
||||||
{
|
|
||||||
//SDL2 backend selected
|
//SDL2 backend selected
|
||||||
case SDL2_JOY:
|
case SDL2_JOY:
|
||||||
g_user_input = new SDLController();
|
g_user_input = new SDLController();
|
||||||
|
@ -57,6 +56,12 @@ void Init(ControllerBackends backend) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Shutdown immediately if backend failed to initialize
|
||||||
|
if((g_user_input != nullptr) && (!g_user_input->activated)) {
|
||||||
|
ShutDown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Setup CoreTiming
|
//Setup CoreTiming
|
||||||
frame_ticks = 268123480 / Settings::values.gpu_refresh_rate / 16;
|
frame_ticks = 268123480 / Settings::values.gpu_refresh_rate / 16;
|
||||||
|
|
||||||
|
@ -65,9 +70,7 @@ void Init(ControllerBackends backend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutDown() {
|
void ShutDown() {
|
||||||
//Delete the current user input plugin
|
if((g_user_input != nullptr)
|
||||||
if(g_user_input != nullptr)
|
|
||||||
{
|
|
||||||
delete g_user_input;
|
delete g_user_input;
|
||||||
g_user_input = nullptr;
|
g_user_input = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ public:
|
||||||
///Returns internal pad state
|
///Returns internal pad state
|
||||||
const Service::HID::PadState GetPadState() const;
|
const Service::HID::PadState GetPadState() const;
|
||||||
|
|
||||||
|
bool activated;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///Internal name of currently selected device
|
///Internal name of currently selected device
|
||||||
std::string device_name;
|
std::string device_name;
|
||||||
|
|
|
@ -18,10 +18,7 @@ SDLController::SDLController() {
|
||||||
controller.touch_screen_x = 0;
|
controller.touch_screen_x = 0;
|
||||||
controller.touch_screen_y = 0;
|
controller.touch_screen_y = 0;
|
||||||
|
|
||||||
//Immediately shutdown if initialization fails
|
activated = Init();
|
||||||
if(!Init()) {
|
|
||||||
ShutDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDLController::~SDLController() {
|
SDLController::~SDLController() {
|
||||||
|
@ -43,6 +40,8 @@ bool SDLController::Init() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device_name = SDL_JoystickNameForIndex(index);
|
||||||
|
|
||||||
//If joystick successfully opened, load up keymap from input configuration
|
//If joystick successfully opened, load up keymap from input configuration
|
||||||
//TODO - Make it NOT hardcoded
|
//TODO - Make it NOT hardcoded
|
||||||
joypad_id = KeyMap::NewDeviceId();
|
joypad_id = KeyMap::NewDeviceId();
|
||||||
|
@ -50,6 +49,8 @@ bool SDLController::Init() {
|
||||||
|
|
||||||
//TODO - Make it NOT hardcoded
|
//TODO - Make it NOT hardcoded
|
||||||
SetDeadZone(8000);
|
SetDeadZone(8000);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLController::DiscoverDevices() {}
|
void SDLController::DiscoverDevices() {}
|
||||||
|
@ -59,8 +60,6 @@ void SDLController::ShutDown() {
|
||||||
if(jpad != nullptr) {
|
if(jpad != nullptr) {
|
||||||
SDL_JoystickClose(jpad);
|
SDL_JoystickClose(jpad);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputCommon::ShutDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLController::Poll() {
|
void SDLController::Poll() {
|
||||||
|
|
Loading…
Reference in a new issue