Hello,
in my project, i'm using add_timeout/repeat_timeout to power my main loop in a game application that does some simple OpenGL rendering.
My objective is to have the loop running at 50 fps, meaning timeout values between frames of about 20 milisecs.
My problem is that while on a Linux host (Ubuntu 17.10 desktop, 64bit), this intervall is reasonably well respected, but i have significant delay on Windows 7 64bit.
On Windows, it seems as if the timer is called only at about half of the frequency specified.
FYI, my callback currently looks like this:
static void cb_update_tick(void* appWnd)
{
((MyAppWindow*) appWnd)->RunUpdate();
#ifdef WIN32
// Windows takes significantly more time here than specified.
Fl::repeat_timeout(0.01, cb_update_tick, appWnd);
#else
// The objective is to run this with 50 fps = one frame every 20 ms.
Fl::repeat_timeout(0.02, cb_update_tick, appWnd);
#endif
}
to obtain similar speeds on both systems.
Strangely, i am able to get about the desired result of 50 fps, when i set a timeout of 10ms (half of the needed value) on Windows like i do above.
Lowering the timeout further will not speed things up any more, so i seem to have hit a threshold.
FYI, at timeout values of about 100 milisecs and above, both Windows and Linux respect the given intervall.
I have read previous posts and comments on the Net that 20ms is probably touching the limit of accuracy of the used system clocks.
But note that i am not much concerned about accuray in the sense that the intervall between calls need not exactly be 20 ms between each frame. I'd be happy if the callback would be called every 20ms *on average* that is about 50 times per second.
Which it seems *is* possbile on Windows, but at the given lower (wrong) 10 ms timeout value.
Did anyone have had similar issues and got a solution?
Also, could there be a solution outside of FLTK?
I know i could use other high accuracy system clocks.
But how would i integrate them to a main loop where i render stuff in an FLTK OpenGL window? Is threading an issue here?
best regards,
Lars R.