pygame-web / pkg-porting-wasm

Tracks porting efforts on some modules you'd like to have working in pygbag
https://pygame-web.github.io/wiki/pkg/
4 stars 0 forks source link

box2d-py to wasm #16

Open shblhy opened 1 year ago

shblhy commented 1 year ago

Hello, I want play gymnasium games in web page, so I use pygbag. The problem is gymnasium use box2d, so i need box2d wasm, but I dont know how to compile box2d. Can any one help? https://github.com/pybox2d/pybox2d

pmp-p commented 1 year ago

building box2d release 2.4.1 to wasm succeed with emcmake cmake -DCMAKE_C_COMPILER=emcc -DCMAKE_INSTALL_PREFIX=${PREFIX} ${SDKROOT}/src/box2d-2.4.1 -DBOX2D_BUILD_TESTBED=OFF -DBOX2D_BUILD_DOCS=OFF

i'll try pybox2d soon that apparently has its own copy of box2d

shblhy commented 1 year ago

I don't know how to compile a python project to wasm which has c-compiled files. If you have any document or idea, please tell me.

pmp-p commented 1 year ago

build of git unmodified pybox2d is available via import Box2D at top of main.py

NB: pygame_framework.PygameFramework.run must be converted upstream to async for running examples. I tested "Box2D/examples/pinball.py" which works but has a bug when framework finds pygame_gui ( balls are launched above table)

pmp-p commented 1 year ago

pygbag git now supports box2d example framework

https://pmp-p.github.io/pybox2d-wasm/

code https://github.com/pmp-p/pybox2d-wasm/

shblhy commented 1 year ago

I meet an error and I can not pass the test: This is the eror: image And this is my project: image

pmp-p commented 1 year ago

that's not a box2d error, but a pygame.gfxdraw one. Where is the source code of experiment ? Since stock gymnasium requires multiprocessing which is not available.

shblhy commented 1 year ago

here the code: https://github.com/shblhy/pygbagcompiles

pmp-p commented 1 year ago

Thanks, it's a wasm pygame port bug and issues is now there https://github.com/pygame-community/pygame-ce/issues/2082 meanwhile you can remove the problematic gfxdraw calls https://pmp-p.github.io/lunarlander-wasm?-i as i did here https://github.com/pmp-p/lunarlander-wasm/commit/d43cb251a967ce521c0dd10c56d953ea7b6dbe82