I would like to announce a small project I recently put on GitHub. It's called SDL_input
. It started out as wanting configurable controls for Chaotic Rage; but I wanted MOAR features than just that.
You see, Chaotic Rage supports split screen, one user on keyboard (move) + keyboard acting like a mouse (aim); the other user on keyboard+mouse like usual. So I wanted keyboard-pretending-to-be-a-mouse support. I wanted joysticks. I wanted to be able to group bindings and then turn groups on and off at will (single player profile, split screen player 1 profile, split screen player 2 profile, etc). The most important thing was I wanted a unified API - the calling code shouldn't care what the actual controls are, just what the results are.
SDL_input is an abstraction of the SDL event structures. Instead of thinking about key presses and mouse moves, you think about what's actually happening ("jump" is currently pressed), and that will work if jump is bound to a key or a mouse button.
So you bind something (a key, a mouse button, a mouse axis) to a variable (float or boolean), and SDL_input will set the values of that variable for you.
There are four binding types:
- onoff - binary, is the key/mouse button currently pressed
- toggle - binary, toggles on each key press/mouse button press
- absolute value - increments/decrements according to movement
- relative value - represents how much movement has happened since last update
So for player movement in a platform game, you would probably use a relative value. You can bind it to a pair of keys (e.g. 'left arrow' and 'right arrow'), or you could bind it to the mouse X axis or a joystick X axis. The bound variable would have values between -1.0 and 1.0, depending on the amount of movement in the last frame, independent of the device bound. Obviously, joysticks and mouse provide analog control (decimal values), whereas the keyboard is only integer values (but it could be changed to vary the value on how long the key had been pressed).
For a first-person shooter, you would use an absolute value for the camera angle variables. There are features for wrapping a value, so you could wrap the X-rot at 0 and 360, to give a value in degrees. There is also limiting, so you could limit the Y-rot to -50 and -50, again directly usable as a value in degrees.
There is still a lot to do. The makefile is pretty bad and I have to decide on a license. There is also a short list of features I am yet to add, like joystick support and mouse sensitivity.
- a fast paced, shooter game that's a little odd, but still fun.