[SDL] Re: Question about ignoring mouse events

Román Gorojovsky rgorojovsky at gmail.com
Wed Nov 16 10:10:31 PST 2005


On 11/16/05, David Olofson <david at olofson.net> wrote:
> On Wednesday 16 November 2005 14.26, Román Gorojovsky wrote:
> > Yes, thank you, that *almost* worked.
> >
> > But if you do "while (SDL_PollEvent(&event))" the loop won't even
> > start, because usually at that point you don't have any event.
>
> Uhm, well, that's the idea; if there are no events, this loop should
> not run. Conversely, the loop should spin as long as there are
> events, in order to empty the queue before exiting.
>
> So, what I'm saying is, this event decoding loop should be an inner
> loop, inside the main/rendering loop. That way, it simply does
> nothing if there are no events.

ok, but is there an important difference between the following?

  while (1)
  {
      if (SDL_PollEvent(&event))
      {
            /* process events */
            case SDL_QUIT:
                   exit(0);
      }
  }

vs

  while (1)
  {
      while (SDL_PollEvent(&event))
      {
            /* process events */
      }
  }

Should I handle the SDL_QUIT case differently?


> Note that the latter (emptying the event queue before you move on) is
> very important! If you don't do it that way, you'll get this horrible
> "rubber band" delay effect as soon as your rendering loop cannot spin
> at least once per input event. (Which it most likely cannot, unless
> the user has a low frame rate mouse and/or you're doing OpenGL
> rendering without retrace sync.)
>
humm I'm not sure if I'm following you.  I don't have a rendering
loop.  I render, then I check events, and then if I have to render
again I do it.  The rendering loop only checks the SDL_QUIT event.

>
>
> (Well, there are cases where you actually want the event loop to be
> the outer loop, or logically equivalent, but then you generally want
> to use SDL_WaitEvent instead, and either way, this rarely applies to
> games, where there is usually stuff going on even when there are no
> input events.)
>
Yes, I think I would have used Wait in that case.

>
> //David Olofson - Programmer, Composer, Open Source Advocate
>
> .- Audiality -----------------------------------------------.
> |  Free/Open Source audio engine for games and multimedia.  |
> | MIDI, modular synthesis, real time effects, scripting,... |
> `-----------------------------------> http://audiality.org -'
>    --- http://olofson.net --- http://www.reologica.se ---
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>


--
Román


More information about the SDL mailing list