Question about handling events

Hi,
I am new with SDL.
I have written an intro to a game, but I cant figure out how to check for
SDL_QUIT effectively while the animation is running. And the other issue is
whenever I switch to another window the program stops responding and
executing. I can give you the code but I am still a beginner and my code is
not very readable.
I searched for a solution for a while now but with no luck.
Thank you in advance.
Ivan Radojkovic

Hi Ivan,

It’s likely that even though your code is not very readable, it does
something that most of us have done many times before. So don’t be worried
about sharing if you think that will help solve your problem. We may be
able to figure it out easier than you expect.

Are you using SDL_PollEvent()? With that controlling an event loop, you can
handle events and display stuff as well.
E.g.
SDL_Event event;
Uint8 done = 0;
while(!done)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
done = 1;
}
SDL_FillRect(screen, NULL, 0x000000);
// Draw stuff here
SDL_Flip(screen);
SDL_Delay(1);
}

Jonny DOn Thu, Jul 28, 2011 at 6:34 PM, Ivan Radojkovic <itsa.registers at gmail.com>wrote:

Hi,
I am new with SDL.
I have written an intro to a game, but I cant figure out how to check for
SDL_QUIT effectively while the animation is running. And the other issue is
whenever I switch to another window the program stops responding and
executing. I can give you the code but I am still a beginner and my code is
not very readable.
I searched for a solution for a while now but with no luck.
Thank you in advance.
Ivan Radojkovic


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

It sounds like you are running animation in a tight loop. There are a
few downsides to such an approach. One is, as you found, it can be
difficult to control the loop externally. Another is that it prevents
simultaneous animation.

In most interactive programs, you’ll want discrete simulation steps
that return control to a “main” loop. So you need to structure your
code so that individual sprites know that they are animating, and
retain enough data between steps to know what to display next.

I’m not sure about your switching window problem, but if you aren’t
regularly calling SDL_PumpEvents() (which you usually call implicitly
by calling SDL_PollEvent or SDLWaitEvent) then the window manager
might assume you application is non responsive. Remember when you
switch windows the window manager sends messages to your program, and
unless you let SDL act on these messages it might not work.

As Jonathan mentions, don’t worry about your code being not readable.
Many of us have experience helping beginner programmers!

Regards,
– Brian.On 28 July 2011 23:34, Ivan Radojkovic <itsa.registers at gmail.com> wrote:

Hi,
I am new with SDL.
I have written an intro to a game, but I cant figure out how to check for
SDL_QUIT?effectively while the animation is running. And the other issue is
whenever I switch to another window the program stops responding and
executing.

Jonathan and Brian, thank you for your replies.
Now its kinda clear what i should do. I will start working on it.
Thank you. Here is the code if you want to read it.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: XOgraphic.cpp
Type: text/x-c++src
Size: 4412 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110729/ec64ad70/attachment.cpp

I going to assume your using 1.2
Typically your app should just poll the events near the beginning of
your game loop. Sounds like you want to check at multiple places.
I think your want to use SDL_PeepEvents with an action of SDL_GETEVENT
and with a mask for SDL_QUITMASK
Check the doc’s for the details on using it (i.e you need to call
SDL_PumpEvents)
http://www.libsdl.org/cgi/docwiki.cgi/SDL_PeepEventsOn 7/28/2011 6:34 PM, Ivan Radojkovic wrote:

Hi,
I am new with SDL.
I have written an intro to a game, but I cant figure out how to check
for SDL_QUIT effectively while the animation is running. And the other
issue is whenever I switch to another window the program stops
responding and executing. I can give you the code but I am still a
beginner and my code is not very readable.
I searched for a solution for a while now but with no luck.
Thank you in advance.
Ivan Radojkovic


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org