>
> > Hi all, i am a bit stuck with a program that is running far too fast
>
> Not often I see people complaining there code is too fast...
>
>
>
> > Ideally i would like to add buttons that can allow user to speed up
> > or slow down the animation from a default 'medium speed' execution
> >=20
> > The flow breaks down to this:
> >=20
> > //start button callback calls 'UpdateWorld()'to begin=20
> > algorithm then its
> >=20
> > #include<string>
> > #include<vector>
> > #include "fluidUI.h"
> > #include "Life.h"
> >=20
> > void UpdateWorld()
> > {
> >     while(running)
> >     {
> >         //code to examine each cell and determine its status
> >         //
> >         //
> >         Fl::check();
> >         if(running)  //button callback controls bool member
> >         DrawWorld(); //step through arrays drawing live cells or not
> >                      //includes call to=20
> > cellGrp->redraw()before returns
> >     }
> > }
>
>
> I think that in this case, calling ::check() from within your game loop
> is not helpful, it makes it too hard to vary things.
>
> I'd suggest that you pass control fully over to fltk then use the timers
> to update your game loop. Dodgy psuedo code follows...
> --------------------------------
> double rate =3D 0.1;
>
>
> Static void game_update(void*)
> {
>     if(running)
>     {
>         DrawWorld();
>         Fl::repeat_timeout(rate, game_update);
>     }
> } // end game_update
>
> int main(....)
> {
>     // set up stuff
>     // add buttons / spinner to control refresh rate
>    =20
>     Fl::add_timeout(rate, game_update);
>     return Fl::run();
> } // end main
> --------------------------------
>
> In this way, changing the value stored in rate will vary how often the
> DrawWorld() function is called, and hence control the speed of the game.
>
> It also means that the rest of the GUI will remain responsive (for the
> most part) since Fl::run() will handle the GUI events processing and so
> forth without you having to pump Fl::check() all the time.
>
> Thats great, thanks for advice, I did dabble a bit with something
similar to what you suggest, however i was not clear on where to call
the timeout repeat, also i had some problems with the function itself
but will try again now its clearer.

>

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to