Skip to content

Commit

Permalink
Merge pull request #54 from ded/fixts-feature-detect
Browse files Browse the repository at this point in the history
feature detect matching scale of timestamp & now()
  • Loading branch information
ded committed Oct 13, 2013
2 parents a03b29f + a754f66 commit 5f3d502
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/morpheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
, perf = win.performance
, perfNow = perf && (perf.now || perf.webkitNow || perf.msNow || perf.mozNow)
, now = perfNow ? function () { return perfNow.call(perf) } : function () { return +new Date() }
, fixTs = false // feature detected below
, html = doc.documentElement
, thousand = 1000
, rgbOhex = /^rgb\(|#/
Expand Down Expand Up @@ -84,6 +85,12 @@
}
}()

frame(function(timestamp) {
// feature-detect if rAF and now() are of the same scale (epoch or high-res),
// if not, we have to do a timestamp fix on each frame
fixTs = timestamp > 1e12 != now() > 1e12
})

var children = []

function has(array, elem, i) {
Expand All @@ -95,9 +102,7 @@

function render(timestamp) {
var i, count = children.length
// if we're using a high res timer, make sure timestamp is not the old epoch-based value.
// http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision
if (perfNow && timestamp > 1e12) timestamp = now()
if (fixTs) timestamp = now()
for (i = count; i--;) {
children[i](timestamp)
}
Expand Down

0 comments on commit 5f3d502

Please sign in to comment.