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

Input Handling (State tracking) #104

Closed
msiglreith opened this Issue Sep 11, 2016 · 11 comments

Comments

Projects
6 participants
@msiglreith
Contributor

msiglreith commented Sep 11, 2016

The current event system allows handling of the input events from the window.
It's often more interesting to check the current state of the key pressed/released for games requiring manual tracking atm (e.g. pong example https://github.com/amethyst/amethyst/blob/develop/examples/04_pong/main.rs#L132-L144).

@ebkalderon

This comment has been minimized.

Show comment
Hide comment
@ebkalderon

ebkalderon Sep 11, 2016

Member

Could we maybe make the keyboard events less verbose? I think they could probably be reduced to Event::KeyPressed(VirtualKeyCode) and Event::KeyReleased(VirtualKeyCode) instead.

Member

ebkalderon commented Sep 11, 2016

Could we maybe make the keyboard events less verbose? I think they could probably be reduced to Event::KeyPressed(VirtualKeyCode) and Event::KeyReleased(VirtualKeyCode) instead.

@nchashch

This comment has been minimized.

Show comment
Hide comment
@nchashch

nchashch Sep 13, 2016

Member

Maybe we can add an InputHandler to Context, which would be updated according to incoming events in Application::advance_frame, and which would provide methods like: InputHandler::get_key_state, InputHandler::get_mouse_position, InputHandler::get_mouse_button_state, etc. So it won't be necessary to have something like InputState in pong example.

Member

nchashch commented Sep 13, 2016

Maybe we can add an InputHandler to Context, which would be updated according to incoming events in Application::advance_frame, and which would provide methods like: InputHandler::get_key_state, InputHandler::get_mouse_position, InputHandler::get_mouse_button_state, etc. So it won't be necessary to have something like InputState in pong example.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Sep 13, 2016

I usually like to write the event list into a state tracker of some sort. Something like this:

https://gist.github.com/csherratt/5647fad71f21d437bd8b561320f9228d

That way you can just query what keys are down each frame, rather then read all the events to listen for the key down event and saving it somewhere. It also has the events that were submitted this frame so that people can handle them in the way they want.

I imagine we might want to expand on something like this to include the config remapping. So you can query if the Forward button is down, and we can reference the W and the Up key. And the mappings would be from a config file.

Not sure how that would work with our current ECS based event system.

ghost commented Sep 13, 2016

I usually like to write the event list into a state tracker of some sort. Something like this:

https://gist.github.com/csherratt/5647fad71f21d437bd8b561320f9228d

That way you can just query what keys are down each frame, rather then read all the events to listen for the key down event and saving it somewhere. It also has the events that were submitted this frame so that people can handle them in the way they want.

I imagine we might want to expand on something like this to include the config remapping. So you can query if the Forward button is down, and we can reference the W and the Up key. And the mappings would be from a config file.

Not sure how that would work with our current ECS based event system.

@nchashch

This comment has been minimized.

Show comment
Hide comment
@nchashch

nchashch Sep 13, 2016

Member

I think you can do the remapping by implementing a system, which would listen to input and then update a custom ECS resource which would act simularly to InputHandler or publish custom events, like if InputHandler::get_key_state(VirtualKeyCode::Up) == KeyState::Pressed set MoveDirection resource to MoveDirection::Forward or publish a MoveDirection::Forward event using Broadcaster.

Member

nchashch commented Sep 13, 2016

I think you can do the remapping by implementing a system, which would listen to input and then update a custom ECS resource which would act simularly to InputHandler or publish custom events, like if InputHandler::get_key_state(VirtualKeyCode::Up) == KeyState::Pressed set MoveDirection resource to MoveDirection::Forward or publish a MoveDirection::Forward event using Broadcaster.

@ebkalderon ebkalderon added this to the 1.0 milestone Sep 14, 2016

@yeliknewo

This comment has been minimized.

Show comment
Hide comment
@yeliknewo

yeliknewo Sep 15, 2016

Would it be valuable to also have a timestamp as well as the KeyState stored? That way you can tell when it was pressed for things like delayed input.

Would it be valuable to also have a timestamp as well as the KeyState stored? That way you can tell when it was pressed for things like delayed input.

@ebkalderon

This comment has been minimized.

Show comment
Hide comment
@ebkalderon

ebkalderon Sep 15, 2016

Member

@yeliknewo That would be a good idea. I think that every event should have a timestamp attached to it somehow, and if you wanted to delay an event, you would just set the delivery timestamp forward X number of milliseconds. Most engines take that approach for recording and replaying demos: start with an initial world snapshot, and then replay a stream of recorded events with correct timings to replay the original gameplay.

Member

ebkalderon commented Sep 15, 2016

@yeliknewo That would be a good idea. I think that every event should have a timestamp attached to it somehow, and if you wanted to delay an event, you would just set the delivery timestamp forward X number of milliseconds. Most engines take that approach for recording and replaying demos: start with an initial world snapshot, and then replay a stream of recorded events with correct timings to replay the original gameplay.

@msiglreith

This comment has been minimized.

Show comment
Hide comment
@msiglreith

msiglreith Dec 2, 2016

Contributor

Feature request from gitter:
Add function to return an iterator over the currently pressed keys

Contributor

msiglreith commented Dec 2, 2016

Feature request from gitter:
Add function to return an iterator over the currently pressed keys

@ivandardi

This comment has been minimized.

Show comment
Hide comment
@ivandardi

ivandardi Feb 6, 2017

Contributor

Now that the feature request from gitter has been implemented, this issue can be closed.

Contributor

ivandardi commented Feb 6, 2017

Now that the feature request from gitter has been implemented, this issue can be closed.

@Aceeri

This comment has been minimized.

Show comment
Hide comment
@Aceeri

Aceeri Feb 6, 2017

Member

I think we might want to keep it open a bit (or maybe open a new one with all interested features like action mapping, etc.)

Member

Aceeri commented Feb 6, 2017

I think we might want to keep it open a bit (or maybe open a new one with all interested features like action mapping, etc.)

@msiglreith

This comment has been minimized.

Show comment
Hide comment
@msiglreith

msiglreith Feb 9, 2017

Contributor

Should close this and add new issues for the different features. As the current one is pretty vague and only was a starting point to implement basic functionality.

Contributor

msiglreith commented Feb 9, 2017

Should close this and add new issues for the different features. As the current one is pretty vague and only was a starting point to implement basic functionality.

@ebkalderon

This comment has been minimized.

Show comment
Hide comment
@ebkalderon

ebkalderon Feb 9, 2017

Member

I am inclined to agree with @msiglreith. Since we have basic input handling support already, we should open separate issues for the other features built upon it. I'll take care of that now.

Member

ebkalderon commented Feb 9, 2017

I am inclined to agree with @msiglreith. Since we have basic input handling support already, we should open separate issues for the other features built upon it. I'll take care of that now.

@ebkalderon ebkalderon closed this Feb 9, 2017

@ebkalderon ebkalderon moved this from In Progress to Shipped in Engine Feb 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment