Closed diwo closed 4 years ago
Thanks for the PR! I think instead of passing all of that to update, you should make a handleInput function to the Gui class which gets all the parameters. It feels messy to have it in update
I originally considered adding a new method to Gui for registering a callback to handle input. But for keysHeld
and JoystickPosition
, the callback would need to be called every frame just as update
would. The result would be that callback(...)
is called right next to update()
every frame.
An alternative API is to register separate callbacks for specific key events, but I'm not sure what keysHeld
and JoystickPosition
would look like with this API. What do you think?
Yeah callbacks are hard with those... I would just split update and handleInput into two functions called right next to each other. Just for the sake of keeping update clean
The only change in this revision is adding Gui::handleInputs
and moving all the parameters from update to it. The Gui::tick()
function is still broken up into Gui::guiChange()
and Gui::draw()
so that it does not need to accept the input data in order to propagate down to handleInputs
.
An alternative is to keep tick()
intact and call Gui::handleInputs
from the main loop instead. But this will exclude handleInputs
from being included in the frame duration measurement. It will also put handleInputs
after update
rather than before within the loop, which looks kinda weird.
handleInputs
could happen before tick
but tick changes gui, so it'd make the code feel as if handleInputs
is for the previous frame rather than the current frame.
Input is already being passed down to Gui in latest version
Passing all raw inputs to update to allow handling things like keys held.