Palm-Studios / sh3redux

SILENT HILL 3 Engine Remake in OpenGL and C++
GNU General Public License v3.0
164 stars 15 forks source link

Input #80

Closed z33ky closed 6 years ago

z33ky commented 7 years ago

We should be able to get input at least from keyboard and mouse. I think a stateful approach, basically maintaining a list of all pressed keys and buttons, is the best for our use case.

I'm working on a system based on SDL that also uses timestamps that can track for how long between frames a key was pressed; the time is normalized in the range [0, 1], so that it can just be multiplied for movement for instance. It also counts how many times a key was pressed, so if something is toggled, for instance the flashlight, one can use count % 2 == 1 to decide whether to turn it on. I'm hoping this can improve the response in the presence of lags.

I'm ripping this code from another project of mine. Here's some sample that shows the API's usage. The code only checks for State::Pressed, but there's also the Released, JustPressed and JustReleased states. The Just* states refer to the key having been started to be pressed/released for the current update and can be used for firing a weapon, for instance.

Quaker762 commented 7 years ago

Sounds good. This should work really well for the inventory screen, which is where most of the input occurs (classic J-Horror resource management gameplay haha)