Eventqueue delay?

Given a program structured as follows-

while (1) {
SDL_Event event;
if (SDL_PollEvent( &event )) {
// print some message A
}

// print some message B
// do some time consuming stuff C
};

I find that in the time between pressing a
key and when message A appears, there are 7-12
occurrences of message B. In other words,
keypresses take a long time to appear in the
SDL event queue… This would be okay if the
loop was tight, but because there is timeconsuming
stuff C which takes about half a second, this
introduces an unacceptable delay between keypress
and response.

Has anyone seen this kind of behavior, and if
so could you please suggest how to circumvent the
problem…

Thanks,

Bilal_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Since your not telling us what Msg A or B is it is hard to tell what’s going
on. Also, your not telling us your OS. This issue is most likely related to
the OS your using and how it prioritizes events when queing them. Keyboard
polling has never been a fast activity and it will surely fall behind
software generated events (resize, mouse move, etc).

If you need to react instantly to keyboard events then do the time
consuming processing in another thread so that the time between
SDL_PollEvent is very small.

You can also re-queue low-priority events into another interal queue so that
you you can handle high-priority events immediatly and handle the other
events when idle.

~Rob> ----- Original Message -----

From: Bilal Khan [mailto:grouptheory@hotmail.com]
Sent: Friday, August 02, 2002 10:40 AM
To: sdl at libsdl.org
Cc: grouptheory at hotmail.com
Subject: [SDL] eventqueue delay?

Given a program structured as follows-

while (1) {
SDL_Event event;
if (SDL_PollEvent( &event )) {
// print some message A
}

// print some message B
// do some time consuming stuff C
};

I find that in the time between pressing a
key and when message A appears, there are 7-12
occurrences of message B. In other words,
keypresses take a long time to appear in the
SDL event queue… This would be okay if the
loop was tight, but because there is timeconsuming
stuff C which takes about half a second, this
introduces an unacceptable delay between keypress
and response.

Has anyone seen this kind of behavior, and if
so could you please suggest how to circumvent the
problem…

Thanks,

Bilal


Chat with friends online, try MSN Messenger: http://messenger.msn.com


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

You should always process all events in the event queue until the event
queue is empty. Just replace the if() with a while() and it should work
fine :wink:

cu,
NicolaiOn Friday 02 August 2002 19:39, Bilal Khan wrote:

Given a program structured as follows-

while (1) {
SDL_Event event;
if (SDL_PollEvent( &event )) {
// print some message A
}

// print some message B
// do some time consuming stuff C
};