> 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
> 
> The flow breaks down to this:
> 
> //start button callback calls 'UpdateWorld()'to begin 
> algorithm then its
> 
> #include<string>
> #include<vector>
> #include "fluidUI.h"
> #include "Life.h"
> 
> 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 
> 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 = 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
    
    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.









SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

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

Reply via email to