Regarding event programming

Hi,

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

Init
loop
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.

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
mousebuttons.

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 :wink:

Thanks a lot
Bettina

Hi,

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

Init
loop
calculate data
Refresh display (including own cursor)
Get SDL_Event
Process Event (change data for next calculation)
loop end

How about this:

Init
loop
calculate data
Refresh display (including own cursor)
while SDL_Event
Process Event (change data for next calculation)
while end
loop end

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Bettina Rathmann wrote:

Hi,

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

Init
loop
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.

	Bob Pendleton> 

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
mousebuttons.

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 :wink:

Thanks a lot
Bettina


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


±-----------------------------------+

Hi,

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

Init
loop
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.

Make sure you’re processing all the available events in the ‘Process
Event’ step. There sure are a lot of mouse motion events, but to notice
a lag by processing them you’d have to be doing something REALLY heavy
for each. On the other hand, if you’re just waiting for any event to
enter to trigger a new frame refresh, and processing only one event per
frame… that would explain the swamping.On Sun, 2002-09-29 at 18:46, Bettina Rathmann wrote:


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Jimmy <@Jimmy>
Jimmy’s World.org
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021001/3b7cce8b/attachment.pgp