Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd manual update operations to keyboard/mouse state. #909
Comments
SiegeLord
added
Enhancement
Easy
labels
May 30, 2018
This comment has been minimized.
This comment has been minimized.
|
I might be interested in doing this. Is this the kind of interface you were imagining? ALLEGRO_KEYBOARD_STATE keyboard_state;
ALLEGRO_MOUSE_STATE mouse_state;
ALLEGRO_TOUCH_INPUT_STATE touch_state;
al_init_keyboard_state(&keyboard_state);
al_init_mouse_state(&mouse_state);
al_init_touch_input_state(&touch_state);
// ...
while (al_wait_for_event(event_queue, &e))
{
al_update_mouse(&mouse_state, e);
al_update_keyboard(&keyboard_state, e);
al_update_touch_input_state(&touch_state, e);
// ...
if (al_key_down(&keyboard_state, ALLEGRO_KEY_ESC))
exit();
}I deliberately left out a set of functions to work with How do you feel about the fact the user isn't filtering events here before passing them to the update functions? Should the documentation / examples encourage the user to filter their events by source? e.g. if (e.source == al_get_mouse_event_source())
al_update_mouse_state(e);
else if (e.source == al_get_keyboard_event_source())
al_update_keyboard_state(e);
// etc...Seems annoyingly redundant and like an extra source of errors. Ignoring un-related events seems like the more Allegro thing to do. |
This comment has been minimized.
This comment has been minimized.
|
Yes, that's exactly what I was thinking, definitely no pre-filtering. Sounds good about leaving out |
This comment has been minimized.
This comment has been minimized.
|
A few more things: • Further issue: the Solution 1: I think this just requires clear documentation (to only use Solution 2: Question: Which sounds better? I think I'd prefer Solution 1, however, Solution 2 could also make sense as the API already starts to break down with multiple displays. • Joysticks have a state API with the same issue that Solution 1: I think this will just have to be a documented pit-fall since Solution 2: I thought that something similar to Question: Should a joystick state update function be added at all? Should Possibly • I guess I should add new functions as unstable API? Just making sure. |
This comment has been minimized.
This comment has been minimized.
|
About For mouse coordinates, perhaps they could be initialized to some invalid state (-1, -1?) or we could document that the state is semi-invalid until the first call Not super concerned about the joystick API (as the API as is very bizzare right now), but what you're saying makes sense. Yes, everything will be unstable, we'll have to play around with it either way. |
This comment has been minimized.
This comment has been minimized.
|
Oops I was wrong about the relationships states have to multiple display, invalidating the first concern I had. A display doesn't need to created before getting state, and you don't need to manage one state per display.
Unless I mis-understand the point of this API, I think it should be a goal to make sure that the state the user is maintaining reflects reality. The only way to achieve that with Here's another scenario to consider: Imagine a Windows user has StickyKeys enabled and holding down a modifier key, and then they start up an Allegro game. The key is never going to get a down/up event, and the only way the game will find out about it is if it calls (At least in terms of the API, that's the way you would get that information -- if a key that's being held down since startup isn't reflected in the keyboard state I think that's a bug that should be fixed)
Each individual piece of state wouldn't be valid until the next event happens that updates that piece of state. In the case of the mouse coordinates, games would have their custom-rendered mouse cursor start off in the top left corner of their game on startup which looks sloppy. People would end up having to get mouse coordinates on start-up to work around this, which defeats the point of making a replacement for a function that already does this. (I checked and it doesn't seem like the Win32 mouse driver correctly sets the x/y values in the mouse state if the window opens with the mouse already over it, but if true that is again a bug that should be fixed IMO) I'm not sure if I really understand the non-determinism problem if Of course, encouraging people to use the order which creates redundant events is important because removes the possibility of a "stuck key" in their state due to a dropped event. A redundant event has no concerns of breaking anything. Thinking about solutions to allow al_register_event_source(&q, al_get_keyboard_event_source());
al_register_event_source(&q, al_get_mouse_event_source());
al_get_keyboard_state(&key_state);
al_get_mouse_state(&mouse_state);I really cannot see why you would ever want "init" over "get"... |
This comment has been minimized.
This comment has been minimized.
|
Yes, you make very good points. Let's omit the |
SiegeLord commentedMay 30, 2018
•
edited
This lets us reuse the terrible API for something more useful. Requires these functions (with obvious functionality: