Birch-san / box2d-wasm

Box2D physics engine compiled to WebAssembly. Supports TypeScript and ES modules.
263 stars 21 forks source link

SIMD #31

Closed Birch-san closed 3 years ago

Birch-san commented 3 years ago

Add support for WASM SIMD.

This could make some parts of Box2D 4x faster. But probably overall performance change will not be as dramatic as that.

Serving the .wasm asset becomes a bit more complicated, because there are now two (in different directories) that will need to be served.

If you were previously serving:

node_modules/box2d-wasm/build/es

You should now instead serve:

node_modules/box2d-wasm/build/flavour/standard/es
node_modules/box2d-wasm/build/flavour/simd/es

To make available the assets Box2D.wasm and Box2D.simd.wasm. I believe the Emscripten boilerplate expects these to be served from the root of your webserver.

But as usual, you can redirect it to lookup the files from a different location, by overriding locateFile:

Box2DFactory({
  /**
   * This is the default implementation of locateFile.
   * Modify this logic if your Box2D.wasm lives in a different directory.
   */
  locateFile: (url, scriptDirectory) => `${scriptDirectory}${url}`
})