mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-01 16:02:39 +00:00
InputCommon/ControllerEmu: Break out functionality of EmulatedController
to eliminate redundant unused members in Wii Remote extension objects.
This commit is contained in:
parent
225039f742
commit
ddb82a5e8c
26 changed files with 312 additions and 245 deletions
|
@ -172,29 +172,83 @@ struct RawValue
|
|||
}
|
||||
};
|
||||
|
||||
class EmulatedController
|
||||
// Maps a float from -1.0..+1.0 to an integer in the provided range.
|
||||
template <typename T, typename F>
|
||||
T MapFloat(F input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
|
||||
T pos_1_value = std::numeric_limits<T>::max())
|
||||
{
|
||||
static_assert(std::is_integral<T>(), "T is only sane for int types.");
|
||||
static_assert(std::is_floating_point<F>(), "F is only sane for float types.");
|
||||
|
||||
static_assert(std::numeric_limits<long long>::min() <= std::numeric_limits<T>::min() &&
|
||||
std::numeric_limits<long long>::max() >= std::numeric_limits<T>::max(),
|
||||
"long long is not a superset of T. use of std::llround is not sane.");
|
||||
|
||||
// Here we round when converting from float to int.
|
||||
// After applying our deadzone, resizing, and reshaping math
|
||||
// we sometimes have a near-zero value which is slightly negative. (e.g. -0.0001)
|
||||
// Casting would round down but rounding will yield our "zero_value".
|
||||
|
||||
if (input_value > 0)
|
||||
return T(std::llround((pos_1_value - zero_value) * input_value + zero_value));
|
||||
else
|
||||
return T(std::llround((zero_value - neg_1_value) * input_value + zero_value));
|
||||
}
|
||||
|
||||
// The inverse of the function above.
|
||||
// Maps an integer in the provided range to a float in the range -1.0..1.0.
|
||||
template <typename F, typename T>
|
||||
F MapToFloat(T input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
|
||||
T pos_1_value = std::numeric_limits<T>::max())
|
||||
{
|
||||
static_assert(std::is_integral<T>(), "T is only sane for int types.");
|
||||
static_assert(std::is_floating_point<F>(), "F is only sane for float types.");
|
||||
|
||||
if (input_value >= zero_value)
|
||||
return F(input_value - zero_value) / F(pos_1_value - zero_value);
|
||||
else
|
||||
return -F(zero_value - input_value) / F(zero_value - neg_1_value);
|
||||
}
|
||||
|
||||
class ControlGroupContainer
|
||||
{
|
||||
public:
|
||||
virtual ~EmulatedController();
|
||||
virtual ~ControlGroupContainer();
|
||||
|
||||
virtual void LoadGroupsConfig(Common::IniFile::Section* sec, const std::string& base);
|
||||
virtual void SaveGroupsConfig(Common::IniFile::Section* sec, const std::string& base);
|
||||
|
||||
virtual std::string GetName() const = 0;
|
||||
virtual std::string GetDisplayName() const;
|
||||
|
||||
void UpdateGroupsReferences(ciface::ExpressionParser::ControlEnvironment& env);
|
||||
|
||||
void SetInputOverrideFunction(InputOverrideFunction override_func);
|
||||
void ClearInputOverrideFunction();
|
||||
|
||||
std::vector<std::unique_ptr<ControlGroup>> groups;
|
||||
|
||||
protected:
|
||||
InputOverrideFunction m_input_override_function;
|
||||
};
|
||||
|
||||
class EmulatedController : public ControlGroupContainer
|
||||
{
|
||||
public:
|
||||
virtual ~EmulatedController();
|
||||
|
||||
virtual InputConfig* GetConfig() const = 0;
|
||||
|
||||
virtual void LoadDefaults(const ControllerInterface& ciface);
|
||||
|
||||
virtual void LoadConfig(Common::IniFile::Section* sec, const std::string& base = "");
|
||||
virtual void SaveConfig(Common::IniFile::Section* sec, const std::string& base = "");
|
||||
void LoadConfig(Common::IniFile::Section* sec);
|
||||
void SaveConfig(Common::IniFile::Section* sec);
|
||||
|
||||
bool IsDefaultDeviceConnected() const;
|
||||
const ciface::Core::DeviceQualifier& GetDefaultDevice() const;
|
||||
void SetDefaultDevice(const std::string& device);
|
||||
void SetDefaultDevice(ciface::Core::DeviceQualifier devq);
|
||||
|
||||
void SetInputOverrideFunction(InputOverrideFunction override_func);
|
||||
void ClearInputOverrideFunction();
|
||||
|
||||
void UpdateReferences(const ControllerInterface& devi);
|
||||
void UpdateSingleControlReference(const ControllerInterface& devi, ControlReference* ref);
|
||||
|
||||
|
@ -209,55 +263,9 @@ public:
|
|||
// Resets the values while keeping the list.
|
||||
void ResetExpressionVariables();
|
||||
|
||||
std::vector<std::unique_ptr<ControlGroup>> groups;
|
||||
|
||||
// Maps a float from -1.0..+1.0 to an integer in the provided range.
|
||||
template <typename T, typename F>
|
||||
static T MapFloat(F input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
|
||||
T pos_1_value = std::numeric_limits<T>::max())
|
||||
{
|
||||
static_assert(std::is_integral<T>(), "T is only sane for int types.");
|
||||
static_assert(std::is_floating_point<F>(), "F is only sane for float types.");
|
||||
|
||||
static_assert(std::numeric_limits<long long>::min() <= std::numeric_limits<T>::min() &&
|
||||
std::numeric_limits<long long>::max() >= std::numeric_limits<T>::max(),
|
||||
"long long is not a superset of T. use of std::llround is not sane.");
|
||||
|
||||
// Here we round when converting from float to int.
|
||||
// After applying our deadzone, resizing, and reshaping math
|
||||
// we sometimes have a near-zero value which is slightly negative. (e.g. -0.0001)
|
||||
// Casting would round down but rounding will yield our "zero_value".
|
||||
|
||||
if (input_value > 0)
|
||||
return T(std::llround((pos_1_value - zero_value) * input_value + zero_value));
|
||||
else
|
||||
return T(std::llround((zero_value - neg_1_value) * input_value + zero_value));
|
||||
}
|
||||
|
||||
// The inverse of the function above.
|
||||
// Maps an integer in the provided range to a float in the range -1.0..1.0.
|
||||
template <typename F, typename T>
|
||||
static F MapToFloat(T input_value, T zero_value, T neg_1_value = std::numeric_limits<T>::min(),
|
||||
T pos_1_value = std::numeric_limits<T>::max())
|
||||
{
|
||||
static_assert(std::is_integral<T>(), "T is only sane for int types.");
|
||||
static_assert(std::is_floating_point<F>(), "F is only sane for float types.");
|
||||
|
||||
if (input_value >= zero_value)
|
||||
return F(input_value - zero_value) / F(pos_1_value - zero_value);
|
||||
else
|
||||
return -F(zero_value - input_value) / F(zero_value - neg_1_value);
|
||||
}
|
||||
|
||||
protected:
|
||||
// TODO: Wiimote attachments actually end up using their parent controller value for this,
|
||||
// so theirs won't be used (and thus shouldn't even exist).
|
||||
ciface::ExpressionParser::ControlEnvironment::VariableContainer m_expression_vars;
|
||||
|
||||
InputOverrideFunction m_input_override_function;
|
||||
|
||||
void UpdateReferences(ciface::ExpressionParser::ControlEnvironment& env);
|
||||
|
||||
private:
|
||||
ciface::Core::DeviceQualifier m_default_device;
|
||||
bool m_default_device_is_connected{false};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue