Question: I want to create a table in mysql the table has 3 columns user\_id,activity - online or offline - and timestamp,
Now I want the table to show all user\_id's along with most recent status. Currently using

```
 SELECT DISTINCT user_id,activity FROM activity ORDER BY timestamp DESC

```

statement shows when the user was last online and offline which is not what I want.

Answer: 
You must decouple your physics simulation stepping timing from your render vsync timing. The easiest solution is to do this:

```
frameCallback(dt) {
  physicsDt += dt;
  if (physicsDt > 16) {
    stepPhysics();
    physicsDt -= 16;
  }
  renderWorld();
  requestAnimFrame(frameCallback);
}

```

The biggest issue here is that sometimes you'll be rendering with an outdated physics world, for example, if physicsDt was 15 no simulation update will occur but your objects would have moved almost an entire frame by that point in time. You can work around this by keeping the physics 1 frame ahead of the rendering and linearly interpolating object positions in the renderer. Something like:

```
var t = dt/16.0;
framePosition = (1-t) * previousFramePositions + (t) * nextFramePositions;

```

That way your objects move smoothly even if you're rendering is out of sync with your physics simulation. Let me know if you have any questions.

John
`requestAnimFrame` isn't meant to guarantee a constant frame rate – it's designed so that the browser only does the calculations for frames it actually draws.

If you want/have to calculate frames that aren't drawn, then it isn't the way to go.