Review Changes 14 - Make backend choice a config setting, comments, cleanup

This commit is contained in:
Daniel Stuart Baxter 2015-06-02 11:27:25 -05:00
parent 892c46fb37
commit 170d511d36
10 changed files with 41 additions and 20 deletions

View file

@ -82,6 +82,9 @@ void Config::ReadValues() {
// System Region
Settings::values.region_value = glfw_config->GetInteger("System Region", "region_value", 1);
// Input Backend
Settings::values.input_backend = glfw_config->GetInteger("Input Backend", "input_backend", 0);
// Miscellaneous
Settings::values.log_filter = glfw_config->Get("Miscellaneous", "log_filter", "*:Info");
}

View file

@ -62,6 +62,11 @@ use_virtual_sd =
# 0: Japan, 1: USA (default), 2: Europe, 3: Australia, 4: China, 5: Korea, 6: Taiwan
region_value =
[Input Backend]
# Input system Citra will use during emulation
# 0: Keyboard (default), 1: SDL2 (gamepad)
input_backend =
[Miscellaneous]
# A filter which removes logs below a certain logging level.
# Examples: *:Debug Kernel.SVC:Trace Service.*:Critical

View file

@ -127,7 +127,7 @@ void EmuWindow_GLFW::SwapBuffers() {
/// Polls window events
void EmuWindow_GLFW::PollEvents() {
glfwPollEvents();
InputCommon::g_user_input->Poll();
if(InputCommon::g_user_input) InputCommon::g_user_input->Poll();
}
/// Makes the GLFW OpenGL context current for the caller thread

View file

@ -161,7 +161,7 @@ void GRenderWindow::DoneCurrent()
}
void GRenderWindow::PollEvents() {
InputCommon::g_user_input->Poll();
if(InputCommon::g_user_input) InputCommon::g_user_input->Poll();
}
// On Qt 5.0+, this correctly gets the size of the framebuffer (pixels).

View file

@ -69,6 +69,10 @@ void Config::ReadValues() {
Settings::values.region_value = qt_config->value("region_value", 1).toInt();
qt_config->endGroup();
qt_config->beginGroup("Input Backend");
Settings::values.input_backend = qt_config->value("input_backend", 0).toInt();
qt_config->endGroup();
qt_config->beginGroup("Miscellaneous");
Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString();
qt_config->endGroup();
@ -123,6 +127,10 @@ void Config::SaveValues() {
qt_config->setValue("region_value", Settings::values.region_value);
qt_config->endGroup();
qt_config->beginGroup("Input Backend");
qt_config->setValue("input_backend", Settings::values.input_backend);
qt_config->endGroup();
qt_config->beginGroup("Miscellaneous");
qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter));
qt_config->endGroup();

View file

@ -51,6 +51,9 @@ struct Values {
float bg_green;
float bg_blue;
// Input backend
int input_backend;
std::string log_filter;
} extern values;

View file

@ -24,7 +24,7 @@ void Init(EmuWindow* emu_window) {
Kernel::Init();
HLE::Init();
VideoCore::Init(emu_window);
InputCommon::Init(InputCommon::InputBackends::SDL2);
InputCommon::Init();
}
void Shutdown() {

View file

@ -8,6 +8,8 @@
#include "input_common/sdl_input/sdl_input.h"
#endif
#include "core/settings.h"
namespace InputCommon {
// User input system
@ -21,8 +23,13 @@ const Service::HID::PadState& InputBase::GetPadState() const {
return controller.pad_state;
}
void Init(InputBackends backend) {
switch (backend) {
void Init() {
// Initialize backend based on configuration settings
// Convert int into a strongly typed enum first
std::cout<<"Setting -> " << Settings::values.input_backend << "\n";
switch (static_cast<InputBackends>(Settings::values.input_backend)) {
#ifdef HAS_SDL
// SDL2 backend selected
case InputBackends::SDL2:
@ -41,10 +48,7 @@ void Init(InputBackends backend) {
}
// Shutdown immediately if backend failed to initialize
if (!g_user_input && !g_user_input->activated) {
Shutdown();
return;
}
if (!g_user_input) Shutdown();
}
void Shutdown() {

View file

@ -11,8 +11,8 @@ namespace InputCommon {
/// Enum defining available backends
enum class InputBackends {
NONE,
SDL2
NONE = 0,
SDL2 = 1
};
class InputBase : NonCopyable {
@ -44,9 +44,6 @@ public:
*/
const Service::HID::PadState& GetPadState() const;
/// Current input system activation status
bool activated;
protected:
/// Internal name of currently selected device
std::string device_name;
@ -55,11 +52,8 @@ protected:
ControllerState controller;
};
/**
* Initializes the user input system
* @param backend Enumeration of the backend to use
*/
void Init(InputBackends backend);
/// Initialize the user input system
void Init();
/// Deactive the user input system
void Shutdown();

View file

@ -18,7 +18,7 @@ SDLController::SDLController() {
controller.touch_screen_x = 0;
controller.touch_screen_y = 0;
activated = Init();
Init();
}
SDLController::~SDLController() {
@ -127,6 +127,10 @@ void SDLController::ProcessInput() {
pad_id = 300;
pad_id += input_event.jhat.hat * 4;
// It is physically impossible for a hat/"dpad" to have certain inputs activated
// That is to say when "left" is activated, "right" must be deactivated
// All of these activate/deactivate combos must be accounted for hat input
// For hats, pad_ids are L/R/U/D, e.g. L = pad_id, R = pad_id + 1, and so on
switch (input_event.jhat.value) {
case SDL_HAT_CENTERED:
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;