SEOLteam / ode-tutorial2

Customizable mass-spring simulation
https://seolteam.github.io/ode-tutorial2/
0 stars 0 forks source link

Stopwatch is not properly working. It is slower than real time. #24

Closed haichuanyu closed 9 years ago

haichuanyu commented 9 years ago

Spotted by Tee

As compared to another online stopwatch, we're getting 48 seconds to the minute. So, in a 10 second real world time passage, we only count 8 seconds. Not sure why.

http://online-stopwatch.chronme.com/

haichuanyu commented 9 years ago

This article explains it fairly well.

Instead of setting a delay and incrementing our counter by that delay, we should take the difference between a starting timestamp and a current timestamp to know what time it is.

The first time will suffer from a cumulating delay, the second time will suffer from a constant delay. So the second seems preferable to the first.

http://www.sitepoint.com/creating-accurate-timers-in-javascript/

haichuanyu commented 9 years ago

Fixed. Now it uses the system clock. Checked against the other online stopwatch above and the timer on my phone. Both are spot on.