Comments (8)
I used VecDaque
in my implementation:
#[derive(Default)]
pub struct KeyDownQueue {
pub keys_pressed: VecDeque<KeyCode>,
}
from rust-sokoban.
@iolivia , @denniskaselow
Take a look at #91 - what do you think? :)
from rust-sokoban.
good catch, we probably want a queue not a stack!
from rust-sokoban.
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 Vec
will never have more than a few keys even in worst case (ignoring automated input).
from rust-sokoban.
that looks great @fineconstant! feel free to submit a PR, will be very helpful for others using the repo 😄
from rust-sokoban.
I looked into it and I think that Vec<KeyCode>
is sufficient, so there is no need to make any changes.
With Vec<KeyCode>
calling input_queue.keys_pressed.pop()
function removes the last element indeed, but input_queue.keys_pressed.push(keycode);
appends an element at the back of the collection - it should not cause any problems.
std::vec::Vec - Rust #method.push
std::vec::Vec - Rust #method.pop
I've just recently started learning Rust so I may be wrong, but if you agree then I think we can close this issue 😄
from rust-sokoban.
Like I said in the initial comment:
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.
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 VecDeque
would be much better.
from rust-sokoban.
Oh I see now, you are right. I will prepare a PR with changes 😃
from rust-sokoban.
Related Issues (20)
- Unused and too big readme.gif file
- `ggez` related code seems outdated HOT 4
- Better README
- Procedural Macros are missing in book HOT 1
- Component traits missing from chapter 3 HOT 1
- Translations HOT 6
- use `sort_by_key` to improve readabilty HOT 1
- Chapter 2 Section 5 Missing code HOT 1
- Box can move in situation where it shouldn't move HOT 2
- Feedback: Confusing imports at interim stages of project HOT 2
- Should be impl RenderingSystem<'_> { instead of pub struct RenderingSystem<'a> {
- Performance Issues due to Debug Mode HOT 2
- Remove unused imports
- Use compact imports
- [Translation] zh_CN HOT 4
- [Translation] ru_RU HOT 1
- [Translation] es_MX HOT 6
- Further performace improvements for rendering (image caching) HOT 1
- Not working with GNOME 3.38 + Wayland 1.19 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-sokoban.