Rework inputs #87

Open
opened 2022-11-08 15:20:12 +01:00 by kazhnuz · 3 comments
Owner

In love, inputs are handled two ways

  • Functions that allow us to check if a key is down, the joystick position, etc... which is useful for stuff that must be done each frame
  • Events that call a certain callback

In our system, we don't have an equivalent of the first, but we would prefer to go more to an event-based system. The current input system is kinda overcomplicated, and it would be good to simplify it, try as much as possible to transform inputs into a thin translation layer.

We have two possibility here:

  • Hybrid way of handling it à la love2D
  • Fully event-driven, with a down event too (it would send an event each frame tho when the key is down, and we might need to think about how we handle the action).
  • Maybe a bit of both ? Having the love2D way, and use the "isDown(key)" in the action system to handle the "continous" action, and make them available in the update function to stuff like computation, etc.

TODO

  • Think about API
In love, inputs are handled two ways - Functions that allow us to check if a key is down, the joystick position, etc... which is useful for stuff that must be done each frame - Events that call a certain callback In our system, we don't have an equivalent of the first, but we would prefer to go more to an event-based system. The current input system is kinda overcomplicated, and it would be good to simplify it, try as much as possible to transform inputs into a thin translation layer. We have two possibility here: - Hybrid way of handling it à la love2D - Fully event-driven, with a down event too (it would send an event each frame tho when the key is down, and we might need to think about how we handle the action). - Maybe a bit of both ? Having the love2D way, and use the "isDown(key)" in the action system to handle the "continous" action, and make them available in the update function to stuff like computation, etc. TODO - Think about API
kazhnuz added this to the epervier 0.7.0 milestone 2022-11-08 15:20:12 +01:00
kazhnuz added the
3. Need investigation
1. Feature
1. Clean-up
4. Birb Core
4. Inputs
labels 2022-11-08 15:20:12 +01:00
Author
Owner

It would be interesting to rethink to replace the virtualpad API by a "binding" API, a bit like :

return {
	menu = {move = "move", apply="jump", cancel="attack"},
	bindings = {
    	{id = "move", name = "Move player", type="stick", defaultKeys= {up = "up", down="down", left="left", right="right"}, defaultAxis="0"},
        {id="jump", name="Jump", defaultkey="A", defaultBtn="1"},
        {id="pause", name="Pause Menu", defaultkey="space", defaultBtn="7"},
    },
}

And then events would be:

events = {
    ["move"] = "move",
    ["jump:pressed"] = "jump",
    ["attack:down"] = "attack",
}
It would be interesting to rethink to replace the virtualpad API by a "binding" API, a bit like : ```lua return { menu = {move = "move", apply="jump", cancel="attack"}, bindings = { {id = "move", name = "Move player", type="stick", defaultKeys= {up = "up", down="down", left="left", right="right"}, defaultAxis="0"}, {id="jump", name="Jump", defaultkey="A", defaultBtn="1"}, {id="pause", name="Pause Menu", defaultkey="space", defaultBtn="7"}, }, } ``` And then events would be: ```lua events = { ["move"] = "move", ["jump:pressed"] = "jump", ["attack:down"] = "attack", }
Author
Owner

API list for bindings:

  • <keyname> called if key is down
  • <keyname>:pressed called if key have been pressed
  • <keyname>:released called if key have been released
  • <dirname> called every frame (argument is a point with value between 1 and -1)
  • <dirname>:axis called every frame for an axis (give its value between 1 and -1)
  • <dirname>:key is the equivalent of <keyname> for a key
API list for bindings: - `<keyname>` called if key is down - `<keyname>:pressed` called if key have been pressed - `<keyname>:released` called if key have been released - `<dirname>` called every frame (argument is a point with value between 1 and -1) - `<dirname>:axis` called every frame for an axis (give its value between 1 and -1) - `<dirname>:key` is the equivalent of `<keyname>` for a key
Author
Owner

The input would be passed like that:
-> If the scene have an action for the input, call the input
-> If a gui element is active/have foucs, catpure all remaining event
-> If the world have an action for the input, call the input
-> If the player object have an action for the input, call the input

The input would be passed like that: -> If the scene have an action for the input, call the input -> If a gui element is active/have foucs, catpure all remaining event -> If the world have an action for the input, call the input -> If the player object have an action for the input, call the input
Sign in to join this conversation.
No description provided.