diff --git a/examples/webgl_demo/worker.js b/examples/webgl_demo/worker.js index 0673dc59f..0b9f5897c 100644 --- a/examples/webgl_demo/worker.js +++ b/examples/webgl_demo/worker.js @@ -107,7 +107,6 @@ function timeToRestart() { // restart if at least one is inactive - the scene is } var meanDt = 0; -var counter = 0; function simulate(dt) { dt = dt || 1; @@ -131,18 +130,18 @@ function simulate(dt) { data.objects[i] = object; } - if (counter % 2 == 0) postMessage(data); + postMessage(data); if (timeToRestart()) resetPositions(); - - counter++; } + var last = Date.now(); -while (1) { +function mainLoop() { var now = Date.now(); simulate(now - last); last = now; - while (Date.now() - now < 1000/60) {} // throttle to 60fps TODO FIXME XXX } +setInterval(mainLoop, 1000/60); +