diff options
| author | 2021-07-05 20:58:52 -0500 | |
|---|---|---|
| committer | 2021-09-18 23:22:48 +0200 | |
| commit | 33a1d790e8a5f67c73d0eef4a141f936345f104f (patch) | |
| tree | 16138c61b831ca3a6016fbb31fe183fbc557c7dd /src/input_common/tas | |
| parent | input_common/tas: Add swap controller (diff) | |
| download | yuzu-33a1d790e8a5f67c73d0eef4a141f936345f104f.tar.gz yuzu-33a1d790e8a5f67c73d0eef4a141f936345f104f.tar.xz yuzu-33a1d790e8a5f67c73d0eef4a141f936345f104f.zip | |
input_common/tas: Document the main class
Diffstat (limited to 'src/input_common/tas')
| -rw-r--r-- | src/input_common/tas/tas_input.cpp | 3 | ||||
| -rw-r--r-- | src/input_common/tas/tas_input.h | 108 | ||||
| -rw-r--r-- | src/input_common/tas/tas_poller.h | 4 |
3 files changed, 112 insertions, 3 deletions
diff --git a/src/input_common/tas/tas_input.cpp b/src/input_common/tas/tas_input.cpp index aceb13adc..877d35088 100644 --- a/src/input_common/tas/tas_input.cpp +++ b/src/input_common/tas/tas_input.cpp | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | namespace TasInput { | 15 | namespace TasInput { |
| 16 | 16 | ||
| 17 | // Supported keywords and buttons from a TAS file | ||
| 17 | constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_button = { | 18 | constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_button = { |
| 18 | std::pair{"KEY_A", TasButton::BUTTON_A}, | 19 | std::pair{"KEY_A", TasButton::BUTTON_A}, |
| 19 | {"KEY_B", TasButton::BUTTON_B}, | 20 | {"KEY_B", TasButton::BUTTON_B}, |
| @@ -214,7 +215,7 @@ void Tas::UpdateThread() { | |||
| 214 | } | 215 | } |
| 215 | } | 216 | } |
| 216 | } else { | 217 | } else { |
| 217 | is_running = Settings::values.tas_loop; | 218 | is_running = Settings::values.tas_loop.GetValue(); |
| 218 | current_command = 0; | 219 | current_command = 0; |
| 219 | tas_data.fill({}); | 220 | tas_data.fill({}); |
| 220 | if (!is_running) { | 221 | if (!is_running) { |
diff --git a/src/input_common/tas/tas_input.h b/src/input_common/tas/tas_input.h index e1f351251..52d000db4 100644 --- a/src/input_common/tas/tas_input.h +++ b/src/input_common/tas/tas_input.h | |||
| @@ -11,6 +11,38 @@ | |||
| 11 | #include "core/frontend/input.h" | 11 | #include "core/frontend/input.h" |
| 12 | #include "input_common/main.h" | 12 | #include "input_common/main.h" |
| 13 | 13 | ||
| 14 | /* | ||
| 15 | To play back TAS scripts on Yuzu, select the folder with scripts in the configuration menu below | ||
| 16 | Emulation -> Configure TAS. The file itself has normal text format and has to be called | ||
| 17 | script0-1.txt for controller 1, script0-2.txt for controller 2 and so forth (with max. 8 players). | ||
| 18 | |||
| 19 | A script file has the same format as TAS-nx uses, so final files will look like this: | ||
| 20 | |||
| 21 | 1 KEY_B 0;0 0;0 | ||
| 22 | 6 KEY_ZL 0;0 0;0 | ||
| 23 | 41 KEY_ZL;KEY_Y 0;0 0;0 | ||
| 24 | 43 KEY_X;KEY_A 32767;0 0;0 | ||
| 25 | 44 KEY_A 32767;0 0;0 | ||
| 26 | 45 KEY_A 32767;0 0;0 | ||
| 27 | 46 KEY_A 32767;0 0;0 | ||
| 28 | 47 KEY_A 32767;0 0;0 | ||
| 29 | |||
| 30 | After placing the file at the correct location, it can be read into Yuzu with the (default) hotkey | ||
| 31 | CTRL+F6 (refresh). In the bottom left corner, it will display the amount of frames the script file | ||
| 32 | has. Playback can be started or stopped using CTRL+F5. | ||
| 33 | |||
| 34 | However, for playback to actually work, the correct input device has to be selected: In the Controls | ||
| 35 | menu, select TAS from the device list for the controller that the script should be played on. | ||
| 36 | |||
| 37 | Recording a new script file is really simple: Just make sure that the proper device (not TAS) is | ||
| 38 | connected on P1, and press CTRL+F7 to start recording. When done, just press the same keystroke | ||
| 39 | again (CTRL+F7). The new script will be saved at the location previously selected, as the filename | ||
| 40 | record.txt. | ||
| 41 | |||
| 42 | For debugging purposes, the common controller debugger can be used (View -> Debugging -> Controller | ||
| 43 | P1). | ||
| 44 | */ | ||
| 45 | |||
| 14 | namespace TasInput { | 46 | namespace TasInput { |
| 15 | 47 | ||
| 16 | constexpr size_t PLAYER_NUMBER = 8; | 48 | constexpr size_t PLAYER_NUMBER = 8; |
| @@ -64,12 +96,26 @@ public: | |||
| 64 | Tas(); | 96 | Tas(); |
| 65 | ~Tas(); | 97 | ~Tas(); |
| 66 | 98 | ||
| 99 | // Changes the input status that will be stored in each frame | ||
| 67 | void RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes); | 100 | void RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes); |
| 101 | |||
| 102 | // Main loop that records or executes input | ||
| 68 | void UpdateThread(); | 103 | void UpdateThread(); |
| 69 | 104 | ||
| 105 | // Sets the flag to start or stop the TAS command excecution and swaps controllers profiles | ||
| 70 | void StartStop(); | 106 | void StartStop(); |
| 107 | |||
| 108 | // Sets the flag to reload the file and start from the begining in the next update | ||
| 71 | void Reset(); | 109 | void Reset(); |
| 110 | |||
| 111 | /** | ||
| 112 | * Sets the flag to enable or disable recording of inputs | ||
| 113 | * @return Returns true if the current recording status is enabled | ||
| 114 | */ | ||
| 72 | bool Record(); | 115 | bool Record(); |
| 116 | |||
| 117 | // Saves contents of record_commands on a file if overwrite is enabled player 1 will be | ||
| 118 | // overwritten with the recorded commands | ||
| 73 | void SaveRecording(bool overwrite_file); | 119 | void SaveRecording(bool overwrite_file); |
| 74 | 120 | ||
| 75 | /** | 121 | /** |
| @@ -80,7 +126,11 @@ public: | |||
| 80 | * Total length of script file currently loaded or amount of frames (so far) for Recording | 126 | * Total length of script file currently loaded or amount of frames (so far) for Recording |
| 81 | */ | 127 | */ |
| 82 | std::tuple<TasState, size_t, size_t> GetStatus() const; | 128 | std::tuple<TasState, size_t, size_t> GetStatus() const; |
| 129 | |||
| 130 | // Retuns an array of the default button mappings | ||
| 83 | InputCommon::ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) const; | 131 | InputCommon::ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) const; |
| 132 | |||
| 133 | // Retuns an array of the default analog mappings | ||
| 84 | InputCommon::AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) const; | 134 | InputCommon::AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) const; |
| 85 | [[nodiscard]] const TasData& GetTasState(std::size_t pad) const; | 135 | [[nodiscard]] const TasData& GetTasState(std::size_t pad) const; |
| 86 | 136 | ||
| @@ -90,23 +140,81 @@ private: | |||
| 90 | TasAnalog l_axis{}; | 140 | TasAnalog l_axis{}; |
| 91 | TasAnalog r_axis{}; | 141 | TasAnalog r_axis{}; |
| 92 | }; | 142 | }; |
| 143 | |||
| 144 | // Loads TAS files from all players | ||
| 93 | void LoadTasFiles(); | 145 | void LoadTasFiles(); |
| 146 | |||
| 147 | // Loads TAS file from the specified player | ||
| 94 | void LoadTasFile(size_t player_index); | 148 | void LoadTasFile(size_t player_index); |
| 149 | |||
| 150 | // Writes a TAS file from the recorded commands | ||
| 95 | void WriteTasFile(std::u8string file_name); | 151 | void WriteTasFile(std::u8string file_name); |
| 152 | |||
| 153 | /** | ||
| 154 | * Parses a string containing the axis values with the following format "x;y" | ||
| 155 | * X and Y have a range from -32767 to 32767 | ||
| 156 | * @return Returns a TAS analog object with axis values with range from -1.0 to 1.0 | ||
| 157 | */ | ||
| 96 | TasAnalog ReadCommandAxis(const std::string& line) const; | 158 | TasAnalog ReadCommandAxis(const std::string& line) const; |
| 159 | |||
| 160 | /** | ||
| 161 | * Parses a string containing the button values with the following format "a;b;c;d..." | ||
| 162 | * Each button is represented by it's text format specified in text_to_tas_button array | ||
| 163 | * @return Returns a u32 with each bit representing the status of a button | ||
| 164 | */ | ||
| 97 | u32 ReadCommandButtons(const std::string& line) const; | 165 | u32 ReadCommandButtons(const std::string& line) const; |
| 166 | |||
| 167 | /** | ||
| 168 | * Converts an u32 containing the button status into the text equivalent | ||
| 169 | * @return Returns a string with the name of the buttons to be written to the file | ||
| 170 | */ | ||
| 98 | std::string WriteCommandButtons(u32 data) const; | 171 | std::string WriteCommandButtons(u32 data) const; |
| 172 | |||
| 173 | /** | ||
| 174 | * Converts an TAS analog object containing the axis status into the text equivalent | ||
| 175 | * @return Returns a string with the value of the axis to be written to the file | ||
| 176 | */ | ||
| 99 | std::string WriteCommandAxis(TasAnalog data) const; | 177 | std::string WriteCommandAxis(TasAnalog data) const; |
| 100 | 178 | ||
| 179 | // Inverts the Y axis polarity | ||
| 101 | std::pair<float, float> FlipAxisY(std::pair<float, float> old); | 180 | std::pair<float, float> FlipAxisY(std::pair<float, float> old); |
| 102 | 181 | ||
| 182 | /** | ||
| 183 | * Converts an u32 containing the button status into the text equivalent | ||
| 184 | * @return Returns a string with the name of the buttons to be printed on console | ||
| 185 | */ | ||
| 103 | std::string DebugButtons(u32 buttons) const; | 186 | std::string DebugButtons(u32 buttons) const; |
| 187 | |||
| 188 | /** | ||
| 189 | * Converts an TAS analog object containing the axis status into the text equivalent | ||
| 190 | * @return Returns a string with the value of the axis to be printed on console | ||
| 191 | */ | ||
| 104 | std::string DebugJoystick(float x, float y) const; | 192 | std::string DebugJoystick(float x, float y) const; |
| 193 | |||
| 194 | /** | ||
| 195 | * Converts the given TAS status into the text equivalent | ||
| 196 | * @return Returns a string with the value of the TAS status to be printed on console | ||
| 197 | */ | ||
| 105 | std::string DebugInput(const TasData& data) const; | 198 | std::string DebugInput(const TasData& data) const; |
| 199 | |||
| 200 | /** | ||
| 201 | * Converts the given TAS status of multiple players into the text equivalent | ||
| 202 | * @return Returns a string with the value of the status of all TAS players to be printed on | ||
| 203 | * console | ||
| 204 | */ | ||
| 106 | std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const; | 205 | std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const; |
| 206 | |||
| 207 | /** | ||
| 208 | * Converts an u32 containing the button status into the text equivalent | ||
| 209 | * @return Returns a string with the name of the buttons | ||
| 210 | */ | ||
| 107 | std::string ButtonsToString(u32 button) const; | 211 | std::string ButtonsToString(u32 button) const; |
| 108 | 212 | ||
| 213 | // Stores current controller configuration and sets a TAS controller for every active controller | ||
| 214 | // to the current config | ||
| 109 | void SwapToTasController(); | 215 | void SwapToTasController(); |
| 216 | |||
| 217 | // Sets the stored controller configuration to the current config | ||
| 110 | void SwapToStoredController(); | 218 | void SwapToStoredController(); |
| 111 | 219 | ||
| 112 | size_t script_length{0}; | 220 | size_t script_length{0}; |
diff --git a/src/input_common/tas/tas_poller.h b/src/input_common/tas/tas_poller.h index 1bc0d173b..09e426cef 100644 --- a/src/input_common/tas/tas_poller.h +++ b/src/input_common/tas/tas_poller.h | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | namespace InputCommon { | 11 | namespace InputCommon { |
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * A button device factory representing a mouse. It receives mouse events and forward them | 14 | * A button device factory representing a tas bot. It receives tas events and forward them |
| 15 | * to all button devices it created. | 15 | * to all button devices it created. |
| 16 | */ | 16 | */ |
| 17 | class TasButtonFactory final : public Input::Factory<Input::ButtonDevice> { | 17 | class TasButtonFactory final : public Input::Factory<Input::ButtonDevice> { |
| @@ -29,7 +29,7 @@ private: | |||
| 29 | std::shared_ptr<TasInput::Tas> tas_input; | 29 | std::shared_ptr<TasInput::Tas> tas_input; |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | /// An analog device factory that creates analog devices from mouse | 32 | /// An analog device factory that creates analog devices from tas |
| 33 | class TasAnalogFactory final : public Input::Factory<Input::AnalogDevice> { | 33 | class TasAnalogFactory final : public Input::Factory<Input::AnalogDevice> { |
| 34 | public: | 34 | public: |
| 35 | explicit TasAnalogFactory(std::shared_ptr<TasInput::Tas> tas_input_); | 35 | explicit TasAnalogFactory(std::shared_ptr<TasInput::Tas> tas_input_); |