summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/fs/fs_paths.h1
-rw-r--r--src/common/fs/path_util.cpp1
-rw-r--r--src/common/fs/path_util.h1
-rw-r--r--src/common/settings.cpp5
-rw-r--r--src/common/settings.h12
-rw-r--r--src/common/threadsafe_queue.h27
-rw-r--r--src/core/core.cpp21
-rw-r--r--src/core/file_sys/vfs.cpp4
-rw-r--r--src/core/file_sys/vfs.h3
-rw-r--r--src/core/file_sys/vfs_real.cpp29
-rw-r--r--src/core/file_sys/vfs_real.h1
-rw-r--r--src/core/file_sys/vfs_types.h9
-rw-r--r--src/core/hle/service/filesystem/filesystem.cpp12
-rw-r--r--src/core/hle/service/filesystem/filesystem.h6
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp20
-rw-r--r--src/core/hle/service/ngct/ngct.cpp15
-rw-r--r--src/core/telemetry_session.cpp2
-rw-r--r--src/input_common/CMakeLists.txt4
-rw-r--r--src/input_common/main.cpp52
-rw-r--r--src/input_common/main.h39
-rw-r--r--src/input_common/sdl/sdl_impl.cpp12
-rw-r--r--src/input_common/tas/tas_input.cpp455
-rw-r--r--src/input_common/tas/tas_input.h237
-rw-r--r--src/input_common/tas/tas_poller.cpp101
-rw-r--r--src/input_common/tas/tas_poller.h43
-rw-r--r--src/input_common/udp/client.h2
-rw-r--r--src/video_core/gpu.cpp8
-rw-r--r--src/video_core/gpu.h3
-rw-r--r--src/video_core/gpu_thread.cpp57
-rw-r--r--src/video_core/gpu_thread.h13
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp2
-rw-r--r--src/video_core/renderer_vulkan/vk_pipeline_cache.cpp2
-rw-r--r--src/video_core/renderer_vulkan/vk_scheduler.cpp19
-rw-r--r--src/video_core/renderer_vulkan/vk_scheduler.h7
-rw-r--r--src/video_core/vulkan_common/vulkan_debug_callback.cpp1
-rw-r--r--src/video_core/vulkan_common/vulkan_device.cpp17
-rw-r--r--src/yuzu/CMakeLists.txt3
-rw-r--r--src/yuzu/bootmanager.cpp2
-rw-r--r--src/yuzu/configuration/config.cpp30
-rw-r--r--src/yuzu/configuration/config.h2
-rw-r--r--src/yuzu/configuration/configure_audio.cpp9
-rw-r--r--src/yuzu/configuration/configure_audio.h2
-rw-r--r--src/yuzu/configuration/configure_audio.ui10
-rw-r--r--src/yuzu/configuration/configure_input_advanced.cpp2
-rw-r--r--src/yuzu/configuration/configure_input_advanced.ui16
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp30
-rw-r--r--src/yuzu/configuration/configure_input_player_widget.cpp19
-rw-r--r--src/yuzu/configuration/configure_input_player_widget.h3
-rw-r--r--src/yuzu/configuration/configure_tas.cpp84
-rw-r--r--src/yuzu/configuration/configure_tas.h38
-rw-r--r--src/yuzu/configuration/configure_tas.ui183
-rw-r--r--src/yuzu/configuration/configure_vibration.cpp2
-rw-r--r--src/yuzu/debugger/controller.cpp18
-rw-r--r--src/yuzu/debugger/controller.h22
-rw-r--r--src/yuzu/main.cpp70
-rw-r--r--src/yuzu/main.h3
-rw-r--r--src/yuzu/main.ui6
-rw-r--r--src/yuzu_cmd/config.cpp1
58 files changed, 1627 insertions, 171 deletions
diff --git a/src/common/fs/fs_paths.h b/src/common/fs/fs_paths.h
index b32614797..5d447f108 100644
--- a/src/common/fs/fs_paths.h
+++ b/src/common/fs/fs_paths.h
@@ -21,6 +21,7 @@
21#define SCREENSHOTS_DIR "screenshots" 21#define SCREENSHOTS_DIR "screenshots"
22#define SDMC_DIR "sdmc" 22#define SDMC_DIR "sdmc"
23#define SHADER_DIR "shader" 23#define SHADER_DIR "shader"
24#define TAS_DIR "tas"
24 25
25// yuzu-specific files 26// yuzu-specific files
26 27
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp
index 6cdd14f13..43b79bd6d 100644
--- a/src/common/fs/path_util.cpp
+++ b/src/common/fs/path_util.cpp
@@ -116,6 +116,7 @@ private:
116 GenerateYuzuPath(YuzuPath::ScreenshotsDir, yuzu_path / SCREENSHOTS_DIR); 116 GenerateYuzuPath(YuzuPath::ScreenshotsDir, yuzu_path / SCREENSHOTS_DIR);
117 GenerateYuzuPath(YuzuPath::SDMCDir, yuzu_path / SDMC_DIR); 117 GenerateYuzuPath(YuzuPath::SDMCDir, yuzu_path / SDMC_DIR);
118 GenerateYuzuPath(YuzuPath::ShaderDir, yuzu_path / SHADER_DIR); 118 GenerateYuzuPath(YuzuPath::ShaderDir, yuzu_path / SHADER_DIR);
119 GenerateYuzuPath(YuzuPath::TASDir, yuzu_path / TAS_DIR);
119 } 120 }
120 121
121 ~PathManagerImpl() = default; 122 ~PathManagerImpl() = default;
diff --git a/src/common/fs/path_util.h b/src/common/fs/path_util.h
index f956ac9a2..0a9e3a145 100644
--- a/src/common/fs/path_util.h
+++ b/src/common/fs/path_util.h
@@ -23,6 +23,7 @@ enum class YuzuPath {
23 ScreenshotsDir, // Where yuzu screenshots are stored. 23 ScreenshotsDir, // Where yuzu screenshots are stored.
24 SDMCDir, // Where the emulated SDMC is stored. 24 SDMCDir, // Where the emulated SDMC is stored.
25 ShaderDir, // Where shaders are stored. 25 ShaderDir, // Where shaders are stored.
26 TASDir, // Where TAS scripts are stored.
26}; 27};
27 28
28/** 29/**
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 0d2df80a8..69f0bd8c0 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -61,7 +61,6 @@ void LogSettings() {
61 log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); 61 log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue());
62 log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); 62 log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue());
63 log_setting("Audio_OutputEngine", values.sink_id.GetValue()); 63 log_setting("Audio_OutputEngine", values.sink_id.GetValue());
64 log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue());
65 log_setting("Audio_OutputDevice", values.audio_device_id.GetValue()); 64 log_setting("Audio_OutputDevice", values.audio_device_id.GetValue());
66 log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue()); 65 log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue());
67 log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir)); 66 log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir));
@@ -72,6 +71,9 @@ void LogSettings() {
72 log_setting("Debugging_ProgramArgs", values.program_args.GetValue()); 71 log_setting("Debugging_ProgramArgs", values.program_args.GetValue());
73 log_setting("Services_BCATBackend", values.bcat_backend.GetValue()); 72 log_setting("Services_BCATBackend", values.bcat_backend.GetValue());
74 log_setting("Services_BCATBoxcatLocal", values.bcat_boxcat_local.GetValue()); 73 log_setting("Services_BCATBoxcatLocal", values.bcat_boxcat_local.GetValue());
74 log_setting("Input_EnableMotion", values.motion_enabled.GetValue());
75 log_setting("Input_EnableVibration", values.vibration_enabled.GetValue());
76 log_setting("Input_EnableRawInput", values.enable_raw_input.GetValue());
75} 77}
76 78
77bool IsConfiguringGlobal() { 79bool IsConfiguringGlobal() {
@@ -112,7 +114,6 @@ void RestoreGlobalState(bool is_powered_on) {
112 } 114 }
113 115
114 // Audio 116 // Audio
115 values.enable_audio_stretching.SetGlobal(true);
116 values.volume.SetGlobal(true); 117 values.volume.SetGlobal(true);
117 118
118 // Core 119 // Core
diff --git a/src/common/settings.h b/src/common/settings.h
index b7195670b..c53d5acc3 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -16,7 +16,6 @@
16 16
17#include "common/common_types.h" 17#include "common/common_types.h"
18#include "common/settings_input.h" 18#include "common/settings_input.h"
19#include "input_common/udp/client.h"
20 19
21namespace Settings { 20namespace Settings {
22 21
@@ -415,7 +414,6 @@ struct Values {
415 BasicSetting<std::string> audio_device_id{"auto", "output_device"}; 414 BasicSetting<std::string> audio_device_id{"auto", "output_device"};
416 BasicSetting<std::string> sink_id{"auto", "output_engine"}; 415 BasicSetting<std::string> sink_id{"auto", "output_engine"};
417 BasicSetting<bool> audio_muted{false, "audio_muted"}; 416 BasicSetting<bool> audio_muted{false, "audio_muted"};
418 Setting<bool> enable_audio_stretching{true, "enable_audio_stretching"};
419 RangedSetting<u8> volume{100, 0, 100, "volume"}; 417 RangedSetting<u8> volume{100, 0, 100, "volume"};
420 418
421 // Core 419 // Core
@@ -504,14 +502,20 @@ struct Values {
504 502
505 Setting<bool> use_docked_mode{true, "use_docked_mode"}; 503 Setting<bool> use_docked_mode{true, "use_docked_mode"};
506 504
505 BasicSetting<bool> enable_raw_input{false, "enable_raw_input"};
506
507 Setting<bool> vibration_enabled{true, "vibration_enabled"}; 507 Setting<bool> vibration_enabled{true, "vibration_enabled"};
508 Setting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"}; 508 Setting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"};
509 509
510 Setting<bool> motion_enabled{true, "motion_enabled"}; 510 Setting<bool> motion_enabled{true, "motion_enabled"};
511 BasicSetting<std::string> motion_device{"engine:motion_emu,update_period:100,sensitivity:0.01", 511 BasicSetting<std::string> motion_device{"engine:motion_emu,update_period:100,sensitivity:0.01",
512 "motion_device"}; 512 "motion_device"};
513 BasicSetting<std::string> udp_input_servers{InputCommon::CemuhookUDP::DEFAULT_SRV, 513 BasicSetting<std::string> udp_input_servers{"127.0.0.1:26760", "udp_input_servers"};
514 "udp_input_servers"}; 514
515 BasicSetting<bool> pause_tas_on_load{true, "pause_tas_on_load"};
516 BasicSetting<bool> tas_enable{false, "tas_enable"};
517 BasicSetting<bool> tas_loop{false, "tas_loop"};
518 BasicSetting<bool> tas_swap_controllers{true, "tas_swap_controllers"};
515 519
516 BasicSetting<bool> mouse_panning{false, "mouse_panning"}; 520 BasicSetting<bool> mouse_panning{false, "mouse_panning"};
517 BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; 521 BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"};
diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h
index 8430b9778..2c8c2b90e 100644
--- a/src/common/threadsafe_queue.h
+++ b/src/common/threadsafe_queue.h
@@ -14,7 +14,7 @@
14#include <utility> 14#include <utility>
15 15
16namespace Common { 16namespace Common {
17template <typename T> 17template <typename T, bool with_stop_token = false>
18class SPSCQueue { 18class SPSCQueue {
19public: 19public:
20 SPSCQueue() { 20 SPSCQueue() {
@@ -84,7 +84,7 @@ public:
84 void Wait() { 84 void Wait() {
85 if (Empty()) { 85 if (Empty()) {
86 std::unique_lock lock{cv_mutex}; 86 std::unique_lock lock{cv_mutex};
87 cv.wait(lock, [this]() { return !Empty(); }); 87 cv.wait(lock, [this] { return !Empty(); });
88 } 88 }
89 } 89 }
90 90
@@ -95,6 +95,19 @@ public:
95 return t; 95 return t;
96 } 96 }
97 97
98 T PopWait(std::stop_token stop_token) {
99 if (Empty()) {
100 std::unique_lock lock{cv_mutex};
101 cv.wait(lock, stop_token, [this] { return !Empty(); });
102 }
103 if (stop_token.stop_requested()) {
104 return T{};
105 }
106 T t;
107 Pop(t);
108 return t;
109 }
110
98 // not thread-safe 111 // not thread-safe
99 void Clear() { 112 void Clear() {
100 size.store(0); 113 size.store(0);
@@ -123,13 +136,13 @@ private:
123 ElementPtr* read_ptr; 136 ElementPtr* read_ptr;
124 std::atomic_size_t size{0}; 137 std::atomic_size_t size{0};
125 std::mutex cv_mutex; 138 std::mutex cv_mutex;
126 std::condition_variable cv; 139 std::conditional_t<with_stop_token, std::condition_variable_any, std::condition_variable> cv;
127}; 140};
128 141
129// a simple thread-safe, 142// a simple thread-safe,
130// single reader, multiple writer queue 143// single reader, multiple writer queue
131 144
132template <typename T> 145template <typename T, bool with_stop_token = false>
133class MPSCQueue { 146class MPSCQueue {
134public: 147public:
135 [[nodiscard]] std::size_t Size() const { 148 [[nodiscard]] std::size_t Size() const {
@@ -166,13 +179,17 @@ public:
166 return spsc_queue.PopWait(); 179 return spsc_queue.PopWait();
167 } 180 }
168 181
182 T PopWait(std::stop_token stop_token) {
183 return spsc_queue.PopWait(stop_token);
184 }
185
169 // not thread-safe 186 // not thread-safe
170 void Clear() { 187 void Clear() {
171 spsc_queue.Clear(); 188 spsc_queue.Clear();
172 } 189 }
173 190
174private: 191private:
175 SPSCQueue<T> spsc_queue; 192 SPSCQueue<T, with_stop_token> spsc_queue;
176 std::mutex write_lock; 193 std::mutex write_lock;
177}; 194};
178} // namespace Common 195} // namespace Common
diff --git a/src/core/core.cpp b/src/core/core.cpp
index ba4629993..54ebed2c1 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -83,6 +83,12 @@ FileSys::StorageId GetStorageIdForFrontendSlot(
83 } 83 }
84} 84}
85 85
86void KProcessDeleter(Kernel::KProcess* process) {
87 process->Destroy();
88}
89
90using KProcessPtr = std::unique_ptr<Kernel::KProcess, decltype(&KProcessDeleter)>;
91
86} // Anonymous namespace 92} // Anonymous namespace
87 93
88FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, 94FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
@@ -233,8 +239,8 @@ struct System::Impl {
233 } 239 }
234 240
235 telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); 241 telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider);
236 auto main_process = Kernel::KProcess::Create(system.Kernel()); 242 main_process = KProcessPtr{Kernel::KProcess::Create(system.Kernel()), KProcessDeleter};
237 ASSERT(Kernel::KProcess::Initialize(main_process, system, "main", 243 ASSERT(Kernel::KProcess::Initialize(main_process.get(), system, "main",
238 Kernel::KProcess::ProcessType::Userland) 244 Kernel::KProcess::ProcessType::Userland)
239 .IsSuccess()); 245 .IsSuccess());
240 main_process->Open(); 246 main_process->Open();
@@ -247,7 +253,7 @@ struct System::Impl {
247 static_cast<u32>(load_result)); 253 static_cast<u32>(load_result));
248 } 254 }
249 AddGlueRegistrationForProcess(*app_loader, *main_process); 255 AddGlueRegistrationForProcess(*app_loader, *main_process);
250 kernel.MakeCurrentProcess(main_process); 256 kernel.MakeCurrentProcess(main_process.get());
251 kernel.InitializeCores(); 257 kernel.InitializeCores();
252 258
253 // Initialize cheat engine 259 // Initialize cheat engine
@@ -299,10 +305,7 @@ struct System::Impl {
299 is_powered_on = false; 305 is_powered_on = false;
300 exit_lock = false; 306 exit_lock = false;
301 307
302 if (gpu_core) { 308 gpu_core.reset();
303 gpu_core->ShutDown();
304 }
305
306 services.reset(); 309 services.reset();
307 service_manager.reset(); 310 service_manager.reset();
308 cheat_engine.reset(); 311 cheat_engine.reset();
@@ -311,11 +314,12 @@ struct System::Impl {
311 time_manager.Shutdown(); 314 time_manager.Shutdown();
312 core_timing.Shutdown(); 315 core_timing.Shutdown();
313 app_loader.reset(); 316 app_loader.reset();
314 gpu_core.reset();
315 perf_stats.reset(); 317 perf_stats.reset();
316 kernel.Shutdown(); 318 kernel.Shutdown();
317 memory.Reset(); 319 memory.Reset();
318 applet_manager.ClearAll(); 320 applet_manager.ClearAll();
321 // TODO: The main process should be freed based on KAutoObject ref counting.
322 main_process.reset();
319 323
320 LOG_DEBUG(Core, "Shutdown OK"); 324 LOG_DEBUG(Core, "Shutdown OK");
321 } 325 }
@@ -374,6 +378,7 @@ struct System::Impl {
374 std::unique_ptr<Tegra::GPU> gpu_core; 378 std::unique_ptr<Tegra::GPU> gpu_core;
375 std::unique_ptr<Hardware::InterruptManager> interrupt_manager; 379 std::unique_ptr<Hardware::InterruptManager> interrupt_manager;
376 std::unique_ptr<Core::DeviceMemory> device_memory; 380 std::unique_ptr<Core::DeviceMemory> device_memory;
381 KProcessPtr main_process{nullptr, KProcessDeleter};
377 Core::Memory::Memory memory; 382 Core::Memory::Memory memory;
378 CpuManager cpu_manager; 383 CpuManager cpu_manager;
379 std::atomic_bool is_powered_on{}; 384 std::atomic_bool is_powered_on{};
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp
index 368419eca..f5ad10b15 100644
--- a/src/core/file_sys/vfs.cpp
+++ b/src/core/file_sys/vfs.cpp
@@ -273,6 +273,10 @@ VirtualFile VfsDirectory::GetFile(std::string_view name) const {
273 return iter == files.end() ? nullptr : *iter; 273 return iter == files.end() ? nullptr : *iter;
274} 274}
275 275
276FileTimeStampRaw VfsDirectory::GetFileTimeStamp([[maybe_unused]] std::string_view path) const {
277 return {};
278}
279
276VirtualDir VfsDirectory::GetSubdirectory(std::string_view name) const { 280VirtualDir VfsDirectory::GetSubdirectory(std::string_view name) const {
277 const auto& subs = GetSubdirectories(); 281 const auto& subs = GetSubdirectories();
278 const auto iter = std::find_if(subs.begin(), subs.end(), 282 const auto iter = std::find_if(subs.begin(), subs.end(),
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h
index afd64e95c..ff6935da6 100644
--- a/src/core/file_sys/vfs.h
+++ b/src/core/file_sys/vfs.h
@@ -199,6 +199,9 @@ public:
199 // file with name. 199 // file with name.
200 virtual VirtualFile GetFile(std::string_view name) const; 200 virtual VirtualFile GetFile(std::string_view name) const;
201 201
202 // Returns a struct containing the file's timestamp.
203 virtual FileTimeStampRaw GetFileTimeStamp(std::string_view path) const;
204
202 // Returns a vector containing all of the subdirectories in this directory. 205 // Returns a vector containing all of the subdirectories in this directory.
203 virtual std::vector<VirtualDir> GetSubdirectories() const = 0; 206 virtual std::vector<VirtualDir> GetSubdirectories() const = 0;
204 // Returns the directory with name matching name. Returns nullptr if directory dosen't have a 207 // Returns the directory with name matching name. Returns nullptr if directory dosen't have a
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp
index 3dad54f49..f4073b76a 100644
--- a/src/core/file_sys/vfs_real.cpp
+++ b/src/core/file_sys/vfs_real.cpp
@@ -13,6 +13,13 @@
13#include "common/logging/log.h" 13#include "common/logging/log.h"
14#include "core/file_sys/vfs_real.h" 14#include "core/file_sys/vfs_real.h"
15 15
16// For FileTimeStampRaw
17#include <sys/stat.h>
18
19#ifdef _MSC_VER
20#define stat _stat64
21#endif
22
16namespace FileSys { 23namespace FileSys {
17 24
18namespace FS = Common::FS; 25namespace FS = Common::FS;
@@ -392,6 +399,28 @@ std::vector<VirtualFile> RealVfsDirectory::GetFiles() const {
392 return IterateEntries<RealVfsFile, VfsFile>(); 399 return IterateEntries<RealVfsFile, VfsFile>();
393} 400}
394 401
402FileTimeStampRaw RealVfsDirectory::GetFileTimeStamp(std::string_view path_) const {
403 const auto full_path = FS::SanitizePath(path + '/' + std::string(path_));
404 const auto fs_path = std::filesystem::path{FS::ToU8String(full_path)};
405 struct stat file_status;
406
407#ifdef _WIN32
408 const auto stat_result = _wstat64(fs_path.c_str(), &file_status);
409#else
410 const auto stat_result = stat(fs_path.c_str(), &file_status);
411#endif
412
413 if (stat_result != 0) {
414 return {};
415 }
416
417 return {
418 .created{static_cast<u64>(file_status.st_ctime)},
419 .accessed{static_cast<u64>(file_status.st_atime)},
420 .modified{static_cast<u64>(file_status.st_mtime)},
421 };
422}
423
395std::vector<VirtualDir> RealVfsDirectory::GetSubdirectories() const { 424std::vector<VirtualDir> RealVfsDirectory::GetSubdirectories() const {
396 return IterateEntries<RealVfsDirectory, VfsDirectory>(); 425 return IterateEntries<RealVfsDirectory, VfsDirectory>();
397} 426}
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h
index e4d1bba79..746e624cb 100644
--- a/src/core/file_sys/vfs_real.h
+++ b/src/core/file_sys/vfs_real.h
@@ -86,6 +86,7 @@ public:
86 VirtualDir CreateDirectoryRelative(std::string_view relative_path) override; 86 VirtualDir CreateDirectoryRelative(std::string_view relative_path) override;
87 bool DeleteSubdirectoryRecursive(std::string_view name) override; 87 bool DeleteSubdirectoryRecursive(std::string_view name) override;
88 std::vector<VirtualFile> GetFiles() const override; 88 std::vector<VirtualFile> GetFiles() const override;
89 FileTimeStampRaw GetFileTimeStamp(std::string_view path) const override;
89 std::vector<VirtualDir> GetSubdirectories() const override; 90 std::vector<VirtualDir> GetSubdirectories() const override;
90 bool IsWritable() const override; 91 bool IsWritable() const override;
91 bool IsReadable() const override; 92 bool IsReadable() const override;
diff --git a/src/core/file_sys/vfs_types.h b/src/core/file_sys/vfs_types.h
index 6215ed7af..ed0724717 100644
--- a/src/core/file_sys/vfs_types.h
+++ b/src/core/file_sys/vfs_types.h
@@ -6,6 +6,8 @@
6 6
7#include <memory> 7#include <memory>
8 8
9#include "common/common_types.h"
10
9namespace FileSys { 11namespace FileSys {
10 12
11class VfsDirectory; 13class VfsDirectory;
@@ -18,4 +20,11 @@ using VirtualDir = std::shared_ptr<VfsDirectory>;
18using VirtualFile = std::shared_ptr<VfsFile>; 20using VirtualFile = std::shared_ptr<VfsFile>;
19using VirtualFilesystem = std::shared_ptr<VfsFilesystem>; 21using VirtualFilesystem = std::shared_ptr<VfsFilesystem>;
20 22
23struct FileTimeStampRaw {
24 u64 created{};
25 u64 accessed{};
26 u64 modified{};
27 u64 padding{};
28};
29
21} // namespace FileSys 30} // namespace FileSys
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp
index c8d65f328..f8f9e32f7 100644
--- a/src/core/hle/service/filesystem/filesystem.cpp
+++ b/src/core/hle/service/filesystem/filesystem.cpp
@@ -261,6 +261,18 @@ ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType(
261 return FileSys::ERROR_PATH_NOT_FOUND; 261 return FileSys::ERROR_PATH_NOT_FOUND;
262} 262}
263 263
264ResultVal<FileSys::FileTimeStampRaw> VfsDirectoryServiceWrapper::GetFileTimeStampRaw(
265 const std::string& path) const {
266 auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path));
267 if (dir == nullptr) {
268 return FileSys::ERROR_PATH_NOT_FOUND;
269 }
270 if (GetEntryType(path).Failed()) {
271 return FileSys::ERROR_PATH_NOT_FOUND;
272 }
273 return MakeResult(dir->GetFileTimeStamp(Common::FS::GetFilename(path)));
274}
275
264FileSystemController::FileSystemController(Core::System& system_) : system{system_} {} 276FileSystemController::FileSystemController(Core::System& system_) : system{system_} {}
265 277
266FileSystemController::~FileSystemController() = default; 278FileSystemController::~FileSystemController() = default;
diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h
index d387af3cb..b155e0811 100644
--- a/src/core/hle/service/filesystem/filesystem.h
+++ b/src/core/hle/service/filesystem/filesystem.h
@@ -240,6 +240,12 @@ public:
240 */ 240 */
241 ResultVal<FileSys::EntryType> GetEntryType(const std::string& path) const; 241 ResultVal<FileSys::EntryType> GetEntryType(const std::string& path) const;
242 242
243 /**
244 * Get the timestamp of the specified path
245 * @return The timestamp of the specified path or error code
246 */
247 ResultVal<FileSys::FileTimeStampRaw> GetFileTimeStampRaw(const std::string& path) const;
248
243private: 249private:
244 FileSys::VirtualDir backing; 250 FileSys::VirtualDir backing;
245}; 251};
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index db4d44c12..50c788dd6 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -326,7 +326,7 @@ public:
326 {11, &IFileSystem::GetFreeSpaceSize, "GetFreeSpaceSize"}, 326 {11, &IFileSystem::GetFreeSpaceSize, "GetFreeSpaceSize"},
327 {12, &IFileSystem::GetTotalSpaceSize, "GetTotalSpaceSize"}, 327 {12, &IFileSystem::GetTotalSpaceSize, "GetTotalSpaceSize"},
328 {13, &IFileSystem::CleanDirectoryRecursively, "CleanDirectoryRecursively"}, 328 {13, &IFileSystem::CleanDirectoryRecursively, "CleanDirectoryRecursively"},
329 {14, nullptr, "GetFileTimeStampRaw"}, 329 {14, &IFileSystem::GetFileTimeStampRaw, "GetFileTimeStampRaw"},
330 {15, nullptr, "QueryEntry"}, 330 {15, nullptr, "QueryEntry"},
331 }; 331 };
332 RegisterHandlers(functions); 332 RegisterHandlers(functions);
@@ -501,6 +501,24 @@ public:
501 rb.Push(size.get_total_size()); 501 rb.Push(size.get_total_size());
502 } 502 }
503 503
504 void GetFileTimeStampRaw(Kernel::HLERequestContext& ctx) {
505 const auto file_buffer = ctx.ReadBuffer();
506 const std::string name = Common::StringFromBuffer(file_buffer);
507
508 LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name);
509
510 auto result = backend.GetFileTimeStampRaw(name);
511 if (result.Failed()) {
512 IPC::ResponseBuilder rb{ctx, 2};
513 rb.Push(result.Code());
514 return;
515 }
516
517 IPC::ResponseBuilder rb{ctx, 10};
518 rb.Push(ResultSuccess);
519 rb.PushRaw(*result);
520 }
521
504private: 522private:
505 VfsDirectoryServiceWrapper backend; 523 VfsDirectoryServiceWrapper backend;
506 SizeGetter size; 524 SizeGetter size;
diff --git a/src/core/hle/service/ngct/ngct.cpp b/src/core/hle/service/ngct/ngct.cpp
index deb3abb28..8ec7d5266 100644
--- a/src/core/hle/service/ngct/ngct.cpp
+++ b/src/core/hle/service/ngct/ngct.cpp
@@ -15,7 +15,7 @@ public:
15 explicit IService(Core::System& system_) : ServiceFramework{system_, "ngct:u"} { 15 explicit IService(Core::System& system_) : ServiceFramework{system_, "ngct:u"} {
16 // clang-format off 16 // clang-format off
17 static const FunctionInfo functions[] = { 17 static const FunctionInfo functions[] = {
18 {0, nullptr, "Match"}, 18 {0, &IService::Match, "Match"},
19 {1, &IService::Filter, "Filter"}, 19 {1, &IService::Filter, "Filter"},
20 }; 20 };
21 // clang-format on 21 // clang-format on
@@ -24,6 +24,19 @@ public:
24 } 24 }
25 25
26private: 26private:
27 void Match(Kernel::HLERequestContext& ctx) {
28 const auto buffer = ctx.ReadBuffer();
29 const auto text = Common::StringFromFixedZeroTerminatedBuffer(
30 reinterpret_cast<const char*>(buffer.data()), buffer.size());
31
32 LOG_WARNING(Service_NGCT, "(STUBBED) called, text={}", text);
33
34 IPC::ResponseBuilder rb{ctx, 3};
35 rb.Push(ResultSuccess);
36 // Return false since we don't censor anything
37 rb.Push(false);
38 }
39
27 void Filter(Kernel::HLERequestContext& ctx) { 40 void Filter(Kernel::HLERequestContext& ctx) {
28 const auto buffer = ctx.ReadBuffer(); 41 const auto buffer = ctx.ReadBuffer();
29 const auto text = Common::StringFromFixedZeroTerminatedBuffer( 42 const auto text = Common::StringFromFixedZeroTerminatedBuffer(
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index 1f1607998..191475f71 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -226,8 +226,6 @@ void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader,
226 // Log user configuration information 226 // Log user configuration information
227 constexpr auto field_type = Telemetry::FieldType::UserConfig; 227 constexpr auto field_type = Telemetry::FieldType::UserConfig;
228 AddField(field_type, "Audio_SinkId", Settings::values.sink_id.GetValue()); 228 AddField(field_type, "Audio_SinkId", Settings::values.sink_id.GetValue());
229 AddField(field_type, "Audio_EnableAudioStretching",
230 Settings::values.enable_audio_stretching.GetValue());
231 AddField(field_type, "Core_UseMultiCore", Settings::values.use_multi_core.GetValue()); 229 AddField(field_type, "Core_UseMultiCore", Settings::values.use_multi_core.GetValue());
232 AddField(field_type, "Renderer_Backend", 230 AddField(field_type, "Renderer_Backend",
233 TranslateRenderer(Settings::values.renderer_backend.GetValue())); 231 TranslateRenderer(Settings::values.renderer_backend.GetValue()));
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt
index c4283a952..dd13d948f 100644
--- a/src/input_common/CMakeLists.txt
+++ b/src/input_common/CMakeLists.txt
@@ -21,6 +21,10 @@ add_library(input_common STATIC
21 mouse/mouse_poller.h 21 mouse/mouse_poller.h
22 sdl/sdl.cpp 22 sdl/sdl.cpp
23 sdl/sdl.h 23 sdl/sdl.h
24 tas/tas_input.cpp
25 tas/tas_input.h
26 tas/tas_poller.cpp
27 tas/tas_poller.h
24 udp/client.cpp 28 udp/client.cpp
25 udp/client.h 29 udp/client.h
26 udp/protocol.cpp 30 udp/protocol.cpp
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index ff23230f0..18d7d8817 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -5,6 +5,7 @@
5#include <memory> 5#include <memory>
6#include <thread> 6#include <thread>
7#include "common/param_package.h" 7#include "common/param_package.h"
8#include "common/settings.h"
8#include "input_common/analog_from_button.h" 9#include "input_common/analog_from_button.h"
9#include "input_common/gcadapter/gc_adapter.h" 10#include "input_common/gcadapter/gc_adapter.h"
10#include "input_common/gcadapter/gc_poller.h" 11#include "input_common/gcadapter/gc_poller.h"
@@ -13,6 +14,8 @@
13#include "input_common/motion_from_button.h" 14#include "input_common/motion_from_button.h"
14#include "input_common/mouse/mouse_input.h" 15#include "input_common/mouse/mouse_input.h"
15#include "input_common/mouse/mouse_poller.h" 16#include "input_common/mouse/mouse_poller.h"
17#include "input_common/tas/tas_input.h"
18#include "input_common/tas/tas_poller.h"
16#include "input_common/touch_from_button.h" 19#include "input_common/touch_from_button.h"
17#include "input_common/udp/client.h" 20#include "input_common/udp/client.h"
18#include "input_common/udp/udp.h" 21#include "input_common/udp/udp.h"
@@ -60,6 +63,12 @@ struct InputSubsystem::Impl {
60 Input::RegisterFactory<Input::MotionDevice>("mouse", mousemotion); 63 Input::RegisterFactory<Input::MotionDevice>("mouse", mousemotion);
61 mousetouch = std::make_shared<MouseTouchFactory>(mouse); 64 mousetouch = std::make_shared<MouseTouchFactory>(mouse);
62 Input::RegisterFactory<Input::TouchDevice>("mouse", mousetouch); 65 Input::RegisterFactory<Input::TouchDevice>("mouse", mousetouch);
66
67 tas = std::make_shared<TasInput::Tas>();
68 tasbuttons = std::make_shared<TasButtonFactory>(tas);
69 Input::RegisterFactory<Input::ButtonDevice>("tas", tasbuttons);
70 tasanalog = std::make_shared<TasAnalogFactory>(tas);
71 Input::RegisterFactory<Input::AnalogDevice>("tas", tasanalog);
63 } 72 }
64 73
65 void Shutdown() { 74 void Shutdown() {
@@ -94,6 +103,12 @@ struct InputSubsystem::Impl {
94 mouseanalog.reset(); 103 mouseanalog.reset();
95 mousemotion.reset(); 104 mousemotion.reset();
96 mousetouch.reset(); 105 mousetouch.reset();
106
107 Input::UnregisterFactory<Input::ButtonDevice>("tas");
108 Input::UnregisterFactory<Input::AnalogDevice>("tas");
109
110 tasbuttons.reset();
111 tasanalog.reset();
97 } 112 }
98 113
99 [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { 114 [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const {
@@ -101,6 +116,10 @@ struct InputSubsystem::Impl {
101 Common::ParamPackage{{"display", "Any"}, {"class", "any"}}, 116 Common::ParamPackage{{"display", "Any"}, {"class", "any"}},
102 Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}}, 117 Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}},
103 }; 118 };
119 if (Settings::values.tas_enable) {
120 devices.emplace_back(
121 Common::ParamPackage{{"display", "TAS Controller"}, {"class", "tas"}});
122 }
104#ifdef HAVE_SDL2 123#ifdef HAVE_SDL2
105 auto sdl_devices = sdl->GetInputDevices(); 124 auto sdl_devices = sdl->GetInputDevices();
106 devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end()); 125 devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end());
@@ -120,6 +139,9 @@ struct InputSubsystem::Impl {
120 if (params.Get("class", "") == "gcpad") { 139 if (params.Get("class", "") == "gcpad") {
121 return gcadapter->GetAnalogMappingForDevice(params); 140 return gcadapter->GetAnalogMappingForDevice(params);
122 } 141 }
142 if (params.Get("class", "") == "tas") {
143 return tas->GetAnalogMappingForDevice(params);
144 }
123#ifdef HAVE_SDL2 145#ifdef HAVE_SDL2
124 if (params.Get("class", "") == "sdl") { 146 if (params.Get("class", "") == "sdl") {
125 return sdl->GetAnalogMappingForDevice(params); 147 return sdl->GetAnalogMappingForDevice(params);
@@ -136,6 +158,9 @@ struct InputSubsystem::Impl {
136 if (params.Get("class", "") == "gcpad") { 158 if (params.Get("class", "") == "gcpad") {
137 return gcadapter->GetButtonMappingForDevice(params); 159 return gcadapter->GetButtonMappingForDevice(params);
138 } 160 }
161 if (params.Get("class", "") == "tas") {
162 return tas->GetButtonMappingForDevice(params);
163 }
139#ifdef HAVE_SDL2 164#ifdef HAVE_SDL2
140 if (params.Get("class", "") == "sdl") { 165 if (params.Get("class", "") == "sdl") {
141 return sdl->GetButtonMappingForDevice(params); 166 return sdl->GetButtonMappingForDevice(params);
@@ -174,9 +199,12 @@ struct InputSubsystem::Impl {
174 std::shared_ptr<MouseAnalogFactory> mouseanalog; 199 std::shared_ptr<MouseAnalogFactory> mouseanalog;
175 std::shared_ptr<MouseMotionFactory> mousemotion; 200 std::shared_ptr<MouseMotionFactory> mousemotion;
176 std::shared_ptr<MouseTouchFactory> mousetouch; 201 std::shared_ptr<MouseTouchFactory> mousetouch;
202 std::shared_ptr<TasButtonFactory> tasbuttons;
203 std::shared_ptr<TasAnalogFactory> tasanalog;
177 std::shared_ptr<CemuhookUDP::Client> udp; 204 std::shared_ptr<CemuhookUDP::Client> udp;
178 std::shared_ptr<GCAdapter::Adapter> gcadapter; 205 std::shared_ptr<GCAdapter::Adapter> gcadapter;
179 std::shared_ptr<MouseInput::Mouse> mouse; 206 std::shared_ptr<MouseInput::Mouse> mouse;
207 std::shared_ptr<TasInput::Tas> tas;
180}; 208};
181 209
182InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} 210InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {}
@@ -207,6 +235,14 @@ const MouseInput::Mouse* InputSubsystem::GetMouse() const {
207 return impl->mouse.get(); 235 return impl->mouse.get();
208} 236}
209 237
238TasInput::Tas* InputSubsystem::GetTas() {
239 return impl->tas.get();
240}
241
242const TasInput::Tas* InputSubsystem::GetTas() const {
243 return impl->tas.get();
244}
245
210std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { 246std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const {
211 return impl->GetInputDevices(); 247 return impl->GetInputDevices();
212} 248}
@@ -287,6 +323,22 @@ const MouseTouchFactory* InputSubsystem::GetMouseTouch() const {
287 return impl->mousetouch.get(); 323 return impl->mousetouch.get();
288} 324}
289 325
326TasButtonFactory* InputSubsystem::GetTasButtons() {
327 return impl->tasbuttons.get();
328}
329
330const TasButtonFactory* InputSubsystem::GetTasButtons() const {
331 return impl->tasbuttons.get();
332}
333
334TasAnalogFactory* InputSubsystem::GetTasAnalogs() {
335 return impl->tasanalog.get();
336}
337
338const TasAnalogFactory* InputSubsystem::GetTasAnalogs() const {
339 return impl->tasanalog.get();
340}
341
290void InputSubsystem::ReloadInputDevices() { 342void InputSubsystem::ReloadInputDevices() {
291 if (!impl->udp) { 343 if (!impl->udp) {
292 return; 344 return;
diff --git a/src/input_common/main.h b/src/input_common/main.h
index 5d6f26385..6390d3f09 100644
--- a/src/input_common/main.h
+++ b/src/input_common/main.h
@@ -29,6 +29,10 @@ namespace MouseInput {
29class Mouse; 29class Mouse;
30} 30}
31 31
32namespace TasInput {
33class Tas;
34}
35
32namespace InputCommon { 36namespace InputCommon {
33namespace Polling { 37namespace Polling {
34 38
@@ -64,6 +68,8 @@ class MouseButtonFactory;
64class MouseAnalogFactory; 68class MouseAnalogFactory;
65class MouseMotionFactory; 69class MouseMotionFactory;
66class MouseTouchFactory; 70class MouseTouchFactory;
71class TasButtonFactory;
72class TasAnalogFactory;
67class Keyboard; 73class Keyboard;
68 74
69/** 75/**
@@ -103,6 +109,11 @@ public:
103 /// Retrieves the underlying mouse device. 109 /// Retrieves the underlying mouse device.
104 [[nodiscard]] const MouseInput::Mouse* GetMouse() const; 110 [[nodiscard]] const MouseInput::Mouse* GetMouse() const;
105 111
112 /// Retrieves the underlying tas device.
113 [[nodiscard]] TasInput::Tas* GetTas();
114
115 /// Retrieves the underlying tas device.
116 [[nodiscard]] const TasInput::Tas* GetTas() const;
106 /** 117 /**
107 * Returns all available input devices that this Factory can create a new device with. 118 * Returns all available input devices that this Factory can create a new device with.
108 * Each returned ParamPackage should have a `display` field used for display, a class field for 119 * Each returned ParamPackage should have a `display` field used for display, a class field for
@@ -144,30 +155,42 @@ public:
144 /// Retrieves the underlying udp touch handler. 155 /// Retrieves the underlying udp touch handler.
145 [[nodiscard]] const UDPTouchFactory* GetUDPTouch() const; 156 [[nodiscard]] const UDPTouchFactory* GetUDPTouch() const;
146 157
147 /// Retrieves the underlying GameCube button handler. 158 /// Retrieves the underlying mouse button handler.
148 [[nodiscard]] MouseButtonFactory* GetMouseButtons(); 159 [[nodiscard]] MouseButtonFactory* GetMouseButtons();
149 160
150 /// Retrieves the underlying GameCube button handler. 161 /// Retrieves the underlying mouse button handler.
151 [[nodiscard]] const MouseButtonFactory* GetMouseButtons() const; 162 [[nodiscard]] const MouseButtonFactory* GetMouseButtons() const;
152 163
153 /// Retrieves the underlying udp touch handler. 164 /// Retrieves the underlying mouse analog handler.
154 [[nodiscard]] MouseAnalogFactory* GetMouseAnalogs(); 165 [[nodiscard]] MouseAnalogFactory* GetMouseAnalogs();
155 166
156 /// Retrieves the underlying udp touch handler. 167 /// Retrieves the underlying mouse analog handler.
157 [[nodiscard]] const MouseAnalogFactory* GetMouseAnalogs() const; 168 [[nodiscard]] const MouseAnalogFactory* GetMouseAnalogs() const;
158 169
159 /// Retrieves the underlying udp motion handler. 170 /// Retrieves the underlying mouse motion handler.
160 [[nodiscard]] MouseMotionFactory* GetMouseMotions(); 171 [[nodiscard]] MouseMotionFactory* GetMouseMotions();
161 172
162 /// Retrieves the underlying udp motion handler. 173 /// Retrieves the underlying mouse motion handler.
163 [[nodiscard]] const MouseMotionFactory* GetMouseMotions() const; 174 [[nodiscard]] const MouseMotionFactory* GetMouseMotions() const;
164 175
165 /// Retrieves the underlying udp touch handler. 176 /// Retrieves the underlying mouse touch handler.
166 [[nodiscard]] MouseTouchFactory* GetMouseTouch(); 177 [[nodiscard]] MouseTouchFactory* GetMouseTouch();
167 178
168 /// Retrieves the underlying udp touch handler. 179 /// Retrieves the underlying mouse touch handler.
169 [[nodiscard]] const MouseTouchFactory* GetMouseTouch() const; 180 [[nodiscard]] const MouseTouchFactory* GetMouseTouch() const;
170 181
182 /// Retrieves the underlying tas button handler.
183 [[nodiscard]] TasButtonFactory* GetTasButtons();
184
185 /// Retrieves the underlying tas button handler.
186 [[nodiscard]] const TasButtonFactory* GetTasButtons() const;
187
188 /// Retrieves the underlying tas analogs handler.
189 [[nodiscard]] TasAnalogFactory* GetTasAnalogs();
190
191 /// Retrieves the underlying tas analogs handler.
192 [[nodiscard]] const TasAnalogFactory* GetTasAnalogs() const;
193
171 /// Reloads the input devices 194 /// Reloads the input devices
172 void ReloadInputDevices(); 195 void ReloadInputDevices();
173 196
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index f102410d1..03888b7cb 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -21,7 +21,7 @@
21#include "common/logging/log.h" 21#include "common/logging/log.h"
22#include "common/math_util.h" 22#include "common/math_util.h"
23#include "common/param_package.h" 23#include "common/param_package.h"
24#include "common/settings_input.h" 24#include "common/settings.h"
25#include "common/threadsafe_queue.h" 25#include "common/threadsafe_queue.h"
26#include "core/frontend/input.h" 26#include "core/frontend/input.h"
27#include "input_common/motion_input.h" 27#include "input_common/motion_input.h"
@@ -889,8 +889,10 @@ SDLState::SDLState() {
889 RegisterFactory<VibrationDevice>("sdl", vibration_factory); 889 RegisterFactory<VibrationDevice>("sdl", vibration_factory);
890 RegisterFactory<MotionDevice>("sdl", motion_factory); 890 RegisterFactory<MotionDevice>("sdl", motion_factory);
891 891
892 // Disable raw input. When enabled this setting causes SDL to die when a web applet opens 892 if (!Settings::values.enable_raw_input) {
893 SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0"); 893 // Disable raw input. When enabled this setting causes SDL to die when a web applet opens
894 SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0");
895 }
894 896
895 // Enable HIDAPI rumble. This prevents SDL from disabling motion on PS4 and PS5 controllers 897 // Enable HIDAPI rumble. This prevents SDL from disabling motion on PS4 and PS5 controllers
896 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); 898 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
@@ -898,10 +900,10 @@ SDLState::SDLState() {
898 900
899 // Tell SDL2 to use the hidapi driver. This will allow joycons to be detected as a 901 // Tell SDL2 to use the hidapi driver. This will allow joycons to be detected as a
900 // GameController and not a generic one 902 // GameController and not a generic one
901 SDL_SetHint("SDL_JOYSTICK_HIDAPI_JOY_CONS", "1"); 903 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
902 904
903 // Turn off Pro controller home led 905 // Turn off Pro controller home led
904 SDL_SetHint("SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED", "0"); 906 SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED, "0");
905 907
906 // If the frontend is going to manage the event loop, then we don't start one here 908 // If the frontend is going to manage the event loop, then we don't start one here
907 start_thread = SDL_WasInit(SDL_INIT_JOYSTICK) == 0; 909 start_thread = SDL_WasInit(SDL_INIT_JOYSTICK) == 0;
diff --git a/src/input_common/tas/tas_input.cpp b/src/input_common/tas/tas_input.cpp
new file mode 100644
index 000000000..1598092b6
--- /dev/null
+++ b/src/input_common/tas/tas_input.cpp
@@ -0,0 +1,455 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2+
3// Refer to the license.txt file included.
4
5#include <cstring>
6#include <regex>
7
8#include "common/fs/file.h"
9#include "common/fs/fs_types.h"
10#include "common/fs/path_util.h"
11#include "common/logging/log.h"
12#include "common/settings.h"
13#include "input_common/tas/tas_input.h"
14
15namespace TasInput {
16
17// Supported keywords and buttons from a TAS file
18constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_button = {
19 std::pair{"KEY_A", TasButton::BUTTON_A},
20 {"KEY_B", TasButton::BUTTON_B},
21 {"KEY_X", TasButton::BUTTON_X},
22 {"KEY_Y", TasButton::BUTTON_Y},
23 {"KEY_LSTICK", TasButton::STICK_L},
24 {"KEY_RSTICK", TasButton::STICK_R},
25 {"KEY_L", TasButton::TRIGGER_L},
26 {"KEY_R", TasButton::TRIGGER_R},
27 {"KEY_PLUS", TasButton::BUTTON_PLUS},
28 {"KEY_MINUS", TasButton::BUTTON_MINUS},
29 {"KEY_DLEFT", TasButton::BUTTON_LEFT},
30 {"KEY_DUP", TasButton::BUTTON_UP},
31 {"KEY_DRIGHT", TasButton::BUTTON_RIGHT},
32 {"KEY_DDOWN", TasButton::BUTTON_DOWN},
33 {"KEY_SL", TasButton::BUTTON_SL},
34 {"KEY_SR", TasButton::BUTTON_SR},
35 {"KEY_CAPTURE", TasButton::BUTTON_CAPTURE},
36 {"KEY_HOME", TasButton::BUTTON_HOME},
37 {"KEY_ZL", TasButton::TRIGGER_ZL},
38 {"KEY_ZR", TasButton::TRIGGER_ZR},
39};
40
41Tas::Tas() {
42 if (!Settings::values.tas_enable) {
43 needs_reset = true;
44 return;
45 }
46 LoadTasFiles();
47}
48
49Tas::~Tas() {
50 Stop();
51};
52
53void Tas::LoadTasFiles() {
54 script_length = 0;
55 for (size_t i = 0; i < commands.size(); i++) {
56 LoadTasFile(i);
57 if (commands[i].size() > script_length) {
58 script_length = commands[i].size();
59 }
60 }
61}
62
63void Tas::LoadTasFile(size_t player_index) {
64 if (!commands[player_index].empty()) {
65 commands[player_index].clear();
66 }
67 std::string file =
68 Common::FS::ReadStringFromFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) /
69 fmt::format("script0-{}.txt", player_index + 1),
70 Common::FS::FileType::BinaryFile);
71 std::stringstream command_line(file);
72 std::string line;
73 int frame_no = 0;
74 while (std::getline(command_line, line, '\n')) {
75 if (line.empty()) {
76 continue;
77 }
78 LOG_DEBUG(Input, "Loading line: {}", line);
79 std::smatch m;
80
81 std::stringstream linestream(line);
82 std::string segment;
83 std::vector<std::string> seglist;
84
85 while (std::getline(linestream, segment, ' ')) {
86 seglist.push_back(segment);
87 }
88
89 if (seglist.size() < 4) {
90 continue;
91 }
92
93 while (frame_no < std::stoi(seglist.at(0))) {
94 commands[player_index].push_back({});
95 frame_no++;
96 }
97
98 TASCommand command = {
99 .buttons = ReadCommandButtons(seglist.at(1)),
100 .l_axis = ReadCommandAxis(seglist.at(2)),
101 .r_axis = ReadCommandAxis(seglist.at(3)),
102 };
103 commands[player_index].push_back(command);
104 frame_no++;
105 }
106 LOG_INFO(Input, "TAS file loaded! {} frames", frame_no);
107}
108
109void Tas::WriteTasFile(std::u8string file_name) {
110 std::string output_text;
111 for (size_t frame = 0; frame < record_commands.size(); frame++) {
112 if (!output_text.empty()) {
113 output_text += "\n";
114 }
115 const TASCommand& line = record_commands[frame];
116 output_text += std::to_string(frame) + " " + WriteCommandButtons(line.buttons) + " " +
117 WriteCommandAxis(line.l_axis) + " " + WriteCommandAxis(line.r_axis);
118 }
119 const auto bytes_written = Common::FS::WriteStringToFile(
120 Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / file_name,
121 Common::FS::FileType::TextFile, output_text);
122 if (bytes_written == output_text.size()) {
123 LOG_INFO(Input, "TAS file written to file!");
124 } else {
125 LOG_ERROR(Input, "Writing the TAS-file has failed! {} / {} bytes written", bytes_written,
126 output_text.size());
127 }
128}
129
130std::pair<float, float> Tas::FlipAxisY(std::pair<float, float> old) {
131 auto [x, y] = old;
132 return {x, -y};
133}
134
135void Tas::RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes) {
136 last_input = {buttons, FlipAxisY(axes[0]), FlipAxisY(axes[1])};
137}
138
139std::tuple<TasState, size_t, size_t> Tas::GetStatus() const {
140 TasState state;
141 if (is_recording) {
142 return {TasState::Recording, 0, record_commands.size()};
143 }
144
145 if (is_running) {
146 state = TasState::Running;
147 } else {
148 state = TasState::Stopped;
149 }
150
151 return {state, current_command, script_length};
152}
153
154std::string Tas::DebugButtons(u32 buttons) const {
155 return fmt::format("{{ {} }}", TasInput::Tas::ButtonsToString(buttons));
156}
157
158std::string Tas::DebugJoystick(float x, float y) const {
159 return fmt::format("[ {} , {} ]", std::to_string(x), std::to_string(y));
160}
161
162std::string Tas::DebugInput(const TasData& data) const {
163 return fmt::format("{{ {} , {} , {} }}", DebugButtons(data.buttons),
164 DebugJoystick(data.axis[0], data.axis[1]),
165 DebugJoystick(data.axis[2], data.axis[3]));
166}
167
168std::string Tas::DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const {
169 std::string returns = "[ ";
170 for (size_t i = 0; i < arr.size(); i++) {
171 returns += DebugInput(arr[i]);
172 if (i != arr.size() - 1) {
173 returns += " , ";
174 }
175 }
176 return returns + "]";
177}
178
179std::string Tas::ButtonsToString(u32 button) const {
180 std::string returns;
181 for (auto [text_button, tas_button] : text_to_tas_button) {
182 if ((button & static_cast<u32>(tas_button)) != 0)
183 returns += fmt::format(", {}", text_button.substr(4));
184 }
185 return returns.empty() ? "" : returns.substr(2);
186}
187
188void Tas::UpdateThread() {
189 if (!Settings::values.tas_enable) {
190 if (is_running) {
191 Stop();
192 }
193 return;
194 }
195
196 if (is_recording) {
197 record_commands.push_back(last_input);
198 }
199 if (needs_reset) {
200 current_command = 0;
201 needs_reset = false;
202 LoadTasFiles();
203 LOG_DEBUG(Input, "tas_reset done");
204 }
205
206 if (!is_running) {
207 tas_data.fill({});
208 return;
209 }
210 if (current_command < script_length) {
211 LOG_DEBUG(Input, "Playing TAS {}/{}", current_command, script_length);
212 size_t frame = current_command++;
213 for (size_t i = 0; i < commands.size(); i++) {
214 if (frame < commands[i].size()) {
215 TASCommand command = commands[i][frame];
216 tas_data[i].buttons = command.buttons;
217 auto [l_axis_x, l_axis_y] = command.l_axis;
218 tas_data[i].axis[0] = l_axis_x;
219 tas_data[i].axis[1] = l_axis_y;
220 auto [r_axis_x, r_axis_y] = command.r_axis;
221 tas_data[i].axis[2] = r_axis_x;
222 tas_data[i].axis[3] = r_axis_y;
223 } else {
224 tas_data[i] = {};
225 }
226 }
227 } else {
228 is_running = Settings::values.tas_loop.GetValue();
229 current_command = 0;
230 tas_data.fill({});
231 if (!is_running) {
232 SwapToStoredController();
233 }
234 }
235 LOG_DEBUG(Input, "TAS inputs: {}", DebugInputs(tas_data));
236}
237
238TasAnalog Tas::ReadCommandAxis(const std::string& line) const {
239 std::stringstream linestream(line);
240 std::string segment;
241 std::vector<std::string> seglist;
242
243 while (std::getline(linestream, segment, ';')) {
244 seglist.push_back(segment);
245 }
246
247 const float x = std::stof(seglist.at(0)) / 32767.0f;
248 const float y = std::stof(seglist.at(1)) / 32767.0f;
249
250 return {x, y};
251}
252
253u32 Tas::ReadCommandButtons(const std::string& data) const {
254 std::stringstream button_text(data);
255 std::string line;
256 u32 buttons = 0;
257 while (std::getline(button_text, line, ';')) {
258 for (auto [text, tas_button] : text_to_tas_button) {
259 if (text == line) {
260 buttons |= static_cast<u32>(tas_button);
261 break;
262 }
263 }
264 }
265 return buttons;
266}
267
268std::string Tas::WriteCommandAxis(TasAnalog data) const {
269 auto [x, y] = data;
270 std::string line;
271 line += std::to_string(static_cast<int>(x * 32767));
272 line += ";";
273 line += std::to_string(static_cast<int>(y * 32767));
274 return line;
275}
276
277std::string Tas::WriteCommandButtons(u32 data) const {
278 if (data == 0) {
279 return "NONE";
280 }
281
282 std::string line;
283 u32 index = 0;
284 while (data > 0) {
285 if ((data & 1) == 1) {
286 for (auto [text, tas_button] : text_to_tas_button) {
287 if (tas_button == static_cast<TasButton>(1 << index)) {
288 if (line.size() > 0) {
289 line += ";";
290 }
291 line += text;
292 break;
293 }
294 }
295 }
296 index++;
297 data >>= 1;
298 }
299 return line;
300}
301
302void Tas::StartStop() {
303 if (!Settings::values.tas_enable) {
304 return;
305 }
306 if (is_running) {
307 Stop();
308 } else {
309 is_running = true;
310 SwapToTasController();
311 }
312}
313
314void Tas::Stop() {
315 is_running = false;
316 SwapToStoredController();
317}
318
319void Tas::SwapToTasController() {
320 if (!Settings::values.tas_swap_controllers) {
321 return;
322 }
323 auto& players = Settings::values.players.GetValue();
324 for (std::size_t index = 0; index < players.size(); index++) {
325 auto& player = players[index];
326 player_mappings[index] = player;
327
328 // Only swap active controllers
329 if (!player.connected) {
330 continue;
331 }
332
333 Common::ParamPackage tas_param;
334 tas_param.Set("pad", static_cast<u8>(index));
335 auto button_mapping = GetButtonMappingForDevice(tas_param);
336 auto analog_mapping = GetAnalogMappingForDevice(tas_param);
337 auto& buttons = player.buttons;
338 auto& analogs = player.analogs;
339
340 for (std::size_t i = 0; i < buttons.size(); ++i) {
341 buttons[i] = button_mapping[static_cast<Settings::NativeButton::Values>(i)].Serialize();
342 }
343 for (std::size_t i = 0; i < analogs.size(); ++i) {
344 analogs[i] = analog_mapping[static_cast<Settings::NativeAnalog::Values>(i)].Serialize();
345 }
346 }
347 is_old_input_saved = true;
348 Settings::values.is_device_reload_pending.store(true);
349}
350
351void Tas::SwapToStoredController() {
352 if (!is_old_input_saved) {
353 return;
354 }
355 auto& players = Settings::values.players.GetValue();
356 for (std::size_t index = 0; index < players.size(); index++) {
357 players[index] = player_mappings[index];
358 }
359 is_old_input_saved = false;
360 Settings::values.is_device_reload_pending.store(true);
361}
362
363void Tas::Reset() {
364 if (!Settings::values.tas_enable) {
365 return;
366 }
367 needs_reset = true;
368}
369
370bool Tas::Record() {
371 if (!Settings::values.tas_enable) {
372 return true;
373 }
374 is_recording = !is_recording;
375 return is_recording;
376}
377
378void Tas::SaveRecording(bool overwrite_file) {
379 if (is_recording) {
380 return;
381 }
382 if (record_commands.empty()) {
383 return;
384 }
385 WriteTasFile(u8"record.txt");
386 if (overwrite_file) {
387 WriteTasFile(u8"script0-1.txt");
388 }
389 needs_reset = true;
390 record_commands.clear();
391}
392
393InputCommon::ButtonMapping Tas::GetButtonMappingForDevice(
394 const Common::ParamPackage& params) const {
395 // This list is missing ZL/ZR since those are not considered buttons.
396 // We will add those afterwards
397 // This list also excludes any button that can't be really mapped
398 static constexpr std::array<std::pair<Settings::NativeButton::Values, TasButton>, 20>
399 switch_to_tas_button = {
400 std::pair{Settings::NativeButton::A, TasButton::BUTTON_A},
401 {Settings::NativeButton::B, TasButton::BUTTON_B},
402 {Settings::NativeButton::X, TasButton::BUTTON_X},
403 {Settings::NativeButton::Y, TasButton::BUTTON_Y},
404 {Settings::NativeButton::LStick, TasButton::STICK_L},
405 {Settings::NativeButton::RStick, TasButton::STICK_R},
406 {Settings::NativeButton::L, TasButton::TRIGGER_L},
407 {Settings::NativeButton::R, TasButton::TRIGGER_R},
408 {Settings::NativeButton::Plus, TasButton::BUTTON_PLUS},
409 {Settings::NativeButton::Minus, TasButton::BUTTON_MINUS},
410 {Settings::NativeButton::DLeft, TasButton::BUTTON_LEFT},
411 {Settings::NativeButton::DUp, TasButton::BUTTON_UP},
412 {Settings::NativeButton::DRight, TasButton::BUTTON_RIGHT},
413 {Settings::NativeButton::DDown, TasButton::BUTTON_DOWN},
414 {Settings::NativeButton::SL, TasButton::BUTTON_SL},
415 {Settings::NativeButton::SR, TasButton::BUTTON_SR},
416 {Settings::NativeButton::Screenshot, TasButton::BUTTON_CAPTURE},
417 {Settings::NativeButton::Home, TasButton::BUTTON_HOME},
418 {Settings::NativeButton::ZL, TasButton::TRIGGER_ZL},
419 {Settings::NativeButton::ZR, TasButton::TRIGGER_ZR},
420 };
421
422 InputCommon::ButtonMapping mapping{};
423 for (const auto& [switch_button, tas_button] : switch_to_tas_button) {
424 Common::ParamPackage button_params({{"engine", "tas"}});
425 button_params.Set("pad", params.Get("pad", 0));
426 button_params.Set("button", static_cast<int>(tas_button));
427 mapping.insert_or_assign(switch_button, std::move(button_params));
428 }
429
430 return mapping;
431}
432
433InputCommon::AnalogMapping Tas::GetAnalogMappingForDevice(
434 const Common::ParamPackage& params) const {
435
436 InputCommon::AnalogMapping mapping = {};
437 Common::ParamPackage left_analog_params;
438 left_analog_params.Set("engine", "tas");
439 left_analog_params.Set("pad", params.Get("pad", 0));
440 left_analog_params.Set("axis_x", static_cast<int>(TasAxes::StickX));
441 left_analog_params.Set("axis_y", static_cast<int>(TasAxes::StickY));
442 mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params));
443 Common::ParamPackage right_analog_params;
444 right_analog_params.Set("engine", "tas");
445 right_analog_params.Set("pad", params.Get("pad", 0));
446 right_analog_params.Set("axis_x", static_cast<int>(TasAxes::SubstickX));
447 right_analog_params.Set("axis_y", static_cast<int>(TasAxes::SubstickY));
448 mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params));
449 return mapping;
450}
451
452const TasData& Tas::GetTasState(std::size_t pad) const {
453 return tas_data[pad];
454}
455} // namespace TasInput
diff --git a/src/input_common/tas/tas_input.h b/src/input_common/tas/tas_input.h
new file mode 100644
index 000000000..3e2db8f00
--- /dev/null
+++ b/src/input_common/tas/tas_input.h
@@ -0,0 +1,237 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8
9#include "common/common_types.h"
10#include "common/settings_input.h"
11#include "core/frontend/input.h"
12#include "input_common/main.h"
13
14/*
15To play back TAS scripts on Yuzu, select the folder with scripts in the configuration menu below
16Tools -> Configure TAS. The file itself has normal text format and has to be called script0-1.txt
17for controller 1, script0-2.txt for controller 2 and so forth (with max. 8 players).
18
19A script file has the same format as TAS-nx uses, so final files will look like this:
20
211 KEY_B 0;0 0;0
226 KEY_ZL 0;0 0;0
2341 KEY_ZL;KEY_Y 0;0 0;0
2443 KEY_X;KEY_A 32767;0 0;0
2544 KEY_A 32767;0 0;0
2645 KEY_A 32767;0 0;0
2746 KEY_A 32767;0 0;0
2847 KEY_A 32767;0 0;0
29
30After placing the file at the correct location, it can be read into Yuzu with the (default) hotkey
31CTRL+F6 (refresh). In the bottom left corner, it will display the amount of frames the script file
32has. Playback can be started or stopped using CTRL+F5.
33
34However, for playback to actually work, the correct input device has to be selected: In the Controls
35menu, select TAS from the device list for the controller that the script should be played on.
36
37Recording a new script file is really simple: Just make sure that the proper device (not TAS) is
38connected on P1, and press CTRL+F7 to start recording. When done, just press the same keystroke
39again (CTRL+F7). The new script will be saved at the location previously selected, as the filename
40record.txt.
41
42For debugging purposes, the common controller debugger can be used (View -> Debugging -> Controller
43P1).
44*/
45
46namespace TasInput {
47
48constexpr size_t PLAYER_NUMBER = 8;
49
50using TasAnalog = std::pair<float, float>;
51
52enum class TasState {
53 Running,
54 Recording,
55 Stopped,
56};
57
58enum class TasButton : u32 {
59 BUTTON_A = 1U << 0,
60 BUTTON_B = 1U << 1,
61 BUTTON_X = 1U << 2,
62 BUTTON_Y = 1U << 3,
63 STICK_L = 1U << 4,
64 STICK_R = 1U << 5,
65 TRIGGER_L = 1U << 6,
66 TRIGGER_R = 1U << 7,
67 TRIGGER_ZL = 1U << 8,
68 TRIGGER_ZR = 1U << 9,
69 BUTTON_PLUS = 1U << 10,
70 BUTTON_MINUS = 1U << 11,
71 BUTTON_LEFT = 1U << 12,
72 BUTTON_UP = 1U << 13,
73 BUTTON_RIGHT = 1U << 14,
74 BUTTON_DOWN = 1U << 15,
75 BUTTON_SL = 1U << 16,
76 BUTTON_SR = 1U << 17,
77 BUTTON_HOME = 1U << 18,
78 BUTTON_CAPTURE = 1U << 19,
79};
80
81enum class TasAxes : u8 {
82 StickX,
83 StickY,
84 SubstickX,
85 SubstickY,
86 Undefined,
87};
88
89struct TasData {
90 u32 buttons{};
91 std::array<float, 4> axis{};
92};
93
94class Tas {
95public:
96 Tas();
97 ~Tas();
98
99 // Changes the input status that will be stored in each frame
100 void RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes);
101
102 // Main loop that records or executes input
103 void UpdateThread();
104
105 // Sets the flag to start or stop the TAS command excecution and swaps controllers profiles
106 void StartStop();
107
108 // Stop the TAS and reverts any controller profile
109 void Stop();
110
111 // Sets the flag to reload the file and start from the begining in the next update
112 void Reset();
113
114 /**
115 * Sets the flag to enable or disable recording of inputs
116 * @return Returns true if the current recording status is enabled
117 */
118 bool Record();
119
120 // Saves contents of record_commands on a file if overwrite is enabled player 1 will be
121 // overwritten with the recorded commands
122 void SaveRecording(bool overwrite_file);
123
124 /**
125 * Returns the current status values of TAS playback/recording
126 * @return Tuple of
127 * TasState indicating the current state out of Running, Recording or Stopped ;
128 * Current playback progress or amount of frames (so far) for Recording ;
129 * Total length of script file currently loaded or amount of frames (so far) for Recording
130 */
131 std::tuple<TasState, size_t, size_t> GetStatus() const;
132
133 // Retuns an array of the default button mappings
134 InputCommon::ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) const;
135
136 // Retuns an array of the default analog mappings
137 InputCommon::AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) const;
138 [[nodiscard]] const TasData& GetTasState(std::size_t pad) const;
139
140private:
141 struct TASCommand {
142 u32 buttons{};
143 TasAnalog l_axis{};
144 TasAnalog r_axis{};
145 };
146
147 // Loads TAS files from all players
148 void LoadTasFiles();
149
150 // Loads TAS file from the specified player
151 void LoadTasFile(size_t player_index);
152
153 // Writes a TAS file from the recorded commands
154 void WriteTasFile(std::u8string file_name);
155
156 /**
157 * Parses a string containing the axis values with the following format "x;y"
158 * X and Y have a range from -32767 to 32767
159 * @return Returns a TAS analog object with axis values with range from -1.0 to 1.0
160 */
161 TasAnalog ReadCommandAxis(const std::string& line) const;
162
163 /**
164 * Parses a string containing the button values with the following format "a;b;c;d..."
165 * Each button is represented by it's text format specified in text_to_tas_button array
166 * @return Returns a u32 with each bit representing the status of a button
167 */
168 u32 ReadCommandButtons(const std::string& line) const;
169
170 /**
171 * Converts an u32 containing the button status into the text equivalent
172 * @return Returns a string with the name of the buttons to be written to the file
173 */
174 std::string WriteCommandButtons(u32 data) const;
175
176 /**
177 * Converts an TAS analog object containing the axis status into the text equivalent
178 * @return Returns a string with the value of the axis to be written to the file
179 */
180 std::string WriteCommandAxis(TasAnalog data) const;
181
182 // Inverts the Y axis polarity
183 std::pair<float, float> FlipAxisY(std::pair<float, float> old);
184
185 /**
186 * Converts an u32 containing the button status into the text equivalent
187 * @return Returns a string with the name of the buttons to be printed on console
188 */
189 std::string DebugButtons(u32 buttons) const;
190
191 /**
192 * Converts an TAS analog object containing the axis status into the text equivalent
193 * @return Returns a string with the value of the axis to be printed on console
194 */
195 std::string DebugJoystick(float x, float y) const;
196
197 /**
198 * Converts the given TAS status into the text equivalent
199 * @return Returns a string with the value of the TAS status to be printed on console
200 */
201 std::string DebugInput(const TasData& data) const;
202
203 /**
204 * Converts the given TAS status of multiple players into the text equivalent
205 * @return Returns a string with the value of the status of all TAS players to be printed on
206 * console
207 */
208 std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const;
209
210 /**
211 * Converts an u32 containing the button status into the text equivalent
212 * @return Returns a string with the name of the buttons
213 */
214 std::string ButtonsToString(u32 button) const;
215
216 // Stores current controller configuration and sets a TAS controller for every active controller
217 // to the current config
218 void SwapToTasController();
219
220 // Sets the stored controller configuration to the current config
221 void SwapToStoredController();
222
223 size_t script_length{0};
224 std::array<TasData, PLAYER_NUMBER> tas_data;
225 bool is_old_input_saved{false};
226 bool is_recording{false};
227 bool is_running{false};
228 bool needs_reset{false};
229 std::array<std::vector<TASCommand>, PLAYER_NUMBER> commands{};
230 std::vector<TASCommand> record_commands{};
231 size_t current_command{0};
232 TASCommand last_input{}; // only used for recording
233
234 // Old settings for swapping controllers
235 std::array<Settings::PlayerInput, 10> player_mappings;
236};
237} // namespace TasInput
diff --git a/src/input_common/tas/tas_poller.cpp b/src/input_common/tas/tas_poller.cpp
new file mode 100644
index 000000000..15810d6b0
--- /dev/null
+++ b/src/input_common/tas/tas_poller.cpp
@@ -0,0 +1,101 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <mutex>
6#include <utility>
7
8#include "common/settings.h"
9#include "common/threadsafe_queue.h"
10#include "input_common/tas/tas_input.h"
11#include "input_common/tas/tas_poller.h"
12
13namespace InputCommon {
14
15class TasButton final : public Input::ButtonDevice {
16public:
17 explicit TasButton(u32 button_, u32 pad_, const TasInput::Tas* tas_input_)
18 : button(button_), pad(pad_), tas_input(tas_input_) {}
19
20 bool GetStatus() const override {
21 return (tas_input->GetTasState(pad).buttons & button) != 0;
22 }
23
24private:
25 const u32 button;
26 const u32 pad;
27 const TasInput::Tas* tas_input;
28};
29
30TasButtonFactory::TasButtonFactory(std::shared_ptr<TasInput::Tas> tas_input_)
31 : tas_input(std::move(tas_input_)) {}
32
33std::unique_ptr<Input::ButtonDevice> TasButtonFactory::Create(const Common::ParamPackage& params) {
34 const auto button_id = params.Get("button", 0);
35 const auto pad = params.Get("pad", 0);
36
37 return std::make_unique<TasButton>(button_id, pad, tas_input.get());
38}
39
40class TasAnalog final : public Input::AnalogDevice {
41public:
42 explicit TasAnalog(u32 pad_, u32 axis_x_, u32 axis_y_, const TasInput::Tas* tas_input_)
43 : pad(pad_), axis_x(axis_x_), axis_y(axis_y_), tas_input(tas_input_) {}
44
45 float GetAxis(u32 axis) const {
46 std::lock_guard lock{mutex};
47 return tas_input->GetTasState(pad).axis.at(axis);
48 }
49
50 std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const {
51 float x = GetAxis(analog_axis_x);
52 float y = GetAxis(analog_axis_y);
53
54 // Make sure the coordinates are in the unit circle,
55 // otherwise normalize it.
56 float r = x * x + y * y;
57 if (r > 1.0f) {
58 r = std::sqrt(r);
59 x /= r;
60 y /= r;
61 }
62
63 return {x, y};
64 }
65
66 std::tuple<float, float> GetStatus() const override {
67 return GetAnalog(axis_x, axis_y);
68 }
69
70 Input::AnalogProperties GetAnalogProperties() const override {
71 return {0.0f, 1.0f, 0.5f};
72 }
73
74private:
75 const u32 pad;
76 const u32 axis_x;
77 const u32 axis_y;
78 const TasInput::Tas* tas_input;
79 mutable std::mutex mutex;
80};
81
82/// An analog device factory that creates analog devices from GC Adapter
83TasAnalogFactory::TasAnalogFactory(std::shared_ptr<TasInput::Tas> tas_input_)
84 : tas_input(std::move(tas_input_)) {}
85
86/**
87 * Creates analog device from joystick axes
88 * @param params contains parameters for creating the device:
89 * - "port": the nth gcpad on the adapter
90 * - "axis_x": the index of the axis to be bind as x-axis
91 * - "axis_y": the index of the axis to be bind as y-axis
92 */
93std::unique_ptr<Input::AnalogDevice> TasAnalogFactory::Create(const Common::ParamPackage& params) {
94 const auto pad = static_cast<u32>(params.Get("pad", 0));
95 const auto axis_x = static_cast<u32>(params.Get("axis_x", 0));
96 const auto axis_y = static_cast<u32>(params.Get("axis_y", 1));
97
98 return std::make_unique<TasAnalog>(pad, axis_x, axis_y, tas_input.get());
99}
100
101} // namespace InputCommon
diff --git a/src/input_common/tas/tas_poller.h b/src/input_common/tas/tas_poller.h
new file mode 100644
index 000000000..09e426cef
--- /dev/null
+++ b/src/input_common/tas/tas_poller.h
@@ -0,0 +1,43 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <memory>
8#include "core/frontend/input.h"
9#include "input_common/tas/tas_input.h"
10
11namespace InputCommon {
12
13/**
14 * A button device factory representing a tas bot. It receives tas events and forward them
15 * to all button devices it created.
16 */
17class TasButtonFactory final : public Input::Factory<Input::ButtonDevice> {
18public:
19 explicit TasButtonFactory(std::shared_ptr<TasInput::Tas> tas_input_);
20
21 /**
22 * Creates a button device from a button press
23 * @param params contains parameters for creating the device:
24 * - "code": the code of the key to bind with the button
25 */
26 std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override;
27
28private:
29 std::shared_ptr<TasInput::Tas> tas_input;
30};
31
32/// An analog device factory that creates analog devices from tas
33class TasAnalogFactory final : public Input::Factory<Input::AnalogDevice> {
34public:
35 explicit TasAnalogFactory(std::shared_ptr<TasInput::Tas> tas_input_);
36
37 std::unique_ptr<Input::AnalogDevice> Create(const Common::ParamPackage& params) override;
38
39private:
40 std::shared_ptr<TasInput::Tas> tas_input;
41};
42
43} // namespace InputCommon
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h
index a11ea3068..380f9bb76 100644
--- a/src/input_common/udp/client.h
+++ b/src/input_common/udp/client.h
@@ -21,8 +21,6 @@
21 21
22namespace InputCommon::CemuhookUDP { 22namespace InputCommon::CemuhookUDP {
23 23
24constexpr char DEFAULT_SRV[] = "127.0.0.1:26760";
25
26class Socket; 24class Socket;
27 25
28namespace Response { 26namespace Response {
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp
index ff024f530..2ae3639b5 100644
--- a/src/video_core/gpu.cpp
+++ b/src/video_core/gpu.cpp
@@ -531,14 +531,6 @@ void GPU::TriggerCpuInterrupt(const u32 syncpoint_id, const u32 value) const {
531 interrupt_manager.GPUInterruptSyncpt(syncpoint_id, value); 531 interrupt_manager.GPUInterruptSyncpt(syncpoint_id, value);
532} 532}
533 533
534void GPU::ShutDown() {
535 // Signal that threads should no longer block on syncpoint fences
536 shutting_down.store(true, std::memory_order_relaxed);
537 sync_cv.notify_all();
538
539 gpu_thread.ShutDown();
540}
541
542void GPU::OnCommandListEnd() { 534void GPU::OnCommandListEnd() {
543 if (is_async) { 535 if (is_async) {
544 // This command only applies to asynchronous GPU mode 536 // This command only applies to asynchronous GPU mode
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index a8e98e51b..e6a02a71b 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -219,9 +219,6 @@ public:
219 return *shader_notify; 219 return *shader_notify;
220 } 220 }
221 221
222 // Stops the GPU execution and waits for the GPU to finish working
223 void ShutDown();
224
225 /// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame. 222 /// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame.
226 void WaitFence(u32 syncpoint_id, u32 value); 223 void WaitFence(u32 syncpoint_id, u32 value);
227 224
diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp
index 46f642b19..9547f277a 100644
--- a/src/video_core/gpu_thread.cpp
+++ b/src/video_core/gpu_thread.cpp
@@ -17,9 +17,9 @@
17namespace VideoCommon::GPUThread { 17namespace VideoCommon::GPUThread {
18 18
19/// Runs the GPU thread 19/// Runs the GPU thread
20static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, 20static void RunThread(std::stop_token stop_token, Core::System& system,
21 Core::Frontend::GraphicsContext& context, Tegra::DmaPusher& dma_pusher, 21 VideoCore::RendererBase& renderer, Core::Frontend::GraphicsContext& context,
22 SynchState& state) { 22 Tegra::DmaPusher& dma_pusher, SynchState& state) {
23 std::string name = "yuzu:GPU"; 23 std::string name = "yuzu:GPU";
24 MicroProfileOnThreadCreate(name.c_str()); 24 MicroProfileOnThreadCreate(name.c_str());
25 SCOPE_EXIT({ MicroProfileOnThreadExit(); }); 25 SCOPE_EXIT({ MicroProfileOnThreadExit(); });
@@ -28,20 +28,14 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer,
28 Common::SetCurrentThreadPriority(Common::ThreadPriority::High); 28 Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
29 system.RegisterHostThread(); 29 system.RegisterHostThread();
30 30
31 // Wait for first GPU command before acquiring the window context
32 state.queue.Wait();
33
34 // If emulation was stopped during disk shader loading, abort before trying to acquire context
35 if (!state.is_running) {
36 return;
37 }
38
39 auto current_context = context.Acquire(); 31 auto current_context = context.Acquire();
40 VideoCore::RasterizerInterface* const rasterizer = renderer.ReadRasterizer(); 32 VideoCore::RasterizerInterface* const rasterizer = renderer.ReadRasterizer();
41 33
42 CommandDataContainer next; 34 while (!stop_token.stop_requested()) {
43 while (state.is_running) { 35 CommandDataContainer next = state.queue.PopWait(stop_token);
44 next = state.queue.PopWait(); 36 if (stop_token.stop_requested()) {
37 break;
38 }
45 if (auto* submit_list = std::get_if<SubmitListCommand>(&next.data)) { 39 if (auto* submit_list = std::get_if<SubmitListCommand>(&next.data)) {
46 dma_pusher.Push(std::move(submit_list->entries)); 40 dma_pusher.Push(std::move(submit_list->entries));
47 dma_pusher.DispatchCalls(); 41 dma_pusher.DispatchCalls();
@@ -55,8 +49,6 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer,
55 rasterizer->FlushRegion(flush->addr, flush->size); 49 rasterizer->FlushRegion(flush->addr, flush->size);
56 } else if (const auto* invalidate = std::get_if<InvalidateRegionCommand>(&next.data)) { 50 } else if (const auto* invalidate = std::get_if<InvalidateRegionCommand>(&next.data)) {
57 rasterizer->OnCPUWrite(invalidate->addr, invalidate->size); 51 rasterizer->OnCPUWrite(invalidate->addr, invalidate->size);
58 } else if (std::holds_alternative<EndProcessingCommand>(next.data)) {
59 ASSERT(state.is_running == false);
60 } else { 52 } else {
61 UNREACHABLE(); 53 UNREACHABLE();
62 } 54 }
@@ -73,16 +65,14 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer,
73ThreadManager::ThreadManager(Core::System& system_, bool is_async_) 65ThreadManager::ThreadManager(Core::System& system_, bool is_async_)
74 : system{system_}, is_async{is_async_} {} 66 : system{system_}, is_async{is_async_} {}
75 67
76ThreadManager::~ThreadManager() { 68ThreadManager::~ThreadManager() = default;
77 ShutDown();
78}
79 69
80void ThreadManager::StartThread(VideoCore::RendererBase& renderer, 70void ThreadManager::StartThread(VideoCore::RendererBase& renderer,
81 Core::Frontend::GraphicsContext& context, 71 Core::Frontend::GraphicsContext& context,
82 Tegra::DmaPusher& dma_pusher) { 72 Tegra::DmaPusher& dma_pusher) {
83 rasterizer = renderer.ReadRasterizer(); 73 rasterizer = renderer.ReadRasterizer();
84 thread = std::thread(RunThread, std::ref(system), std::ref(renderer), std::ref(context), 74 thread = std::jthread(RunThread, std::ref(system), std::ref(renderer), std::ref(context),
85 std::ref(dma_pusher), std::ref(state)); 75 std::ref(dma_pusher), std::ref(state));
86} 76}
87 77
88void ThreadManager::SubmitList(Tegra::CommandList&& entries) { 78void ThreadManager::SubmitList(Tegra::CommandList&& entries) {
@@ -117,26 +107,6 @@ void ThreadManager::FlushAndInvalidateRegion(VAddr addr, u64 size) {
117 rasterizer->OnCPUWrite(addr, size); 107 rasterizer->OnCPUWrite(addr, size);
118} 108}
119 109
120void ThreadManager::ShutDown() {
121 if (!state.is_running) {
122 return;
123 }
124
125 {
126 std::lock_guard lk(state.write_lock);
127 state.is_running = false;
128 state.cv.notify_all();
129 }
130
131 if (!thread.joinable()) {
132 return;
133 }
134
135 // Notify GPU thread that a shutdown is pending
136 PushCommand(EndProcessingCommand());
137 thread.join();
138}
139
140void ThreadManager::OnCommandListEnd() { 110void ThreadManager::OnCommandListEnd() {
141 PushCommand(OnCommandListEndCommand()); 111 PushCommand(OnCommandListEndCommand());
142} 112}
@@ -152,9 +122,8 @@ u64 ThreadManager::PushCommand(CommandData&& command_data, bool block) {
152 state.queue.Push(CommandDataContainer(std::move(command_data), fence, block)); 122 state.queue.Push(CommandDataContainer(std::move(command_data), fence, block));
153 123
154 if (block) { 124 if (block) {
155 state.cv.wait(lk, [this, fence] { 125 state.cv.wait(lk, thread.get_stop_token(), [this, fence] {
156 return fence <= state.signaled_fence.load(std::memory_order_relaxed) || 126 return fence <= state.signaled_fence.load(std::memory_order_relaxed);
157 !state.is_running;
158 }); 127 });
159 } 128 }
160 129
diff --git a/src/video_core/gpu_thread.h b/src/video_core/gpu_thread.h
index 11a648f38..91bada925 100644
--- a/src/video_core/gpu_thread.h
+++ b/src/video_core/gpu_thread.h
@@ -33,9 +33,6 @@ class RendererBase;
33 33
34namespace VideoCommon::GPUThread { 34namespace VideoCommon::GPUThread {
35 35
36/// Command to signal to the GPU thread that processing has ended
37struct EndProcessingCommand final {};
38
39/// Command to signal to the GPU thread that a command list is ready for processing 36/// Command to signal to the GPU thread that a command list is ready for processing
40struct SubmitListCommand final { 37struct SubmitListCommand final {
41 explicit SubmitListCommand(Tegra::CommandList&& entries_) : entries{std::move(entries_)} {} 38 explicit SubmitListCommand(Tegra::CommandList&& entries_) : entries{std::move(entries_)} {}
@@ -83,7 +80,7 @@ struct OnCommandListEndCommand final {};
83struct GPUTickCommand final {}; 80struct GPUTickCommand final {};
84 81
85using CommandData = 82using CommandData =
86 std::variant<EndProcessingCommand, SubmitListCommand, SwapBuffersCommand, FlushRegionCommand, 83 std::variant<std::monostate, SubmitListCommand, SwapBuffersCommand, FlushRegionCommand,
87 InvalidateRegionCommand, FlushAndInvalidateRegionCommand, OnCommandListEndCommand, 84 InvalidateRegionCommand, FlushAndInvalidateRegionCommand, OnCommandListEndCommand,
88 GPUTickCommand>; 85 GPUTickCommand>;
89 86
@@ -100,14 +97,12 @@ struct CommandDataContainer {
100 97
101/// Struct used to synchronize the GPU thread 98/// Struct used to synchronize the GPU thread
102struct SynchState final { 99struct SynchState final {
103 std::atomic_bool is_running{true}; 100 using CommandQueue = Common::SPSCQueue<CommandDataContainer, true>;
104
105 using CommandQueue = Common::SPSCQueue<CommandDataContainer>;
106 std::mutex write_lock; 101 std::mutex write_lock;
107 CommandQueue queue; 102 CommandQueue queue;
108 u64 last_fence{}; 103 u64 last_fence{};
109 std::atomic<u64> signaled_fence{}; 104 std::atomic<u64> signaled_fence{};
110 std::condition_variable cv; 105 std::condition_variable_any cv;
111}; 106};
112 107
113/// Class used to manage the GPU thread 108/// Class used to manage the GPU thread
@@ -149,7 +144,7 @@ private:
149 VideoCore::RasterizerInterface* rasterizer = nullptr; 144 VideoCore::RasterizerInterface* rasterizer = nullptr;
150 145
151 SynchState state; 146 SynchState state;
152 std::thread thread; 147 std::jthread thread;
153}; 148};
154 149
155} // namespace VideoCommon::GPUThread 150} // namespace VideoCommon::GPUThread
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index b0e14182e..02682bd76 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -293,6 +293,8 @@ void ShaderCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading,
293 }}; 293 }};
294 LoadPipelines(stop_loading, shader_cache_filename, CACHE_VERSION, load_compute, load_graphics); 294 LoadPipelines(stop_loading, shader_cache_filename, CACHE_VERSION, load_compute, load_graphics);
295 295
296 LOG_INFO(Render_OpenGL, "Total Pipeline Count: {}", state.total);
297
296 std::unique_lock lock{state.mutex}; 298 std::unique_lock lock{state.mutex};
297 callback(VideoCore::LoadCallbackStage::Build, 0, state.total); 299 callback(VideoCore::LoadCallbackStage::Build, 0, state.total);
298 state.has_loaded = true; 300 state.has_loaded = true;
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
index 31bfbcb06..eb8b4e08b 100644
--- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
@@ -447,6 +447,8 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading
447 VideoCommon::LoadPipelines(stop_loading, pipeline_cache_filename, CACHE_VERSION, load_compute, 447 VideoCommon::LoadPipelines(stop_loading, pipeline_cache_filename, CACHE_VERSION, load_compute,
448 load_graphics); 448 load_graphics);
449 449
450 LOG_INFO(Render_Vulkan, "Total Pipeline Count: {}", state.total);
451
450 std::unique_lock lock{state.mutex}; 452 std::unique_lock lock{state.mutex};
451 callback(VideoCore::LoadCallbackStage::Build, 0, state.total); 453 callback(VideoCore::LoadCallbackStage::Build, 0, state.total);
452 state.has_loaded = true; 454 state.has_loaded = true;
diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp
index 1d438787a..0c11c814f 100644
--- a/src/video_core/renderer_vulkan/vk_scheduler.cpp
+++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp
@@ -43,17 +43,10 @@ VKScheduler::VKScheduler(const Device& device_, StateTracker& state_tracker_)
43 command_pool{std::make_unique<CommandPool>(*master_semaphore, device)} { 43 command_pool{std::make_unique<CommandPool>(*master_semaphore, device)} {
44 AcquireNewChunk(); 44 AcquireNewChunk();
45 AllocateWorkerCommandBuffer(); 45 AllocateWorkerCommandBuffer();
46 worker_thread = std::thread(&VKScheduler::WorkerThread, this); 46 worker_thread = std::jthread([this](std::stop_token token) { WorkerThread(token); });
47} 47}
48 48
49VKScheduler::~VKScheduler() { 49VKScheduler::~VKScheduler() = default;
50 {
51 std::lock_guard lock{work_mutex};
52 quit = true;
53 }
54 work_cv.notify_all();
55 worker_thread.join();
56}
57 50
58void VKScheduler::Flush(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore) { 51void VKScheduler::Flush(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore) {
59 SubmitExecution(signal_semaphore, wait_semaphore); 52 SubmitExecution(signal_semaphore, wait_semaphore);
@@ -135,7 +128,7 @@ bool VKScheduler::UpdateGraphicsPipeline(GraphicsPipeline* pipeline) {
135 return true; 128 return true;
136} 129}
137 130
138void VKScheduler::WorkerThread() { 131void VKScheduler::WorkerThread(std::stop_token stop_token) {
139 Common::SetCurrentThreadName("yuzu:VulkanWorker"); 132 Common::SetCurrentThreadName("yuzu:VulkanWorker");
140 do { 133 do {
141 if (work_queue.empty()) { 134 if (work_queue.empty()) {
@@ -144,8 +137,8 @@ void VKScheduler::WorkerThread() {
144 std::unique_ptr<CommandChunk> work; 137 std::unique_ptr<CommandChunk> work;
145 { 138 {
146 std::unique_lock lock{work_mutex}; 139 std::unique_lock lock{work_mutex};
147 work_cv.wait(lock, [this] { return !work_queue.empty() || quit; }); 140 work_cv.wait(lock, stop_token, [this] { return !work_queue.empty(); });
148 if (quit) { 141 if (stop_token.stop_requested()) {
149 continue; 142 continue;
150 } 143 }
151 work = std::move(work_queue.front()); 144 work = std::move(work_queue.front());
@@ -158,7 +151,7 @@ void VKScheduler::WorkerThread() {
158 } 151 }
159 std::lock_guard reserve_lock{reserve_mutex}; 152 std::lock_guard reserve_lock{reserve_mutex};
160 chunk_reserve.push_back(std::move(work)); 153 chunk_reserve.push_back(std::move(work));
161 } while (!quit); 154 } while (!stop_token.stop_requested());
162} 155}
163 156
164void VKScheduler::AllocateWorkerCommandBuffer() { 157void VKScheduler::AllocateWorkerCommandBuffer() {
diff --git a/src/video_core/renderer_vulkan/vk_scheduler.h b/src/video_core/renderer_vulkan/vk_scheduler.h
index 759ed5a48..bd22e4e83 100644
--- a/src/video_core/renderer_vulkan/vk_scheduler.h
+++ b/src/video_core/renderer_vulkan/vk_scheduler.h
@@ -187,7 +187,7 @@ private:
187 GraphicsPipeline* graphics_pipeline = nullptr; 187 GraphicsPipeline* graphics_pipeline = nullptr;
188 }; 188 };
189 189
190 void WorkerThread(); 190 void WorkerThread(std::stop_token stop_token);
191 191
192 void AllocateWorkerCommandBuffer(); 192 void AllocateWorkerCommandBuffer();
193 193
@@ -212,7 +212,7 @@ private:
212 vk::CommandBuffer current_cmdbuf; 212 vk::CommandBuffer current_cmdbuf;
213 213
214 std::unique_ptr<CommandChunk> chunk; 214 std::unique_ptr<CommandChunk> chunk;
215 std::thread worker_thread; 215 std::jthread worker_thread;
216 216
217 State state; 217 State state;
218 218
@@ -224,9 +224,8 @@ private:
224 std::vector<std::unique_ptr<CommandChunk>> chunk_reserve; 224 std::vector<std::unique_ptr<CommandChunk>> chunk_reserve;
225 std::mutex reserve_mutex; 225 std::mutex reserve_mutex;
226 std::mutex work_mutex; 226 std::mutex work_mutex;
227 std::condition_variable work_cv; 227 std::condition_variable_any work_cv;
228 std::condition_variable wait_cv; 228 std::condition_variable wait_cv;
229 std::atomic_bool quit{};
230}; 229};
231 230
232} // namespace Vulkan 231} // namespace Vulkan
diff --git a/src/video_core/vulkan_common/vulkan_debug_callback.cpp b/src/video_core/vulkan_common/vulkan_debug_callback.cpp
index 0f60765bb..cf94e1d39 100644
--- a/src/video_core/vulkan_common/vulkan_debug_callback.cpp
+++ b/src/video_core/vulkan_common/vulkan_debug_callback.cpp
@@ -16,6 +16,7 @@ VkBool32 Callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
16 switch (static_cast<u32>(data->messageIdNumber)) { 16 switch (static_cast<u32>(data->messageIdNumber)) {
17 case 0x682a878au: // VUID-vkCmdBindVertexBuffers2EXT-pBuffers-parameter 17 case 0x682a878au: // VUID-vkCmdBindVertexBuffers2EXT-pBuffers-parameter
18 case 0x99fb7dfdu: // UNASSIGNED-RequiredParameter (vkCmdBindVertexBuffers2EXT pBuffers[0]) 18 case 0x99fb7dfdu: // UNASSIGNED-RequiredParameter (vkCmdBindVertexBuffers2EXT pBuffers[0])
19 case 0xe8616bf2u: // Bound VkDescriptorSet 0x0[] was destroyed. Likely push_descriptor related
19 return VK_FALSE; 20 return VK_FALSE;
20 default: 21 default:
21 break; 22 break;
diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp
index 24fb50db9..c2ec9f76a 100644
--- a/src/video_core/vulkan_common/vulkan_device.cpp
+++ b/src/video_core/vulkan_common/vulkan_device.cpp
@@ -243,7 +243,6 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
243 SetupFamilies(surface); 243 SetupFamilies(surface);
244 SetupFeatures(); 244 SetupFeatures();
245 SetupProperties(); 245 SetupProperties();
246 CollectTelemetryParameters();
247 246
248 const auto queue_cis = GetDeviceQueueCreateInfos(); 247 const auto queue_cis = GetDeviceQueueCreateInfos();
249 const std::vector extensions = LoadExtensions(surface != nullptr); 248 const std::vector extensions = LoadExtensions(surface != nullptr);
@@ -369,20 +368,9 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
369 }; 368 };
370 SetNext(next, demote); 369 SetNext(next, demote);
371 370
372 if (driver_id == VK_DRIVER_ID_AMD_PROPRIETARY || driver_id == VK_DRIVER_ID_AMD_OPEN_SOURCE) { 371 VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
373 const u32 version = properties.driverVersion;
374 // Broken in this driver
375 if (version > VK_MAKE_API_VERSION(0, 2, 0, 193)) {
376 LOG_WARNING(Render_Vulkan, "AMD proprietary driver versions newer than 21.9.1 "
377 "(windows) / 0.2.0.194 (amdvlk) have "
378 "broken VkPhysicalDeviceFloat16Int8FeaturesKHR");
379 is_int8_supported = false;
380 is_float16_supported = false;
381 }
382 }
383
384 if (is_int8_supported || is_float16_supported) { 372 if (is_int8_supported || is_float16_supported) {
385 VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8{ 373 float16_int8 = {
386 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR, 374 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
387 .pNext = nullptr, 375 .pNext = nullptr,
388 .shaderFloat16 = is_float16_supported, 376 .shaderFloat16 = is_float16_supported,
@@ -573,6 +561,7 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
573 logical = vk::Device::Create(physical, queue_cis, extensions, first_next, dld); 561 logical = vk::Device::Create(physical, queue_cis, extensions, first_next, dld);
574 562
575 CollectPhysicalMemoryInfo(); 563 CollectPhysicalMemoryInfo();
564 CollectTelemetryParameters();
576 CollectToolingInfo(); 565 CollectToolingInfo();
577 566
578 if (driver_id == VK_DRIVER_ID_NVIDIA_PROPRIETARY_KHR) { 567 if (driver_id == VK_DRIVER_ID_NVIDIA_PROPRIETARY_KHR) {
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt
index 19ba0dbba..b6dda283d 100644
--- a/src/yuzu/CMakeLists.txt
+++ b/src/yuzu/CMakeLists.txt
@@ -108,6 +108,9 @@ add_executable(yuzu
108 configuration/configure_system.cpp 108 configuration/configure_system.cpp
109 configuration/configure_system.h 109 configuration/configure_system.h
110 configuration/configure_system.ui 110 configuration/configure_system.ui
111 configuration/configure_tas.cpp
112 configuration/configure_tas.h
113 configuration/configure_tas.ui
111 configuration/configure_touch_from_button.cpp 114 configuration/configure_touch_from_button.cpp
112 configuration/configure_touch_from_button.h 115 configuration/configure_touch_from_button.h
113 configuration/configure_touch_from_button.ui 116 configuration/configure_touch_from_button.ui
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 2e0ade815..1519a46ed 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -36,6 +36,7 @@
36#include "input_common/keyboard.h" 36#include "input_common/keyboard.h"
37#include "input_common/main.h" 37#include "input_common/main.h"
38#include "input_common/mouse/mouse_input.h" 38#include "input_common/mouse/mouse_input.h"
39#include "input_common/tas/tas_input.h"
39#include "video_core/renderer_base.h" 40#include "video_core/renderer_base.h"
40#include "video_core/video_core.h" 41#include "video_core/video_core.h"
41#include "yuzu/bootmanager.h" 42#include "yuzu/bootmanager.h"
@@ -312,6 +313,7 @@ GRenderWindow::~GRenderWindow() {
312} 313}
313 314
314void GRenderWindow::OnFrameDisplayed() { 315void GRenderWindow::OnFrameDisplayed() {
316 input_subsystem->GetTas()->UpdateThread();
315 if (!first_frame) { 317 if (!first_frame) {
316 first_frame = true; 318 first_frame = true;
317 emit FirstFrameDisplayed(); 319 emit FirstFrameDisplayed();
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp
index 8744d8e5d..27b67fd9e 100644
--- a/src/yuzu/configuration/config.cpp
+++ b/src/yuzu/configuration/config.cpp
@@ -221,7 +221,7 @@ const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> Config::default
221// This must be in alphabetical order according to action name as it must have the same order as 221// This must be in alphabetical order according to action name as it must have the same order as
222// UISetting::values.shortcuts, which is alphabetically ordered. 222// UISetting::values.shortcuts, which is alphabetically ordered.
223// clang-format off 223// clang-format off
224const std::array<UISettings::Shortcut, 18> Config::default_hotkeys{{ 224const std::array<UISettings::Shortcut, 21> Config::default_hotkeys{{
225 {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::WidgetWithChildrenShortcut}}, 225 {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::WidgetWithChildrenShortcut}},
226 {QStringLiteral("Change Docked Mode"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::ApplicationShortcut}}, 226 {QStringLiteral("Change Docked Mode"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::ApplicationShortcut}},
227 {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, 227 {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}},
@@ -235,6 +235,9 @@ const std::array<UISettings::Shortcut, 18> Config::default_hotkeys{{
235 {QStringLiteral("Mute Audio"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}}, 235 {QStringLiteral("Mute Audio"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}},
236 {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, 236 {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}},
237 {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}}, 237 {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}},
238 {QStringLiteral("TAS Start/Stop"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F5"), Qt::ApplicationShortcut}},
239 {QStringLiteral("TAS Reset"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F6"), Qt::ApplicationShortcut}},
240 {QStringLiteral("TAS Record"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F7"), Qt::ApplicationShortcut}},
238 {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, 241 {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}},
239 {QStringLiteral("Toggle Framerate Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+U"), Qt::ApplicationShortcut}}, 242 {QStringLiteral("Toggle Framerate Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+U"), Qt::ApplicationShortcut}},
240 {QStringLiteral("Toggle Mouse Panning"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F9"), Qt::ApplicationShortcut}}, 243 {QStringLiteral("Toggle Mouse Panning"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F9"), Qt::ApplicationShortcut}},
@@ -542,7 +545,6 @@ void Config::ReadAudioValues() {
542 ReadBasicSetting(Settings::values.audio_device_id); 545 ReadBasicSetting(Settings::values.audio_device_id);
543 ReadBasicSetting(Settings::values.sink_id); 546 ReadBasicSetting(Settings::values.sink_id);
544 } 547 }
545 ReadGlobalSetting(Settings::values.enable_audio_stretching);
546 ReadGlobalSetting(Settings::values.volume); 548 ReadGlobalSetting(Settings::values.volume);
547 549
548 qt_config->endGroup(); 550 qt_config->endGroup();
@@ -560,10 +562,16 @@ void Config::ReadControlValues() {
560 ReadTouchscreenValues(); 562 ReadTouchscreenValues();
561 ReadMotionTouchValues(); 563 ReadMotionTouchValues();
562 564
565 ReadBasicSetting(Settings::values.enable_raw_input);
563 ReadBasicSetting(Settings::values.emulate_analog_keyboard); 566 ReadBasicSetting(Settings::values.emulate_analog_keyboard);
564 Settings::values.mouse_panning = false; 567 Settings::values.mouse_panning = false;
565 ReadBasicSetting(Settings::values.mouse_panning_sensitivity); 568 ReadBasicSetting(Settings::values.mouse_panning_sensitivity);
566 569
570 ReadBasicSetting(Settings::values.tas_enable);
571 ReadBasicSetting(Settings::values.tas_loop);
572 ReadBasicSetting(Settings::values.tas_swap_controllers);
573 ReadBasicSetting(Settings::values.pause_tas_on_load);
574
567 ReadGlobalSetting(Settings::values.use_docked_mode); 575 ReadGlobalSetting(Settings::values.use_docked_mode);
568 576
569 // Disable docked mode if handheld is selected 577 // Disable docked mode if handheld is selected
@@ -661,6 +669,13 @@ void Config::ReadDataStorageValues() {
661 QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir))) 669 QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)))
662 .toString() 670 .toString()
663 .toStdString()); 671 .toStdString());
672 FS::SetYuzuPath(FS::YuzuPath::TASDir,
673 qt_config
674 ->value(QStringLiteral("tas_directory"),
675 QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::TASDir)))
676 .toString()
677 .toStdString());
678
664 ReadBasicSetting(Settings::values.gamecard_inserted); 679 ReadBasicSetting(Settings::values.gamecard_inserted);
665 ReadBasicSetting(Settings::values.gamecard_current_game); 680 ReadBasicSetting(Settings::values.gamecard_current_game);
666 ReadBasicSetting(Settings::values.gamecard_path); 681 ReadBasicSetting(Settings::values.gamecard_path);
@@ -1163,7 +1178,6 @@ void Config::SaveAudioValues() {
1163 WriteBasicSetting(Settings::values.sink_id); 1178 WriteBasicSetting(Settings::values.sink_id);
1164 WriteBasicSetting(Settings::values.audio_device_id); 1179 WriteBasicSetting(Settings::values.audio_device_id);
1165 } 1180 }
1166 WriteGlobalSetting(Settings::values.enable_audio_stretching);
1167 WriteGlobalSetting(Settings::values.volume); 1181 WriteGlobalSetting(Settings::values.volume);
1168 1182
1169 qt_config->endGroup(); 1183 qt_config->endGroup();
@@ -1184,10 +1198,16 @@ void Config::SaveControlValues() {
1184 WriteGlobalSetting(Settings::values.vibration_enabled); 1198 WriteGlobalSetting(Settings::values.vibration_enabled);
1185 WriteGlobalSetting(Settings::values.enable_accurate_vibrations); 1199 WriteGlobalSetting(Settings::values.enable_accurate_vibrations);
1186 WriteGlobalSetting(Settings::values.motion_enabled); 1200 WriteGlobalSetting(Settings::values.motion_enabled);
1201 WriteBasicSetting(Settings::values.enable_raw_input);
1187 WriteBasicSetting(Settings::values.keyboard_enabled); 1202 WriteBasicSetting(Settings::values.keyboard_enabled);
1188 WriteBasicSetting(Settings::values.emulate_analog_keyboard); 1203 WriteBasicSetting(Settings::values.emulate_analog_keyboard);
1189 WriteBasicSetting(Settings::values.mouse_panning_sensitivity); 1204 WriteBasicSetting(Settings::values.mouse_panning_sensitivity);
1190 1205
1206 WriteBasicSetting(Settings::values.tas_enable);
1207 WriteBasicSetting(Settings::values.tas_loop);
1208 WriteBasicSetting(Settings::values.tas_swap_controllers);
1209 WriteBasicSetting(Settings::values.pause_tas_on_load);
1210
1191 qt_config->endGroup(); 1211 qt_config->endGroup();
1192} 1212}
1193 1213
@@ -1215,6 +1235,10 @@ void Config::SaveDataStorageValues() {
1215 WriteSetting(QStringLiteral("dump_directory"), 1235 WriteSetting(QStringLiteral("dump_directory"),
1216 QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)), 1236 QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)),
1217 QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir))); 1237 QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)));
1238 WriteSetting(QStringLiteral("tas_directory"),
1239 QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::TASDir)),
1240 QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::TASDir)));
1241
1218 WriteBasicSetting(Settings::values.gamecard_inserted); 1242 WriteBasicSetting(Settings::values.gamecard_inserted);
1219 WriteBasicSetting(Settings::values.gamecard_current_game); 1243 WriteBasicSetting(Settings::values.gamecard_current_game);
1220 WriteBasicSetting(Settings::values.gamecard_path); 1244 WriteBasicSetting(Settings::values.gamecard_path);
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h
index 4733227b6..3ee694e7c 100644
--- a/src/yuzu/configuration/config.h
+++ b/src/yuzu/configuration/config.h
@@ -42,7 +42,7 @@ public:
42 default_mouse_buttons; 42 default_mouse_buttons;
43 static const std::array<int, Settings::NativeKeyboard::NumKeyboardKeys> default_keyboard_keys; 43 static const std::array<int, Settings::NativeKeyboard::NumKeyboardKeys> default_keyboard_keys;
44 static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods; 44 static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods;
45 static const std::array<UISettings::Shortcut, 18> default_hotkeys; 45 static const std::array<UISettings::Shortcut, 21> default_hotkeys;
46 46
47private: 47private:
48 void Initialize(const std::string& config_name); 48 void Initialize(const std::string& config_name);
diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp
index 1d84bf4ed..f437cb53d 100644
--- a/src/yuzu/configuration/configure_audio.cpp
+++ b/src/yuzu/configuration/configure_audio.cpp
@@ -50,8 +50,6 @@ void ConfigureAudio::SetConfiguration() {
50 const auto volume_value = static_cast<int>(Settings::values.volume.GetValue()); 50 const auto volume_value = static_cast<int>(Settings::values.volume.GetValue());
51 ui->volume_slider->setValue(volume_value); 51 ui->volume_slider->setValue(volume_value);
52 52
53 ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching.GetValue());
54
55 if (!Settings::IsConfiguringGlobal()) { 53 if (!Settings::IsConfiguringGlobal()) {
56 if (Settings::values.volume.UsingGlobal()) { 54 if (Settings::values.volume.UsingGlobal()) {
57 ui->volume_combo_box->setCurrentIndex(0); 55 ui->volume_combo_box->setCurrentIndex(0);
@@ -100,8 +98,6 @@ void ConfigureAudio::SetVolumeIndicatorText(int percentage) {
100} 98}
101 99
102void ConfigureAudio::ApplyConfiguration() { 100void ConfigureAudio::ApplyConfiguration() {
103 ConfigurationShared::ApplyPerGameSetting(&Settings::values.enable_audio_stretching,
104 ui->toggle_audio_stretching, enable_audio_stretching);
105 101
106 if (Settings::IsConfiguringGlobal()) { 102 if (Settings::IsConfiguringGlobal()) {
107 Settings::values.sink_id = 103 Settings::values.sink_id =
@@ -162,15 +158,10 @@ void ConfigureAudio::RetranslateUI() {
162void ConfigureAudio::SetupPerGameUI() { 158void ConfigureAudio::SetupPerGameUI() {
163 if (Settings::IsConfiguringGlobal()) { 159 if (Settings::IsConfiguringGlobal()) {
164 ui->volume_slider->setEnabled(Settings::values.volume.UsingGlobal()); 160 ui->volume_slider->setEnabled(Settings::values.volume.UsingGlobal());
165 ui->toggle_audio_stretching->setEnabled(
166 Settings::values.enable_audio_stretching.UsingGlobal());
167 161
168 return; 162 return;
169 } 163 }
170 164
171 ConfigurationShared::SetColoredTristate(ui->toggle_audio_stretching,
172 Settings::values.enable_audio_stretching,
173 enable_audio_stretching);
174 connect(ui->volume_combo_box, qOverload<int>(&QComboBox::activated), this, [this](int index) { 165 connect(ui->volume_combo_box, qOverload<int>(&QComboBox::activated), this, [this](int index) {
175 ui->volume_slider->setEnabled(index == 1); 166 ui->volume_slider->setEnabled(index == 1);
176 ConfigurationShared::SetHighlight(ui->volume_layout, index == 1); 167 ConfigurationShared::SetHighlight(ui->volume_layout, index == 1);
diff --git a/src/yuzu/configuration/configure_audio.h b/src/yuzu/configuration/configure_audio.h
index 9dbd3d93e..5a01c8de7 100644
--- a/src/yuzu/configuration/configure_audio.h
+++ b/src/yuzu/configuration/configure_audio.h
@@ -41,6 +41,4 @@ private:
41 void SetupPerGameUI(); 41 void SetupPerGameUI();
42 42
43 std::unique_ptr<Ui::ConfigureAudio> ui; 43 std::unique_ptr<Ui::ConfigureAudio> ui;
44
45 ConfigurationShared::CheckState enable_audio_stretching;
46}; 44};
diff --git a/src/yuzu/configuration/configure_audio.ui b/src/yuzu/configuration/configure_audio.ui
index 9bd0cca96..bf736fc2c 100644
--- a/src/yuzu/configuration/configure_audio.ui
+++ b/src/yuzu/configuration/configure_audio.ui
@@ -32,16 +32,6 @@
32 </layout> 32 </layout>
33 </item> 33 </item>
34 <item> 34 <item>
35 <widget class="QCheckBox" name="toggle_audio_stretching">
36 <property name="toolTip">
37 <string>This post-processing effect adjusts audio speed to match emulation speed and helps prevent audio stutter. This however increases audio latency.</string>
38 </property>
39 <property name="text">
40 <string>Enable audio stretching</string>
41 </property>
42 </widget>
43 </item>
44 <item>
45 <layout class="QHBoxLayout" name="_2"> 35 <layout class="QHBoxLayout" name="_2">
46 <item> 36 <item>
47 <widget class="QLabel" name="audio_device_label"> 37 <widget class="QLabel" name="audio_device_label">
diff --git a/src/yuzu/configuration/configure_input_advanced.cpp b/src/yuzu/configuration/configure_input_advanced.cpp
index 2f1419b5b..d20fd86b6 100644
--- a/src/yuzu/configuration/configure_input_advanced.cpp
+++ b/src/yuzu/configuration/configure_input_advanced.cpp
@@ -126,6 +126,7 @@ void ConfigureInputAdvanced::ApplyConfiguration() {
126 Settings::values.mouse_panning_sensitivity = 126 Settings::values.mouse_panning_sensitivity =
127 static_cast<float>(ui->mouse_panning_sensitivity->value()); 127 static_cast<float>(ui->mouse_panning_sensitivity->value());
128 Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked(); 128 Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked();
129 Settings::values.enable_raw_input = ui->enable_raw_input->isChecked();
129} 130}
130 131
131void ConfigureInputAdvanced::LoadConfiguration() { 132void ConfigureInputAdvanced::LoadConfiguration() {
@@ -155,6 +156,7 @@ void ConfigureInputAdvanced::LoadConfiguration() {
155 ui->mouse_panning->setChecked(Settings::values.mouse_panning.GetValue()); 156 ui->mouse_panning->setChecked(Settings::values.mouse_panning.GetValue());
156 ui->mouse_panning_sensitivity->setValue(Settings::values.mouse_panning_sensitivity.GetValue()); 157 ui->mouse_panning_sensitivity->setValue(Settings::values.mouse_panning_sensitivity.GetValue());
157 ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled); 158 ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled);
159 ui->enable_raw_input->setChecked(Settings::values.enable_raw_input.GetValue());
158 160
159 UpdateUIEnabled(); 161 UpdateUIEnabled();
160} 162}
diff --git a/src/yuzu/configuration/configure_input_advanced.ui b/src/yuzu/configuration/configure_input_advanced.ui
index d3ef5bd06..9095206a0 100644
--- a/src/yuzu/configuration/configure_input_advanced.ui
+++ b/src/yuzu/configuration/configure_input_advanced.ui
@@ -2672,6 +2672,22 @@
2672 </property> 2672 </property>
2673 </widget> 2673 </widget>
2674 </item> 2674 </item>
2675 <item row="9" column="0">
2676 <widget class="QCheckBox" name="enable_raw_input">
2677 <property name="toolTip">
2678 <string>Requires restarting yuzu</string>
2679 </property>
2680 <property name="minimumSize">
2681 <size>
2682 <width>0</width>
2683 <height>23</height>
2684 </size>
2685 </property>
2686 <property name="text">
2687 <string>Enable XInput 8 player support (disables web applet)</string>
2688 </property>
2689 </widget>
2690 </item>
2675 </layout> 2691 </layout>
2676 </widget> 2692 </widget>
2677 </item> 2693 </item>
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 7527c068b..88f4bf388 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -124,6 +124,19 @@ QString ButtonToText(const Common::ParamPackage& param) {
124 return GetKeyName(param.Get("code", 0)); 124 return GetKeyName(param.Get("code", 0));
125 } 125 }
126 126
127 if (param.Get("engine", "") == "tas") {
128 if (param.Has("axis")) {
129 const QString axis_str = QString::fromStdString(param.Get("axis", ""));
130
131 return QObject::tr("TAS Axis %1").arg(axis_str);
132 }
133 if (param.Has("button")) {
134 const QString button_str = QString::number(int(std::log2(param.Get("button", 0))));
135 return QObject::tr("TAS Btn %1").arg(button_str);
136 }
137 return GetKeyName(param.Get("code", 0));
138 }
139
127 if (param.Get("engine", "") == "cemuhookudp") { 140 if (param.Get("engine", "") == "cemuhookudp") {
128 if (param.Has("pad_index")) { 141 if (param.Has("pad_index")) {
129 const QString motion_str = QString::fromStdString(param.Get("pad_index", "")); 142 const QString motion_str = QString::fromStdString(param.Get("pad_index", ""));
@@ -187,7 +200,8 @@ QString AnalogToText(const Common::ParamPackage& param, const std::string& dir)
187 const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); 200 const QString axis_y_str = QString::fromStdString(param.Get("axis_y", ""));
188 const bool invert_x = param.Get("invert_x", "+") == "-"; 201 const bool invert_x = param.Get("invert_x", "+") == "-";
189 const bool invert_y = param.Get("invert_y", "+") == "-"; 202 const bool invert_y = param.Get("invert_y", "+") == "-";
190 if (engine_str == "sdl" || engine_str == "gcpad" || engine_str == "mouse") { 203 if (engine_str == "sdl" || engine_str == "gcpad" || engine_str == "mouse" ||
204 engine_str == "tas") {
191 if (dir == "modifier") { 205 if (dir == "modifier") {
192 return QObject::tr("[unused]"); 206 return QObject::tr("[unused]");
193 } 207 }
@@ -926,9 +940,9 @@ void ConfigureInputPlayer::UpdateUI() {
926 940
927 int slider_value; 941 int slider_value;
928 auto& param = analogs_param[analog_id]; 942 auto& param = analogs_param[analog_id];
929 const bool is_controller = param.Get("engine", "") == "sdl" || 943 const bool is_controller =
930 param.Get("engine", "") == "gcpad" || 944 param.Get("engine", "") == "sdl" || param.Get("engine", "") == "gcpad" ||
931 param.Get("engine", "") == "mouse"; 945 param.Get("engine", "") == "mouse" || param.Get("engine", "") == "tas";
932 946
933 if (is_controller) { 947 if (is_controller) {
934 if (!param.Has("deadzone")) { 948 if (!param.Has("deadzone")) {
@@ -1045,8 +1059,12 @@ int ConfigureInputPlayer::GetIndexFromControllerType(Settings::ControllerType ty
1045void ConfigureInputPlayer::UpdateInputDevices() { 1059void ConfigureInputPlayer::UpdateInputDevices() {
1046 input_devices = input_subsystem->GetInputDevices(); 1060 input_devices = input_subsystem->GetInputDevices();
1047 ui->comboDevices->clear(); 1061 ui->comboDevices->clear();
1048 for (auto device : input_devices) { 1062 for (auto& device : input_devices) {
1049 ui->comboDevices->addItem(QString::fromStdString(device.Get("display", "Unknown")), {}); 1063 const std::string display = device.Get("display", "Unknown");
1064 ui->comboDevices->addItem(QString::fromStdString(display), {});
1065 if (display == "TAS") {
1066 device.Set("pad", static_cast<u8>(player_index));
1067 }
1050 } 1068 }
1051} 1069}
1052 1070
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp
index 9c890ed5d..da328d904 100644
--- a/src/yuzu/configuration/configure_input_player_widget.cpp
+++ b/src/yuzu/configuration/configure_input_player_widget.cpp
@@ -175,7 +175,7 @@ void PlayerControlPreview::ResetInputs() {
175} 175}
176 176
177void PlayerControlPreview::UpdateInput() { 177void PlayerControlPreview::UpdateInput() {
178 if (!is_enabled && !mapping_active) { 178 if (!is_enabled && !mapping_active && !Settings::values.tas_enable) {
179 return; 179 return;
180 } 180 }
181 bool input_changed = false; 181 bool input_changed = false;
@@ -222,6 +222,19 @@ void PlayerControlPreview::UpdateInput() {
222 222
223 if (input_changed) { 223 if (input_changed) {
224 update(); 224 update();
225 if (controller_callback.input != nullptr) {
226 ControllerInput input{
227 .axis_values = {std::pair<float, float>{
228 axis_values[Settings::NativeAnalog::LStick].value.x(),
229 axis_values[Settings::NativeAnalog::LStick].value.y()},
230 std::pair<float, float>{
231 axis_values[Settings::NativeAnalog::RStick].value.x(),
232 axis_values[Settings::NativeAnalog::RStick].value.y()}},
233 .button_values = button_values,
234 .changed = true,
235 };
236 controller_callback.input(std::move(input));
237 }
225 } 238 }
226 239
227 if (mapping_active) { 240 if (mapping_active) {
@@ -229,6 +242,10 @@ void PlayerControlPreview::UpdateInput() {
229 } 242 }
230} 243}
231 244
245void PlayerControlPreview::SetCallBack(ControllerCallback callback_) {
246 controller_callback = std::move(callback_);
247}
248
232void PlayerControlPreview::paintEvent(QPaintEvent* event) { 249void PlayerControlPreview::paintEvent(QPaintEvent* event) {
233 QFrame::paintEvent(event); 250 QFrame::paintEvent(event);
234 QPainter p(this); 251 QPainter p(this);
diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h
index f4a6a5e1b..f4bbfa528 100644
--- a/src/yuzu/configuration/configure_input_player_widget.h
+++ b/src/yuzu/configuration/configure_input_player_widget.h
@@ -9,6 +9,7 @@
9#include <QPointer> 9#include <QPointer>
10#include "common/settings.h" 10#include "common/settings.h"
11#include "core/frontend/input.h" 11#include "core/frontend/input.h"
12#include "yuzu/debugger/controller.h"
12 13
13class QLabel; 14class QLabel;
14 15
@@ -33,6 +34,7 @@ public:
33 void BeginMappingAnalog(std::size_t button_id); 34 void BeginMappingAnalog(std::size_t button_id);
34 void EndMapping(); 35 void EndMapping();
35 void UpdateInput(); 36 void UpdateInput();
37 void SetCallBack(ControllerCallback callback_);
36 38
37protected: 39protected:
38 void paintEvent(QPaintEvent* event) override; 40 void paintEvent(QPaintEvent* event) override;
@@ -181,6 +183,7 @@ private:
181 using StickArray = 183 using StickArray =
182 std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>; 184 std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>;
183 185
186 ControllerCallback controller_callback;
184 bool is_enabled{}; 187 bool is_enabled{};
185 bool mapping_active{}; 188 bool mapping_active{};
186 int blink_counter{}; 189 int blink_counter{};
diff --git a/src/yuzu/configuration/configure_tas.cpp b/src/yuzu/configuration/configure_tas.cpp
new file mode 100644
index 000000000..b666b175a
--- /dev/null
+++ b/src/yuzu/configuration/configure_tas.cpp
@@ -0,0 +1,84 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <QFileDialog>
6#include <QMessageBox>
7#include "common/fs/fs.h"
8#include "common/fs/path_util.h"
9#include "common/settings.h"
10#include "ui_configure_tas.h"
11#include "yuzu/configuration/configure_tas.h"
12#include "yuzu/uisettings.h"
13
14ConfigureTasDialog::ConfigureTasDialog(QWidget* parent)
15 : QDialog(parent), ui(std::make_unique<Ui::ConfigureTas>()) {
16
17 ui->setupUi(this);
18
19 setFocusPolicy(Qt::ClickFocus);
20 setWindowTitle(tr("TAS Configuration"));
21
22 connect(ui->tas_path_button, &QToolButton::pressed, this,
23 [this] { SetDirectory(DirectoryTarget::TAS, ui->tas_path_edit); });
24
25 LoadConfiguration();
26}
27
28ConfigureTasDialog::~ConfigureTasDialog() = default;
29
30void ConfigureTasDialog::LoadConfiguration() {
31 ui->tas_path_edit->setText(
32 QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::TASDir)));
33 ui->tas_enable->setChecked(Settings::values.tas_enable.GetValue());
34 ui->tas_control_swap->setChecked(Settings::values.tas_swap_controllers.GetValue());
35 ui->tas_loop_script->setChecked(Settings::values.tas_loop.GetValue());
36 ui->tas_pause_on_load->setChecked(Settings::values.pause_tas_on_load.GetValue());
37}
38
39void ConfigureTasDialog::ApplyConfiguration() {
40 Common::FS::SetYuzuPath(Common::FS::YuzuPath::TASDir, ui->tas_path_edit->text().toStdString());
41 Settings::values.tas_enable.SetValue(ui->tas_enable->isChecked());
42 Settings::values.tas_swap_controllers.SetValue(ui->tas_control_swap->isChecked());
43 Settings::values.tas_loop.SetValue(ui->tas_loop_script->isChecked());
44 Settings::values.pause_tas_on_load.SetValue(ui->tas_pause_on_load->isChecked());
45}
46
47void ConfigureTasDialog::SetDirectory(DirectoryTarget target, QLineEdit* edit) {
48 QString caption;
49
50 switch (target) {
51 case DirectoryTarget::TAS:
52 caption = tr("Select TAS Load Directory...");
53 break;
54 }
55
56 QString str = QFileDialog::getExistingDirectory(this, caption, edit->text());
57
58 if (str.isEmpty()) {
59 return;
60 }
61
62 if (str.back() != QChar::fromLatin1('/')) {
63 str.append(QChar::fromLatin1('/'));
64 }
65
66 edit->setText(str);
67}
68
69void ConfigureTasDialog::changeEvent(QEvent* event) {
70 if (event->type() == QEvent::LanguageChange) {
71 RetranslateUI();
72 }
73
74 QDialog::changeEvent(event);
75}
76
77void ConfigureTasDialog::RetranslateUI() {
78 ui->retranslateUi(this);
79}
80
81void ConfigureTasDialog::HandleApplyButtonClicked() {
82 UISettings::values.configuration_applied = true;
83 ApplyConfiguration();
84}
diff --git a/src/yuzu/configuration/configure_tas.h b/src/yuzu/configuration/configure_tas.h
new file mode 100644
index 000000000..1546bf16f
--- /dev/null
+++ b/src/yuzu/configuration/configure_tas.h
@@ -0,0 +1,38 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <QDialog>
8
9namespace Ui {
10class ConfigureTas;
11}
12
13class ConfigureTasDialog : public QDialog {
14 Q_OBJECT
15
16public:
17 explicit ConfigureTasDialog(QWidget* parent);
18 ~ConfigureTasDialog() override;
19
20 /// Save all button configurations to settings file
21 void ApplyConfiguration();
22
23private:
24 enum class DirectoryTarget {
25 TAS,
26 };
27
28 void LoadConfiguration();
29
30 void SetDirectory(DirectoryTarget target, QLineEdit* edit);
31
32 void changeEvent(QEvent* event) override;
33 void RetranslateUI();
34
35 void HandleApplyButtonClicked();
36
37 std::unique_ptr<Ui::ConfigureTas> ui;
38};
diff --git a/src/yuzu/configuration/configure_tas.ui b/src/yuzu/configuration/configure_tas.ui
new file mode 100644
index 000000000..8a3ecb834
--- /dev/null
+++ b/src/yuzu/configuration/configure_tas.ui
@@ -0,0 +1,183 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>ConfigureTas</class>
4 <widget class="QDialog" name="ConfigureTas">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>800</width>
10 <height>300</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>Dialog</string>
15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout_1">
17 <item>
18 <layout class="QHBoxLayout" name="horizontalLayout">
19 <item>
20 <widget class="QGroupBox" name="groupBox">
21 <property name="title">
22 <string>TAS</string>
23 </property>
24 <layout class="QGridLayout" name="gridLayout">
25 <item row="0" column="0" colspan="1">
26 <widget class="QLabel" name="label_1">
27 <property name="text">
28 <string>Reads controller input from scripts in the same format as TAS-nx scripts. For a more detailed explanation please consult the FAQ on the yuzu website.</string>
29 </property>
30 <property name="wordWrap">
31 <bool>true</bool>
32 </property>
33 </widget>
34 </item>
35 <item row="1" column="0" colspan="1">
36 <widget class="QLabel" name="label_2">
37 <property name="text">
38 <string>To check which hotkeys control the playback/recording, please refer to the Hotkey settings (General -> Hotkeys).</string>
39 </property>
40 <property name="wordWrap">
41 <bool>true</bool>
42 </property>
43 </widget>
44 </item>
45 <item row="2" column="0" colspan="1">
46 <widget class="QLabel" name="label_2">
47 <property name="text">
48 <string>WARNING: This is an experimental feature. It will not play back scripts frame perfectly with the current, imperfect syncing method.</string>
49 </property>
50 <property name="wordWrap">
51 <bool>true</bool>
52 </property>
53 </widget>
54 </item>
55 </layout>
56 </widget>
57 </item>
58 </layout>
59 </item>
60 <item>
61 <layout class="QHBoxLayout" name="horizontalLayout">
62 <item>
63 <widget class="QGroupBox" name="groupBox">
64 <property name="title">
65 <string>Settings</string>
66 </property>
67 <layout class="QGridLayout" name="gridLayout">
68 <item row="0" column="0" colspan="4">
69 <widget class="QCheckBox" name="tas_enable">
70 <property name="text">
71 <string>Enable TAS features</string>
72 </property>
73 </widget>
74 </item>
75 <item row="1" column="0" colspan="4">
76 <widget class="QCheckBox" name="tas_control_swap">
77 <property name="text">
78 <string>Automatic controller profile swapping</string>
79 </property>
80 </widget>
81 </item>
82 <item row="2" column="0" colspan="4">
83 <widget class="QCheckBox" name="tas_loop_script">
84 <property name="text">
85 <string>Loop script</string>
86 </property>
87 </widget>
88 </item>
89 <item row="3" column="0" colspan="4">
90 <widget class="QCheckBox" name="tas_pause_on_load">
91 <property name="enabled">
92 <bool>false</bool>
93 </property>
94 <property name="text">
95 <string>Pause execution during loads</string>
96 </property>
97 </widget>
98 </item>
99 </layout>
100 </widget>
101 </item>
102 </layout>
103 </item>
104 <item>
105 <layout class="QHBoxLayout" name="horizontalLayout">
106 <item>
107 <widget class="QGroupBox" name="groupBox">
108 <property name="title">
109 <string>Script Directory</string>
110 </property>
111 <layout class="QGridLayout" name="gridLayout">
112 <item row="0" column="0">
113 <widget class="QLabel" name="label">
114 <property name="text">
115 <string>Path</string>
116 </property>
117 </widget>
118 </item>
119 <item row="0" column="3">
120 <widget class="QToolButton" name="tas_path_button">
121 <property name="text">
122 <string>...</string>
123 </property>
124 </widget>
125 </item>
126 <item row="0" column="2">
127 <widget class="QLineEdit" name="tas_path_edit"/>
128 </item>
129 <item row="0" column="1">
130 <spacer name="horizontalSpacer">
131 <property name="orientation">
132 <enum>Qt::Horizontal</enum>
133 </property>
134 <property name="sizeType">
135 <enum>QSizePolicy::Maximum</enum>
136 </property>
137 <property name="sizeHint" stdset="0">
138 <size>
139 <width>60</width>
140 <height>20</height>
141 </size>
142 </property>
143 </spacer>
144 </item>
145 </layout>
146 </widget>
147 </item>
148 </layout>
149 </item>
150 <item>
151 <widget class="QDialogButtonBox" name="buttonBox">
152 <property name="sizePolicy">
153 <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
154 <horstretch>0</horstretch>
155 <verstretch>0</verstretch>
156 </sizepolicy>
157 </property>
158 <property name="orientation">
159 <enum>Qt::Horizontal</enum>
160 </property>
161 <property name="standardButtons">
162 <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
163 </property>
164 </widget>
165 </item>
166 </layout>
167 </widget>
168 <resources/>
169 <connections>
170 <connection>
171 <sender>buttonBox</sender>
172 <signal>accepted()</signal>
173 <receiver>ConfigureTas</receiver>
174 <slot>accept()</slot>
175 </connection>
176 <connection>
177 <sender>buttonBox</sender>
178 <signal>rejected()</signal>
179 <receiver>ConfigureTas</receiver>
180 <slot>reject()</slot>
181 </connection>
182 </connections>
183</ui>
diff --git a/src/yuzu/configuration/configure_vibration.cpp b/src/yuzu/configuration/configure_vibration.cpp
index 9d92c4949..46a0f3025 100644
--- a/src/yuzu/configuration/configure_vibration.cpp
+++ b/src/yuzu/configuration/configure_vibration.cpp
@@ -99,7 +99,7 @@ void ConfigureVibration::SetVibrationDevices(std::size_t player_index) {
99 const auto guid = param.Get("guid", ""); 99 const auto guid = param.Get("guid", "");
100 const auto port = param.Get("port", ""); 100 const auto port = param.Get("port", "");
101 101
102 if (engine.empty() || engine == "keyboard" || engine == "mouse") { 102 if (engine.empty() || engine == "keyboard" || engine == "mouse" || engine == "tas") {
103 continue; 103 continue;
104 } 104 }
105 105
diff --git a/src/yuzu/debugger/controller.cpp b/src/yuzu/debugger/controller.cpp
index c1fc69578..5a844409b 100644
--- a/src/yuzu/debugger/controller.cpp
+++ b/src/yuzu/debugger/controller.cpp
@@ -6,10 +6,13 @@
6#include <QLayout> 6#include <QLayout>
7#include <QString> 7#include <QString>
8#include "common/settings.h" 8#include "common/settings.h"
9#include "input_common/main.h"
10#include "input_common/tas/tas_input.h"
9#include "yuzu/configuration/configure_input_player_widget.h" 11#include "yuzu/configuration/configure_input_player_widget.h"
10#include "yuzu/debugger/controller.h" 12#include "yuzu/debugger/controller.h"
11 13
12ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) { 14ControllerDialog::ControllerDialog(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_)
15 : QWidget(parent, Qt::Dialog), input_subsystem{input_subsystem_} {
13 setObjectName(QStringLiteral("Controller")); 16 setObjectName(QStringLiteral("Controller"));
14 setWindowTitle(tr("Controller P1")); 17 setWindowTitle(tr("Controller P1"));
15 resize(500, 350); 18 resize(500, 350);
@@ -38,6 +41,9 @@ void ControllerDialog::refreshConfiguration() {
38 constexpr std::size_t player = 0; 41 constexpr std::size_t player = 0;
39 widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs); 42 widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs);
40 widget->SetControllerType(players[player].controller_type); 43 widget->SetControllerType(players[player].controller_type);
44 ControllerCallback callback{[this](ControllerInput input) { InputController(input); }};
45 widget->SetCallBack(callback);
46 widget->repaint();
41 widget->SetConnectedStatus(players[player].connected); 47 widget->SetConnectedStatus(players[player].connected);
42} 48}
43 49
@@ -67,3 +73,13 @@ void ControllerDialog::hideEvent(QHideEvent* ev) {
67 widget->SetConnectedStatus(false); 73 widget->SetConnectedStatus(false);
68 QWidget::hideEvent(ev); 74 QWidget::hideEvent(ev);
69} 75}
76
77void ControllerDialog::InputController(ControllerInput input) {
78 u32 buttons = 0;
79 int index = 0;
80 for (bool btn : input.button_values) {
81 buttons |= (btn ? 1U : 0U) << index;
82 index++;
83 }
84 input_subsystem->GetTas()->RecordInput(buttons, input.axis_values);
85}
diff --git a/src/yuzu/debugger/controller.h b/src/yuzu/debugger/controller.h
index c54750070..7742db58b 100644
--- a/src/yuzu/debugger/controller.h
+++ b/src/yuzu/debugger/controller.h
@@ -4,18 +4,35 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <QFileSystemWatcher>
7#include <QWidget> 8#include <QWidget>
9#include "common/settings.h"
8 10
9class QAction; 11class QAction;
10class QHideEvent; 12class QHideEvent;
11class QShowEvent; 13class QShowEvent;
12class PlayerControlPreview; 14class PlayerControlPreview;
13 15
16namespace InputCommon {
17class InputSubsystem;
18}
19
20struct ControllerInput {
21 std::array<std::pair<float, float>, Settings::NativeAnalog::NUM_STICKS_HID> axis_values{};
22 std::array<bool, Settings::NativeButton::NumButtons> button_values{};
23 bool changed{};
24};
25
26struct ControllerCallback {
27 std::function<void(ControllerInput)> input;
28};
29
14class ControllerDialog : public QWidget { 30class ControllerDialog : public QWidget {
15 Q_OBJECT 31 Q_OBJECT
16 32
17public: 33public:
18 explicit ControllerDialog(QWidget* parent = nullptr); 34 explicit ControllerDialog(QWidget* parent = nullptr,
35 InputCommon::InputSubsystem* input_subsystem_ = nullptr);
19 36
20 /// Returns a QAction that can be used to toggle visibility of this dialog. 37 /// Returns a QAction that can be used to toggle visibility of this dialog.
21 QAction* toggleViewAction(); 38 QAction* toggleViewAction();
@@ -26,6 +43,9 @@ protected:
26 void hideEvent(QHideEvent* ev) override; 43 void hideEvent(QHideEvent* ev) override;
27 44
28private: 45private:
46 void InputController(ControllerInput input);
29 QAction* toggle_view_action = nullptr; 47 QAction* toggle_view_action = nullptr;
48 QFileSystemWatcher* watcher = nullptr;
30 PlayerControlPreview* widget; 49 PlayerControlPreview* widget;
50 InputCommon::InputSubsystem* input_subsystem;
31}; 51};
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 77d53e7bc..3c2824362 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -19,6 +19,7 @@
19#include "common/nvidia_flags.h" 19#include "common/nvidia_flags.h"
20#include "configuration/configure_input.h" 20#include "configuration/configure_input.h"
21#include "configuration/configure_per_game.h" 21#include "configuration/configure_per_game.h"
22#include "configuration/configure_tas.h"
22#include "configuration/configure_vibration.h" 23#include "configuration/configure_vibration.h"
23#include "core/file_sys/vfs.h" 24#include "core/file_sys/vfs.h"
24#include "core/file_sys/vfs_real.h" 25#include "core/file_sys/vfs_real.h"
@@ -102,6 +103,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
102#include "core/perf_stats.h" 103#include "core/perf_stats.h"
103#include "core/telemetry_session.h" 104#include "core/telemetry_session.h"
104#include "input_common/main.h" 105#include "input_common/main.h"
106#include "input_common/tas/tas_input.h"
105#include "util/overlay_dialog.h" 107#include "util/overlay_dialog.h"
106#include "video_core/gpu.h" 108#include "video_core/gpu.h"
107#include "video_core/renderer_base.h" 109#include "video_core/renderer_base.h"
@@ -557,7 +559,8 @@ void GMainWindow::WebBrowserOpenWebPage(const std::string& main_url,
557 const std::string& additional_args, bool is_local) { 559 const std::string& additional_args, bool is_local) {
558#ifdef YUZU_USE_QT_WEB_ENGINE 560#ifdef YUZU_USE_QT_WEB_ENGINE
559 561
560 if (disable_web_applet) { 562 // Raw input breaks with the web applet, Disable web applets if enabled
563 if (disable_web_applet || Settings::values.enable_raw_input) {
561 emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed, 564 emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed,
562 "http://localhost/"); 565 "http://localhost/");
563 return; 566 return;
@@ -746,6 +749,11 @@ void GMainWindow::InitializeWidgets() {
746 statusBar()->addPermanentWidget(label); 749 statusBar()->addPermanentWidget(label);
747 } 750 }
748 751
752 tas_label = new QLabel();
753 tas_label->setObjectName(QStringLiteral("TASlabel"));
754 tas_label->setFocusPolicy(Qt::NoFocus);
755 statusBar()->insertPermanentWidget(0, tas_label);
756
749 // Setup Dock button 757 // Setup Dock button
750 dock_status_button = new QPushButton(); 758 dock_status_button = new QPushButton();
751 dock_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); 759 dock_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton"));
@@ -840,7 +848,7 @@ void GMainWindow::InitializeDebugWidgets() {
840 waitTreeWidget->hide(); 848 waitTreeWidget->hide();
841 debug_menu->addAction(waitTreeWidget->toggleViewAction()); 849 debug_menu->addAction(waitTreeWidget->toggleViewAction());
842 850
843 controller_dialog = new ControllerDialog(this); 851 controller_dialog = new ControllerDialog(this, input_subsystem.get());
844 controller_dialog->hide(); 852 controller_dialog->hide();
845 debug_menu->addAction(controller_dialog->toggleViewAction()); 853 debug_menu->addAction(controller_dialog->toggleViewAction());
846 854
@@ -1013,6 +1021,28 @@ void GMainWindow::InitializeHotkeys() {
1013 render_window->setAttribute(Qt::WA_Hover, true); 1021 render_window->setAttribute(Qt::WA_Hover, true);
1014 } 1022 }
1015 }); 1023 });
1024 connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Start/Stop"), this),
1025 &QShortcut::activated, this, [&] {
1026 if (!emulation_running) {
1027 return;
1028 }
1029 input_subsystem->GetTas()->StartStop();
1030 });
1031 connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Reset"), this),
1032 &QShortcut::activated, this, [&] { input_subsystem->GetTas()->Reset(); });
1033 connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Record"), this),
1034 &QShortcut::activated, this, [&] {
1035 if (!emulation_running) {
1036 return;
1037 }
1038 bool is_recording = input_subsystem->GetTas()->Record();
1039 if (!is_recording) {
1040 const auto res = QMessageBox::question(this, tr("TAS Recording"),
1041 tr("Overwrite file of player 1?"),
1042 QMessageBox::Yes | QMessageBox::No);
1043 input_subsystem->GetTas()->SaveRecording(res == QMessageBox::Yes);
1044 }
1045 });
1016} 1046}
1017 1047
1018void GMainWindow::SetDefaultUIGeometry() { 1048void GMainWindow::SetDefaultUIGeometry() {
@@ -1131,6 +1161,7 @@ void GMainWindow::ConnectMenuEvents() {
1131 connect(ui.action_Open_FAQ, &QAction::triggered, this, &GMainWindow::OnOpenFAQ); 1161 connect(ui.action_Open_FAQ, &QAction::triggered, this, &GMainWindow::OnOpenFAQ);
1132 connect(ui.action_Restart, &QAction::triggered, this, [this] { BootGame(QString(game_path)); }); 1162 connect(ui.action_Restart, &QAction::triggered, this, [this] { BootGame(QString(game_path)); });
1133 connect(ui.action_Configure, &QAction::triggered, this, &GMainWindow::OnConfigure); 1163 connect(ui.action_Configure, &QAction::triggered, this, &GMainWindow::OnConfigure);
1164 connect(ui.action_Configure_Tas, &QAction::triggered, this, &GMainWindow::OnConfigureTas);
1134 connect(ui.action_Configure_Current_Game, &QAction::triggered, this, 1165 connect(ui.action_Configure_Current_Game, &QAction::triggered, this,
1135 &GMainWindow::OnConfigurePerGame); 1166 &GMainWindow::OnConfigurePerGame);
1136 1167
@@ -1463,6 +1494,8 @@ void GMainWindow::ShutdownGame() {
1463 game_list->show(); 1494 game_list->show();
1464 } 1495 }
1465 game_list->SetFilterFocus(); 1496 game_list->SetFilterFocus();
1497 tas_label->clear();
1498 input_subsystem->GetTas()->Stop();
1466 1499
1467 render_window->removeEventFilter(render_window); 1500 render_window->removeEventFilter(render_window);
1468 render_window->setAttribute(Qt::WA_Hover, false); 1501 render_window->setAttribute(Qt::WA_Hover, false);
@@ -2697,6 +2730,19 @@ void GMainWindow::OnConfigure() {
2697 UpdateStatusButtons(); 2730 UpdateStatusButtons();
2698} 2731}
2699 2732
2733void GMainWindow::OnConfigureTas() {
2734 const auto& system = Core::System::GetInstance();
2735 ConfigureTasDialog dialog(this);
2736 const auto result = dialog.exec();
2737
2738 if (result != QDialog::Accepted && !UISettings::values.configuration_applied) {
2739 Settings::RestoreGlobalState(system.IsPoweredOn());
2740 return;
2741 } else if (result == QDialog::Accepted) {
2742 dialog.ApplyConfiguration();
2743 }
2744}
2745
2700void GMainWindow::OnConfigurePerGame() { 2746void GMainWindow::OnConfigurePerGame() {
2701 const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); 2747 const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID();
2702 OpenPerGameConfiguration(title_id, game_path.toStdString()); 2748 OpenPerGameConfiguration(title_id, game_path.toStdString());
@@ -2873,12 +2919,32 @@ void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_vie
2873 } 2919 }
2874} 2920}
2875 2921
2922QString GMainWindow::GetTasStateDescription() const {
2923 auto [tas_status, current_tas_frame, total_tas_frames] = input_subsystem->GetTas()->GetStatus();
2924 switch (tas_status) {
2925 case TasInput::TasState::Running:
2926 return tr("TAS state: Running %1/%2").arg(current_tas_frame).arg(total_tas_frames);
2927 case TasInput::TasState::Recording:
2928 return tr("TAS state: Recording %1").arg(total_tas_frames);
2929 case TasInput::TasState::Stopped:
2930 return tr("TAS state: Idle %1/%2").arg(current_tas_frame).arg(total_tas_frames);
2931 default:
2932 return tr("TAS State: Invalid");
2933 }
2934}
2935
2876void GMainWindow::UpdateStatusBar() { 2936void GMainWindow::UpdateStatusBar() {
2877 if (emu_thread == nullptr) { 2937 if (emu_thread == nullptr) {
2878 status_bar_update_timer.stop(); 2938 status_bar_update_timer.stop();
2879 return; 2939 return;
2880 } 2940 }
2881 2941
2942 if (Settings::values.tas_enable) {
2943 tas_label->setText(GetTasStateDescription());
2944 } else {
2945 tas_label->clear();
2946 }
2947
2882 auto& system = Core::System::GetInstance(); 2948 auto& system = Core::System::GetInstance();
2883 auto results = system.GetAndResetPerfStats(); 2949 auto results = system.GetAndResetPerfStats();
2884 auto& shader_notify = system.GPU().ShaderNotify(); 2950 auto& shader_notify = system.GPU().ShaderNotify();
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 38e66ccd0..36eed6103 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -259,6 +259,7 @@ private slots:
259 void OnMenuInstallToNAND(); 259 void OnMenuInstallToNAND();
260 void OnMenuRecentFile(); 260 void OnMenuRecentFile();
261 void OnConfigure(); 261 void OnConfigure();
262 void OnConfigureTas();
262 void OnConfigurePerGame(); 263 void OnConfigurePerGame();
263 void OnLoadAmiibo(); 264 void OnLoadAmiibo();
264 void OnOpenYuzuFolder(); 265 void OnOpenYuzuFolder();
@@ -300,6 +301,7 @@ private:
300 void OpenURL(const QUrl& url); 301 void OpenURL(const QUrl& url);
301 void LoadTranslation(); 302 void LoadTranslation();
302 void OpenPerGameConfiguration(u64 title_id, const std::string& file_name); 303 void OpenPerGameConfiguration(u64 title_id, const std::string& file_name);
304 QString GetTasStateDescription() const;
303 305
304 Ui::MainWindow ui; 306 Ui::MainWindow ui;
305 307
@@ -318,6 +320,7 @@ private:
318 QLabel* emu_speed_label = nullptr; 320 QLabel* emu_speed_label = nullptr;
319 QLabel* game_fps_label = nullptr; 321 QLabel* game_fps_label = nullptr;
320 QLabel* emu_frametime_label = nullptr; 322 QLabel* emu_frametime_label = nullptr;
323 QLabel* tas_label = nullptr;
321 QPushButton* gpu_accuracy_button = nullptr; 324 QPushButton* gpu_accuracy_button = nullptr;
322 QPushButton* renderer_status_button = nullptr; 325 QPushButton* renderer_status_button = nullptr;
323 QPushButton* dock_status_button = nullptr; 326 QPushButton* dock_status_button = nullptr;
diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui
index 048870687..653c010d8 100644
--- a/src/yuzu/main.ui
+++ b/src/yuzu/main.ui
@@ -100,6 +100,7 @@
100 <addaction name="action_Rederive"/> 100 <addaction name="action_Rederive"/>
101 <addaction name="separator"/> 101 <addaction name="separator"/>
102 <addaction name="action_Capture_Screenshot"/> 102 <addaction name="action_Capture_Screenshot"/>
103 <addaction name="action_Configure_Tas"/>
103 </widget> 104 </widget>
104 <widget class="QMenu" name="menu_Help"> 105 <widget class="QMenu" name="menu_Help">
105 <property name="title"> 106 <property name="title">
@@ -294,6 +295,11 @@
294 <string>&amp;Capture Screenshot</string> 295 <string>&amp;Capture Screenshot</string>
295 </property> 296 </property>
296 </action> 297 </action>
298 <action name="action_Configure_Tas">
299 <property name="text">
300 <string>Configure &amp;TAS...</string>
301 </property>
302 </action>
297 <action name="action_Configure_Current_Game"> 303 <action name="action_Configure_Current_Game">
298 <property name="enabled"> 304 <property name="enabled">
299 <bool>false</bool> 305 <bool>false</bool>
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp
index 891f7be6f..d74eb7e2b 100644
--- a/src/yuzu_cmd/config.cpp
+++ b/src/yuzu_cmd/config.cpp
@@ -475,7 +475,6 @@ void Config::ReadValues() {
475 475
476 // Audio 476 // Audio
477 ReadSetting("Audio", Settings::values.sink_id); 477 ReadSetting("Audio", Settings::values.sink_id);
478 ReadSetting("Audio", Settings::values.enable_audio_stretching);
479 ReadSetting("Audio", Settings::values.audio_device_id); 478 ReadSetting("Audio", Settings::values.audio_device_id);
480 ReadSetting("Audio", Settings::values.volume); 479 ReadSetting("Audio", Settings::values.volume);
481 480