Re: [AD] keyboard buffer (proposal) |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2008-12-20, Matthew Leverton <meffer@xxxxxxxxxx> wrote:
> On Sat, Dec 20, 2008 at 3:06 PM, Elias Pschernig
> <elias.pschernig@xxxxxxxxxx> wrote:
> > My vote is to completely remove ALLEGRO_KEYBOARD_STATE and al_key_down.
> >
> > It's not easier to use than events, and means you randomly lose key
> > presses whenever the user starts typing/playing fast. So basically as
> > soon as you use them, your game is broken. There's simply no reason at
> > all to ever use them.
> >
> I disagree. And plus, as SiegeLord pointed out, using events could
> break your game too.
It shouldn't. At least for the mouse, if you hold down a mouse button
in one window then release it outside that window, the original window
should get the release event, not whatever window the mouse cursor is
on top of now.
> However, I wouldn't mind removing ALLEGRO_KEYBOARD_STATE from the
> programmer's view. How would people use it, other than:
>
> al_poll_keyboard();
> if (al_key_down(ALLEGRO_KEY_LEFT)) p.x--;
>
> i.e., is that sufficient, or is there a good reason to expose
> ALLEGRO_KEYBOARD_STATE?
Yes, due to multiple threads. One thread could be updating the keyboard
state with al_poll_keyboard() while another is calling al_key_down().
Practically speaking, I *think* we can get away with only locking in
al_poll_keyboard() and just letting al_key_down() read from the internal
buffer without any synchronisation, but I'd rather not introduce a known
design defect.
I don't see that your example all that different from:
ALLEGRO_KEYBOARD_STATE kst; /* global */
...
al_get_keyboard_state(&kst);
if (al_key_down(&kst, ALLEGRO_KEY_LEFT)) p.x--;
Peter