Fl::add_timeout(((x % TOTAL) == 0) ? 2.0 : RATE, ShowNextImage_CB); so this won't work?
void timer_cb(...) {
// do something that takes a variant time...
sleep(100); // sleep 100 ms (note: pseudo code!)
Fl::repeat_timeout(1.0, ...); // callback should be every 1.0 seconds#
}
On 3/29/25 14:15 Heart Bleed wrote:
Fl::add_timeout(((x % TOTAL) == 0) ? 2.0 : RATE, ShowNextImage_CB); so this won't work?It does work, but maybe with less precision.
void timer_cb(...) { // do something that takes a variant time... sleep(100); // sleep 100 ms (note: pseudo code!) Fl::repeat_timeout(1.0, ...); // callback should be every 1.0 seconds# }
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
Fl_Window *win;
Fl_Box *box;
Fl_Timestamp start;
void timer_cb(void*) {
// we want 25 frames per second, but here we ask for the time that actually elapsed
char text[80];
snprintf(text, 79, "%f seconds since start", Fl::seconds_since(start));
box->copy_label(text);
box->redraw();
// Now we may do some time consuming things here that take more than 1/25th of a second
Fl::repeat_timeout(1.0/20.0, timer_cb); // but ideally we want 25 redraws per second
}
int main(int argc, char** argv) {
win = new Fl_Window(400, 100);
box = new Fl_Box(10, 10, 380, 80);
box->labelfont(FL_COURIER);
win->show(argc, argv);
start = Fl::now();
Fl::add_timeout(1.0, timer_cb);
Fl::run();
}
Am I right in thinking thatFl::repeat_timeout calculates the time from the start of the functionwhileFl::add_timeout calculates the time from the call of Fl::add_timeout ?
Also, if "do some time consuming things" takes longer than the timeout,does Fl::repeat_timeout fire immediately ?