Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your FPS may (and usually will) vary, so counting frames is not a great idea.</p> <p>Assume this example to see how this could bite you:<br> Your application runs vsynced to 60 FPS, and your frame time is 16.58ms. That means to have the object on screen for 2 seconds, you will have to draw your object for 120 frames. Easy, let's go!<br> Drawing the object adds 0.1 ms, giving a total frame time of 16.68ms. Oh sh*t. Now you have 30 FPS, and your object shows for 4 seconds...</p> <p>Use <strong>proper time</strong> to decide whether or not to draw your object. When you've reached the conclusion that your object's time is up, just set a flag so you won't draw it (or, remove it from the scenegraph, if you have one, or delete it, or whatever).</p> <p>This can be done in a variety of ways:</p> <ul> <li>Under Windows <ul> <li>Use <code>SetTimer</code>, which will post a message to your window's message queue. When you receive the WM_TIMER notification, set the object's <code>do_draw</code> flag (or whatever you want to call it) to false.</li> <li>If you already use <code>WaitFor(Single|Multiple)Object</code> somewhere once every frame, do a <code>CreateWaitableTimer</code>, and wait on this as well. You can use <code>MsgWaitForMultipleObjectsEx</code> to do the message pumping and waiting in one go, and check APCs at the same time.</li> <li>Nothing prevents you from reading time manually once per frame. <code>GetTickCount</code> once, add 2000, and do an <code>if(new_count &lt;= old_count + 2000) draw_object()</code>. While the accuracy of <code>GetTickCount</code> is abysmal (several dozens of milliseconds), this does not matter at all when waiting for 2 seconds.</li> </ul></li> <li>Under Linux <ul> <li>Use a <code>timerfd</code> and an <code>epoll</code> to check readiness, or set the <code>timerfd</code> it to nonblocking and see whether reading from it returns EAGAIN</li> <li>Use <code>clock_gettime</code> and do it manually (as with <code>GetTickCount</code>)</li> <li>Use <code>setitimer</code></li> </ul></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload