-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello all,
My application event loop looks like the following:
while(true)
{
repaint();
// Point A (see below)
while(SDL_PollEvent(&e))
{
ProcessEvent(&e);
} // end while events waiting.
} // end while true
This event loop runs beautifully, provides very fast response times, etc. The
only problem I have with it is that it busy waits [while(true)] and uses 100% of
the CPU. So, I figured, I’d make it wait until an event appeared with some code
that looks like this:
if (SDL_WaitEvent(&e) == 1)
{
SDL_PushEvent(&e);
}
which I would insert at “Point A” above. That mostly worked. CPU usage was now
low, but the WaitEvent/PushEvent combination was adding a very perceptible lag
to my application’s response time. (Not LARGE, but perceptible if you were
looking for it, I’d guestimate in the range of 70-100ms.)
I eventually used the following code instead:
while( SDL_PeepEvents(&peep,1,
SDL_PEEKEVENT,SDL_EVENTMASK(SDL_KEYDOWN)) == 0)
{
SDL_PumpEvents();
SDL_Delay(10);
}
This works as I expected (lowering CPU usage to around 4% when idle), and
provides the snappy response time I’m trying for.
My question: Is this a problem with SDL_WaitEvent or SDL_PushEvent? I imagine
that SDL_WaitEvent is implemented something like my PeepEvent code above
internally, perhaps with a larger Delay than 10?
Why doesn’t a combination of SDL_WaitEvent/PushEvent deliver the same
performance as my PeepEvent code? It’s simpler from a programmers prospective,
and easier to understand.
Thanks,
Jay
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org
iQCVAwUBRIidirWkkhmZq4xxAQKbWQQAj+Z/m1CwKNxm2ZnFpzIkvkmbqxkuET5M
z7jFypasRLMiuXBzbNaek6c8ciKPjMsFDsuAbfkUEA4FCdC9sWcQIOtPRRHM11K8
TRvtdOq2m89buixFH/p4urzNaMfzoGvpoW/kcfhSeXczzdta8pFS162igLQi8c7V
I7Fi5lrBZro=
=p060
-----END PGP SIGNATURE-----