[SDL] SDL_WaitEvent in 1.3

Ryan C. Gordon icculus at icculus.org
Sat Jan 10 19:13:50 PST 2009


> the mouse and the joystick have movement and button push events. When
> the mouse moves you can just modify the event at the top of the queue
> (if it is a movement event) and add the current dx,dy to the existing
> dx,dy and sort of lie about where the mouse has been. The application

It's even simpler than that on Windows (outside of SDL): when mouse 
motion triggers a hardware interrupt, Windows sets a flag for each app 
that is looking for mouse events. When the app pumps the event queue, 
they supply the event then, in relation to the previous x,y coordinates 
for that application, and clear the flag until the next interrupt.

So total storage for mouse motion events, per app, is one bit, plus X 
and Y coordinates, and you don't ever have to dig through the queue to 
replace or update an existing mouse motion event. It's actually really 
smart, since this is probably the only event type that would ever really 
risk overflowing a well-written program's queue.

But then again, it's also a pathological case of event queue overflow: 
you literally drop all mouse motion events between pumps of the queue, 
but it doesn't cause overflow that makes you lose _other_ events...and 
between losing a key release and losing mouse motion resolution, it's 
the wiser choice.

--ryan.




More information about the SDL mailing list