HIGH LEVEL NOTES
This will offer a pollable state of two styles of controller: a PS1 or an XBox 360.
Returns the number of players actually connected
For a real ps1 controller/// For a real ps1 controller
If you have a real xbox 360 controller, use this mapping/// If you have a real xbox 360 controller, use this mapping
Actually, maybe I'll combine the two controller types. Make L2 and R2 just digital aliases for the triggers, which are analog aliases for it.
Then have a virtual left stick which has the dpad aliases, while keeping the other two independent (physical dpad and physical left stick).
Everything else should basically just work. We'll simply be left with naming and I can do them with aliases too.
I do NOT bother with pressure sensitive other buttons, though Xbox original and PS2 had them, they have been removed from the newer models. It makes things simpler anyway since we can check "was just pressed" instead of all deltas.
The PS1 controller style works for a lot of games: * The D-pad is an alias for the left stick. Analog input still works too. * L2 and R2 are given as buttons * The keyboard works as buttons * The mouse is an alias for the right stick * Buttons are given as labeled on a playstation controller
The XBox controller style works if you need full, modern features: * The left stick and D-pad works independently of one another the d pad works as additional buttons. * The triggers work as independent analog inputs note that the WinMM driver doesn't support full independence since it is sent as a z-axis. Linux and modern Windows does though. * Buttons are labeled as they are on the XBox controller * The rumble motors are available, if the underlying driver supports it and noop if not. * Audio I/O is available, if the underlying driver supports it. NOT IMPLEMENTED.
You chose which one you want at compile time with a -version=xbox_style or -version=ps1_style switch. The default is ps1_style which works with xbox controllers too, it just simplifies them.
TODO: handling keyboard+mouse input as joystick aliases remapping support network transparent joysticks for at least the basic stuff.
LOW LEVEL NOTES
On Linux, I'll just use /dev/input/js*. It is easy and works with everything I care about. It can fire events to arsd.eventloop and also maintains state internally for polling. You do have to let it get events though to handle that input - either doing your own select (etc.) on the js file descriptor, or running the event loop (which is what I recommend).
On Windows, I'll support the mmsystem messages as far as I can, and XInput for more capabilities of the XBox 360 controller. (The mmsystem should support my old PS1 controller and xbox is the other one I have. I have PS3 controllers too which would be nice but since they require additional drivers, meh.)
linux notes: all basic input is available, no audio (I think), no force feedback (I think)
winmm notes: the xbox 360 controller basically works and sends events to the window for the buttons, left stick, and triggers. It doesn't send events for the right stick or dpad, but these are available through joyGetPosEx (the dpad is the POV hat and the right stick is the other axes).
The triggers are considered a z-axis with the left one going negative and right going positive.
windows xinput notes: all xbox 360 controller features are available via a polling api.
it doesn't seem to support events. That's OK for games generally though, because we just want to check state on each loop.
For non-games however, using the traditional message loop is probably easier.
XInput is only supported on newer operating systems (Vista I think), so I'm going to dynamically load it all and fallback on the old one if it fails.