Page 1 of 1

Some love features I think would be useful

Posted: Sat Jun 01, 2019 10:07 pm
by Shadowblitz16
I just had a suggestion for love2d to make input easier to manage
adding these functions would make life a lot easier and I think could speed up development time for people.

- Love.keyboard.isDownPrevious()
- Love.mouse.isDownPrevious()
- Love.joystick.isDownPrevious()
- Love.joystick.GetAxisPrevious()

- Love.keyboard.GetKeysDown()
- Love.keyboard.GetKeysDownPrevious()
- Love.mouse.GetButtonsDown()
- Love.mouse.GetButtonsDownPrevious()
- Love.joystick.GetButtonsDown()
- Love.joystick.GetButtonsDownPrevious()
- Love.joystick.GetAxesDown()
- Love.joystick.GetAxesDownPrevious()

not only this but you could make a input manager without a update function because you have access to all the inputs that is needed to check if something was just pressed, something is pressed, or something is released for example..

Code: Select all

local joystickAxesCurr               = joystick:GetAxesButtonsDown(1)
local joystickAxesPrev               = joystick:GetAxesButtonsDownPrevious(1)
local joystickAxisJustChangedFrom0   = joystick:GetAxis(joystickAxesCurr ) == 0 and joystick:GetAxisPrevious(joystickAxesPrev) ~= 0;
local joystickAxisJustChangedTo0     = joystick:GetAxis(joystickAxesCurr ) ~= 0 and joystick:GetAxisPrevious(joystickAxesPrev) == 0;
it also supports people making their own input managers because you don't have access to pressed and release functions directly but just the current and previous inputs.

also we can now easily check for if anything was pressed by just passing in the one of the new constant getting functions.

what do you guys think?

Re: Some love features I think would be useful

Posted: Sun Jun 02, 2019 12:47 am
by 4vZEROv
I don't understand how this would be usefull, just use a variable to stock the previous key and voila ?

Re: Some love features I think would be useful

Posted: Sun Jun 02, 2019 5:50 am
by raidho36
My input library does exactly this, by a popular request. I'm convinced though that the framework itself doesn't need this functionality.

Re: Some love features I think would be useful

Posted: Sun Jun 02, 2019 8:05 am
by zorg
People usually should detect whether something was pressed or released at the current frame (if using the callbacks) or detect whether something is still held down (if using methods in update); Anything else can be implemented using your own code, by storing such state, and querying that state, giving the "classic" 4-state input model of "de-pressed", "pressed", "held", "released".

Or as raidho said, use a library that implements such a thing.

To me, all those function duplications scream bad news; what do the Previous functions return? The same as the regular ones?
So now i have to manually truth-table-combine both results into all 4 possibilities; Why not just return that state itself? And by then, again, you'd use a library.

Re: Some love features I think would be useful

Posted: Sun Jun 02, 2019 8:45 pm
by Shadowblitz16
you would still be able to implement a library you would just be able to do it easier.

the previous functions return the previous frames value.

if duplication is a problem then there could be a constant that you could pass that would edit the return value to the current frame or previous frame with the current frame being the default.

I think making input manager easier to make would be a good thing since they are already very complicated.

Re: Some love features I think would be useful

Posted: Mon Jun 03, 2019 5:39 am
by raidho36
That's what libraries are for. The engine itself doens't need to be any more complicated than to do the bare minimum it's supposed to do.

Re: Some love features I think would be useful

Posted: Mon Jun 03, 2019 7:40 am
by zorg
What löve provides itself is already capable of making implementing such a -stateful- input system possible; hence, it's a perfect candidate for a library.

Re: Some love features I think would be useful

Posted: Mon Jun 03, 2019 11:39 am
by pgimeno
The values in the previous frame are not so useful, because several events (e.g. a key down and up) can occur within one frame.

Best to leave that up to a library, which knows what to do with them. If the programmer doesn't want to miss any single press, they would use the events rather than the isDown() functions.