This is something I wanted to do but I am cannot, too busy. Got for it!
Just a question: how do you plan to suppot the buttons since ALL of them are
analog?
- Just read the “pressed” boolean and treat it like a digital button
anyway?
For all of those aware of ABI issues, please scrutinize this in case I
screwed up. But for analog buttons, I’m thinking there is enough
memory space in the SDL_event structure that we can add fields for
values and not break backwards compatibility.
The main SDL_event structure seems to have 56 bytes:
/* This is necessary for ABI compatibility between Visual C++ and GCC
Visual C++ will respect the push pack pragma and use 52 bytes for
this structure, and GCC will use the alignment of the largest datatype
within the union, which is 8 bytes.
So... we'll add padding to force the size to be 56 bytes for both.
*/
Uint8 padding[56];
I count 16 bytes for the SDL_ControllerButtonEvent. (I’m assuming this
already accounts for alignment padding, which in this case there isn’t
any.)
typedef struct SDL_ControllerButtonEvent
{
Uint32 type; /< ::SDL_CONTROLLERBUTTONDOWN or
::SDL_CONTROLLERBUTTONUP */
Uint32 timestamp;
SDL_JoystickID which; /< The joystick instance id */
Uint8 button; /< The controller button (SDL_GameControllerButton) */
Uint8 state; /< ::SDL_PRESSED or ::SDL_RELEASED */
Uint8 padding1;
Uint8 padding2;
} SDL_ControllerButtonEvent;
So we can add a double value to the end of this type. We should also
have enough space for another variable to denote if the button
actually supports analog button values or not.
typedef struct SDL_ControllerButtonEvent
{
Uint32 type; /< ::SDL_CONTROLLERBUTTONDOWN or
::SDL_CONTROLLERBUTTONUP */
Uint32 timestamp;
SDL_JoystickID which; /< The joystick instance id */
Uint8 button; /< The controller button (SDL_GameControllerButton) */
Uint8 state; /< ::SDL_PRESSED or ::SDL_RELEASED */
Uint8 padding1;
Uint8 padding2;
double analogState;
Uint8 supportsAnalog;
} SDL_ControllerButtonEvent;
So Uint8 state should return SDL_PRESSED or SDL_RELEASED as it does
now so existing SDL behavior will continue to work.
For those who want analog enhancements, they may use Uint8
supportsAnalog and double analogState.
Uint8 supportsAnalog will be 1 for buttons that are analog, and 0
otherwise. analogState which contains the normalized value between 0.0
and 1.0 where 1.0 is fully pressed and 0.0 is fully released.
The same may be applied to SDL_JoyButtonEvent.
- Let only the triggers be axes?
- treat them as both?
I’m not up to speed on triggers and axes, but it sounds like a real
problem I have today with my very old, but very awesome Gravis
Xterminator gamepad (Win95/98 era gamepad). There are several areas
that don’t work that really annoy me. The D-Pad on it provides axes,
but it looks like Steam Big Picture mode, it expects each direction to
be a button (and in fact doesn’t let me map the d-pad to anything).
Instead the HAT is the only thing I can map it to. But more relevant
to this talk, it has rear analog shoulder buttons which also register
as an axis. So in Steam Big Picture mode, I can only register the left
or the right side, but never both. If there is a way to fix both the
Apple controller problem and my legacy pad problem, I would love it.
As I said, I’m not up to speed on the problem, but I think I’m
gravitating towards “treat them as both”.
Since I hope to have experts scrutinizing this, I have two digressions…
First, why 56 bytes and not say a nice round power-of-two 64 bytes?
I’ve been dealing with custom events and I’ve had a few cases I really
would have liked a few more bytes. It seems like 64-bytes would
simplify the platform specific padding issues too.
Second, I noticed that SDL_GameController.h and SDL_RWops.h use
anonymous unions which are a C11 feature. This is giving me some
headaches with a compiler tool I’m using. Is there a way to change
this so it is C89/C90 compliant without breaking things?
(One more digression…my compiler tool is related to language bindings.
In a few cases, the ivars in the SDL structs use language keywords
which is a nuisance.)
Thanks,
EricOn 4/18/14, RodrigoCard wrote:
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/