diff options
Diffstat (limited to 'src/citra')
-rw-r--r-- | src/citra/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/citra/citra.cpp | 11 | ||||
-rw-r--r-- | src/citra/config.cpp | 77 | ||||
-rw-r--r-- | src/citra/config.h | 26 | ||||
-rw-r--r-- | src/citra/default_ini.h | 37 | ||||
-rw-r--r-- | src/citra/emu_window/emu_window_glfw.cpp | 57 | ||||
-rw-r--r-- | src/citra/emu_window/emu_window_glfw.h | 18 |
7 files changed, 210 insertions, 21 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 @@ set(SRCS emu_window/emu_window_glfw.cpp citra.cpp + config.cpp ) set(HEADERS emu_window/emu_window_glfw.h + config.h + default_ini.h resource.h ) @@ -16,7 +19,7 @@ endif() add_executable(citra ${SRCS} ${HEADERS}) target_link_libraries(citra core common video_core) -target_link_libraries(citra ${OPENGL_gl_LIBRARY} ${GLFW_LIBRARIES}) +target_link_libraries(citra ${OPENGL_gl_LIBRARY} ${GLFW_LIBRARIES} inih) if (APPLE) target_link_libraries(citra iconv pthread ${COREFOUNDATION_LIBRARY}) diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index 7dc721dc3..6ac5c5dc5 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp @@ -4,12 +4,12 @@ #include "common/common.h" #include "common/log_manager.h" -#include "common/file_util.h" #include "core/system.h" #include "core/core.h" #include "core/loader/loader.h" +#include "citra/config.h" #include "citra/emu_window/emu_window_glfw.h" /// Application entry point @@ -21,17 +21,20 @@ int __cdecl main(int argc, char **argv) { return -1; } + Config config; + std::string boot_filename = argv[1]; EmuWindow_GLFW* emu_window = new EmuWindow_GLFW; System::Init(emu_window); - if (Loader::ResultStatus::Success != Loader::LoadFile(boot_filename)) { - ERROR_LOG(BOOT, "Failed to load ROM!"); + Loader::ResultStatus load_result = Loader::LoadFile(boot_filename); + if (Loader::ResultStatus::Success != load_result) { + ERROR_LOG(BOOT, "Failed to load ROM (Error %i)!", load_result); return -1; } - while(true) { + while (emu_window->IsOpen()) { Core::RunLoop(); } diff --git a/src/citra/config.cpp b/src/citra/config.cpp new file mode 100644 index 000000000..c5ce8a164 --- /dev/null +++ b/src/citra/config.cpp @@ -0,0 +1,77 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include <GLFW/glfw3.h> + +#include "citra/default_ini.h" +#include "common/file_util.h" +#include "core/settings.h" +#include "core/core.h" + +#include "config.h" + +Config::Config() { + // TODO: Don't hardcode the path; let the frontend decide where to put the config files. + glfw_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "glfw-config.ini"; + glfw_config = new INIReader(glfw_config_loc); + + Reload(); +} + +bool Config::LoadINI(INIReader* config, const char* location, const std::string& default_contents, bool retry) { + if (config->ParseError() < 0) { + if (retry) { + ERROR_LOG(CONFIG, "Failed to load %s. Creating file from defaults...", location); + FileUtil::CreateFullPath(location); + FileUtil::WriteStringToFile(true, default_contents, location); + *config = INIReader(location); // Reopen file + + return LoadINI(config, location, default_contents, false); + } + ERROR_LOG(CONFIG, "Failed."); + return false; + } + INFO_LOG(CONFIG, "Successfully loaded %s", location); + return true; +} + +void Config::ReadControls() { + Settings::values.pad_a_key = glfw_config->GetInteger("Controls", "pad_a", GLFW_KEY_A); + Settings::values.pad_b_key = glfw_config->GetInteger("Controls", "pad_b", GLFW_KEY_S); + Settings::values.pad_x_key = glfw_config->GetInteger("Controls", "pad_x", GLFW_KEY_Z); + Settings::values.pad_y_key = glfw_config->GetInteger("Controls", "pad_y", GLFW_KEY_X); + Settings::values.pad_l_key = glfw_config->GetInteger("Controls", "pad_l", GLFW_KEY_Q); + Settings::values.pad_r_key = glfw_config->GetInteger("Controls", "pad_r", GLFW_KEY_W); + Settings::values.pad_start_key = glfw_config->GetInteger("Controls", "pad_start", GLFW_KEY_M); + Settings::values.pad_select_key = glfw_config->GetInteger("Controls", "pad_select", GLFW_KEY_N); + Settings::values.pad_home_key = glfw_config->GetInteger("Controls", "pad_home", GLFW_KEY_B); + Settings::values.pad_dup_key = glfw_config->GetInteger("Controls", "pad_dup", GLFW_KEY_T); + Settings::values.pad_ddown_key = glfw_config->GetInteger("Controls", "pad_ddown", GLFW_KEY_G); + Settings::values.pad_dleft_key = glfw_config->GetInteger("Controls", "pad_dleft", GLFW_KEY_F); + Settings::values.pad_dright_key = glfw_config->GetInteger("Controls", "pad_dright", GLFW_KEY_H); + Settings::values.pad_sup_key = glfw_config->GetInteger("Controls", "pad_sup", GLFW_KEY_UP); + Settings::values.pad_sdown_key = glfw_config->GetInteger("Controls", "pad_sdown", GLFW_KEY_DOWN); + Settings::values.pad_sleft_key = glfw_config->GetInteger("Controls", "pad_sleft", GLFW_KEY_LEFT); + Settings::values.pad_sright_key = glfw_config->GetInteger("Controls", "pad_sright", GLFW_KEY_RIGHT); +} + +void Config::ReadCore() { + Settings::values.cpu_core = glfw_config->GetInteger("Core", "cpu_core", Core::CPU_Interpreter); + Settings::values.gpu_refresh_rate = glfw_config->GetInteger("Core", "gpu_refresh_rate", 60); +} + +void Config::ReadData() { + Settings::values.use_virtual_sd = glfw_config->GetBoolean("Data Storage", "use_virtual_sd", true); +} + +void Config::Reload() { + LoadINI(glfw_config, glfw_config_loc.c_str(), DefaultINI::glfw_config_file); + ReadControls(); + ReadCore(); + ReadData(); +} + +Config::~Config() { + delete glfw_config; +} diff --git a/src/citra/config.h b/src/citra/config.h new file mode 100644 index 000000000..4f6551876 --- /dev/null +++ b/src/citra/config.h @@ -0,0 +1,26 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +#include <map> + +#include <inih/cpp/INIReader.h> + +#include "common/common_types.h" + +class Config { + INIReader* glfw_config; + std::string glfw_config_loc; + + bool LoadINI(INIReader* config, const char* location, const std::string& default_contents="", bool retry=true); + void ReadControls(); + void ReadCore(); + void ReadData(); +public: + Config(); + ~Config(); + + void Reload(); +}; diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h new file mode 100644 index 000000000..557da881b --- /dev/null +++ b/src/citra/default_ini.h @@ -0,0 +1,37 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +namespace DefaultINI { + +const char* glfw_config_file = R"( +[Controls] +pad_start = +pad_select = +pad_home = +pad_dup = +pad_ddown = +pad_dleft = +pad_dright = +pad_a = +pad_b = +pad_x = +pad_y = +pad_r = +pad_l = +pad_sup = +pad_sdown = +pad_sleft = +pad_sright = + +[Core] +cpu_core = ## 0: Interpreter (default), 1: FastInterpreter (experimental) +gpu_refresh_rate = ## 60 (default) + +[Data Storage] +use_virtual_sd = +)"; + +} diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index 02f524e03..0c774bbc5 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp @@ -6,20 +6,40 @@ #include "video_core/video_core.h" +#include "core/settings.h" + #include "citra/emu_window/emu_window_glfw.h" -static void OnKeyEvent(GLFWwindow* win, int key, int action) { - // TODO(bunnei): ImplementMe +/// Called by GLFW when a key event occurs +void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { + + if (!VideoCore::g_emu_window) { + return; + } + + int keyboard_id = ((EmuWindow_GLFW*)VideoCore::g_emu_window)->keyboard_id; + + if (action == GLFW_PRESS) { + EmuWindow::KeyPressed({key, keyboard_id}); + } + + if (action == GLFW_RELEASE) { + EmuWindow::KeyReleased({key, keyboard_id}); + } + HID_User::PadUpdateComplete(); } -static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { - EmuWindow_GLFW* emu_window = (EmuWindow_GLFW*)glfwGetWindowUserPointer(win); - emu_window->SetClientAreaWidth(width); - emu_window->SetClientAreaHeight(height); +/// Whether the window is still open, and a close request hasn't yet been sent +const bool EmuWindow_GLFW::IsOpen() { + return glfwWindowShouldClose(m_render_window) == 0; } /// EmuWindow_GLFW constructor EmuWindow_GLFW::EmuWindow_GLFW() { + keyboard_id = KeyMap::NewDeviceId(); + + ReloadSetKeymaps(); + // Initialize the window if(glfwInit() != GL_TRUE) { printf("Failed to initialize GLFW! Exiting..."); @@ -27,12 +47,9 @@ EmuWindow_GLFW::EmuWindow_GLFW() { } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); - -#if EMU_PLATFORM == PLATFORM_MACOSX // GLFW on OSX requires these window hints to be set to create a 3.2+ GL context. glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#endif m_render_window = glfwCreateWindow(VideoCore::kScreenTopWidth, (VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight), @@ -45,8 +62,7 @@ EmuWindow_GLFW::EmuWindow_GLFW() { // Setup callbacks glfwSetWindowUserPointer(m_render_window, this); - //glfwSetKeyCallback(m_render_window, OnKeyEvent); - //glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent); + glfwSetKeyCallback(m_render_window, OnKeyEvent); DoneCurrent(); } @@ -75,3 +91,22 @@ void EmuWindow_GLFW::MakeCurrent() { void EmuWindow_GLFW::DoneCurrent() { glfwMakeContextCurrent(NULL); } + +void EmuWindow_GLFW::ReloadSetKeymaps() { + KeyMap::SetKeyMapping({Settings::values.pad_a_key, keyboard_id}, HID_User::PAD_A); + KeyMap::SetKeyMapping({Settings::values.pad_b_key, keyboard_id}, HID_User::PAD_B); + KeyMap::SetKeyMapping({Settings::values.pad_select_key, keyboard_id}, HID_User::PAD_SELECT); + KeyMap::SetKeyMapping({Settings::values.pad_start_key, keyboard_id}, HID_User::PAD_START); + KeyMap::SetKeyMapping({Settings::values.pad_dright_key, keyboard_id}, HID_User::PAD_RIGHT); + KeyMap::SetKeyMapping({Settings::values.pad_dleft_key, keyboard_id}, HID_User::PAD_LEFT); + KeyMap::SetKeyMapping({Settings::values.pad_dup_key, keyboard_id}, HID_User::PAD_UP); + KeyMap::SetKeyMapping({Settings::values.pad_ddown_key, keyboard_id}, HID_User::PAD_DOWN); + KeyMap::SetKeyMapping({Settings::values.pad_r_key, keyboard_id}, HID_User::PAD_R); + KeyMap::SetKeyMapping({Settings::values.pad_l_key, keyboard_id}, HID_User::PAD_L); + KeyMap::SetKeyMapping({Settings::values.pad_x_key, keyboard_id}, HID_User::PAD_X); + KeyMap::SetKeyMapping({Settings::values.pad_y_key, keyboard_id}, HID_User::PAD_Y); + KeyMap::SetKeyMapping({Settings::values.pad_sright_key, keyboard_id}, HID_User::PAD_CIRCLE_RIGHT); + KeyMap::SetKeyMapping({Settings::values.pad_sleft_key, keyboard_id}, HID_User::PAD_CIRCLE_LEFT); + KeyMap::SetKeyMapping({Settings::values.pad_sup_key, keyboard_id}, HID_User::PAD_CIRCLE_UP); + KeyMap::SetKeyMapping({Settings::values.pad_sdown_key, keyboard_id}, HID_User::PAD_CIRCLE_DOWN); +} diff --git a/src/citra/emu_window/emu_window_glfw.h b/src/citra/emu_window/emu_window_glfw.h index c1b41203b..7c3072145 100644 --- a/src/citra/emu_window/emu_window_glfw.h +++ b/src/citra/emu_window/emu_window_glfw.h @@ -14,19 +14,27 @@ public: ~EmuWindow_GLFW(); /// Swap buffers to display the next frame - void SwapBuffers(); + void SwapBuffers() override; /// Polls window events - void PollEvents(); + void PollEvents() override; /// Makes the graphics context current for the caller thread - void MakeCurrent(); + void MakeCurrent() override; /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread - void DoneCurrent(); + void DoneCurrent() override; - GLFWwindow* m_render_window; ///< Internal GLFW render window + static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods); + + /// Whether the window is still open, and a close request hasn't yet been sent + const bool IsOpen(); + + void ReloadSetKeymaps() override; private: + GLFWwindow* m_render_window; ///< Internal GLFW render window + /// Device id of keyboard for use with KeyMap + int keyboard_id; }; |