diff options
| author | untodesu <kirill@untode.su> | 2025-09-11 15:48:53 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-09-11 15:48:53 +0500 |
| commit | d0fbd68055e3f4a796330cc8acc6c0954b5327ff (patch) | |
| tree | e581014ea02711efa5e71f00f9862e5bca58f2ed /game/client/config/gamepad_axis.cc | |
| parent | cbd823aa2154a956e7da4319eecbf7afc10441ae (diff) | |
| download | voxelius-d0fbd68055e3f4a796330cc8acc6c0954b5327ff.tar.bz2 voxelius-d0fbd68055e3f4a796330cc8acc6c0954b5327ff.zip | |
Run clang-format across the project
Diffstat (limited to 'game/client/config/gamepad_axis.cc')
| -rw-r--r-- | game/client/config/gamepad_axis.cc | 230 |
1 files changed, 115 insertions, 115 deletions
diff --git a/game/client/config/gamepad_axis.cc b/game/client/config/gamepad_axis.cc index 8ae74be..c782c19 100644 --- a/game/client/config/gamepad_axis.cc +++ b/game/client/config/gamepad_axis.cc @@ -1,115 +1,115 @@ -#include "client/pch.hh" - -#include "client/config/gamepad_axis.hh" - -#include "core/math/constexpr.hh" - -#include "client/io/gamepad.hh" - -constexpr static std::string_view UNKNOWN_AXIS_NAME = "UNKNOWN"; - -static const std::pair<int, std::string_view> axis_names[] = { - { GLFW_GAMEPAD_AXIS_LEFT_X, "LEFT_X" }, - { GLFW_GAMEPAD_AXIS_LEFT_Y, "LEFT_Y" }, - { GLFW_GAMEPAD_AXIS_RIGHT_X, "RIGHT_X" }, - { GLFW_GAMEPAD_AXIS_RIGHT_Y, "RIGHT_Y" }, - { GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, "LEFT_TRIG" }, - { GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, "RIGHT_TRIG" }, -}; - -static std::string_view get_axis_name(int axis) -{ - for(const auto& it : axis_names) { - if(it.first != axis) { - continue; - } - - return it.second; - } - - return UNKNOWN_AXIS_NAME; -} - -config::GamepadAxis::GamepadAxis(void) : GamepadAxis(io::INVALID_GAMEPAD_AXIS, false) -{ -} - -config::GamepadAxis::GamepadAxis(int axis, bool inverted) -{ - m_inverted = inverted; - m_gamepad_axis = axis; - m_name = get_axis_name(axis); - m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U); -} - -std::string_view config::GamepadAxis::get(void) const -{ - return m_full_string; -} - -void config::GamepadAxis::set(std::string_view value) -{ - char new_name[64]; - unsigned int new_invert; - std::string value_str(value); - - if(2 == std::sscanf(value_str.c_str(), "%63[^:]:%u", new_name, &new_invert)) { - for(const auto& it : axis_names) { - if(0 == it.second.compare(new_name)) { - m_inverted = new_invert; - m_gamepad_axis = it.first; - m_name = get_axis_name(m_gamepad_axis); - m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U); - return; - } - } - } - - m_inverted = false; - m_gamepad_axis = io::INVALID_GAMEPAD_AXIS; - m_name = UNKNOWN_AXIS_NAME; - m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U); -} - -int config::GamepadAxis::get_axis(void) const -{ - return m_gamepad_axis; -} - -void config::GamepadAxis::set_axis(int axis) -{ - m_gamepad_axis = axis; - m_name = get_axis_name(axis); - m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U); -} - -bool config::GamepadAxis::is_inverted(void) const -{ - return m_inverted; -} - -void config::GamepadAxis::set_inverted(bool inverted) -{ - m_inverted = inverted; - m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U); -} - -float config::GamepadAxis::get_value(const GLFWgamepadstate& state, float deadzone) const -{ - if(m_gamepad_axis <= math::array_size(state.axes)) { - auto value = state.axes[m_gamepad_axis]; - - if(math::abs(value) > deadzone) { - return m_inverted ? -value : value; - } - - return 0.0f; - } - - return 0.0f; -} - -std::string_view config::GamepadAxis::get_name(void) const -{ - return m_name; -} +#include "client/pch.hh"
+
+#include "client/config/gamepad_axis.hh"
+
+#include "core/math/constexpr.hh"
+
+#include "client/io/gamepad.hh"
+
+constexpr static std::string_view UNKNOWN_AXIS_NAME = "UNKNOWN";
+
+static const std::pair<int, std::string_view> axis_names[] = {
+ { GLFW_GAMEPAD_AXIS_LEFT_X, "LEFT_X" },
+ { GLFW_GAMEPAD_AXIS_LEFT_Y, "LEFT_Y" },
+ { GLFW_GAMEPAD_AXIS_RIGHT_X, "RIGHT_X" },
+ { GLFW_GAMEPAD_AXIS_RIGHT_Y, "RIGHT_Y" },
+ { GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, "LEFT_TRIG" },
+ { GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, "RIGHT_TRIG" },
+};
+
+static std::string_view get_axis_name(int axis)
+{
+ for(const auto& it : axis_names) {
+ if(it.first != axis) {
+ continue;
+ }
+
+ return it.second;
+ }
+
+ return UNKNOWN_AXIS_NAME;
+}
+
+config::GamepadAxis::GamepadAxis(void) : GamepadAxis(io::INVALID_GAMEPAD_AXIS, false)
+{
+}
+
+config::GamepadAxis::GamepadAxis(int axis, bool inverted)
+{
+ m_inverted = inverted;
+ m_gamepad_axis = axis;
+ m_name = get_axis_name(axis);
+ m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U);
+}
+
+std::string_view config::GamepadAxis::get(void) const
+{
+ return m_full_string;
+}
+
+void config::GamepadAxis::set(std::string_view value)
+{
+ char new_name[64];
+ unsigned int new_invert;
+ std::string value_str(value);
+
+ if(2 == std::sscanf(value_str.c_str(), "%63[^:]:%u", new_name, &new_invert)) {
+ for(const auto& it : axis_names) {
+ if(0 == it.second.compare(new_name)) {
+ m_inverted = new_invert;
+ m_gamepad_axis = it.first;
+ m_name = get_axis_name(m_gamepad_axis);
+ m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U);
+ return;
+ }
+ }
+ }
+
+ m_inverted = false;
+ m_gamepad_axis = io::INVALID_GAMEPAD_AXIS;
+ m_name = UNKNOWN_AXIS_NAME;
+ m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U);
+}
+
+int config::GamepadAxis::get_axis(void) const
+{
+ return m_gamepad_axis;
+}
+
+void config::GamepadAxis::set_axis(int axis)
+{
+ m_gamepad_axis = axis;
+ m_name = get_axis_name(axis);
+ m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U);
+}
+
+bool config::GamepadAxis::is_inverted(void) const
+{
+ return m_inverted;
+}
+
+void config::GamepadAxis::set_inverted(bool inverted)
+{
+ m_inverted = inverted;
+ m_full_string = std::format("{}:{}", m_name, m_inverted ? 1U : 0U);
+}
+
+float config::GamepadAxis::get_value(const GLFWgamepadstate& state, float deadzone) const
+{
+ if(m_gamepad_axis <= math::array_size(state.axes)) {
+ auto value = state.axes[m_gamepad_axis];
+
+ if(math::abs(value) > deadzone) {
+ return m_inverted ? -value : value;
+ }
+
+ return 0.0f;
+ }
+
+ return 0.0f;
+}
+
+std::string_view config::GamepadAxis::get_name(void) const
+{
+ return m_name;
+}
|
