Kamujin's picture

[GameWindow] Make main loop interchangeable

Project:The Open Toolkit library
Category:bug report

The following attachments support the proposed interleaved scheduler as described in the forums.

The scheduler uses an interleaved pattern of sleep times to approximate sleep durations of greater precision then is support by the operating system.

The scheduler uses an adaptive logic to continuously tune the sleep interval pattern to match the target render frame rate and update frame rate.

Fiddler, do you want me to improve upon this to include things like Update/Render interval smoothing? bounding?
I've been trying to keep it simple so as not to over reach.

Although I do use this already internally, there are enhancements that I add to make it more consistent. As it stands, this scheduler assumes the consumer will do some pre-processing with the elapsed times to clean them up.

GameWindow.patch3.81 KB
InterleavedScheduler.cs8.1 KB


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture


Status:open» in progress (review)

Many thanks for your work, Kamujin, I am going to do some extensive testing tonight (XP, Vista, Linux, x86/x64). I am trying to see whether the new scheduler can completely replace the current one, or if there should be an option to disable sleeping completely (I am using OpenTK on a VR application where the slightest jitter can cause nausea).

Kamujin's picture


I think you should consider offering both solutions. If you are optimizing for minimum jitter then I don't think this scheduler is best. I think this scheduler is more suited to a low jitter / low cpu load use case. Also, since I did not include any smoothing of the elapsed times, you will need to provide your own.

FWIW, I see some jitter with both the Run()+VSync=On and the RunSimple()+VSync=Off schedulers. On my system Run()+VSync=On has about half the jitter.

Kamujin's picture


Have you had a chance to look at the submission yet? I am curious to know what you think?

the Fiddler's picture


I'll be doing that as soon as the text renderer is ready (it's been brewing since August) :)

Kamujin's picture


Have you been able to look at this submission yet?

FWIW, I am willing to do more work on this scheduler if you are interested. This would include smoothing the update time values.

I am trying not to be too pushy, I am not disinterested.

the Fiddler's picture


I was about to say I have commited the code to the gamewindow branch, but then I realized I have yet to push the branch to the server.

I didn't see any issues either on windows or linux - the question now is how to proceed with the GameWindow (I'll post my concerns to the roadmap discussion.)

the Fiddler's picture


This issue depends on the results of issue #668: Investigate possible WinForms-based GameWindow implementation..

the Fiddler's picture


Status:in progress (review)» postponed
Kamujin's picture


As the link is not longer valid, can you give me a status update on this submission?

the Fiddler's picture


Status:postponed» in progress

(Fixed link: #668: Investigate possible WinForms-based GameWindow implementation.).

I am currently testing a simpler scheduler which doesn't perform any frame-limiting, unless you enable vsync. Regardless of the default implementation, it will be possible to replace the scheduler using simple inheritance.

Both #668 and this issue will be resolved in OpenTK 0.9.8.