[SDL] Regarding event programming
bob at pendleton.com
Sun Sep 29 19:08:01 PDT 2002
Bettina Rathmann wrote:
> well this is my first attempt at SDL event programming and I have
> a small problem, which got me stumped for the last hour. A quick
> search with google returned nothing useful (except for standard
> documentation). Maybe it's to late... :o)
> I have an application which does something like that
> calculate data
> Refresh display (including own cursor)
> Get SDL_Event
> Process Event (change data for next calculation)
> loop end
> Everything work fine except that I get swamped with
> SDL_MOUSEMOTION events. As I process every one, my
> application slows down to a crawl.
Usually you don't need to process mouse events until either some other
event comes in, or the mouse has moved "enough" to be important.
So, instead of doing the whole process for motion events for every event
you just keep track of the total change in position. Then, if the total
change is large enough, you do the processing for a motion event. Or, if
you get another event, like a button press or a key press, you do the
mouse motion processing first, and then process the other event.
Doing something like that not only keeps you from having to process
millions of motion events, it can make your game smoother since it will
ignore all the little mouse jiggles you get.
> For that case the docs suggest SDL_EventState()
> to turn off SDL_MOUSEMOTION events. If needed,
> do SDL_PumpEvents() followed SDL_GetMouseState() to get
> the x/y pos of the mouse. However that doesn't work as
> I expected. Now I get only the mouse position if the XFree
> Cursor leaves or enters the SDL window, or if I press
> So I thought, I would enable SDL_MOUSEMOTION shortly before
> polling the event queue and after polling disabling it again.
> Doesn't seem to work (only updates when leaving window or
> pressing buttons).
> Surely I do something wrong, but right now I'm at a loss.
> Some tipps would be very appreciated. Obviously I'm either
> too dumb or it is definately too late over here (I tend
> toward the latter ;)
> Thanks a lot
> SDL mailing list
> SDL at libsdl.org
+ Bob Pendleton, consultant for hire +
+ Resume: http://www.jump.net/~bobp +
+ Email: bob at pendleton.com +
More information about the SDL