Input: misc updates to some functions in PadHandler

This commit is contained in:
Megamouse 2020-02-23 11:32:32 +01:00
parent 1dc2eb1cc8
commit 17f335648c
2 changed files with 33 additions and 31 deletions

View file

@ -186,15 +186,17 @@ std::tuple<u16, u16> PadHandlerBase::NormalizeStickDeadzone(s32 inX, s32 inY, u3
return std::tuple<u16, u16>(ConvertAxis(X), ConvertAxis(Y)); return std::tuple<u16, u16>(ConvertAxis(X), ConvertAxis(Y));
} }
if (mag > dzRange) { if (mag > dzRange)
float pos = lerp(0.13f, 1.f, (mag - dzRange) / (1 - dzRange)); {
float scale = pos / mag; const float pos = std::lerp(0.13f, 1.f, (mag - dzRange) / (1 - dzRange));
const float scale = pos / mag;
X = X * scale; X = X * scale;
Y = Y * scale; Y = Y * scale;
} }
else { else
float pos = lerp(0.f, 0.13f, mag / dzRange); {
float scale = pos / mag; const float pos = std::lerp(0.f, 0.13f, mag / dzRange);
const float scale = pos / mag;
X = X * scale; X = X * scale;
Y = Y * scale; Y = Y * scale;
} }
@ -244,32 +246,32 @@ std::tuple<u16, u16> PadHandlerBase::ConvertToSquirclePoint(u16 inX, u16 inY, in
return std::tuple<u16, u16>(newX, newY); return std::tuple<u16, u16>(newX, newY);
} }
std::string PadHandlerBase::name_string() std::string PadHandlerBase::name_string() const
{ {
return m_name_string; return m_name_string;
} }
size_t PadHandlerBase::max_devices() size_t PadHandlerBase::max_devices() const
{ {
return m_max_devices; return m_max_devices;
} }
bool PadHandlerBase::has_config() bool PadHandlerBase::has_config() const
{ {
return b_has_config; return b_has_config;
} }
bool PadHandlerBase::has_rumble() bool PadHandlerBase::has_rumble() const
{ {
return b_has_rumble; return b_has_rumble;
} }
bool PadHandlerBase::has_deadzones() bool PadHandlerBase::has_deadzones() const
{ {
return b_has_deadzones; return b_has_deadzones;
} }
bool PadHandlerBase::has_led() bool PadHandlerBase::has_led() const
{ {
return b_has_led; return b_has_led;
} }
@ -332,8 +334,8 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const std:
std::pair<u16, std::string> pressed_button = { 0, "" }; std::pair<u16, std::string> pressed_button = { 0, "" };
for (const auto& button : button_list) for (const auto& button : button_list)
{ {
u32 keycode = button.first; const u32 keycode = button.first;
u16 value = data[keycode]; const u16 value = data[keycode];
if (!get_blacklist && std::find(blacklist.begin(), blacklist.end(), keycode) != blacklist.end()) if (!get_blacklist && std::find(blacklist.begin(), blacklist.end(), keycode) != blacklist.end())
continue; continue;

View file

@ -327,22 +327,22 @@ protected:
} }
// Search an unordered map for a string value and return found keycode // Search an unordered map for a string value and return found keycode
int FindKeyCode(const std::unordered_map<u32, std::string>& map, const cfg::string& name, bool fallback = true); static int FindKeyCode(const std::unordered_map<u32, std::string>& map, const cfg::string& name, bool fallback = true);
// Search an unordered map for a string value and return found keycode // Search an unordered map for a string value and return found keycode
long FindKeyCode(const std::unordered_map<u64, std::string>& map, const cfg::string& name, bool fallback = true); static long FindKeyCode(const std::unordered_map<u64, std::string>& map, const cfg::string& name, bool fallback = true);
// Search an unordered map for a string value and return found keycode // Search an unordered map for a string value and return found keycode
int FindKeyCodeByString(const std::unordered_map<u32, std::string>& map, const std::string& name, bool fallback = true); static int FindKeyCodeByString(const std::unordered_map<u32, std::string>& map, const std::string& name, bool fallback = true);
// Search an unordered map for a string value and return found keycode // Search an unordered map for a string value and return found keycode
long FindKeyCodeByString(const std::unordered_map<u64, std::string>& map, const std::string& name, bool fallback = true); static long FindKeyCodeByString(const std::unordered_map<u64, std::string>& map, const std::string& name, bool fallback = true);
// Get new scaled value between 0 and 255 based on its minimum and maximum // Get new scaled value between 0 and 255 based on its minimum and maximum
float ScaleStickInput(s32 raw_value, int minimum, int maximum); static float ScaleStickInput(s32 raw_value, int minimum, int maximum);
// Get new scaled value between -255 and 255 based on its minimum and maximum // Get new scaled value between -255 and 255 based on its minimum and maximum
float ScaleStickInput2(s32 raw_value, int minimum, int maximum); static float ScaleStickInput2(s32 raw_value, int minimum, int maximum);
// Get normalized trigger value based on the range defined by a threshold // Get normalized trigger value based on the range defined by a threshold
u16 NormalizeTriggerInput(u16 value, int threshold); u16 NormalizeTriggerInput(u16 value, int threshold);
@ -359,18 +359,18 @@ protected:
std::tuple<u16, u16> NormalizeStickDeadzone(s32 inX, s32 inY, u32 deadzone); std::tuple<u16, u16> NormalizeStickDeadzone(s32 inX, s32 inY, u32 deadzone);
// get clamped value between 0 and 255 // get clamped value between 0 and 255
u16 Clamp0To255(f32 input); static u16 Clamp0To255(f32 input);
// get clamped value between 0 and 1023 // get clamped value between 0 and 1023
u16 Clamp0To1023(f32 input); static u16 Clamp0To1023(f32 input);
// input has to be [-1,1]. result will be [0,255] // input has to be [-1,1]. result will be [0,255]
u16 ConvertAxis(float value); static u16 ConvertAxis(float value);
// The DS3, (and i think xbox controllers) give a 'square-ish' type response, so that the corners will give (almost)max x/y instead of the ~30x30 from a perfect circle // The DS3, (and i think xbox controllers) give a 'square-ish' type response, so that the corners will give (almost)max x/y instead of the ~30x30 from a perfect circle
// using a simple scale/sensitivity increase would *work* although it eats a chunk of our usable range in exchange // using a simple scale/sensitivity increase would *work* although it eats a chunk of our usable range in exchange
// this might be the best for now, in practice it seems to push the corners to max of 20x20, with a squircle_factor of 8000 // this might be the best for now, in practice it seems to push the corners to max of 20x20, with a squircle_factor of 8000
// This function assumes inX and inY is already in 0-255 // This function assumes inX and inY is already in 0-255
std::tuple<u16, u16> ConvertToSquirclePoint(u16 inX, u16 inY, int squircle_factor); static std::tuple<u16, u16> ConvertToSquirclePoint(u16 inX, u16 inY, int squircle_factor);
public: public:
s32 thumb_min = 0; s32 thumb_min = 0;
@ -383,12 +383,12 @@ public:
pad_handler m_type; pad_handler m_type;
std::string name_string(); std::string name_string() const;
size_t max_devices(); size_t max_devices() const;
bool has_config(); bool has_config() const;
bool has_rumble(); bool has_rumble() const;
bool has_deadzones(); bool has_deadzones() const;
bool has_led(); bool has_led() const;
static std::string get_config_dir(pad_handler type, const std::string& title_id = ""); static std::string get_config_dir(pad_handler type, const std::string& title_id = "");
static std::string get_config_filename(int i, const std::string& title_id = ""); static std::string get_config_filename(int i, const std::string& title_id = "");