-
Notifications
You must be signed in to change notification settings - Fork 30
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
InputSystem doesn't use input in correct order #87
Comments
good catch, we probably want a queue not a stack! |
Something simple as this could also be sufficient: impl InputQueue {
pub fn get_first(&mut self) -> Option<KeyCode> {
if self.keys_pressed.is_empty() {
None
} else {
Some(self.keys_pressed.remove(0))
}
}
} But I'm new to Rust, so I have no idea if this is the Rust way to do things, but it's what I'd do, considering the key_pressed |
I used #[derive(Default)]
pub struct KeyDownQueue {
pub keys_pressed: VecDeque<KeyCode>,
} |
that looks great @fineconstant! feel free to submit a PR, will be very helpful for others using the repo 😄 |
I looked into it and I think that With std::vec::Vec - Rust #method.push I've just recently started learning Rust so I may be wrong, but if you agree then I think we can close this issue 😄 |
Like I said in the initial comment:
A push can happen several times in the time it takes one pop to move the character. Thus you can input up, left, down and it'll move the character down, left, up. So your |
Oh I see now, you are right. I will prepare a PR with changes 😃 |
@iolivia , @denniskaselow |
InputSystem
usesinput_queue.keys_pressed.pop()
and is commented as// Get the first key pressed
butpop()
removes the last item.If you input keys fast enough (very easy when not using release mode and batch rendering) this can be seen because of erratic movement of the player character.
The text was updated successfully, but these errors were encountered: