-
Notifications
You must be signed in to change notification settings - Fork 5
run the physics engine on a web worker thread to free main thread to focus on rendering #9
Comments
Physics engines have a notion of a Renderer, in our case we are only concerned with DOM Renderer at the moment. We first approached this design for web worker thinking that we need to tun Renderer on a main thread and Physics engine on the web worker. But this notion was too simplistic. Note that Sliding window component below. It supposedly belongs to the Renderer, as it controls which objects are added or removed from DOM, but it can do all its calculations on web worker. Same with the Layout Manager, which probably corresponds best to a Scene manager in typical Physics engines. So we ended up with the following architecture: Web worker thread runs code for:
There is a message passing mechanism between worker and the main thread. |
I'm not sure how @wellcaffeinated planned to use the web worker, the way we use it may not be quite generic enough for inclusion in the PhysicsJS library. Currently we have the whole physics engine in the worker. The main thread wouldn't know mass from acceleration if an apple fell on its head. There are/were a few considerations:
|
Many of today's mobiles have more than one processor, and this allows to efficiently do computations without disrupting the rendering. This should reduce the amount of yellow spikes showing in the devtools timeline.
The text was updated successfully, but these errors were encountered: