diff options
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; } }; |