diff options
Diffstat (limited to 'src/input_common/tas/tas_input.cpp')
| -rw-r--r-- | src/input_common/tas/tas_input.cpp | 88 |
1 files changed, 56 insertions, 32 deletions
diff --git a/src/input_common/tas/tas_input.cpp b/src/input_common/tas/tas_input.cpp index 877d35088..1598092b6 100644 --- a/src/input_common/tas/tas_input.cpp +++ b/src/input_common/tas/tas_input.cpp | |||
| @@ -40,12 +40,15 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but | |||
| 40 | 40 | ||
| 41 | Tas::Tas() { | 41 | Tas::Tas() { |
| 42 | if (!Settings::values.tas_enable) { | 42 | if (!Settings::values.tas_enable) { |
| 43 | needs_reset = true; | ||
| 43 | return; | 44 | return; |
| 44 | } | 45 | } |
| 45 | LoadTasFiles(); | 46 | LoadTasFiles(); |
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | Tas::~Tas() = default; | 49 | Tas::~Tas() { |
| 50 | Stop(); | ||
| 51 | }; | ||
| 49 | 52 | ||
| 50 | void Tas::LoadTasFiles() { | 53 | void Tas::LoadTasFiles() { |
| 51 | script_length = 0; | 54 | script_length = 0; |
| @@ -184,6 +187,9 @@ std::string Tas::ButtonsToString(u32 button) const { | |||
| 184 | 187 | ||
| 185 | void Tas::UpdateThread() { | 188 | void Tas::UpdateThread() { |
| 186 | if (!Settings::values.tas_enable) { | 189 | if (!Settings::values.tas_enable) { |
| 190 | if (is_running) { | ||
| 191 | Stop(); | ||
| 192 | } | ||
| 187 | return; | 193 | return; |
| 188 | } | 194 | } |
| 189 | 195 | ||
| @@ -196,34 +202,35 @@ void Tas::UpdateThread() { | |||
| 196 | LoadTasFiles(); | 202 | LoadTasFiles(); |
| 197 | LOG_DEBUG(Input, "tas_reset done"); | 203 | LOG_DEBUG(Input, "tas_reset done"); |
| 198 | } | 204 | } |
| 199 | if (is_running) { | 205 | |
| 200 | if (current_command < script_length) { | 206 | if (!is_running) { |
| 201 | LOG_DEBUG(Input, "Playing TAS {}/{}", current_command, script_length); | 207 | tas_data.fill({}); |
| 202 | size_t frame = current_command++; | 208 | return; |
| 203 | for (size_t i = 0; i < commands.size(); i++) { | 209 | } |
| 204 | if (frame < commands[i].size()) { | 210 | if (current_command < script_length) { |
| 205 | TASCommand command = commands[i][frame]; | 211 | LOG_DEBUG(Input, "Playing TAS {}/{}", current_command, script_length); |
| 206 | tas_data[i].buttons = command.buttons; | 212 | size_t frame = current_command++; |
| 207 | auto [l_axis_x, l_axis_y] = command.l_axis; | 213 | for (size_t i = 0; i < commands.size(); i++) { |
| 208 | tas_data[i].axis[0] = l_axis_x; | 214 | if (frame < commands[i].size()) { |
| 209 | tas_data[i].axis[1] = l_axis_y; | 215 | TASCommand command = commands[i][frame]; |
| 210 | auto [r_axis_x, r_axis_y] = command.r_axis; | 216 | tas_data[i].buttons = command.buttons; |
| 211 | tas_data[i].axis[2] = r_axis_x; | 217 | auto [l_axis_x, l_axis_y] = command.l_axis; |
| 212 | tas_data[i].axis[3] = r_axis_y; | 218 | tas_data[i].axis[0] = l_axis_x; |
| 213 | } else { | 219 | tas_data[i].axis[1] = l_axis_y; |
| 214 | tas_data[i] = {}; | 220 | auto [r_axis_x, r_axis_y] = command.r_axis; |
| 215 | } | 221 | tas_data[i].axis[2] = r_axis_x; |
| 216 | } | 222 | tas_data[i].axis[3] = r_axis_y; |
| 217 | } else { | 223 | } else { |
| 218 | is_running = Settings::values.tas_loop.GetValue(); | 224 | tas_data[i] = {}; |
| 219 | current_command = 0; | ||
| 220 | tas_data.fill({}); | ||
| 221 | if (!is_running) { | ||
| 222 | SwapToStoredController(); | ||
| 223 | } | 225 | } |
| 224 | } | 226 | } |
| 225 | } else { | 227 | } else { |
| 228 | is_running = Settings::values.tas_loop.GetValue(); | ||
| 229 | current_command = 0; | ||
| 226 | tas_data.fill({}); | 230 | tas_data.fill({}); |
| 231 | if (!is_running) { | ||
| 232 | SwapToStoredController(); | ||
| 233 | } | ||
| 227 | } | 234 | } |
| 228 | LOG_DEBUG(Input, "TAS inputs: {}", DebugInputs(tas_data)); | 235 | LOG_DEBUG(Input, "TAS inputs: {}", DebugInputs(tas_data)); |
| 229 | } | 236 | } |
| @@ -237,8 +244,8 @@ TasAnalog Tas::ReadCommandAxis(const std::string& line) const { | |||
| 237 | seglist.push_back(segment); | 244 | seglist.push_back(segment); |
| 238 | } | 245 | } |
| 239 | 246 | ||
| 240 | const float x = std::stof(seglist.at(0)) / 32767.f; | 247 | const float x = std::stof(seglist.at(0)) / 32767.0f; |
| 241 | const float y = std::stof(seglist.at(1)) / 32767.f; | 248 | const float y = std::stof(seglist.at(1)) / 32767.0f; |
| 242 | 249 | ||
| 243 | return {x, y}; | 250 | return {x, y}; |
| 244 | } | 251 | } |
| @@ -293,14 +300,22 @@ std::string Tas::WriteCommandButtons(u32 data) const { | |||
| 293 | } | 300 | } |
| 294 | 301 | ||
| 295 | void Tas::StartStop() { | 302 | void Tas::StartStop() { |
| 296 | is_running = !is_running; | 303 | if (!Settings::values.tas_enable) { |
| 304 | return; | ||
| 305 | } | ||
| 297 | if (is_running) { | 306 | if (is_running) { |
| 298 | SwapToTasController(); | 307 | Stop(); |
| 299 | } else { | 308 | } else { |
| 300 | SwapToStoredController(); | 309 | is_running = true; |
| 310 | SwapToTasController(); | ||
| 301 | } | 311 | } |
| 302 | } | 312 | } |
| 303 | 313 | ||
| 314 | void Tas::Stop() { | ||
| 315 | is_running = false; | ||
| 316 | SwapToStoredController(); | ||
| 317 | } | ||
| 318 | |||
| 304 | void Tas::SwapToTasController() { | 319 | void Tas::SwapToTasController() { |
| 305 | if (!Settings::values.tas_swap_controllers) { | 320 | if (!Settings::values.tas_swap_controllers) { |
| 306 | return; | 321 | return; |
| @@ -315,7 +330,8 @@ void Tas::SwapToTasController() { | |||
| 315 | continue; | 330 | continue; |
| 316 | } | 331 | } |
| 317 | 332 | ||
| 318 | auto tas_param = Common::ParamPackage{{"pad", static_cast<u8>(index)}}; | 333 | Common::ParamPackage tas_param; |
| 334 | tas_param.Set("pad", static_cast<u8>(index)); | ||
| 319 | auto button_mapping = GetButtonMappingForDevice(tas_param); | 335 | auto button_mapping = GetButtonMappingForDevice(tas_param); |
| 320 | auto analog_mapping = GetAnalogMappingForDevice(tas_param); | 336 | auto analog_mapping = GetAnalogMappingForDevice(tas_param); |
| 321 | auto& buttons = player.buttons; | 337 | auto& buttons = player.buttons; |
| @@ -328,25 +344,33 @@ void Tas::SwapToTasController() { | |||
| 328 | analogs[i] = analog_mapping[static_cast<Settings::NativeAnalog::Values>(i)].Serialize(); | 344 | analogs[i] = analog_mapping[static_cast<Settings::NativeAnalog::Values>(i)].Serialize(); |
| 329 | } | 345 | } |
| 330 | } | 346 | } |
| 347 | is_old_input_saved = true; | ||
| 331 | Settings::values.is_device_reload_pending.store(true); | 348 | Settings::values.is_device_reload_pending.store(true); |
| 332 | } | 349 | } |
| 333 | 350 | ||
| 334 | void Tas::SwapToStoredController() { | 351 | void Tas::SwapToStoredController() { |
| 335 | if (!Settings::values.tas_swap_controllers) { | 352 | if (!is_old_input_saved) { |
| 336 | return; | 353 | return; |
| 337 | } | 354 | } |
| 338 | auto& players = Settings::values.players.GetValue(); | 355 | auto& players = Settings::values.players.GetValue(); |
| 339 | for (std::size_t index = 0; index < players.size(); index++) { | 356 | for (std::size_t index = 0; index < players.size(); index++) { |
| 340 | players[index] = player_mappings[index]; | 357 | players[index] = player_mappings[index]; |
| 341 | } | 358 | } |
| 359 | is_old_input_saved = false; | ||
| 342 | Settings::values.is_device_reload_pending.store(true); | 360 | Settings::values.is_device_reload_pending.store(true); |
| 343 | } | 361 | } |
| 344 | 362 | ||
| 345 | void Tas::Reset() { | 363 | void Tas::Reset() { |
| 364 | if (!Settings::values.tas_enable) { | ||
| 365 | return; | ||
| 366 | } | ||
| 346 | needs_reset = true; | 367 | needs_reset = true; |
| 347 | } | 368 | } |
| 348 | 369 | ||
| 349 | bool Tas::Record() { | 370 | bool Tas::Record() { |
| 371 | if (!Settings::values.tas_enable) { | ||
| 372 | return true; | ||
| 373 | } | ||
| 350 | is_recording = !is_recording; | 374 | is_recording = !is_recording; |
| 351 | return is_recording; | 375 | return is_recording; |
| 352 | } | 376 | } |