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

Improved Axis API #684

Closed
wants to merge 2 commits into from
Closed

Conversation

simpuid
Copy link
Contributor

@simpuid simpuid commented Oct 15, 2020

Added functions to get current value, previous value and delta value of Axis<T>
previous value means the value before calling Axis<T>::update and current value means the value after calling Axis<T>::update. delta value is the difference between current and previous values and it can be 0.0f32. delta would be None when axis' value is not set after calling Axis<T>::update
This will help to detect actual changes to axis value by the caller system easily, like in the updated gamepad_input example.
The other way is to approx compare delta with 0.0f32 but that's tiring (see the first commit)

@simpuid simpuid marked this pull request as draft October 15, 2020 13:50
@simpuid simpuid marked this pull request as ready for review October 15, 2020 18:16
@cart
Copy link
Member

cart commented Oct 15, 2020

I'm a little hesitant about this one. If there are multiple "axis input events" in the same update, that would result in some of the delta being missed.

I also think most axis use cases use absolute values / don't require deltas (ex: "how fast should I move this thing" and "is this axis past a certain threshold"), so I think I'm fine letting the user track this themselves. For use cases that need to track "did something happen since the last time we ran", I think exposing the axis events in an Events queue is a more generic approach.

@simpuid
Copy link
Contributor Author

simpuid commented Oct 15, 2020

I'm a little hesitant about this one. If there are multiple "axis input events" in the same update, that would result in some of the delta being missed.

Actually the delta would be the sum of all the deltas

I also think most axis use cases use absolute values / don't require deltas (ex: "how fast should I move this thing" and "is this axis past a certain threshold"), so I think I'm fine letting the user track this themselves. For use cases that need to track "did something happen since the last time we ran", I think exposing the axis events in an Events queue is a more generic approach.

Events seems like a good approach to solve this problem. I shall open a new PR with AxisChange(GamepadAxisType, f32) and ButtonChange(GamepadButtonType, f32) variants of GamepadEventType. This would allow users to apply custom deadzones for axis and buttons which was discussed in #681

Closing because it's redundant

@simpuid simpuid closed this Oct 15, 2020
@cart
Copy link
Member

cart commented Oct 15, 2020

Actually the delta would be the sum of all the deltas

I don't thats true. If there are two EventType::AxisChanged events processed in the same frame (lets say with original value 0, new1 == 0.5, new2 == 0.75), this is what I'm pretty sure happens:

  1. new1 is processed, set is called. previous = 0, current = 0.5
  • if we called delta() now, we would get a value of 0.5
  1. new2 is procesed, set is called. previous = 0.5, current = 0.75
  • if we called delta() now, we would get a value of 0.25
  1. some user system runs in update and calls .delta(), we get 0.25 despite the fact that it actually should be 0.75

@simpuid
Copy link
Contributor Author

simpuid commented Oct 15, 2020

new2 is procesed, set is called. previous = 0.5, current = 0.75

it would be previous() = 0, current() = 0.75 and delta() = 0.75
If you look closely in the Axis<T>::set function, the previous values are inserted when they are absent (vacant entry), they are never updated .

Axis<T>::update clears the previous values so the previous value is inserted only at the first call of Axis<T>::set after Axis<T>::update

Whatever the case, the event approach looks better

@cart
Copy link
Member

cart commented Oct 15, 2020

Oops yeah you're right. Thanks for bearing with me 😄

@karroffel karroffel added A-Input Player input via keyboard, mouse, gamepad, and more C-Feature A new feature, making something new possible labels Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants