2014-01-03 13:32:13 -05:00
|
|
|
Dropper = class Dropper
|
2014-10-08 15:38:23 -04:00
|
|
|
lostFrames: 0.0
|
|
|
|
dropCounter: 0
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
constructor: ->
|
|
|
|
@listener = (e) => @tick(e)
|
|
|
|
|
|
|
|
tick: ->
|
|
|
|
unless @tickedOnce
|
2014-10-08 15:38:23 -04:00
|
|
|
@tickedOnce = true # Can't get measured FPS on the 0th frame.
|
2014-01-03 13:32:13 -05:00
|
|
|
return
|
|
|
|
|
2014-10-08 15:38:23 -04:00
|
|
|
--@dropCounter if @dropCounter > 0
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-10-08 15:38:23 -04:00
|
|
|
# Track number of frames we've lost since the last tick.
|
2014-01-03 13:32:13 -05:00
|
|
|
fps = createjs.Ticker.getFPS()
|
|
|
|
actual = createjs.Ticker.getMeasuredFPS(1)
|
2014-10-08 15:38:23 -04:00
|
|
|
@lostFrames += (fps - actual) / fps
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-10-08 15:38:23 -04:00
|
|
|
# If lostFrames > 1, drop that number for the next tick.
|
|
|
|
@dropCounter += parseInt @lostFrames
|
|
|
|
@lostFrames = @lostFrames % 1
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
drop: ->
|
2014-10-08 15:38:23 -04:00
|
|
|
return @dropCounter > 0
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
module.exports = new Dropper()
|