diff options
Diffstat (limited to 'src/input_common/drivers/tas_input.h')
| -rw-r--r-- | src/input_common/drivers/tas_input.h | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/src/input_common/drivers/tas_input.h b/src/input_common/drivers/tas_input.h index c95a130fc..4b4e6c417 100644 --- a/src/input_common/drivers/tas_input.h +++ b/src/input_common/drivers/tas_input.h | |||
| @@ -5,11 +5,11 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <string> | ||
| 9 | #include <vector> | ||
| 8 | 10 | ||
| 9 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 10 | #include "common/settings_input.h" | ||
| 11 | #include "input_common/input_engine.h" | 12 | #include "input_common/input_engine.h" |
| 12 | #include "input_common/main.h" | ||
| 13 | 13 | ||
| 14 | /* | 14 | /* |
| 15 | To play back TAS scripts on Yuzu, select the folder with scripts in the configuration menu below | 15 | To play back TAS scripts on Yuzu, select the folder with scripts in the configuration menu below |
| @@ -81,46 +81,46 @@ enum class TasState { | |||
| 81 | Stopped, | 81 | Stopped, |
| 82 | }; | 82 | }; |
| 83 | 83 | ||
| 84 | class Tas final : public InputCommon::InputEngine { | 84 | class Tas final : public InputEngine { |
| 85 | public: | 85 | public: |
| 86 | explicit Tas(const std::string& input_engine_); | 86 | explicit Tas(std::string input_engine_); |
| 87 | ~Tas(); | 87 | ~Tas() override; |
| 88 | 88 | ||
| 89 | /** | 89 | /** |
| 90 | * Changes the input status that will be stored in each frame | 90 | * Changes the input status that will be stored in each frame |
| 91 | * @param buttons: bitfield with the status of the buttons | 91 | * @param buttons Bitfield with the status of the buttons |
| 92 | * @param left_axis: value of the left axis | 92 | * @param left_axis Value of the left axis |
| 93 | * @param right_axis: value of the right axis | 93 | * @param right_axis Value of the right axis |
| 94 | */ | 94 | */ |
| 95 | void RecordInput(u64 buttons, TasAnalog left_axis, TasAnalog right_axis); | 95 | void RecordInput(u64 buttons, TasAnalog left_axis, TasAnalog right_axis); |
| 96 | 96 | ||
| 97 | // Main loop that records or executes input | 97 | // Main loop that records or executes input |
| 98 | void UpdateThread(); | 98 | void UpdateThread(); |
| 99 | 99 | ||
| 100 | // Sets the flag to start or stop the TAS command excecution and swaps controllers profiles | 100 | // Sets the flag to start or stop the TAS command execution and swaps controllers profiles |
| 101 | void StartStop(); | 101 | void StartStop(); |
| 102 | 102 | ||
| 103 | // Stop the TAS and reverts any controller profile | 103 | // Stop the TAS and reverts any controller profile |
| 104 | void Stop(); | 104 | void Stop(); |
| 105 | 105 | ||
| 106 | // Sets the flag to reload the file and start from the begining in the next update | 106 | // Sets the flag to reload the file and start from the beginning in the next update |
| 107 | void Reset(); | 107 | void Reset(); |
| 108 | 108 | ||
| 109 | /** | 109 | /** |
| 110 | * Sets the flag to enable or disable recording of inputs | 110 | * Sets the flag to enable or disable recording of inputs |
| 111 | * @return Returns true if the current recording status is enabled | 111 | * @returns true if the current recording status is enabled |
| 112 | */ | 112 | */ |
| 113 | bool Record(); | 113 | bool Record(); |
| 114 | 114 | ||
| 115 | /** | 115 | /** |
| 116 | * Saves contents of record_commands on a file | 116 | * Saves contents of record_commands on a file |
| 117 | * @param overwrite_file: Indicates if player 1 should be overwritten | 117 | * @param overwrite_file Indicates if player 1 should be overwritten |
| 118 | */ | 118 | */ |
| 119 | void SaveRecording(bool overwrite_file); | 119 | void SaveRecording(bool overwrite_file); |
| 120 | 120 | ||
| 121 | /** | 121 | /** |
| 122 | * Returns the current status values of TAS playback/recording | 122 | * Returns the current status values of TAS playback/recording |
| 123 | * @return Tuple of | 123 | * @returns A Tuple of |
| 124 | * TasState indicating the current state out of Running ; | 124 | * TasState indicating the current state out of Running ; |
| 125 | * Current playback progress ; | 125 | * Current playback progress ; |
| 126 | * Total length of script file currently loaded or being recorded | 126 | * Total length of script file currently loaded or being recorded |
| @@ -128,6 +128,8 @@ public: | |||
| 128 | std::tuple<TasState, size_t, size_t> GetStatus() const; | 128 | std::tuple<TasState, size_t, size_t> GetStatus() const; |
| 129 | 129 | ||
| 130 | private: | 130 | private: |
| 131 | enum class TasAxis : u8; | ||
| 132 | |||
| 131 | struct TASCommand { | 133 | struct TASCommand { |
| 132 | u64 buttons{}; | 134 | u64 buttons{}; |
| 133 | TasAnalog l_axis{}; | 135 | TasAnalog l_axis{}; |
| @@ -137,29 +139,31 @@ private: | |||
| 137 | /// Loads TAS files from all players | 139 | /// Loads TAS files from all players |
| 138 | void LoadTasFiles(); | 140 | void LoadTasFiles(); |
| 139 | 141 | ||
| 140 | /** Loads TAS file from the specified player | 142 | /** |
| 141 | * @param player_index: player number to save the script | 143 | * Loads TAS file from the specified player |
| 142 | * @param file_index: script number of the file | 144 | * @param player_index Player number to save the script |
| 145 | * @param file_index Script number of the file | ||
| 143 | */ | 146 | */ |
| 144 | void LoadTasFile(size_t player_index, size_t file_index); | 147 | void LoadTasFile(size_t player_index, size_t file_index); |
| 145 | 148 | ||
| 146 | /** Writes a TAS file from the recorded commands | 149 | /** |
| 147 | * @param file_name: name of the file to be written | 150 | * Writes a TAS file from the recorded commands |
| 151 | * @param file_name Name of the file to be written | ||
| 148 | */ | 152 | */ |
| 149 | void WriteTasFile(std::u8string file_name); | 153 | void WriteTasFile(std::u8string_view file_name); |
| 150 | 154 | ||
| 151 | /** | 155 | /** |
| 152 | * Parses a string containing the axis values. X and Y have a range from -32767 to 32767 | 156 | * Parses a string containing the axis values. X and Y have a range from -32767 to 32767 |
| 153 | * @param line: string containing axis values with the following format "x;y" | 157 | * @param line String containing axis values with the following format "x;y" |
| 154 | * @return Returns a TAS analog object with axis values with range from -1.0 to 1.0 | 158 | * @returns A TAS analog object with axis values with range from -1.0 to 1.0 |
| 155 | */ | 159 | */ |
| 156 | TasAnalog ReadCommandAxis(const std::string& line) const; | 160 | TasAnalog ReadCommandAxis(const std::string& line) const; |
| 157 | 161 | ||
| 158 | /** | 162 | /** |
| 159 | * Parses a string containing the button values. Each button is represented by it's text format | 163 | * Parses a string containing the button values. Each button is represented by it's text format |
| 160 | * specified in text_to_tas_button array | 164 | * specified in text_to_tas_button array |
| 161 | * @param line: string containing button name with the following format "a;b;c;d..." | 165 | * @param line string containing button name with the following format "a;b;c;d..." |
| 162 | * @return Returns a u64 with each bit representing the status of a button | 166 | * @returns A u64 with each bit representing the status of a button |
| 163 | */ | 167 | */ |
| 164 | u64 ReadCommandButtons(const std::string& line) const; | 168 | u64 ReadCommandButtons(const std::string& line) const; |
| 165 | 169 | ||
| @@ -170,17 +174,20 @@ private: | |||
| 170 | 174 | ||
| 171 | /** | 175 | /** |
| 172 | * Converts an u64 containing the button status into the text equivalent | 176 | * Converts an u64 containing the button status into the text equivalent |
| 173 | * @param buttons: bitfield with the status of the buttons | 177 | * @param buttons Bitfield with the status of the buttons |
| 174 | * @return Returns a string with the name of the buttons to be written to the file | 178 | * @returns A string with the name of the buttons to be written to the file |
| 175 | */ | 179 | */ |
| 176 | std::string WriteCommandButtons(u64 buttons) const; | 180 | std::string WriteCommandButtons(u64 buttons) const; |
| 177 | 181 | ||
| 178 | /** | 182 | /** |
| 179 | * Converts an TAS analog object containing the axis status into the text equivalent | 183 | * Converts an TAS analog object containing the axis status into the text equivalent |
| 180 | * @param data: value of the axis | 184 | * @param analog Value of the axis |
| 181 | * @return A string with the value of the axis to be written to the file | 185 | * @returns A string with the value of the axis to be written to the file |
| 182 | */ | 186 | */ |
| 183 | std::string WriteCommandAxis(TasAnalog data) const; | 187 | std::string WriteCommandAxis(TasAnalog analog) const; |
| 188 | |||
| 189 | /// Sets an axis for a particular pad to the given value. | ||
| 190 | void SetTasAxis(const PadIdentifier& identifier, TasAxis axis, f32 value); | ||
| 184 | 191 | ||
| 185 | size_t script_length{0}; | 192 | size_t script_length{0}; |
| 186 | bool is_recording{false}; | 193 | bool is_recording{false}; |