Closed jcyuan closed 2 years ago
that binding code is generated via Emscripten; if you want it to work differently: you'll need to file an issue with them (or contribute a pull request).
I suspect that if they changed b.hasOwnProperty('DrawSegment')
to 'DrawSegment' in b
it'd fix it (i.e. it would look for method implementations on the prototype chain).
typically I use this technique to satisfy the validation:
const debugDraw = Object.assign(new JSDraw(), {
/**
* @param {number} vert1_p pointer to {@link Box2D.b2Vec2}
* @param {number} vert2_p pointer to {@link Box2D.b2Vec2}
* @param {number} color_p pointer to {@link Box2D.b2Color}
* @returns {void}
*/
DrawSegment(vert1_p, vert2_p, color_p) {
},
});
there's probably a better way.
btw, the current way to import methods, i feel inconvenient, because i have to pass the b2d instance everywhere....
i prefer justimport { what i need } from 'box2d';
import
s are evaluated synchronously, but any WebAssembly module requires asynchronous setup (you have to download the bytecode and then parse it).
the way I typically solve this is to make an asynchronous module box2d.ts
which exports an initialized Box2D Emscripten module:
https://github.com/Birch-san/liquidfun-play-2/blob/master/src/box2d.ts#L6
and then use ES7 dynamic import()
+ top-level await
to wait for the asynchronous module:
https://github.com/Birch-san/liquidfun-play-2/blob/master/src/demo/gravity.ts#L6
(you'll need to make sure your build system is configured with modern settings if you want to use these language features).
btw, the current way to import methods, i feel inconvenient, because i have to pass the b2d instance everywhere.... i prefer just
import { what i need } from 'box2d';
import
s are evaluated synchronously, but any WebAssembly module requires asynchronous setup (you have to download the bytecode and then parse it).the way I typically solve this is to make an asynchronous module
box2d.ts
which exports an initialized Box2D Emscripten module: https://github.com/Birch-san/liquidfun-play-2/blob/master/src/box2d.ts#L6and then use ES7 dynamic
import()
+ top-levelawait
to wait for the asynchronous module: https://github.com/Birch-san/liquidfun-play-2/blob/master/src/demo/gravity.ts#L6 (you'll need to make sure your build system is configured with modern settings if you want to use these language features).
ok, thank you.
it means i have to implement the
JSDrawer
like this?im doing this:
and then
the method is just right there:![image](https://user-images.githubusercontent.com/850854/148900935-b808452c-bf4e-471c-8fdf-bc27a5379898.png)
btw, the current way to import methods, i feel inconvenient, because i have to pass the
b2d
instance everywhere.... i prefer justimport { what i need } from 'box2d';
i'm doing test on this proj.
thank you.