kripken / box2d.js

Port of Box2D to JavaScript using Emscripten
1.32k stars 196 forks source link

missing runtime methods for allocating arrays #105

Open ahicks92 opened 5 years ago

ahicks92 commented 5 years ago

based off the helpers and the Emscripten docs, there needs to be a Box2D.allocate, Box2D.getValue, and Box2D.setValue, possibly others. Using the asm.js build these don't seem to exist anymore. This might be because I'm doing something very wrong, or because Emscripten now wants you to specify runtime methods to export (specifically that doc implies that they can get optimized out if you don't).

At the moment I can move forward without this functionality. I don't know enough about Emscripten to fix this trivially, but I'll come back to it if/when I get blocked, if it's still open.

ahicks92 commented 5 years ago

Also if these are missing, are there other things from the preamble that we should be exporting? Might be best to check them all at once.

kripken commented 5 years ago

Yeah, emscripten now requires explicit exporting of runtime methods. We should add any of those that are mentioned in the docs as working, I guess.

Do we mention allocate, though? That's an internal API I hope isn't used outside of core emscripten code.

And getValue/setValue are kind of slow - may be better to document using Box2D.HEAPF32 or such.

ahicks92 commented 5 years ago

They're used in the helpers, for building chain and polygon shapes. Here.

I guess it's more of an Emscripten issue, but if there's another way to allocate arrays it's not documented well. I guess it could export C's malloc.

kripken commented 5 years ago

I see, thanks. Yeah, malloc would be a much better option to use here (faster too).