Relying on SDL_Joystick constants?

Hello,

I have noticed that some joysticks without analog sticks return JOYAXISMOTION
events instead of JOYHATMOTION events. I am going to make a backward
conversion but I was wondering if other oddities may happen.

If so, are they specific to each joystick model or are they some known strange
behaviour that I have to deal with ?

For example, I guess not any joysticks return the same constant for L1 button.
Are there better solutions that involving the final player or dealing with
a known database of configurations ?

Thanks,
Guillaume

Le Wed, 7 Sep 2005 14:04:10 +0000 (UTC)
Guillaume Denis a ?crit:

I have noticed that some joysticks without analog sticks return
JOYAXISMOTION events instead of JOYHATMOTION events. I am going to
make a backward conversion but I was wondering if other oddities may
happen.

You’ll never know what the user will have: only 1 hat (old joysticks), 4
axis (like playstation paddles), or both (1 hat+analog paddles).

If so, are they specific to each joystick model or are they some known
strange behaviour that I have to deal with ?

I think is is more driver/OS specific. For example, joysticks plugged on
sound card port on PC must return analog values, even if they are
digital. In this case it is done at hardware level.

Or from my personal experience, I implemented the Atari joystick driver
as emulating an analog joystick (2-axis), because I did not know what a
hat was. Then I fixed that to match the hardware reality, which was 1
hat.

For example, I guess not any joysticks return the same constant for L1
button. Are there better solutions that involving the final player or
dealing with a known database of configurations ?

Except on platforms where everyone is using the same joystick (like on
game consoles), you’ll never know what button is, and where it is on
the joystick. In fact, don’t even consider that axis 0 is horizontal,
and axis 1 is vertical.

The solution is to make it configurable which can be a tedious task, but
it is the price to pay, to have a joystick layer independent from the
hardware/driver/OS.

Note: I did not check for Playstation 2 paddle button stuff in SDL, but
the buttons can return an analog value, not only pressed/depressed. Does
SDL consider the buttons as on/off hardware?–
Patrice Mandin
WWW: http://pmandin.atari.org/
Programmeur Linux, Atari
Sp?cialit?: D?veloppement, jeux

I have noticed that some joysticks without analog sticks return JOYAXISMOTION
events instead of JOYHATMOTION events. I am going to make a backward
conversion but I was wondering if other oddities may happen.

In most cases, SDL isn’t making any calls on this and just reporting
what the OS/kernel/etc reported.

These vary between sticks, driver versions, OSes, everything. You cannot
count on a single property of anything that you don’t dynamically query
at runtime! Don’t assume that buttons won’t look like hats, or axes
won’t really be buttons, etc…this is almost always out of SDL’s control.

For example, I guess not any joysticks return the same constant for L1 button.
Are there better solutions that involving the final player or dealing with
a known database of configurations ?

No one likes hearing this, but the BEST THING you can do is put a
configuration option in-game.

Something like “Move forward: [SOME DEFAULT]” that when the user clicks
on, you pop up a message saying “press the key/button/axis you want to
use” and then check for new keypresses and joystick input, iterating
over all new buttons. When you see a new input, use that. There are lots
of good examples of this in existing games.

This, of course, takes more work, but it’s the only reasonable way to
handle joysticks…and really, this also solves a lot of problems when
your game doesn’t work as expected on AZERTY keyboards, too, so sooner
or later you’ll want to do this.

–ryan.

  • Ryan C. Gordon wrote:
> >For example, I guess not any joysticks return the same constant for L1 > >button. > >Are there better solutions that involving the final player or dealing with > >a known database of configurations ? > > No one likes hearing this, but the BEST THING you can do is put a > configuration option in-game. > > Something like "Move forward: [SOME DEFAULT]" that when the user clicks > on, you pop up a message saying "press the key/button/axis you want to > use" and then check for new keypresses and joystick input, iterating > over all new buttons. When you see a new input, use that. There are lots > of good examples of this in existing games.

I’d prefer the idea of a common database. This could reside in the
user’s homedir and is configured by a separate config app, which works
as you’ve pointed out. I don’t see any need for having evryone doing
his own implementation. This is redundant.

We just have to define a standard for this configs.

cu–

Enrico Weigelt == metux IT service

phone: +49 36207 519931 www: http://www.metux.de/
fax: +49 36207 519932 email: contact at metux.de
cellphone: +49 174 7066481

– DSL ab 0 Euro. – statische IP – UUCP – Hosting – Webshops –

Ryan C. Gordon <icculus clutteredmind.org> writes:

No one likes hearing this, but the BEST THING you can do is put a
configuration option in-game.

This, of course, takes more work, but it’s the only reasonable way to
handle joysticks…and really, this also solves a lot of problems when
your game doesn’t work as expected on AZERTY keyboards, too, so sooner
or later you’ll want to do this.

–ryan.

This can be a lot of work, considering hats recognized as buttons or axis, etc.
The next step being to save configurations…

Guillaume

I have noticed that some joysticks without analog sticks return JOYAXISMOTION
events instead of JOYHATMOTION events. I am going to make a backward
conversion but I was wondering if other oddities may happen.

What platform are you running on?

If you’re using Linux, there is some support in the SDL joystick code for
mapping axes to hats - take a look at src/joystick/linux/SDL_sysjoystick.c

-Sam Lantinga, Software Engineer, Blizzard Entertainment

Sam Lantinga <slouken twomix.devolution.com> writes:

I have noticed that some joysticks without analog sticks return JOYAXISMOTION
events instead of JOYHATMOTION events. I am going to make a backward
conversion but I was wondering if other oddities may happen.

What platform are you running on?

If you’re using Linux, there is some support in the SDL joystick code for
mapping axes to hats - take a look at src/joystick/linux/SDL_sysjoystick.c

-Sam Lantinga, Software Engineer, Blizzard Entertainment

I am going to have a look at this code, but I develop for Windows.
Thanks, Guillaume

Guillaume Denis <denis cri.ensmp.fr> writes:

I have a more precise question on the subject, since I am writing
some code to allow players to configure their gamepads.
Is is guaranteed that an axis motion event, returning to center
(neutral position), returns -1 as its jaxis.value ?

Thanks, Guillaume