Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace axis-like input configuration with new input processors #494

Merged
merged 64 commits into from
Apr 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6b5b344
Add input processors and input settings
Shute052 Feb 27, 2024
88f7a7a
Merge branch 'main' into input-processors
Shute052 Feb 28, 2024
fd18dcb
Replace all usage
Shute052 Feb 28, 2024
91f6e4e
RELEASES.md
Shute052 Feb 28, 2024
08a6acf
Document
Shute052 Feb 28, 2024
d7ac626
Document
Shute052 Feb 28, 2024
03e54fa
Document
Shute052 Feb 28, 2024
714c296
Document
Shute052 Feb 28, 2024
09579bb
Add more test cases
Shute052 Feb 28, 2024
f58953d
Split out deadzones into another module
Shute052 Feb 29, 2024
491c38f
Fix CI and examples
Shute052 Feb 29, 2024
789017c
add `with_settings`
Shute052 Feb 29, 2024
cfd4afd
Update comment
Shute052 Feb 29, 2024
4c44577
Split axis settings into separate modules
Shute052 Feb 29, 2024
a3ccf29
Update the documentation
Shute052 Mar 1, 2024
f8a3d4d
typo
Shute052 Mar 1, 2024
f4468cc
RELEASES.md
Shute052 Mar 1, 2024
324e76e
fix ci
Shute052 Mar 1, 2024
ed9b72e
fix RELEASES.md
Shute052 Mar 2, 2024
6b8d445
fix documentation
Shute052 Mar 2, 2024
1eb50b2
fix documentation
Shute052 Mar 2, 2024
34de561
Use new implementation
Shute052 Mar 22, 2024
9066278
Add comments
Shute052 Mar 28, 2024
cf860d7
Merge branch 'main' into input-processors
Shute052 Mar 28, 2024
fed7811
Add an example
Shute052 Mar 28, 2024
e9810ef
Fix warnings in examples
Shute052 Mar 28, 2024
f572244
Remove compilation configuration
Shute052 Mar 28, 2024
3513305
Doc typo
Shute052 Mar 28, 2024
b181a30
Doc typo
Shute052 Mar 28, 2024
d4a4f35
Fix hashing
Shute052 Mar 28, 2024
070e815
Simplify
Shute052 Mar 30, 2024
a191dd4
Fix macros
Shute052 Apr 4, 2024
3623571
Merge branch 'main' into input-processors
Shute052 Apr 4, 2024
3d8d7ad
Improve docs
Shute052 Apr 4, 2024
84ad6ef
Improve docs
Shute052 Apr 4, 2024
ee10149
Improve
Shute052 Apr 4, 2024
b130c8a
Rename macros.rs
Shute052 Apr 4, 2024
64f23ce
Prefer import from bevy::prelude
Shute052 Apr 4, 2024
feefdf1
Improve macro
Shute052 Apr 4, 2024
25011c8
Improve docs
Shute052 Apr 5, 2024
f7808aa
Improve docs
Shute052 Apr 5, 2024
6b08029
Improve docs and fix CI
Shute052 Apr 5, 2024
bc63f18
Rename Square* to DualAxis*
Shute052 Apr 5, 2024
729948f
Split dual_axis.rs
Shute052 Apr 5, 2024
a10d675
Update module docs
Shute052 Apr 5, 2024
c700dae
Rename `with_processor` to `replace_processor`, add `with_processor`
Shute052 Apr 5, 2024
e79f5d2
Improve docs
Shute052 Apr 5, 2024
48a8929
Improve docs
Shute052 Apr 5, 2024
5a9dc5a
Rearrange the order of match arms
Shute052 Apr 5, 2024
2bacf98
Improve docs
Shute052 Apr 5, 2024
953a935
Typo
Shute052 Apr 5, 2024
f2d8cd3
Expand macros and refine the results
Shute052 Apr 9, 2024
a444164
Rearrange dual-axis input processors
Shute052 Apr 9, 2024
4a8afa0
Rearrange processors
Shute052 Apr 12, 2024
de7ca2b
Remove macros.rs
Shute052 Apr 12, 2024
531cf51
Switch to `serde_flexitos`
Shute052 Apr 12, 2024
ff18aa4
Add tests
Shute052 Apr 12, 2024
d614f7c
Minor
Shute052 Apr 12, 2024
5c1821c
Improve docs
Shute052 Apr 12, 2024
5a4d4de
Inline doc alias
Shute052 Apr 12, 2024
1f35022
Typo
Shute052 Apr 12, 2024
c846c38
Add missing tests
Shute052 Apr 12, 2024
8a9c864
Cleanup
Shute052 Apr 12, 2024
9fe0a6d
Cleanup
Shute052 Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve docs and fix CI
Shute052 committed Apr 5, 2024
commit 6b080296d2d72f603d6f00dcfad38eea1ab34d17
50 changes: 30 additions & 20 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -5,27 +5,37 @@
### Breaking Changes

