This could work, however WebWorker
s follow the observer pattern, the document
(html page that owns the worker) can only listen and post messages to/from a worker. From that, there's a few options, I guess. In all cases I think you will need to find someway to determine the optimal FPS of the user agent in order to optimize the information. Then you could either:
- Tell the workers to post messages at those time intervals
- Downside(s?): you have to assume that the
document
will be ready for the response when it happens.
- Tell the
document
to send a message to the worker requesting physics at time interval x
, then the worker would post a response (hopefully) shortly after that.
- Downside(s?): since all posts and responses are asyncronous, there may be delays between the request and response from the worker. In this case you would also have to null out the
onmessage
event to prevent your document
from listening when it doesn't expect to be.
I'm sure there's other things I missed or ways to handle communications as well. I'll be looking forward to other answers on the subject myself!