PistonDevelopers / input

DEPRECATED - moved into the piston repo
MIT License
7 stars 11 forks source link

Event transformations for higher level events #32

Closed lucidd closed 9 years ago

lucidd commented 10 years ago

Idea

The basic idea is to have some kind of stream of input events that can be transformed. With that it would be possible to transfrom a stream of raw low level events like button pressed or mouse moved to higher level events like double click or mouse dragged.

Transformations should be able to:

It could also potentaly used to solve #11

You could also go as far as implementing an application specific transformation that transforms raw or higher level events to application specific events like Move or Attack.

raw touch events => swipe gesture event => Attack Event

Implementation

I don't think it is possible to implement something like that with the current design since you cant extend the Events. I think #30 with the Event trait should help with this.

Open Questions

bvssvni commented 10 years ago

Good idea! @Denommus Is also looking into FRP.

Are you on IRC (#rust-gamedev) sometimes?

lucidd commented 10 years ago

yeah im usually on IRC in #rust and #rust-gamedev. Its good to know that im not the only one looking into this stuff :smile:

bvssvni commented 10 years ago

I am thinking about this as well. Perhaps we could do something like this:

// Triggers on double click of left mouse button.
let mut dc = Event::new().double_click(mouse::Left).once();
...
for e in ... {
    if dc.trigger(&e) {
        // Handle event.
        ...
        // Resets event so it can trigger again.
        dc.reset();
    }
}

This is similar to the current design in rust-event, but without a "event center" and much more simplified. I wonder if we could use a nested type structure like iterators in Rust, for example Once<T> which stores a flag whether it triggered. Methods can propagate to the wrapper type by using traits. For key mapping we can use Box<Trigger>, to store in struct members to control player actions, and pass in the event through a method on the controller, like we do in FirstPerson in Piston. Other traits can be added for AbsoluteAxis and RelativeAxis etc.

bvssvni commented 10 years ago

@Coeuvre What do you think about this design?

Denommus commented 10 years ago

I'm probably basing myself mostly on signal function FRP, which is talked about in this paper: https://dl.dropboxusercontent.com/u/23124877/FRP/20103_amsden_istudy.pdf

bvssvni commented 9 years ago

It is possible to use ai_behavior to something like this.

Any this is outside the scope of this library, so I'll close this.