From 0ab89c83a7dcccc353a0310477009c4457d9bba6 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 16 Mar 2013 17:16:44 -0700 Subject: [PATCH] use setInterval in worker --- examples/webgl_demo/worker.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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); +