craftyjs/Crafty — pull request #490 by starwed (2013-06-14 19:15:16+00:00)
Title: Timing events

This is a pretty simple patch that measures how long the various stages of the game loop take. It uses this info to

* On "EnterFrame", pass along the time since the last frame occurred. I was able to use this to have physics run in a time based rather than frame based manner.
* Trigger some events: "MeasureFrameTime", "MeasureRenderTime", and "MeasureWaitTime" that let you measure and benchmark how long each stage takes. Waiting is the time between the end of one step and the beginning of the next.

I didn't change the internal logic of the game loop at all; it will still render multiple frames to "catch up" to the desired frame rate. For the deltaT info to be more useful, it might be nice to have that behavior be customizable.

I was able to tweak one of my games pretty easily to use the dt in its physics; it did seem to run a lot more smoothly. Long term, if we land something like this we might want to let the various animation components take advantage of it.

I haven't any docs or tests yet, just wanted to see what people thought.