Skip to main content

DeadzoneStrategy.ixx File

Abstract base class for gamepad axis deadzone normalization strategies. More...

Included Headers

#include <algorithm>

Namespaces Index

namespacehelios
namespaceinput

Input handling and management. More...

namespacegamepad

Gamepad input handling and configuration. More...

Classes Index

classDeadzoneStrategy

Abstract strategy interface for normalizing gamepad stick input with deadzone handling. More...

Description

Abstract base class for gamepad axis deadzone normalization strategies.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file DeadzoneStrategy.ixx
3 * @brief Abstract base class for gamepad axis deadzone normalization strategies.
4 */
5module;
6
7#include <algorithm>
8
9export module helios.input.gamepad.DeadzoneStrategy;
10
11
12export namespace helios::input::gamepad {
13
14 /**
15 * @brief Abstract strategy interface for normalizing gamepad stick input with deadzone handling.
16 *
17 * Gamepad analog sticks rarely return exactly (0, 0) when at rest due to hardware drift.
18 * A deadzone defines a threshold below which input is ignored. Implementations of this
19 * interface define how input values are normalized once they exceed the deadzone threshold.
20 *
21 * @see RadialDeadzoneStrategy for a circular deadzone implementation.
22 */
24
25 protected:
26
27 /**
28 * @brief Threshold used to filter out minor noise in gamepad stick input.
29 *
30 * This value represents the minimum magnitude of stick input required
31 * to be treated as valid. Input signals with a magnitude below this
32 * threshold are considered noise, helping to mitigate the effect of
33 * hardware drift or minor stick movements. Adjusting this parameter
34 * can improve input precision and reduce unintended drift behavior.
35 */
37
38 public:
39
40 /**
41 * @brief Default threshold used to filter out minor noise in gamepad stick input.
42 */
43 static constexpr float DEFAULT_STICK_NOISE_THRESHOLD = 0.002f;
44
45 /**
46 * @brief Virtual destructor for proper polymorphic cleanup.
47 */
48 virtual ~DeadzoneStrategy() = default;
49
50 /**
51 * @brief Default constructor.
52 */
53 DeadzoneStrategy() = default;
54
55 /**
56 * @brief Interface for applying deadzone handling to gamepad stick input.
57 *
58 * Defines a method for processing and normalizing analog stick input while accounting
59 * for a deadzone. A deadzone eliminates unintended small input values caused
60 * by hardware imperfections. Implementations of this interface provide specific
61 * strategies for handling the deadzone and input normalization.
62 *
63 * @see AxisDeadzoneStrategy for an axis-aligned deadzone implementation.
64 */
66
67 /**
68 * @brief Normalizes stick input values based on the configured deadzone.
69 *
70 * This method modifies the input coordinates in-place. Values within the deadzone
71 * are typically zeroed out, while values outside are scaled to provide a smooth
72 * response curve from the edge of the deadzone to the maximum input value.
73 *
74 * @param deadzone The deadzone threshold in the range [0.0, 1.0].
75 * @param x Reference to the x-axis value, modified in-place.
76 * @param y Reference to the y-axis value, modified in-place.
77 */
78 virtual void normalize(float deadzone, float& x, float& y) const noexcept = 0;
79
80
81 /**
82 * @brief Retrieves the current noise threshold for stick input.
83 *
84 * The noise threshold determines the minimum magnitude of input
85 * required to be processed as valid. Values below this threshold are
86 * considered noise and ignored to prevent unintentional drift detection.
87 *
88 * @return The configured noise threshold value.
89 */
90 [[nodiscard]] float stickNoiseThreshold() const noexcept {
92 }
93
94 /**
95 * @brief Sets the noise threshold for stick inputs to handle minor hardware drift.
96 *
97 * The noise threshold defines the minimum magnitude for stick input to be considered valid.
98 * Inputs with a magnitude below this threshold are ignored to prevent unintentional movement
99 * caused by hardware noise or drift.
100 *
101 * @param threshold The new stick noise threshold, typically in the range [0.0, 1.0].
102 */
103 void setStickNoiseThreshold(float threshold) noexcept {
104 stickNoiseThreshold_ = std::clamp(threshold, 0.0f, 0.9f);
105 }
106 };
107
108}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.