summaryrefslogtreecommitdiff
path: root/src/yuzu_cmd
diff options
context:
space:
mode:
authorGravatar Levi2021-01-10 22:09:56 -0700
committerGravatar Levi2021-01-10 22:09:56 -0700
commit7a3c884e39fccfbb498b855080bffabc9ce2e7f1 (patch)
tree5056f9406dec188439cb0deb87603498243a9412 /src/yuzu_cmd
parentMore forgetting... duh (diff)
parentMerge pull request #5229 from Morph1984/fullscreen-opt (diff)
downloadyuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.gz
yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.xz
yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.zip
Merge remote-tracking branch 'upstream/master' into int-flags
Diffstat (limited to 'src/yuzu_cmd')
-rw-r--r--src/yuzu_cmd/CMakeLists.txt17
-rw-r--r--src/yuzu_cmd/config.cpp43
-rw-r--r--src/yuzu_cmd/default_ini.h17
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp108
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.h20
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp1
-rw-r--r--src/yuzu_cmd/yuzu.cpp50
7 files changed, 113 insertions, 143 deletions
diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt
index a15719a0f..0b3f2cb54 100644
--- a/src/yuzu_cmd/CMakeLists.txt
+++ b/src/yuzu_cmd/CMakeLists.txt
@@ -4,26 +4,17 @@ add_executable(yuzu-cmd
4 config.cpp 4 config.cpp
5 config.h 5 config.h
6 default_ini.h 6 default_ini.h
7 emu_window/emu_window_sdl2_gl.cpp
8 emu_window/emu_window_sdl2_gl.h
9 emu_window/emu_window_sdl2.cpp 7 emu_window/emu_window_sdl2.cpp
10 emu_window/emu_window_sdl2.h 8 emu_window/emu_window_sdl2.h
11 emu_window/emu_window_sdl2_gl.cpp 9 emu_window/emu_window_sdl2_gl.cpp
12 emu_window/emu_window_sdl2_gl.h 10 emu_window/emu_window_sdl2_gl.h
11 emu_window/emu_window_sdl2_vk.cpp
12 emu_window/emu_window_sdl2_vk.h
13 resource.h 13 resource.h
14 yuzu.cpp 14 yuzu.cpp
15 yuzu.rc 15 yuzu.rc
16) 16)
17 17
18if (ENABLE_VULKAN)
19 target_sources(yuzu-cmd PRIVATE
20 emu_window/emu_window_sdl2_vk.cpp
21 emu_window/emu_window_sdl2_vk.h)
22
23 target_include_directories(yuzu-cmd PRIVATE ../../externals/Vulkan-Headers/include)
24 target_compile_definitions(yuzu-cmd PRIVATE HAS_VULKAN)
25endif()
26
27create_target_directory_groups(yuzu-cmd) 18create_target_directory_groups(yuzu-cmd)
28 19
29target_link_libraries(yuzu-cmd PRIVATE common core input_common) 20target_link_libraries(yuzu-cmd PRIVATE common core input_common)
@@ -33,13 +24,13 @@ if (MSVC)
33endif() 24endif()
34target_link_libraries(yuzu-cmd PRIVATE ${PLATFORM_LIBRARIES} SDL2 Threads::Threads) 25target_link_libraries(yuzu-cmd PRIVATE ${PLATFORM_LIBRARIES} SDL2 Threads::Threads)
35 26
27target_include_directories(yuzu-cmd PRIVATE ../../externals/Vulkan-Headers/include)
28
36if(UNIX AND NOT APPLE) 29if(UNIX AND NOT APPLE)
37 install(TARGETS yuzu-cmd RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") 30 install(TARGETS yuzu-cmd RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
38endif() 31endif()
39 32
40if (MSVC) 33if (MSVC)
41 include(CopyYuzuSDLDeps) 34 include(CopyYuzuSDLDeps)
42 include(CopyYuzuUnicornDeps)
43 copy_yuzu_SDL_deps(yuzu-cmd) 35 copy_yuzu_SDL_deps(yuzu-cmd)
44 copy_yuzu_unicorn_deps(yuzu-cmd)
45endif() 36endif()
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp
index 23448e747..41ef6f6b8 100644
--- a/src/yuzu_cmd/config.cpp
+++ b/src/yuzu_cmd/config.cpp
@@ -228,24 +228,24 @@ static const std::array<int, 8> keyboard_mods{
228 228
229void Config::ReadValues() { 229void Config::ReadValues() {
230 // Controls 230 // Controls
231 for (std::size_t p = 0; p < Settings::values.players.size(); ++p) { 231 for (std::size_t p = 0; p < Settings::values.players.GetValue().size(); ++p) {
232 const auto group = fmt::format("ControlsP{}", p); 232 const auto group = fmt::format("ControlsP{}", p);
233 for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { 233 for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
234 std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); 234 std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
235 Settings::values.players[p].buttons[i] = 235 Settings::values.players.GetValue()[p].buttons[i] =
236 sdl2_config->Get(group, Settings::NativeButton::mapping[i], default_param); 236 sdl2_config->Get(group, Settings::NativeButton::mapping[i], default_param);
237 if (Settings::values.players[p].buttons[i].empty()) 237 if (Settings::values.players.GetValue()[p].buttons[i].empty())
238 Settings::values.players[p].buttons[i] = default_param; 238 Settings::values.players.GetValue()[p].buttons[i] = default_param;
239 } 239 }
240 240
241 for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { 241 for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
242 std::string default_param = InputCommon::GenerateAnalogParamFromKeys( 242 std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
243 default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], 243 default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
244 default_analogs[i][3], default_analogs[i][4], 0.5f); 244 default_analogs[i][3], default_analogs[i][4], 0.5f);
245 Settings::values.players[p].analogs[i] = 245 Settings::values.players.GetValue()[p].analogs[i] =
246 sdl2_config->Get(group, Settings::NativeAnalog::mapping[i], default_param); 246 sdl2_config->Get(group, Settings::NativeAnalog::mapping[i], default_param);
247 if (Settings::values.players[p].analogs[i].empty()) 247 if (Settings::values.players.GetValue()[p].analogs[i].empty())
248 Settings::values.players[p].analogs[i] = default_param; 248 Settings::values.players.GetValue()[p].analogs[i] = default_param;
249 } 249 }
250 } 250 }
251 251
@@ -288,10 +288,12 @@ void Config::ReadValues() {
288 Settings::values.debug_pad_analogs[i] = default_param; 288 Settings::values.debug_pad_analogs[i] = default_param;
289 } 289 }
290 290
291 Settings::values.vibration_enabled = 291 Settings::values.vibration_enabled.SetValue(
292 sdl2_config->GetBoolean("ControlsGeneral", "vibration_enabled", true); 292 sdl2_config->GetBoolean("ControlsGeneral", "vibration_enabled", true));
293 Settings::values.motion_enabled = 293 Settings::values.enable_accurate_vibrations.SetValue(
294 sdl2_config->GetBoolean("ControlsGeneral", "motion_enabled", true); 294 sdl2_config->GetBoolean("ControlsGeneral", "enable_accurate_vibrations", false));
295 Settings::values.motion_enabled.SetValue(
296 sdl2_config->GetBoolean("ControlsGeneral", "motion_enabled", true));
295 Settings::values.touchscreen.enabled = 297 Settings::values.touchscreen.enabled =
296 sdl2_config->GetBoolean("ControlsGeneral", "touch_enabled", true); 298 sdl2_config->GetBoolean("ControlsGeneral", "touch_enabled", true);
297 Settings::values.touchscreen.device = 299 Settings::values.touchscreen.device =
@@ -304,10 +306,8 @@ void Config::ReadValues() {
304 sdl2_config->GetInteger("ControlsGeneral", "touch_diameter_x", 15); 306 sdl2_config->GetInteger("ControlsGeneral", "touch_diameter_x", 15);
305 Settings::values.touchscreen.diameter_y = 307 Settings::values.touchscreen.diameter_y =
306 sdl2_config->GetInteger("ControlsGeneral", "touch_diameter_y", 15); 308 sdl2_config->GetInteger("ControlsGeneral", "touch_diameter_y", 15);
307 Settings::values.udp_input_address = 309 Settings::values.udp_input_servers =
308 sdl2_config->Get("Controls", "udp_input_address", InputCommon::CemuhookUDP::DEFAULT_ADDR); 310 sdl2_config->Get("Controls", "udp_input_address", InputCommon::CemuhookUDP::DEFAULT_SRV);
309 Settings::values.udp_input_port = static_cast<u16>(sdl2_config->GetInteger(
310 "Controls", "udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT));
311 311
312 std::transform(keyboard_keys.begin(), keyboard_keys.end(), 312 std::transform(keyboard_keys.begin(), keyboard_keys.end(),
313 Settings::values.keyboard_keys.begin(), InputCommon::GenerateKeyboardParam); 313 Settings::values.keyboard_keys.begin(), InputCommon::GenerateKeyboardParam);
@@ -343,8 +343,8 @@ void Config::ReadValues() {
343 Settings::values.gamecard_path = sdl2_config->Get("Data Storage", "gamecard_path", ""); 343 Settings::values.gamecard_path = sdl2_config->Get("Data Storage", "gamecard_path", "");
344 344
345 // System 345 // System
346 Settings::values.use_docked_mode = sdl2_config->GetBoolean("System", "use_docked_mode", false); 346 Settings::values.use_docked_mode.SetValue(
347 const auto size = sdl2_config->GetInteger("System", "users_size", 0); 347 sdl2_config->GetBoolean("System", "use_docked_mode", true));
348 348
349 Settings::values.current_user = std::clamp<int>( 349 Settings::values.current_user = std::clamp<int>(
350 sdl2_config->GetInteger("System", "current_user", 0), 0, Service::Account::MAX_USERS - 1); 350 sdl2_config->GetInteger("System", "current_user", 0), 0, Service::Account::MAX_USERS - 1);
@@ -371,7 +371,7 @@ void Config::ReadValues() {
371 371
372 // Core 372 // Core
373 Settings::values.use_multi_core.SetValue( 373 Settings::values.use_multi_core.SetValue(
374 sdl2_config->GetBoolean("Core", "use_multi_core", false)); 374 sdl2_config->GetBoolean("Core", "use_multi_core", true));
375 375
376 // Renderer 376 // Renderer
377 const int renderer_backend = sdl2_config->GetInteger( 377 const int renderer_backend = sdl2_config->GetInteger(
@@ -395,11 +395,11 @@ void Config::ReadValues() {
395 const int gpu_accuracy_level = sdl2_config->GetInteger("Renderer", "gpu_accuracy", 0); 395 const int gpu_accuracy_level = sdl2_config->GetInteger("Renderer", "gpu_accuracy", 0);
396 Settings::values.gpu_accuracy.SetValue(static_cast<Settings::GPUAccuracy>(gpu_accuracy_level)); 396 Settings::values.gpu_accuracy.SetValue(static_cast<Settings::GPUAccuracy>(gpu_accuracy_level));
397 Settings::values.use_asynchronous_gpu_emulation.SetValue( 397 Settings::values.use_asynchronous_gpu_emulation.SetValue(
398 sdl2_config->GetBoolean("Renderer", "use_asynchronous_gpu_emulation", false)); 398 sdl2_config->GetBoolean("Renderer", "use_asynchronous_gpu_emulation", true));
399 Settings::values.use_vsync.SetValue( 399 Settings::values.use_vsync.SetValue(
400 static_cast<u16>(sdl2_config->GetInteger("Renderer", "use_vsync", 1))); 400 static_cast<u16>(sdl2_config->GetInteger("Renderer", "use_vsync", 1)));
401 Settings::values.use_assembly_shaders.SetValue( 401 Settings::values.use_assembly_shaders.SetValue(
402 sdl2_config->GetBoolean("Renderer", "use_assembly_shaders", false)); 402 sdl2_config->GetBoolean("Renderer", "use_assembly_shaders", true));
403 Settings::values.use_asynchronous_shaders.SetValue( 403 Settings::values.use_asynchronous_shaders.SetValue(
404 sdl2_config->GetBoolean("Renderer", "use_asynchronous_shaders", false)); 404 sdl2_config->GetBoolean("Renderer", "use_asynchronous_shaders", false));
405 Settings::values.use_asynchronous_shaders.SetValue( 405 Settings::values.use_asynchronous_shaders.SetValue(
@@ -429,9 +429,6 @@ void Config::ReadValues() {
429 // Debugging 429 // Debugging
430 Settings::values.record_frame_times = 430 Settings::values.record_frame_times =
431 sdl2_config->GetBoolean("Debugging", "record_frame_times", false); 431 sdl2_config->GetBoolean("Debugging", "record_frame_times", false);
432 Settings::values.use_gdbstub = sdl2_config->GetBoolean("Debugging", "use_gdbstub", false);
433 Settings::values.gdbstub_port =
434 static_cast<u16>(sdl2_config->GetInteger("Debugging", "gdbstub_port", 24689));
435 Settings::values.program_args = sdl2_config->Get("Debugging", "program_args", ""); 432 Settings::values.program_args = sdl2_config->Get("Debugging", "program_args", "");
436 Settings::values.dump_exefs = sdl2_config->GetBoolean("Debugging", "dump_exefs", false); 433 Settings::values.dump_exefs = sdl2_config->GetBoolean("Debugging", "dump_exefs", false);
437 Settings::values.dump_nso = sdl2_config->GetBoolean("Debugging", "dump_nso", false); 434 Settings::values.dump_nso = sdl2_config->GetBoolean("Debugging", "dump_nso", false);
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h
index aa9e40380..3ee0e037d 100644
--- a/src/yuzu_cmd/default_ini.h
+++ b/src/yuzu_cmd/default_ini.h
@@ -65,6 +65,14 @@ button_screenshot=
65lstick= 65lstick=
66rstick= 66rstick=
67 67
68# Whether to enable or disable vibration
69# 0: Disabled, 1 (default): Enabled
70vibration_enabled=
71
72# Whether to enable or disable accurate vibrations
73# 0 (default): Disabled, 1: Enabled
74enable_accurate_vibrations=
75
68# for motion input, the following devices are available: 76# for motion input, the following devices are available:
69# - "motion_emu" (default) for emulating motion input from mouse input. Required parameters: 77# - "motion_emu" (default) for emulating motion input from mouse input. Required parameters:
70# - "update_period": update period in milliseconds (default to 100) 78# - "update_period": update period in milliseconds (default to 100)
@@ -94,7 +102,7 @@ udp_pad_index=
94 102
95[Core] 103[Core]
96# Whether to use multi-core for CPU emulation 104# Whether to use multi-core for CPU emulation
97# 0 (default): Disabled, 1: Enabled 105# 0: Disabled, 1 (default): Enabled
98use_multi_core= 106use_multi_core=
99 107
100[Cpu] 108[Cpu]
@@ -163,7 +171,7 @@ max_anisotropy =
163use_vsync = 171use_vsync =
164 172
165# Whether to use OpenGL assembly shaders or not. NV_gpu_program5 is required. 173# Whether to use OpenGL assembly shaders or not. NV_gpu_program5 is required.
166# 0 (default): Off, 1: On 174# 0: Off, 1 (default): On
167use_assembly_shaders = 175use_assembly_shaders =
168 176
169# Whether to allow asynchronous shader building. 177# Whether to allow asynchronous shader building.
@@ -266,7 +274,7 @@ gamecard_path =
266 274
267[System] 275[System]
268# Whether the system is docked 276# Whether the system is docked
269# 1: Yes, 0 (default): No 277# 1 (default): Yes, 0: No
270use_docked_mode = 278use_docked_mode =
271 279
272# Allow the use of NFC in games 280# Allow the use of NFC in games
@@ -310,9 +318,6 @@ log_filter = *:Trace
310[Debugging] 318[Debugging]
311# Record frame time data, can be found in the log directory. Boolean value 319# Record frame time data, can be found in the log directory. Boolean value
312record_frame_times = 320record_frame_times =
313# Port for listening to GDB connections.
314use_gdbstub=false
315gdbstub_port=24689
316# Determines whether or not yuzu will dump the ExeFS of all games it attempts to load while loading them 321# Determines whether or not yuzu will dump the ExeFS of all games it attempts to load while loading them
317dump_exefs=false 322dump_exefs=false
318# Determines whether or not yuzu will dump all NSOs it attempts to load while loading them 323# Determines whether or not yuzu will dump all NSOs it attempts to load while loading them
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index 521209622..e32bed5e6 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -9,7 +9,7 @@
9#include "core/perf_stats.h" 9#include "core/perf_stats.h"
10#include "input_common/keyboard.h" 10#include "input_common/keyboard.h"
11#include "input_common/main.h" 11#include "input_common/main.h"
12#include "input_common/motion_emu.h" 12#include "input_common/mouse/mouse_input.h"
13#include "input_common/sdl/sdl.h" 13#include "input_common/sdl/sdl.h"
14#include "yuzu_cmd/emu_window/emu_window_sdl2.h" 14#include "yuzu_cmd/emu_window/emu_window_sdl2.h"
15 15
@@ -30,7 +30,7 @@ EmuWindow_SDL2::~EmuWindow_SDL2() {
30 30
31void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { 31void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
32 TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); 32 TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));
33 input_subsystem->GetMotionEmu()->Tilt(x, y); 33 input_subsystem->GetMouse()->MouseMove(x, y);
34} 34}
35 35
36void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { 36void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
@@ -42,9 +42,9 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
42 } 42 }
43 } else if (button == SDL_BUTTON_RIGHT) { 43 } else if (button == SDL_BUTTON_RIGHT) {
44 if (state == SDL_PRESSED) { 44 if (state == SDL_PRESSED) {
45 input_subsystem->GetMotionEmu()->BeginTilt(x, y); 45 input_subsystem->GetMouse()->PressButton(x, y, button);
46 } else { 46 } else {
47 input_subsystem->GetMotionEmu()->EndTilt(); 47 input_subsystem->GetMouse()->ReleaseButton(button);
48 } 48 }
49 } 49 }
50} 50}
@@ -121,62 +121,64 @@ void EmuWindow_SDL2::Fullscreen() {
121 SDL_MaximizeWindow(render_window); 121 SDL_MaximizeWindow(render_window);
122} 122}
123 123
124void EmuWindow_SDL2::PollEvents() { 124void EmuWindow_SDL2::WaitEvent() {
125 // Called on main thread
125 SDL_Event event; 126 SDL_Event event;
126 127
127 // SDL_PollEvent returns 0 when there are no more events in the event queue 128 if (!SDL_WaitEvent(&event)) {
128 while (SDL_PollEvent(&event)) { 129 LOG_CRITICAL(Frontend, "SDL_WaitEvent failed: {}", SDL_GetError());
129 switch (event.type) { 130 exit(1);
130 case SDL_WINDOWEVENT: 131 }
131 switch (event.window.event) { 132
132 case SDL_WINDOWEVENT_SIZE_CHANGED: 133 switch (event.type) {
133 case SDL_WINDOWEVENT_RESIZED: 134 case SDL_WINDOWEVENT:
134 case SDL_WINDOWEVENT_MAXIMIZED: 135 switch (event.window.event) {
135 case SDL_WINDOWEVENT_RESTORED: 136 case SDL_WINDOWEVENT_SIZE_CHANGED:
136 OnResize(); 137 case SDL_WINDOWEVENT_RESIZED:
137 break; 138 case SDL_WINDOWEVENT_MAXIMIZED:
138 case SDL_WINDOWEVENT_MINIMIZED: 139 case SDL_WINDOWEVENT_RESTORED:
139 case SDL_WINDOWEVENT_EXPOSED: 140 OnResize();
140 is_shown = event.window.event == SDL_WINDOWEVENT_EXPOSED;
141 OnResize();
142 break;
143 case SDL_WINDOWEVENT_CLOSE:
144 is_open = false;
145 break;
146 }
147 break;
148 case SDL_KEYDOWN:
149 case SDL_KEYUP:
150 OnKeyEvent(static_cast<int>(event.key.keysym.scancode), event.key.state);
151 break;
152 case SDL_MOUSEMOTION:
153 // ignore if it came from touch
154 if (event.button.which != SDL_TOUCH_MOUSEID)
155 OnMouseMotion(event.motion.x, event.motion.y);
156 break;
157 case SDL_MOUSEBUTTONDOWN:
158 case SDL_MOUSEBUTTONUP:
159 // ignore if it came from touch
160 if (event.button.which != SDL_TOUCH_MOUSEID) {
161 OnMouseButton(event.button.button, event.button.state, event.button.x,
162 event.button.y);
163 }
164 break;
165 case SDL_FINGERDOWN:
166 OnFingerDown(event.tfinger.x, event.tfinger.y);
167 break;
168 case SDL_FINGERMOTION:
169 OnFingerMotion(event.tfinger.x, event.tfinger.y);
170 break; 141 break;
171 case SDL_FINGERUP: 142 case SDL_WINDOWEVENT_MINIMIZED:
172 OnFingerUp(); 143 case SDL_WINDOWEVENT_EXPOSED:
144 is_shown = event.window.event == SDL_WINDOWEVENT_EXPOSED;
145 OnResize();
173 break; 146 break;
174 case SDL_QUIT: 147 case SDL_WINDOWEVENT_CLOSE:
175 is_open = false; 148 is_open = false;
176 break; 149 break;
177 default:
178 break;
179 } 150 }
151 break;
152 case SDL_KEYDOWN:
153 case SDL_KEYUP:
154 OnKeyEvent(static_cast<int>(event.key.keysym.scancode), event.key.state);
155 break;
156 case SDL_MOUSEMOTION:
157 // ignore if it came from touch
158 if (event.button.which != SDL_TOUCH_MOUSEID)
159 OnMouseMotion(event.motion.x, event.motion.y);
160 break;
161 case SDL_MOUSEBUTTONDOWN:
162 case SDL_MOUSEBUTTONUP:
163 // ignore if it came from touch
164 if (event.button.which != SDL_TOUCH_MOUSEID) {
165 OnMouseButton(event.button.button, event.button.state, event.button.x, event.button.y);
166 }
167 break;
168 case SDL_FINGERDOWN:
169 OnFingerDown(event.tfinger.x, event.tfinger.y);
170 break;
171 case SDL_FINGERMOTION:
172 OnFingerMotion(event.tfinger.x, event.tfinger.y);
173 break;
174 case SDL_FINGERUP:
175 OnFingerUp();
176 break;
177 case SDL_QUIT:
178 is_open = false;
179 break;
180 default:
181 break;
180 } 182 }
181 183
182 const u32 current_time = SDL_GetTicks(); 184 const u32 current_time = SDL_GetTicks();
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h
index 53d756c3c..a93141240 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h
@@ -23,38 +23,38 @@ public:
23 explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem); 23 explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem);
24 ~EmuWindow_SDL2(); 24 ~EmuWindow_SDL2();
25 25
26 /// Polls window events
27 void PollEvents() override;
28
29 /// Whether the window is still open, and a close request hasn't yet been sent 26 /// Whether the window is still open, and a close request hasn't yet been sent
30 bool IsOpen() const; 27 bool IsOpen() const;
31 28
32 /// Returns if window is shown (not minimized) 29 /// Returns if window is shown (not minimized)
33 bool IsShown() const override; 30 bool IsShown() const override;
34 31
32 /// Wait for the next event on the main thread.
33 void WaitEvent();
34
35protected: 35protected:
36 /// Called by PollEvents when a key is pressed or released. 36 /// Called by WaitEvent when a key is pressed or released.
37 void OnKeyEvent(int key, u8 state); 37 void OnKeyEvent(int key, u8 state);
38 38
39 /// Called by PollEvents when the mouse moves. 39 /// Called by WaitEvent when the mouse moves.
40 void OnMouseMotion(s32 x, s32 y); 40 void OnMouseMotion(s32 x, s32 y);
41 41
42 /// Called by PollEvents when a mouse button is pressed or released 42 /// Called by WaitEvent when a mouse button is pressed or released
43 void OnMouseButton(u32 button, u8 state, s32 x, s32 y); 43 void OnMouseButton(u32 button, u8 state, s32 x, s32 y);
44 44
45 /// Translates pixel position (0..1) to pixel positions 45 /// Translates pixel position (0..1) to pixel positions
46 std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const; 46 std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const;
47 47
48 /// Called by PollEvents when a finger starts touching the touchscreen 48 /// Called by WaitEvent when a finger starts touching the touchscreen
49 void OnFingerDown(float x, float y); 49 void OnFingerDown(float x, float y);
50 50
51 /// Called by PollEvents when a finger moves while touching the touchscreen 51 /// Called by WaitEvent when a finger moves while touching the touchscreen
52 void OnFingerMotion(float x, float y); 52 void OnFingerMotion(float x, float y);
53 53
54 /// Called by PollEvents when a finger stops touching the touchscreen 54 /// Called by WaitEvent when a finger stops touching the touchscreen
55 void OnFingerUp(); 55 void OnFingerUp();
56 56
57 /// Called by PollEvents when any event that may cause the window to be resized occurs 57 /// Called by WaitEvent when any event that may cause the window to be resized occurs
58 void OnResize(); 58 void OnResize();
59 59
60 /// Called when user passes the fullscreen parameter flag 60 /// Called when user passes the fullscreen parameter flag
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp
index 5f35233b5..a103b04bd 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp
@@ -17,7 +17,6 @@
17#include "core/settings.h" 17#include "core/settings.h"
18#include "input_common/keyboard.h" 18#include "input_common/keyboard.h"
19#include "input_common/main.h" 19#include "input_common/main.h"
20#include "input_common/motion_emu.h"
21#include "video_core/renderer_base.h" 20#include "video_core/renderer_base.h"
22#include "yuzu_cmd/emu_window/emu_window_sdl2_gl.h" 21#include "yuzu_cmd/emu_window/emu_window_sdl2_gl.h"
23 22
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index 3a76c785f..4faf62ede 100644
--- a/src/yuzu_cmd/yuzu.cpp
+++ b/src/yuzu_cmd/yuzu.cpp
@@ -25,7 +25,6 @@
25#include "core/crypto/key_manager.h" 25#include "core/crypto/key_manager.h"
26#include "core/file_sys/registered_cache.h" 26#include "core/file_sys/registered_cache.h"
27#include "core/file_sys/vfs_real.h" 27#include "core/file_sys/vfs_real.h"
28#include "core/gdbstub/gdbstub.h"
29#include "core/hle/kernel/process.h" 28#include "core/hle/kernel/process.h"
30#include "core/hle/service/filesystem/filesystem.h" 29#include "core/hle/service/filesystem/filesystem.h"
31#include "core/loader/loader.h" 30#include "core/loader/loader.h"
@@ -36,9 +35,7 @@
36#include "yuzu_cmd/config.h" 35#include "yuzu_cmd/config.h"
37#include "yuzu_cmd/emu_window/emu_window_sdl2.h" 36#include "yuzu_cmd/emu_window/emu_window_sdl2.h"
38#include "yuzu_cmd/emu_window/emu_window_sdl2_gl.h" 37#include "yuzu_cmd/emu_window/emu_window_sdl2_gl.h"
39#ifdef HAS_VULKAN
40#include "yuzu_cmd/emu_window/emu_window_sdl2_vk.h" 38#include "yuzu_cmd/emu_window/emu_window_sdl2_vk.h"
41#endif
42 39
43#ifdef _WIN32 40#ifdef _WIN32
44// windows.h needs to be included before shellapi.h 41// windows.h needs to be included before shellapi.h
@@ -65,7 +62,6 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
65static void PrintHelp(const char* argv0) { 62static void PrintHelp(const char* argv0) {
66 std::cout << "Usage: " << argv0 63 std::cout << "Usage: " << argv0
67 << " [options] <filename>\n" 64 << " [options] <filename>\n"
68 "-g, --gdbport=NUMBER Enable gdb stub on port NUMBER\n"
69 "-f, --fullscreen Start in fullscreen mode\n" 65 "-f, --fullscreen Start in fullscreen mode\n"
70 "-h, --help Display this help and exit\n" 66 "-h, --help Display this help and exit\n"
71 "-v, --version Output version information and exit\n" 67 "-v, --version Output version information and exit\n"
@@ -97,12 +93,8 @@ int main(int argc, char** argv) {
97 Config config; 93 Config config;
98 94
99 int option_index = 0; 95 int option_index = 0;
100 bool use_gdbstub = Settings::values.use_gdbstub;
101 u32 gdb_port = static_cast<u32>(Settings::values.gdbstub_port);
102 96
103 InitializeLogging(); 97 InitializeLogging();
104
105 char* endarg;
106#ifdef _WIN32 98#ifdef _WIN32
107 int argc_w; 99 int argc_w;
108 auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w); 100 auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w);
@@ -117,26 +109,17 @@ int main(int argc, char** argv) {
117 bool fullscreen = false; 109 bool fullscreen = false;
118 110
119 static struct option long_options[] = { 111 static struct option long_options[] = {
120 {"gdbport", required_argument, 0, 'g'}, {"fullscreen", no_argument, 0, 'f'}, 112 {"fullscreen", no_argument, 0, 'f'},
121 {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, 113 {"help", no_argument, 0, 'h'},
122 {"program", optional_argument, 0, 'p'}, {0, 0, 0, 0}, 114 {"version", no_argument, 0, 'v'},
115 {"program", optional_argument, 0, 'p'},
116 {0, 0, 0, 0},
123 }; 117 };
124 118
125 while (optind < argc) { 119 while (optind < argc) {
126 int arg = getopt_long(argc, argv, "g:fhvp::", long_options, &option_index); 120 int arg = getopt_long(argc, argv, "g:fhvp::", long_options, &option_index);
127 if (arg != -1) { 121 if (arg != -1) {
128 switch (static_cast<char>(arg)) { 122 switch (static_cast<char>(arg)) {
129 case 'g':
130 errno = 0;
131 gdb_port = strtoul(optarg, &endarg, 0);
132 use_gdbstub = true;
133 if (endarg == optarg)
134 errno = EINVAL;
135 if (errno != 0) {
136 perror("--gdbport");
137 exit(1);
138 }
139 break;
140 case 'f': 123 case 'f':
141 fullscreen = true; 124 fullscreen = true;
142 LOG_INFO(Frontend, "Starting in fullscreen mode..."); 125 LOG_INFO(Frontend, "Starting in fullscreen mode...");
@@ -174,27 +157,20 @@ int main(int argc, char** argv) {
174 return -1; 157 return -1;
175 } 158 }
176 159
177 // Apply the command line arguments 160 auto& system{Core::System::GetInstance()};
178 Settings::values.gdbstub_port = gdb_port;
179 Settings::values.use_gdbstub = use_gdbstub;
180 Settings::Apply();
181
182 Core::System& system{Core::System::GetInstance()};
183 InputCommon::InputSubsystem input_subsystem; 161 InputCommon::InputSubsystem input_subsystem;
184 162
163 // Apply the command line arguments
164 Settings::Apply(system);
165
185 std::unique_ptr<EmuWindow_SDL2> emu_window; 166 std::unique_ptr<EmuWindow_SDL2> emu_window;
186 switch (Settings::values.renderer_backend.GetValue()) { 167 switch (Settings::values.renderer_backend.GetValue()) {
187 case Settings::RendererBackend::OpenGL: 168 case Settings::RendererBackend::OpenGL:
188 emu_window = std::make_unique<EmuWindow_SDL2_GL>(&input_subsystem, fullscreen); 169 emu_window = std::make_unique<EmuWindow_SDL2_GL>(&input_subsystem, fullscreen);
189 break; 170 break;
190 case Settings::RendererBackend::Vulkan: 171 case Settings::RendererBackend::Vulkan:
191#ifdef HAS_VULKAN
192 emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem); 172 emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem);
193 break; 173 break;
194#else
195 LOG_CRITICAL(Frontend, "Vulkan backend has not been compiled!");
196 return 1;
197#endif
198 } 174 }
199 175
200 system.SetContentProvider(std::make_unique<FileSys::ContentProviderUnion>()); 176 system.SetContentProvider(std::make_unique<FileSys::ContentProviderUnion>());
@@ -224,7 +200,7 @@ int main(int argc, char** argv) {
224 const u16 loader_id = static_cast<u16>(Core::System::ResultStatus::ErrorLoader); 200 const u16 loader_id = static_cast<u16>(Core::System::ResultStatus::ErrorLoader);
225 const u16 error_id = static_cast<u16>(load_result) - loader_id; 201 const u16 error_id = static_cast<u16>(load_result) - loader_id;
226 LOG_CRITICAL(Frontend, 202 LOG_CRITICAL(Frontend,
227 "While attempting to load the ROM requested, an error occured. Please " 203 "While attempting to load the ROM requested, an error occurred. Please "
228 "refer to the yuzu wiki for more information or the yuzu discord for " 204 "refer to the yuzu wiki for more information or the yuzu discord for "
229 "additional help.\n\nError Code: {:04X}-{:04X}\nError Description: {}", 205 "additional help.\n\nError Code: {:04X}-{:04X}\nError Description: {}",
230 loader_id, error_id, static_cast<Loader::ResultStatus>(error_id)); 206 loader_id, error_id, static_cast<Loader::ResultStatus>(error_id));
@@ -240,11 +216,11 @@ int main(int argc, char** argv) {
240 system.CurrentProcess()->GetTitleID(), false, 216 system.CurrentProcess()->GetTitleID(), false,
241 [](VideoCore::LoadCallbackStage, size_t value, size_t total) {}); 217 [](VideoCore::LoadCallbackStage, size_t value, size_t total) {});
242 218
243 system.Run(); 219 void(system.Run());
244 while (emu_window->IsOpen()) { 220 while (emu_window->IsOpen()) {
245 std::this_thread::sleep_for(std::chrono::milliseconds(1)); 221 emu_window->WaitEvent();
246 } 222 }
247 system.Pause(); 223 void(system.Pause());
248 system.Shutdown(); 224 system.Shutdown();
249 225
250 detached_tasks.WaitForAllTasks(); 226 detached_tasks.WaitForAllTasks();