Skip to content

Commit

Permalink
use setInterval in worker
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Mar 17, 2013
1 parent 97fa2b1 commit 0ab89c8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions examples/webgl_demo/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

0 comments on commit 0ab89c8

Please sign in to comment.