diff options
Diffstat (limited to 'src/citra')
| -rw-r--r-- | src/citra/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/citra/citra.cpp | 9 | ||||
| -rw-r--r-- | src/citra/config.cpp | 65 | ||||
| -rw-r--r-- | src/citra/config.h | 24 | ||||
| -rw-r--r-- | src/citra/default_ini.h | 30 | ||||
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.cpp | 47 | ||||
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.h | 6 |
7 files changed, 156 insertions, 30 deletions
diff --git a/src/citra/CMakeLists.txt b/src/citra/CMakeLists.txt index f10f3e603..f2add394f 100644 --- a/src/citra/CMakeLists.txt +++ b/src/citra/CMakeLists.txt | |||
| @@ -1,9 +1,12 @@ | |||
| 1 | set(SRCS | 1 | set(SRCS |
| 2 | emu_window/emu_window_glfw.cpp | 2 | emu_window/emu_window_glfw.cpp |
| 3 | citra.cpp | 3 | citra.cpp |
| 4 | config.cpp | ||
| 4 | ) | 5 | ) |
| 5 | set(HEADERS | 6 | set(HEADERS |
| 6 | emu_window/emu_window_glfw.h | 7 | emu_window/emu_window_glfw.h |
| 8 | config.h | ||
| 9 | default_ini.h | ||
| 7 | resource.h | 10 | resource.h |
| 8 | ) | 11 | ) |
| 9 | 12 | ||
| @@ -16,7 +19,7 @@ endif() | |||
| 16 | 19 | ||
| 17 | add_executable(citra ${SRCS} ${HEADERS}) | 20 | add_executable(citra ${SRCS} ${HEADERS}) |
| 18 | target_link_libraries(citra core common video_core) | 21 | target_link_libraries(citra core common video_core) |
| 19 | target_link_libraries(citra ${OPENGL_gl_LIBRARY} ${GLFW_LIBRARIES}) | 22 | target_link_libraries(citra ${OPENGL_gl_LIBRARY} ${GLFW_LIBRARIES} inih) |
| 20 | 23 | ||
| 21 | if (APPLE) | 24 | if (APPLE) |
| 22 | target_link_libraries(citra iconv pthread ${COREFOUNDATION_LIBRARY}) | 25 | target_link_libraries(citra iconv pthread ${COREFOUNDATION_LIBRARY}) |
diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index 7dc721dc3..46781defa 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp | |||
| @@ -4,12 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/common.h" | 5 | #include "common/common.h" |
| 6 | #include "common/log_manager.h" | 6 | #include "common/log_manager.h" |
| 7 | #include "common/file_util.h" | ||
| 8 | 7 | ||
| 9 | #include "core/system.h" | 8 | #include "core/system.h" |
| 10 | #include "core/core.h" | 9 | #include "core/core.h" |
| 11 | #include "core/loader/loader.h" | 10 | #include "core/loader/loader.h" |
| 12 | 11 | ||
| 12 | #include "citra/config.h" | ||
| 13 | #include "citra/emu_window/emu_window_glfw.h" | 13 | #include "citra/emu_window/emu_window_glfw.h" |
| 14 | 14 | ||
| 15 | /// Application entry point | 15 | /// Application entry point |
| @@ -21,13 +21,16 @@ int __cdecl main(int argc, char **argv) { | |||
| 21 | return -1; | 21 | return -1; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | Config config; | ||
| 25 | |||
| 24 | std::string boot_filename = argv[1]; | 26 | std::string boot_filename = argv[1]; |
| 25 | EmuWindow_GLFW* emu_window = new EmuWindow_GLFW; | 27 | EmuWindow_GLFW* emu_window = new EmuWindow_GLFW; |
| 26 | 28 | ||
| 27 | System::Init(emu_window); | 29 | System::Init(emu_window); |
| 28 | 30 | ||
| 29 | if (Loader::ResultStatus::Success != Loader::LoadFile(boot_filename)) { | 31 | Loader::ResultStatus load_result = Loader::LoadFile(boot_filename); |
| 30 | ERROR_LOG(BOOT, "Failed to load ROM!"); | 32 | if (Loader::ResultStatus::Success != load_result) { |
| 33 | ERROR_LOG(BOOT, "Failed to load ROM (Error %i)!", load_result); | ||
| 31 | return -1; | 34 | return -1; |
| 32 | } | 35 | } |
| 33 | 36 | ||
diff --git a/src/citra/config.cpp b/src/citra/config.cpp new file mode 100644 index 000000000..1d5e9c717 --- /dev/null +++ b/src/citra/config.cpp | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <GLFW/glfw3.h> | ||
| 6 | |||
| 7 | #include "citra/default_ini.h" | ||
| 8 | #include "common/file_util.h" | ||
| 9 | #include "core/settings.h" | ||
| 10 | |||
| 11 | #include "config.h" | ||
| 12 | |||
| 13 | Config::Config() { | ||
| 14 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. | ||
| 15 | glfw_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "glfw-config.ini"; | ||
| 16 | glfw_config = new INIReader(glfw_config_loc); | ||
| 17 | |||
| 18 | Reload(); | ||
| 19 | } | ||
| 20 | |||
| 21 | bool Config::LoadINI(INIReader* config, const char* location, const std::string& default_contents, bool retry) { | ||
| 22 | if (config->ParseError() < 0) { | ||
| 23 | if (retry) { | ||
| 24 | ERROR_LOG(CONFIG, "Failed to load %s. Creating file from defaults...", location); | ||
| 25 | FileUtil::CreateFullPath(location); | ||
| 26 | FileUtil::WriteStringToFile(true, default_contents, location); | ||
| 27 | *config = INIReader(location); // Reopen file | ||
| 28 | |||
| 29 | return LoadINI(config, location, default_contents, false); | ||
| 30 | } | ||
| 31 | ERROR_LOG(CONFIG, "Failed."); | ||
| 32 | return false; | ||
| 33 | } | ||
| 34 | INFO_LOG(CONFIG, "Successfully loaded %s", location); | ||
| 35 | return true; | ||
| 36 | } | ||
| 37 | |||
| 38 | void Config::ReadControls() { | ||
| 39 | Settings::values.pad_a_key = glfw_config->GetInteger("Controls", "pad_a", GLFW_KEY_A); | ||
| 40 | Settings::values.pad_b_key = glfw_config->GetInteger("Controls", "pad_b", GLFW_KEY_S); | ||
| 41 | Settings::values.pad_x_key = glfw_config->GetInteger("Controls", "pad_x", GLFW_KEY_Z); | ||
| 42 | Settings::values.pad_y_key = glfw_config->GetInteger("Controls", "pad_y", GLFW_KEY_X); | ||
| 43 | Settings::values.pad_l_key = glfw_config->GetInteger("Controls", "pad_l", GLFW_KEY_Q); | ||
| 44 | Settings::values.pad_r_key = glfw_config->GetInteger("Controls", "pad_r", GLFW_KEY_W); | ||
| 45 | Settings::values.pad_start_key = glfw_config->GetInteger("Controls", "pad_start", GLFW_KEY_M); | ||
| 46 | Settings::values.pad_select_key = glfw_config->GetInteger("Controls", "pad_select", GLFW_KEY_N); | ||
| 47 | Settings::values.pad_home_key = glfw_config->GetInteger("Controls", "pad_home", GLFW_KEY_B); | ||
| 48 | Settings::values.pad_dup_key = glfw_config->GetInteger("Controls", "pad_dup", GLFW_KEY_T); | ||
| 49 | Settings::values.pad_ddown_key = glfw_config->GetInteger("Controls", "pad_ddown", GLFW_KEY_G); | ||
| 50 | Settings::values.pad_dleft_key = glfw_config->GetInteger("Controls", "pad_dleft", GLFW_KEY_F); | ||
| 51 | Settings::values.pad_dright_key = glfw_config->GetInteger("Controls", "pad_dright", GLFW_KEY_H); | ||
| 52 | Settings::values.pad_sup_key = glfw_config->GetInteger("Controls", "pad_sup", GLFW_KEY_UP); | ||
| 53 | Settings::values.pad_sdown_key = glfw_config->GetInteger("Controls", "pad_sdown", GLFW_KEY_DOWN); | ||
| 54 | Settings::values.pad_sleft_key = glfw_config->GetInteger("Controls", "pad_sleft", GLFW_KEY_LEFT); | ||
| 55 | Settings::values.pad_sright_key = glfw_config->GetInteger("Controls", "pad_sright", GLFW_KEY_RIGHT); | ||
| 56 | } | ||
| 57 | |||
| 58 | void Config::Reload() { | ||
| 59 | LoadINI(glfw_config, glfw_config_loc.c_str(), DefaultINI::glfw_config_file); | ||
| 60 | ReadControls(); | ||
| 61 | } | ||
| 62 | |||
| 63 | Config::~Config() { | ||
| 64 | delete glfw_config; | ||
| 65 | } | ||
diff --git a/src/citra/config.h b/src/citra/config.h new file mode 100644 index 000000000..de0570b42 --- /dev/null +++ b/src/citra/config.h | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <map> | ||
| 8 | |||
| 9 | #include <inih/cpp/INIReader.h> | ||
| 10 | |||
| 11 | #include "common/common_types.h" | ||
| 12 | |||
| 13 | class Config { | ||
| 14 | INIReader* glfw_config; | ||
| 15 | std::string glfw_config_loc; | ||
| 16 | |||
| 17 | bool LoadINI(INIReader* config, const char* location, const std::string& default_contents="", bool retry=true); | ||
| 18 | void ReadControls(); | ||
| 19 | public: | ||
| 20 | Config(); | ||
| 21 | ~Config(); | ||
| 22 | |||
| 23 | void Reload(); | ||
| 24 | }; | ||
diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h new file mode 100644 index 000000000..11b985e1b --- /dev/null +++ b/src/citra/default_ini.h | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | namespace DefaultINI { | ||
| 8 | |||
| 9 | const char* glfw_config_file = R"( | ||
| 10 | [Controls] | ||
| 11 | pad_start = | ||
| 12 | pad_select = | ||
| 13 | pad_home = | ||
| 14 | pad_dup = | ||
| 15 | pad_ddown = | ||
| 16 | pad_dleft = | ||
| 17 | pad_dright = | ||
| 18 | pad_a = | ||
| 19 | pad_b = | ||
| 20 | pad_x = | ||
| 21 | pad_y = | ||
| 22 | pad_r = | ||
| 23 | pad_l = | ||
| 24 | pad_sup = | ||
| 25 | pad_sdown = | ||
| 26 | pad_sleft = | ||
| 27 | pad_sright = | ||
| 28 | )"; | ||
| 29 | |||
| 30 | } | ||
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index b911e60c5..661521eb7 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp | |||
| @@ -6,26 +6,9 @@ | |||
| 6 | 6 | ||
| 7 | #include "video_core/video_core.h" | 7 | #include "video_core/video_core.h" |
| 8 | 8 | ||
| 9 | #include "citra/emu_window/emu_window_glfw.h" | 9 | #include "core/settings.h" |
| 10 | 10 | ||
| 11 | static const std::pair<int, HID_User::PadState> default_key_map[] = { | 11 | #include "citra/emu_window/emu_window_glfw.h" |
| 12 | { GLFW_KEY_A, HID_User::PAD_A }, | ||
| 13 | { GLFW_KEY_B, HID_User::PAD_B }, | ||
| 14 | { GLFW_KEY_BACKSLASH, HID_User::PAD_SELECT }, | ||
| 15 | { GLFW_KEY_ENTER, HID_User::PAD_START }, | ||
| 16 | { GLFW_KEY_RIGHT, HID_User::PAD_RIGHT }, | ||
| 17 | { GLFW_KEY_LEFT, HID_User::PAD_LEFT }, | ||
| 18 | { GLFW_KEY_UP, HID_User::PAD_UP }, | ||
| 19 | { GLFW_KEY_DOWN, HID_User::PAD_DOWN }, | ||
| 20 | { GLFW_KEY_R, HID_User::PAD_R }, | ||
| 21 | { GLFW_KEY_L, HID_User::PAD_L }, | ||
| 22 | { GLFW_KEY_X, HID_User::PAD_X }, | ||
| 23 | { GLFW_KEY_Y, HID_User::PAD_Y }, | ||
| 24 | { GLFW_KEY_H, HID_User::PAD_CIRCLE_RIGHT }, | ||
| 25 | { GLFW_KEY_F, HID_User::PAD_CIRCLE_LEFT }, | ||
| 26 | { GLFW_KEY_T, HID_User::PAD_CIRCLE_UP }, | ||
| 27 | { GLFW_KEY_G, HID_User::PAD_CIRCLE_DOWN }, | ||
| 28 | }; | ||
| 29 | 12 | ||
| 30 | /// Called by GLFW when a key event occurs | 13 | /// Called by GLFW when a key event occurs |
| 31 | void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { | 14 | void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { |
| @@ -48,14 +31,9 @@ void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int acti | |||
| 48 | 31 | ||
| 49 | /// EmuWindow_GLFW constructor | 32 | /// EmuWindow_GLFW constructor |
| 50 | EmuWindow_GLFW::EmuWindow_GLFW() { | 33 | EmuWindow_GLFW::EmuWindow_GLFW() { |
| 51 | |||
| 52 | // Register a new ID for the default keyboard | ||
| 53 | keyboard_id = KeyMap::NewDeviceId(); | 34 | keyboard_id = KeyMap::NewDeviceId(); |
| 54 | 35 | ||
| 55 | // Set default key mappings for keyboard | 36 | ReloadSetKeymaps(); |
| 56 | for (auto mapping : default_key_map) { | ||
| 57 | KeyMap::SetKeyMapping({mapping.first, keyboard_id}, mapping.second); | ||
| 58 | } | ||
| 59 | 37 | ||
| 60 | // Initialize the window | 38 | // Initialize the window |
| 61 | if(glfwInit() != GL_TRUE) { | 39 | if(glfwInit() != GL_TRUE) { |
| @@ -111,3 +89,22 @@ void EmuWindow_GLFW::MakeCurrent() { | |||
| 111 | void EmuWindow_GLFW::DoneCurrent() { | 89 | void EmuWindow_GLFW::DoneCurrent() { |
| 112 | glfwMakeContextCurrent(NULL); | 90 | glfwMakeContextCurrent(NULL); |
| 113 | } | 91 | } |
| 92 | |||
| 93 | void EmuWindow_GLFW::ReloadSetKeymaps() { | ||
| 94 | KeyMap::SetKeyMapping({Settings::values.pad_a_key, keyboard_id}, HID_User::PAD_A); | ||
| 95 | KeyMap::SetKeyMapping({Settings::values.pad_b_key, keyboard_id}, HID_User::PAD_B); | ||
| 96 | KeyMap::SetKeyMapping({Settings::values.pad_select_key, keyboard_id}, HID_User::PAD_SELECT); | ||
| 97 | KeyMap::SetKeyMapping({Settings::values.pad_start_key, keyboard_id}, HID_User::PAD_START); | ||
| 98 | KeyMap::SetKeyMapping({Settings::values.pad_dright_key, keyboard_id}, HID_User::PAD_RIGHT); | ||
| 99 | KeyMap::SetKeyMapping({Settings::values.pad_dleft_key, keyboard_id}, HID_User::PAD_LEFT); | ||
| 100 | KeyMap::SetKeyMapping({Settings::values.pad_dup_key, keyboard_id}, HID_User::PAD_UP); | ||
| 101 | KeyMap::SetKeyMapping({Settings::values.pad_ddown_key, keyboard_id}, HID_User::PAD_DOWN); | ||
| 102 | KeyMap::SetKeyMapping({Settings::values.pad_r_key, keyboard_id}, HID_User::PAD_R); | ||
| 103 | KeyMap::SetKeyMapping({Settings::values.pad_l_key, keyboard_id}, HID_User::PAD_L); | ||
| 104 | KeyMap::SetKeyMapping({Settings::values.pad_x_key, keyboard_id}, HID_User::PAD_X); | ||
| 105 | KeyMap::SetKeyMapping({Settings::values.pad_y_key, keyboard_id}, HID_User::PAD_Y); | ||
| 106 | KeyMap::SetKeyMapping({Settings::values.pad_sright_key, keyboard_id}, HID_User::PAD_CIRCLE_RIGHT); | ||
| 107 | KeyMap::SetKeyMapping({Settings::values.pad_sleft_key, keyboard_id}, HID_User::PAD_CIRCLE_LEFT); | ||
| 108 | KeyMap::SetKeyMapping({Settings::values.pad_sup_key, keyboard_id}, HID_User::PAD_CIRCLE_UP); | ||
| 109 | KeyMap::SetKeyMapping({Settings::values.pad_sdown_key, keyboard_id}, HID_User::PAD_CIRCLE_DOWN); | ||
| 110 | } | ||
diff --git a/src/citra/emu_window/emu_window_glfw.h b/src/citra/emu_window/emu_window_glfw.h index 29325bb75..d38a11c2c 100644 --- a/src/citra/emu_window/emu_window_glfw.h +++ b/src/citra/emu_window/emu_window_glfw.h | |||
| @@ -27,7 +27,11 @@ public: | |||
| 27 | 27 | ||
| 28 | static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods); | 28 | static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods); |
| 29 | 29 | ||
| 30 | void ReloadSetKeymaps() override; | ||
| 31 | |||
| 30 | private: | 32 | private: |
| 31 | GLFWwindow* m_render_window; ///< Internal GLFW render window | 33 | GLFWwindow* m_render_window; ///< Internal GLFW render window |
| 32 | int keyboard_id; ///< Device id of keyboard for use with KeyMap | 34 | |
| 35 | /// Device id of keyboard for use with KeyMap | ||
| 36 | int keyboard_id; | ||
| 33 | }; | 37 | }; |