citra/src/input_common/input_common.cpp

57 lines
1.2 KiB
C++

// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "input_common/input_common.h"
#ifdef HAS_SDL
#include "input_common/sdl_input/sdl_input.h"
#endif
namespace InputCommon {
// User input system
std::unique_ptr<InputBase> g_user_input;
const std::string& InputBase::GetDeviceName() const {
return device_name;
}
const Service::HID::PadState& InputBase::GetPadState() const {
return controller.pad_state;
}
void Init(InputBackends backend) {
switch (backend) {
#ifdef HAS_SDL
// SDL2 backend selected
case InputBackends::SDL2:
g_user_input.reset(new SDLController);
break;
#endif
// No backend selected
case InputBackends::NONE:
break;
// If no backend whatsoever inits, launch a critical log
default:
LOG_CRITICAL(Input, "Input backend initialization failed!");
break;
}
// Shutdown immediately if backend failed to initialize
if (!g_user_input && !g_user_input->activated) {
Shutdown();
return;
}
}
void Shutdown() {
if (g_user_input) g_user_input.release();
}
} // namespace