Talk:VSYNC vs WAIT/@comment-5334617-20141209183434

Flickering depends on the relative locations of the clear screen, draw screen, and sync operations, which you have in different orders for different code fragments above (and indeed the draw screen operation isn't in either of the last two code fragments). Since you don't justify rearranging the order or take into account how that may affect flickering, the conclusions aren't convincing.

My understanding is that  will wait from 'now', when the system sees the   command, until the nth following 'tick' of the frame clock. If 'now' is just before a tick,  will not wait long at all. If 'now' is just after a tick,  will wait almost a full 1/60th of a second. , however, will wait until the nth tick following the last  or   - and if the nth tick has already passed, it waits no time at all.

Another way of thinking about it is that the  clock is reset every time a   or   command ends. The  clock is reset at the beginning of that   statement. If less than one frame passes between one and the next, they behave identically. If between one and two frames pass, then a  clock would be one frame behind the   clock; if between two and three frames pass, then a   clock would be two frames behind the   clock, etc..

Also, a  is guaranteed to end exactly on a tick. If the 'deadline' set in a  is already passed, it will take no time at all, and so the time might be at any phase relative to the frame clock. So,  is more likely to eliminate flicker, when used correctly. Of course, the downside is that  will always take at least as long as , and sometimes longer. also makes it much easier to maintain a more consistent relationship between 'game time' (the number of iterations through your game's main loop) and 'wall time' (the number of ticks of the second hand on the clock on the wall) without having to use  and. This is important if, for most of a game, you do less than one frame's worth of calculations per iteration, but during the climax, you do more than one frame of calculation, but you don't want the action to slow down. If you use, the refresh rate of the game will drop from 60 per second to 30 per second, but if you use  , and calculations never take more than 2 frames, you will have a consistent 30 refreshes per second throughout, and no flickering either (if drawing takes less than 1/60th of a second and is put right after the  ).