l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
August 5: Social gathering
Next Installfest:
TBD
Latest News:
Jul. 4: July, August and September: Security, Photography and Programming for Kids
Page last updated:
2004 May 19 07:48

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] fltk + SDL and questions about handling events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



--- "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/
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.