- removed `Direction` type in favor of `bevy::math::primitives::Direction2d`.

- added input processors for `SingleAxis`, `DualAxis`, `VirtualAxis`, and `VirtualDpad`:
- Pipeline:
- Dynamic pipeline (wrapped a `Vec<Box<dyn Processor>>`): `AxisProcessingPipeline` for single-axis inputs and `DualAxisProcessingPipeline` for dual-axis inputs.
- For production-use solutions, please `define_axis_processing_pipeline` and `define_dual_axis_processing_pipeline` macros to create inlined pipelines for compiler optimization.
- Inversion: `AxisInverted` for single-axis inversion; `DualAxisInverted` for dual-axis inversion.
- Sensitivity: `AxisSensitivity` for single-axis scaling; `DualAxisSensitivity` for dual-axis scaling.
- Bounds:
- `AxisBounds` for limiting single-axis input values in a specified min-max range;
- `CircleBounds` for limiting dual-axis input magnitudes to a maximum threshold;
- `SquareBounds` for limiting dual-axis input values in a specified min-max range on each axis;
- Exclusion, in simple terms, just is unscaled deadzones:
- `AxisExclusion` for excluding single-axis input values, treating values as zeros;
- `CircleExclusion` for excluding dual-axis input magnitudes, treating values as zeros;
- `SquareExclusion` for excluding dual-axis input values on each axis, treating values as zeros;
- Deadzone (normalized):
- `AxisDeadzone` for smoothing single-axis input values into the livezone ranges defined by `AxisExclusion` and `AxisBounds`;
- `CircleDeadzone` for smoothing dual-axis input values into the livezone ranges defined by `CircleExclusion` and `CircleBounds`;
- `SquareDeadzone` for smoothing dual-axis input values into the livezone ranges defined by `SquareExclusion` and `SquareBounds`;
- removed `DualAxisShape`.
- removed functions for inversion, sensitivity scaling, and deadzone creation from these axis-like inputs.
- added input processors for `SingleAxis`, `DualAxis`, `VirtualAxis`, and `VirtualDpad` to refine input values:
- Traits:
- `AxisProcessor`: Handles single-axis values.
- `DualAxisProcessor`: Handles dual-axis values.
- Built-in processors:
- Composite Processors: Combine multiple processors function as a pipeline.
- `AxisProcessingPipeline`: Chain processors for single-axis values.
- `define_axis_processing_pipeline` macro: Inlined processor chaining for single-axis values with fixed steps.
- `DualAxisProcessingPipeline`: Chain processors for dual-axis values.
- `define_dual_axis_processing_pipeline` macro: Inlined processor chaining for dual-axis values with fixed steps.
- Inversion: Reverses control (positive becomes negative, etc.)
- `AxisInverted`: Single-axis inversion.
- `DualAxisInverted`: Dual-axis inversion.
- Sensitivity: Adjusts control responsiveness (doubling, halving, etc.).
- `AxisSensitivity`: Single-axis scaling.
- `DualAxisSensitivity`: Dual-axis scaling.
- Value Bounds: Define the boundaries for constraining input values.
- `AxisBounds`: Restricts single-axis values to a range.
- `CircleBounds`: Limits dual-axis values to a maximum magnitude.
- `SquareBounds`: Restricts single-axis values to a range along each axis.
- Deadzone: Ignores near-zero values, treating them as zero.
- Unscaled Deadzone:
- `AxisExclusion`: Excludes small single-axis values.
- `CircleExclusion`: Excludes dual-axis values below a specified magnitude threshold.
- `SquareExclusion`: Excludes small dual-axis values along each axis.
- Scaled Deadzone:
- `AxisDeadzone`: Normalizes single-axis values based on `AxisExclusion` and `AxisBounds::default`.
- `CircleDeadzone`: Normalizes dual-axis values based on `CircleExclusion` and `CircleBounds::default`.
- `SquareDeadzone`: Normalizes dual-axis values based on `SquareExclusion` and `SquareBounds::default`.
- removed functions for inverting, adjusting sensitivity, and creating deadzones from `SingleAxis` and `DualAxis`.

