Re: [AD] ex_joystick_hotplugging.c |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2010-08-21, Trent Gamblin <trent@xxxxxxxxxx> wrote:
> On 2010-08-21, at 6:39 PM, Peter Wang wrote:
> > Hi,
> >
> > I still think it's a bad idea that al_get_num_joysticks can now
> > invalidate existing ALLEGRO_JOYSTICK structures.
>
> Yeah, I agree.
>
> > curr_joy is invalid at this point.
> >
> > It crashes when I unplug a joystick. (I will fix it while fixing some
> > issues with the linux joystick driver)
>
> Alright. I wanted to get it into SVN because I have
> other commitments that aren't going to leave me much
> time to tune this how I'd like right now. I think the
> issues are pretty minor and shouldn't be too hard to
> fix.
Ok. The Linux joystick driver is much improved now.
The other drivers seem to require similar changes.
I think we should not require Allegro programs to put in extra effort to
cope with hotplugging. Anything that requires the program to remember
an old id/index/whatever, in addition to ALLEGRO_JOYSTICK handles, is
too much work. I have a feeling most programs wouldn't bother.
Rather, ALLEGRO_JOYSTICK handles should persist after reconfiguration,
and they should continue to refer to the same physical devices (which
are still plugged in). No re-getting of handles required.
Handles for devices which have been unplugged should *also* persist, so
nothing will crash. Inactive handles should be reused when devices are
plugged in. That would make this common situation just work:
if I pull out device A during a game and plug in device B, I probably
wanted to use device B in place of device A. Since the old
ALLEGRO_JOYSTICK handle is valid, a program that doesn't do anything
special will work as expected.
We can add a function:
bool al_get_joystick_active(ALLEGRO_JOYSTICK *joy);
to tell if the handle has a physical device associated with it.
Comments?
Peter