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 // System Region
Settings::values.region_value = glfw_config->GetInteger("System Region", "region_value", 1); 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 // Miscellaneous
Settings::values.log_filter = glfw_config->Get("Miscellaneous", "log_filter", "*:Info"); 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 # 0: Japan, 1: USA (default), 2: Europe, 3: Australia, 4: China, 5: Korea, 6: Taiwan
region_value = region_value =
[Input Backend]
# Input system Citra will use during emulation
# 0: Keyboard (default), 1: SDL2 (gamepad)
input_backend =
[Miscellaneous] [Miscellaneous]
# A filter which removes logs below a certain logging level. # A filter which removes logs below a certain logging level.
# Examples: *:Debug Kernel.SVC:Trace Service.*:Critical # Examples: *:Debug Kernel.SVC:Trace Service.*:Critical

View File

@ -127,7 +127,7 @@ void EmuWindow_GLFW::SwapBuffers() {
/// Polls window events /// Polls window events
void EmuWindow_GLFW::PollEvents() { void EmuWindow_GLFW::PollEvents() {
glfwPollEvents(); 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 /// Makes the GLFW OpenGL context current for the caller thread

View File

@ -161,7 +161,7 @@ void GRenderWindow::DoneCurrent()
} }
void GRenderWindow::PollEvents() { 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). // 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(); Settings::values.region_value = qt_config->value("region_value", 1).toInt();
qt_config->endGroup(); 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"); qt_config->beginGroup("Miscellaneous");
Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString(); Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString();
qt_config->endGroup(); qt_config->endGroup();
@ -123,6 +127,10 @@ void Config::SaveValues() {
qt_config->setValue("region_value", Settings::values.region_value); qt_config->setValue("region_value", Settings::values.region_value);
qt_config->endGroup(); 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->beginGroup("Miscellaneous");
qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter)); qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter));
qt_config->endGroup(); qt_config->endGroup();

View File

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

View File

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

View File

@ -8,6 +8,8 @@
#include "input_common/sdl_input/sdl_input.h" #include "input_common/sdl_input/sdl_input.h"
#endif #endif
#include "core/settings.h"
namespace InputCommon { namespace InputCommon {
// User input system // User input system
@ -21,8 +23,13 @@ const Service::HID::PadState& InputBase::GetPadState() const {
return controller.pad_state; return controller.pad_state;
} }
void Init(InputBackends backend) { void Init() {
switch (backend) { // 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 #ifdef HAS_SDL
// SDL2 backend selected // SDL2 backend selected
case InputBackends::SDL2: case InputBackends::SDL2:
@ -41,10 +48,7 @@ void Init(InputBackends backend) {
} }
// Shutdown immediately if backend failed to initialize // Shutdown immediately if backend failed to initialize
if (!g_user_input && !g_user_input->activated) { if (!g_user_input) Shutdown();
Shutdown();
return;
}
} }
void Shutdown() { void Shutdown() {

View File

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

View File

@ -18,7 +18,7 @@ SDLController::SDLController() {
controller.touch_screen_x = 0; controller.touch_screen_x = 0;
controller.touch_screen_y = 0; controller.touch_screen_y = 0;
activated = Init(); Init();
} }
SDLController::~SDLController() { SDLController::~SDLController() {
@ -127,6 +127,10 @@ void SDLController::ProcessInput() {
pad_id = 300; pad_id = 300;
pad_id += input_event.jhat.hat * 4; 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) { switch (input_event.jhat.value) {
case SDL_HAT_CENTERED: case SDL_HAT_CENTERED:
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex; controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;