I have been trying to rewrite my DirectX PC demo code so it can run in a Window and FullScreen, just like Steem.
My code uses WaitForVerticalBlank() which hogs the CPU time. I didn't really care 10 years ago, but with laptops running so fast these days I think my little demos should only use about 3% CPU time.
The problem is waiting for a vertical blank in DirectX without using all the CPU time waiting for the vertical blank.
I thought I would check the source code and see how it does it, but I am a bit confused.
In display.cpp we have SteemDisplay::VSync()
It cleverly uses GetScanLine() to wait until it is at line 480 or 400 then calls WaitForVerticalBlank() to hog the CPU a bit. Also unexpecetdly the Sleep(0) code is commented out, so how does Windows yield to other threads? On a 2GHz CPU GetScanLine() might be called 140 times per scanline!
On a Centrino 2GHz dual core Steem uses 30-40% on one core. This is OK I guess, but in this day of many different screen resolutions and refresh rates shouldn't this be dynamic and use the screen resolution to determine the scan line?
Of course the problem is that Windows is so bad at timing and DirectX doesn't have a low overhead WaitForVerticalBlank() method. A sleep(0) might have a 20ms jitter so it could easily miss the vertical blank.
Leonard's code in his demos seems to do it correctly with low CPU use but I don't have the source code to these demos. Any advice would be very helpful.
Still got, still working: Atari 4Mb STe, 520STFM, 2.5Mb STF.
Hardware: Cumana CSA 354, Ultimate Ripper, Blitz Turbo, Synchro Express II (US and UK Versions).