### Bugs

8 changes: 4 additions & 4 deletions src/input_processing/dual_axis.rs
Original file line number Diff line number Diff line change
@@ -437,10 +437,10 @@ macro_rules! define_dual_axis_processor {
impl ::core::fmt::Debug for $DualAxisProcessor {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
match self {
Self::All(p) => f.write_fmt(format_args!("DualAxis::All({p})")),
Self::Separate(px, py) => f.write_fmt(format_args!("DualAxis::Separate({px}, {py})"))
Self::OnlyX(p) => f.write_fmt(format_args!("DualAxis::OnlyX({p})")),
Self::OnlyY(p) => f.write_fmt(format_args!("DualAxis::OnlyY({p})")),
Self::All(p) => f.write_fmt(format_args!("DualAxis::All({p:?})")),
Self::Separate(px, py) => f.write_fmt(format_args!("DualAxis::Separate({px:?}, {py:?})")),
Self::OnlyX(p) => f.write_fmt(format_args!("DualAxis::OnlyX({p:?})")),
Self::OnlyY(p) => f.write_fmt(format_args!("DualAxis::OnlyY({p:?})")),
}
}
}
21 changes: 11 additions & 10 deletions src/input_processing/mod.rs
Original file line number Diff line number Diff line change
@@ -20,24 +20,25 @@
//!
//! Inversion reverses the control, such as positive value becomes negative or up becomes down.
//!
//! - [`AxisInverted`]: Inverts single-axis input values.
//! - [`DualAxisInverted`]: Inverts dual-axis input values.
//! - [`AxisInverted`]: Single-axis inversion.
//! - [`DualAxisInverted`]: Dual-axis inversion.
//!
//! ## Sensitivity
//!
//! Sensitivity adjusts control responsiveness by scaling input values with a multiplier.
//! Sensitivity adjusts control responsiveness by scaling input values with a multiplier (doubling, halving, etc.).
//!
//! - [`AxisSensitivity`]: Scales single-axis input values.
//! - [`DualAxisSensitivity`]: Scales dual-axis input values.
//! - [`AxisSensitivity`]: Single-axis scaling.
//! - [`DualAxisSensitivity`]: Dual-axis scaling.
//!
//! ## Value Bounds
//!
//! Value bounds define valid limits for input values to prevent unexpected behavior that might occur outside these boundaries.
//! Value bounds define the boundaries for constraining input values,
//! preventing unexpected behavior that might occur outside these bounds.
//! Values exceeding the bounds are clamped to fit within the specified range.
//!
//! - [`AxisBounds`]: Limits single-axis input values within a specified range.
//! - [`CircleBounds`]: Limits dual-axis input values with a magnitude greater than a specified threshold.
//! - [`SquareBounds`]: Limits dual-axis input values within a specified range along each axis.
//! - [`AxisBounds`]: Restricts single-axis input values to a range.
//! - [`CircleBounds`]: Limits dual-axis input values to a maximum magnitude.
//! - [`SquareBounds`]: Restricts dual-axis input values to a range along each axis.
//!
//! ## Deadzones
//!
@@ -46,7 +47,7 @@
//! Unscaled deadzones specify ranges where near-zero input values are excluded, treating them as zero.
//!
//! - [`AxisExclusion`]: Excludes single-axis input values within a specified range.
//! - [`CircleExclusion`]: Excludes dual-axis input values with a magnitude smaller than a specified threshold.
//! - [`CircleExclusion`]: Excludes dual-axis input values below a specified magnitude threshold.
//! - [`SquareExclusion`]: Excludes dual-axis input values within a specified range along each axis.
//!
//! ### Scaled Versions
2 changes: 1 addition & 1 deletion tests/gamepad_axis.rs
Original file line number Diff line number Diff line change
@@ -382,7 +382,7 @@ fn game_pad_dual_axis_circle() {
#[test]
fn test_zero_square() {
let mut app = test_app();
let deadzone = SquareExclusion::AllAxes(AxisExclusion::magnitude(0.0));
let deadzone = SquareExclusion::All(AxisExclusion::magnitude(0.0));
app.insert_resource(InputMap::new([(
AxislikeTestAction::XY,
DualAxis::left_stick().with_processor(deadzone),