Re: [AD] Should al_set_mouse_xy generate events?

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 28 feb 2009, at 09:17, Elias Pschernig wrote:
user movement. The two solutions I see are:

A) Add a field event.mouse.was_set to ALLEGRO_MOUSE_EVENT. If this field
is true, the movement came from al_set_mouse_xy and is not a real user
movement. Now dx/dy from only user events can be used in the game for
perfectly smooth movement.

B) Do not generate any mouse events for al_set_mouse_xy in the first
place. This also can prevent a "feedback loop" where a user does
something foolish like calling al_set_mouse_xy(event.mouse.x + 1, 0) in
response to each mouse movement event...

I have a very slight preference for B.

I prefer C:
C) If the mouse position was changed by al_set_mouse_xy, send ALLEGRO_EVENT_MOUSE_WARPED instead of ALLEGRO_EVENT_MOUSE_AXES. The structure is set exactly the same as for ALLEGRO_EVENT_MOUSE_AXES.

This avoids the hacky nature of adding an extra field to the struct of the first solution and it includes the second solution implicitly by allowing the user to ignore ALLEGRO_EVENT_MOUSE_WARPED events. If you want to catch both, you simply do

case ALLEGRO_EVENT_MOUSE_AXES:
case ALLEGRO_EVENT_MOUSE_WARPED:
   do_stuff();

I think it's the most elegant solution to the problem (but then, I thought of it). It's not stupid user proof in the sense of "al_set_mouse_xy(event.mouse.x + 1, 0)", but can we trust to people to not be that stupid (or at least tell them not to be)? ;)

Evert




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/