Re: [AD] al_set_mouse_xy asynchronous on X

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


On 2013-02-23, at 11:43 PM, Peter Wang <novalazy@xxxxxxxxxx> wrote:
> On Sat, 23 Feb 2013 22:46:05 -0700, Trent Gamblin <nooskewl@xxxxxxxxxx> wrote:
>> This poses a problem. In my game I have (simplified):
>> 
>> al_set_mouse_xy(...);
>> // bunch of code later
>> al_get_mouse_state();
>> // state.x/y are still not the same as I set them
>> 
>> So my submarine crashes.
>> 
>> The fix that I think should be applied (but I want to check with the X/Linux "guys") is an XFlush in the X set_mouse_xy implementation. Works like a charm.
>> 
> 
> That wouldn't really do it.  The XFlush forces the message out of the
> library's buffer to the X server, but there's no guarantee that the X
> server sends back the pointer moved event, and that it is processed by
> the time you call al_get_mouse_state().
> 
> Also, wouldn't your code still be susceptible to the X event thread
> changing the mouse state after the [synchronous] al_set_mouse_xy call
> and al_get_mouse_state?

It does matter if it changes relative to the position I set. The game warps the mouse cursor to the center of the screen and uses relative differences to calculate how much to move. What's happening is I open a dialog and if I click to cancel it (button on the right half of the screen) the position way right of center gets read by al_get_mouse_state so I crash into a wall on the right. I know events are better for this but I made this game with Allegro 4 originally. I guess I'll just hook into my event loop. This code is pretty bad and I'll just have to add to the already long list of globals/spaghetti.

Trent



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