diff options
Diffstat (limited to '')
-rw-r--r-- | src/input_common/drivers/tas_input.h (renamed from src/input_common/tas/tas_input.h) | 151 |
1 files changed, 54 insertions, 97 deletions
diff --git a/src/input_common/tas/tas_input.h b/src/input_common/drivers/tas_input.h index 3e2db8f00..c95a130fc 100644 --- a/src/input_common/tas/tas_input.h +++ b/src/input_common/drivers/tas_input.h @@ -8,7 +8,7 @@ #include "common/common_types.h" #include "common/settings_input.h" -#include "core/frontend/input.h" +#include "input_common/input_engine.h" #include "input_common/main.h" /* @@ -43,19 +43,11 @@ For debugging purposes, the common controller debugger can be used (View -> Debu P1). */ -namespace TasInput { +namespace InputCommon::TasInput { -constexpr size_t PLAYER_NUMBER = 8; +constexpr size_t PLAYER_NUMBER = 10; -using TasAnalog = std::pair<float, float>; - -enum class TasState { - Running, - Recording, - Stopped, -}; - -enum class TasButton : u32 { +enum class TasButton : u64 { BUTTON_A = 1U << 0, BUTTON_B = 1U << 1, BUTTON_X = 1U << 2, @@ -78,26 +70,29 @@ enum class TasButton : u32 { BUTTON_CAPTURE = 1U << 19, }; -enum class TasAxes : u8 { - StickX, - StickY, - SubstickX, - SubstickY, - Undefined, +struct TasAnalog { + float x{}; + float y{}; }; -struct TasData { - u32 buttons{}; - std::array<float, 4> axis{}; +enum class TasState { + Running, + Recording, + Stopped, }; -class Tas { +class Tas final : public InputCommon::InputEngine { public: - Tas(); + explicit Tas(const std::string& input_engine_); ~Tas(); - // Changes the input status that will be stored in each frame - void RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes); + /** + * Changes the input status that will be stored in each frame + * @param buttons: bitfield with the status of the buttons + * @param left_axis: value of the left axis + * @param right_axis: value of the right axis + */ + void RecordInput(u64 buttons, TasAnalog left_axis, TasAnalog right_axis); // Main loop that records or executes input void UpdateThread(); @@ -117,112 +112,77 @@ public: */ bool Record(); - // Saves contents of record_commands on a file if overwrite is enabled player 1 will be - // overwritten with the recorded commands + /** + * Saves contents of record_commands on a file + * @param overwrite_file: Indicates if player 1 should be overwritten + */ void SaveRecording(bool overwrite_file); /** * Returns the current status values of TAS playback/recording * @return Tuple of - * TasState indicating the current state out of Running, Recording or Stopped ; - * Current playback progress or amount of frames (so far) for Recording ; - * Total length of script file currently loaded or amount of frames (so far) for Recording + * TasState indicating the current state out of Running ; + * Current playback progress ; + * Total length of script file currently loaded or being recorded */ std::tuple<TasState, size_t, size_t> GetStatus() const; - // Retuns an array of the default button mappings - InputCommon::ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) const; - - // Retuns an array of the default analog mappings - InputCommon::AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) const; - [[nodiscard]] const TasData& GetTasState(std::size_t pad) const; - private: struct TASCommand { - u32 buttons{}; + u64 buttons{}; TasAnalog l_axis{}; TasAnalog r_axis{}; }; - // Loads TAS files from all players + /// Loads TAS files from all players void LoadTasFiles(); - // Loads TAS file from the specified player - void LoadTasFile(size_t player_index); + /** Loads TAS file from the specified player + * @param player_index: player number to save the script + * @param file_index: script number of the file + */ + void LoadTasFile(size_t player_index, size_t file_index); - // Writes a TAS file from the recorded commands + /** Writes a TAS file from the recorded commands + * @param file_name: name of the file to be written + */ void WriteTasFile(std::u8string file_name); /** - * Parses a string containing the axis values with the following format "x;y" - * X and Y have a range from -32767 to 32767 + * Parses a string containing the axis values. X and Y have a range from -32767 to 32767 + * @param line: string containing axis values with the following format "x;y" * @return Returns a TAS analog object with axis values with range from -1.0 to 1.0 */ TasAnalog ReadCommandAxis(const std::string& line) const; /** - * Parses a string containing the button values with the following format "a;b;c;d..." - * Each button is represented by it's text format specified in text_to_tas_button array - * @return Returns a u32 with each bit representing the status of a button - */ - u32 ReadCommandButtons(const std::string& line) const; - - /** - * Converts an u32 containing the button status into the text equivalent - * @return Returns a string with the name of the buttons to be written to the file + * Parses a string containing the button values. Each button is represented by it's text format + * specified in text_to_tas_button array + * @param line: string containing button name with the following format "a;b;c;d..." + * @return Returns a u64 with each bit representing the status of a button */ - std::string WriteCommandButtons(u32 data) const; + u64 ReadCommandButtons(const std::string& line) const; /** - * Converts an TAS analog object containing the axis status into the text equivalent - * @return Returns a string with the value of the axis to be written to the file + * Reset state of all players */ - std::string WriteCommandAxis(TasAnalog data) const; - - // Inverts the Y axis polarity - std::pair<float, float> FlipAxisY(std::pair<float, float> old); + void ClearInput(); /** - * Converts an u32 containing the button status into the text equivalent - * @return Returns a string with the name of the buttons to be printed on console + * Converts an u64 containing the button status into the text equivalent + * @param buttons: bitfield with the status of the buttons + * @return Returns a string with the name of the buttons to be written to the file */ - std::string DebugButtons(u32 buttons) const; + std::string WriteCommandButtons(u64 buttons) const; /** * Converts an TAS analog object containing the axis status into the text equivalent - * @return Returns a string with the value of the axis to be printed on console - */ - std::string DebugJoystick(float x, float y) const; - - /** - * Converts the given TAS status into the text equivalent - * @return Returns a string with the value of the TAS status to be printed on console + * @param data: value of the axis + * @return A string with the value of the axis to be written to the file */ - std::string DebugInput(const TasData& data) const; - - /** - * Converts the given TAS status of multiple players into the text equivalent - * @return Returns a string with the value of the status of all TAS players to be printed on - * console - */ - std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const; - - /** - * Converts an u32 containing the button status into the text equivalent - * @return Returns a string with the name of the buttons - */ - std::string ButtonsToString(u32 button) const; - - // Stores current controller configuration and sets a TAS controller for every active controller - // to the current config - void SwapToTasController(); - - // Sets the stored controller configuration to the current config - void SwapToStoredController(); + std::string WriteCommandAxis(TasAnalog data) const; size_t script_length{0}; - std::array<TasData, PLAYER_NUMBER> tas_data; - bool is_old_input_saved{false}; bool is_recording{false}; bool is_running{false}; bool needs_reset{false}; @@ -230,8 +190,5 @@ private: std::vector<TASCommand> record_commands{}; size_t current_command{0}; TASCommand last_input{}; // only used for recording - - // Old settings for swapping controllers - std::array<Settings::PlayerInput, 10> player_mappings; }; -} // namespace TasInput +} // namespace InputCommon::TasInput |