2019-09-20 16:47:41 +10:00
|
|
|
#pragma once
|
2020-07-01 00:35:13 +10:00
|
|
|
#include "common/image.h"
|
2020-07-01 00:33:45 +10:00
|
|
|
#include "settings.h"
|
2019-09-20 16:47:41 +10:00
|
|
|
#include "types.h"
|
2019-12-10 23:05:19 +10:00
|
|
|
#include <memory>
|
2019-12-09 00:46:04 +10:00
|
|
|
#include <optional>
|
2020-01-02 16:10:42 +10:00
|
|
|
#include <string>
|
2019-12-09 00:46:04 +10:00
|
|
|
#include <string_view>
|
2020-01-02 16:10:42 +10:00
|
|
|
#include <vector>
|
2019-09-20 16:47:41 +10:00
|
|
|
|
2019-09-30 01:59:35 +10:00
|
|
|
class StateWrapper;
|
2020-07-01 00:33:45 +10:00
|
|
|
class HostInterface;
|
2019-09-30 01:59:35 +10:00
|
|
|
|
2019-12-09 00:51:52 +10:00
|
|
|
class Controller
|
2019-09-20 16:47:41 +10:00
|
|
|
{
|
|
|
|
|
public:
|
2020-08-29 14:19:28 +02:00
|
|
|
enum class AxisType : u8
|
|
|
|
|
{
|
|
|
|
|
Full,
|
|
|
|
|
Half
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-02 16:10:42 +10:00
|
|
|
using ButtonList = std::vector<std::pair<std::string, s32>>;
|
2020-08-29 14:19:28 +02:00
|
|
|
using AxisList = std::vector<std::tuple<std::string, s32, AxisType>>;
|
2020-07-01 00:33:45 +10:00
|
|
|
using SettingList = std::vector<SettingInfo>;
|
2020-01-02 16:10:42 +10:00
|
|
|
|
2019-12-09 00:51:52 +10:00
|
|
|
Controller();
|
|
|
|
|
virtual ~Controller();
|
2019-09-20 16:47:41 +10:00
|
|
|
|
2019-12-15 00:17:43 +10:00
|
|
|
/// Returns the type of controller.
|
|
|
|
|
virtual ControllerType GetType() const = 0;
|
|
|
|
|
|
2019-12-15 00:31:07 +10:00
|
|
|
/// Gets the integer code for an axis in the specified controller type.
|
|
|
|
|
virtual std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const;
|
|
|
|
|
|
2019-12-15 00:17:43 +10:00
|
|
|
/// Gets the integer code for a button in the specified controller type.
|
|
|
|
|
virtual std::optional<s32> GetButtonCodeByName(std::string_view button_name) const;
|
|
|
|
|
|
2019-09-30 01:59:35 +10:00
|
|
|
virtual void Reset();
|
2020-12-17 00:09:32 +10:00
|
|
|
virtual bool DoState(StateWrapper& sw, bool apply_input_state);
|
2019-09-30 01:59:35 +10:00
|
|
|
|
2019-09-30 01:07:38 +10:00
|
|
|
// Resets all state for the transferring to/from the device.
|
|
|
|
|
virtual void ResetTransferState();
|
|
|
|
|
|
2019-09-20 16:47:41 +10:00
|
|
|
// Returns the value of ACK, as well as filling out_data.
|
|
|
|
|
virtual bool Transfer(const u8 data_in, u8* data_out);
|
|
|
|
|
|
2019-12-15 00:31:07 +10:00
|
|
|
/// Changes the specified axis state. Values are normalized from -1..1.
|
|
|
|
|
virtual void SetAxisState(s32 axis_code, float value);
|
|
|
|
|
|
2019-12-09 01:06:58 +10:00
|
|
|
/// Changes the specified button state.
|
|
|
|
|
virtual void SetButtonState(s32 button_code, bool pressed);
|
|
|
|
|
|
2020-12-06 15:47:00 +10:00
|
|
|
/// Returns a bitmask of the current button states, 1 = on.
|
|
|
|
|
virtual u32 GetButtonStateBits() const;
|
|
|
|
|
|
2021-01-03 22:54:16 -08:00
|
|
|
/// Returns analog input bytes packed as a u32. Values are specific to controller type.
|
|
|
|
|
virtual std::optional<u32> GetAnalogInputBytes() const;
|
|
|
|
|
|
2019-12-15 23:22:53 +10:00
|
|
|
/// Returns the number of vibration motors.
|
|
|
|
|
virtual u32 GetVibrationMotorCount() const;
|
|
|
|
|
|
|
|
|
|
/// Queries the state of the specified vibration motor. Values are normalized from 0..1.
|
|
|
|
|
virtual float GetVibrationMotorStrength(u32 motor);
|
|
|
|
|
|
2020-07-01 00:33:45 +10:00
|
|
|
/// Loads/refreshes any per-controller settings.
|
2020-07-31 17:09:18 +10:00
|
|
|
virtual void LoadSettings(const char* section);
|
2020-07-01 00:33:45 +10:00
|
|
|
|
2020-07-01 00:35:13 +10:00
|
|
|
/// Returns the software cursor to use for this controller, if any.
|
2020-12-27 14:08:13 +10:00
|
|
|
virtual bool GetSoftwareCursor(const Common::RGBA8Image** image, float* image_scale, bool* relative_mode);
|
2020-07-01 00:35:13 +10:00
|
|
|
|
2019-12-09 00:46:04 +10:00
|
|
|
/// Creates a new controller of the specified type.
|
2020-07-31 17:09:18 +10:00
|
|
|
static std::unique_ptr<Controller> Create(ControllerType type, u32 index);
|
2019-12-09 00:46:04 +10:00
|
|
|
|
2019-12-15 00:31:07 +10:00
|
|
|
/// Gets the integer code for an axis in the specified controller type.
|
|
|
|
|
static std::optional<s32> GetAxisCodeByName(ControllerType type, std::string_view axis_name);
|
|
|
|
|
|
2019-12-09 00:46:04 +10:00
|
|
|
/// Gets the integer code for a button in the specified controller type.
|
2019-12-14 23:29:26 +10:00
|
|
|
static std::optional<s32> GetButtonCodeByName(ControllerType type, std::string_view button_name);
|
2020-01-02 16:10:42 +10:00
|
|
|
|
|
|
|
|
/// Returns a list of axises for the specified controller type.
|
|
|
|
|
static AxisList GetAxisNames(ControllerType type);
|
|
|
|
|
|
|
|
|
|
/// Returns a list of buttons for the specified controller type.
|
|
|
|
|
static ButtonList GetButtonNames(ControllerType type);
|
2020-04-14 16:34:39 +10:00
|
|
|
|
|
|
|
|
/// Returns the number of vibration motors.
|
|
|
|
|
static u32 GetVibrationMotorCount(ControllerType type);
|
2020-07-01 00:33:45 +10:00
|
|
|
|
|
|
|
|
/// Returns settings for the controller.
|
|
|
|
|
static SettingList GetSettings(ControllerType type);
|
2019-12-09 00:46:04 +10:00
|
|
|
};
|