summaryrefslogtreecommitdiff
path: root/src/citra
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra')
-rw-r--r--src/citra/CMakeLists.txt5
-rw-r--r--src/citra/citra.cpp9
-rw-r--r--src/citra/config.cpp65
-rw-r--r--src/citra/config.h24
-rw-r--r--src/citra/default_ini.h30
-rw-r--r--src/citra/emu_window/emu_window_glfw.cpp47
-rw-r--r--src/citra/emu_window/emu_window_glfw.h6
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 @@
1set(SRCS 1set(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 )
5set(HEADERS 6set(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
17add_executable(citra ${SRCS} ${HEADERS}) 20add_executable(citra ${SRCS} ${HEADERS})
18target_link_libraries(citra core common video_core) 21target_link_libraries(citra core common video_core)
19target_link_libraries(citra ${OPENGL_gl_LIBRARY} ${GLFW_LIBRARIES}) 22target_link_libraries(citra ${OPENGL_gl_LIBRARY} ${GLFW_LIBRARIES} inih)
20 23
21if (APPLE) 24if (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
13Config::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
21bool 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
38void 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
58void Config::Reload() {
59 LoadINI(glfw_config, glfw_config_loc.c_str(), DefaultINI::glfw_config_file);
60 ReadControls();
61}
62
63Config::~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
13class 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();
19public:
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
7namespace DefaultINI {
8
9const char* glfw_config_file = R"(
10[Controls]
11pad_start =
12pad_select =
13pad_home =
14pad_dup =
15pad_ddown =
16pad_dleft =
17pad_dright =
18pad_a =
19pad_b =
20pad_x =
21pad_y =
22pad_r =
23pad_l =
24pad_sup =
25pad_sdown =
26pad_sleft =
27pad_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
11static 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
31void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { 14void 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
50EmuWindow_GLFW::EmuWindow_GLFW() { 33EmuWindow_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() {
111void EmuWindow_GLFW::DoneCurrent() { 89void EmuWindow_GLFW::DoneCurrent() {
112 glfwMakeContextCurrent(NULL); 90 glfwMakeContextCurrent(NULL);
113} 91}
92
93void 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
30private: 32private:
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};