[vox-tech] fltk + SDL and questions about handling events

Jan W vox-tech@lists.lugod.org
Tue, 18 May 2004 23:49:27 -0700 (PDT)


--- "Mark K. Kim" <lugod@cbreak.org> wrote:
> So basically you're doing the following, right?:
> 
>    while(1) {
>      // poll FLTK
>      // poll SDL events
> 
>      // do something
>    }
> 
> But the problem is this is a tight-loop and it's gonna eat up all of CPU
> time.  So you'll need some sleeping code to yield some timeslices to other
> processes, so your code becomes like this:
> 
>    while(1) {
>      // poll FLTK
>      // poll SDL events
> 
>      // do something
> 
>      usleep(100000);
>    }
> 
> But this is problematic for SDL because SDL window freezes while usleep()
> is running.  This is because SDL's event handler can't run while usleep()
> is active.  So you'll need to use SDL's SDL_Delay() call instead, like
> this:
> 
>    while(1) {
>      // poll FLTK
>      // poll SDL events
> 
>      // do something
> 
>      SDL_Delay(100);
>    }

Thanks, Mark.  I was hogging up everything there for a bit.  I didn't realize  
my CPU was MAXED.  I was happy enough that it worked such that I didn't see the
obvious.  The one that ended up working was:

while(fl::check){
  if (SDL_PollEvent(&event))
      my_event_handler(0);
  else
      SDL_Delay(50);
}

> 
> This is fine for SDL, but (without knowing FLTK too much) perhaps FLTK has
> similar problems of freezing when non-FLTK sleep call is called? Looking
> at the FLTK demo on the SDL website it looks like it's okay to do this
> so... I guess it's good.
> 
> BTW, is this for Tuxpaint-config?  What's the SDL window for?

No, just for my own know-how, because I want to make an image viewer based on
sdl and fltk.  I wanted to get it figured out, thou, originally, so you could
test fullscreen mode with tuxpaint-config (when you clicked on or off a 'test'
button).  But it was for down the road, if it was wanted to be added...

> 
> -Mark
> 
> 
--thanks again...

jan

=====
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
EDUCATION, n. That which discloses to the wise and disguises from the
foolish their lack of understanding.
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><


	
		
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/