diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-06-12 17:19:21 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-06-12 17:19:21 -0700 |
commit | e141881ad1b43a1cf5ab9a570b52f11ce5befc62 (patch) | |
tree | 195882f36be1c59082c7a49757d7ca0869f2a7f7 /src/proxyWorker.js | |
parent | 68e6cd231b58ae8fe2a921ba43675317ecfd84b0 (diff) |
throttle proxied frames
Diffstat (limited to 'src/proxyWorker.js')
-rw-r--r-- | src/proxyWorker.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/proxyWorker.js b/src/proxyWorker.js index dd572dad..70b55244 100644 --- a/src/proxyWorker.js +++ b/src/proxyWorker.js @@ -125,6 +125,19 @@ Browser.resizeListeners.push(function(width, height) { postMessage({ target: 'canvas', op: 'resize', width: width, height: height }); }); +// Frame throttling + +var frameId = 0; +var clientFrameId = 0; + +var postMainLoop = Module['postMainLoop']; +Module['postMainLoop'] = function() { + if (postMainLoop) postMainLoop(); + // frame complete, send a frame id + postMessage({ target: 'tick', id: frameId++ }); + commandBuffer = []; +}; + // buffer messages until the program starts to run var messageBuffer = null; @@ -171,6 +184,10 @@ onmessage = function onmessage(message) { webGLWorker.onmessage(message.data); break; } + case 'tock': { + clientFrameId = message.data.id; + break; + } default: throw 'wha? ' + message.data.target; } }; |