Hi,

>> My question is, in my typical programs (physics simulations),
>> interactivity is extremely limited, essentially I want to treat the
>> window as a canvas on which I am drawing, possibly displaying the
>> values of a few relevant parameters in Fl_Output's, and which updates
>> itself on screen every 50 ms or so. I am calling redraw() by hand for
>> that. Somehow it feels like using FLTK backwards ... what would be
>> the least awkward to do it ?

IM> You may have to expand your description, just in case I am
IM> misunderstanding what you are trying to do.

IM> However, I think what you are asking is how to trigger a redraw of
IM> your window every 50ms or so.  For that, I would use
IM> Fl::add_timeout() to trigger a callback which would call redraw on
IM> your window.

OK, I did miss the existence of add_timeout somehow, and coded it up
myself instead (not a huge deal, if only because I would like my code to
be compilable without fltk). But as far as I understand, add_timeout
will do nothing if check() or wait() is never called ... To make things
more explicit : my main goal is to make the end-user code look as dumb
as possible (because I am the end-user ;->), more or less like this :

int main () {
    Image I (200,200,"title");
    I.show();
    while (1) { I.put (rand()%200, rand()%200, randomcolor()); }
}

So the job of auto-update would lie within Image::put. It sounds like a
very bad idea to call check() every time in such a tight loop, and my
typical use case would in fact be very similar, 100% CPU bound. The
solution I found was to keep a counter, decrease it on each call of
put(), call redraw() whenever it hits 0, and then reset it to some
positive value computed so that the refresh occurs at the appropriate
frequency. The assumption being that put() will be called at regular
intervals. Like this :

https://github.com/vbeffara/Simulations/blob/master/libvb/vb/Clock.h

and then Image registers the update and keeps calling step().


It does work well, but I have the feeling that it is a bit cobbled up in
a non-optimal way. What would be a better design ? Maybe spawning a
thread for the display (though I seem to remember reading that display
was only allowed to be done in the main thread) ?

The one thing I want to avoid is "while (check()) { compute(); }"
because I would like the emphasis to be on the (non-interactive)
computation itself, the display being very secondary - plus it would
require storing some additional state, defining compute() in a
reasonable way, which would be nice enough to return early, ... I dont't
mind for the definition of Image to be complicated, but main() should
really be as simple as shown above.

What do you think ? Am I having all the wrong ideas ?

Thanks,

        /vincent

-- 
|                 |   UMPA - ENS Lyon   | Mél: [email protected] |
| Vincent Beffara |  46 allée d'Italie  | Tél: (+33) 4 72 72 85 25  |
|                 | 69364 Lyon Cedex 07 | Fax: (+33) 4 72 72 84 80  |

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

Reply via email to