-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable run video games using WebAssembly #385
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the web-resources
directory to assets
to allow for the inclusion of a wider range of relevant resource files.
WEB_RESOURCES := web-resources | ||
WEB_JS_RESOURCES := $(WEB_RESOURCES)/js | ||
doom_action := (cd $(OUT); ../$(BIN) doom.elf) | ||
ifeq ("$(CC_IS_EMCC)", "1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file mk/external.mk
was meant to be related to retrieve something from external sources. Don't specify emscripten rules here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file
mk/external.mk
was meant to be related to retrieve something from external sources. Don't specify emscripten rules here.
I want to distinguish between the steps that need to be taken when utilizing emcc. Furthermore, when emcc is not being utilized, we do not want the emcc CFLAGS to be used. Also, notice that only just emcc needs the TIMIDITY_DATA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimize the necessary changes when possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to embed all build executable and configuration files such as doomrc into wasm. Although the size getting larger (fetching time might be longer but only once because it will be cached by the browser for further fetch), but we can select and run them in a single web page from a menu bar.
Consequently, we do not need to check the makefile build target and embed corresponding files respectively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to embed all build executable and configuration files such as doomrc into wasm.
It sounds like a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to embed all build executable and configuration files such as doomrc into wasm. Although the size getting larger (fetching time might be longer but only once because it will be cached by the browser for further fetch), but we can select and run them in a single web page from a menu bar.
Consequently, we do not need to check the makefile build target and embed corresponding files respectively.
The final wasm is 61.40 MB, this is larger than GitHub's recommended maximum file size of 50.00 MB. I am going to test it out if this is fine to host on GitHub Pages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to embed all build executable and configuration files such as doomrc into wasm. Although the size getting larger (fetching time might be longer but only once because it will be cached by the browser for further fetch), but we can select and run them in a single web page from a menu bar.
Consequently, we do not need to check the makefile build target and embed corresponding files respectively.The final wasm is 61.40 MB, this is larger than GitHub's recommended maximum file size of 50.00 MB. I am going to test it out if this is fine to host on GitHub Pages.
Github Pages are fine even exceeds GitHub's recommended maximum file size of 50.00 MB. See here.
b97c73c
to
bef66b8
Compare
Done. |
See the result in here. |
To play sound effects and musics, we would use software synthesizer, here I choose Timidity. When doom and quake target are specified, the Timidity related data are downloaded and extracted. As previous dicussion in the issue forum, the web workers are not reaped after return, thus adding pthread_join to reap them. As I tested, the sound effects and musics are only playable using the emcc version 3.1.51 which will fetch specific SDL2_mixer library, thus warning the user if the emcc version is not 3.1.51. Embed all ELF and their dependencies into single wasm when building with emcc. Consequently, a ELF executable menu bar can be introduced to select and run desired ELF programs. Since we are running the wasm program inside web browser, we have to yield to the web browser in some interval, so emscripten_set_main_loop_arg provided by emscripten comes to help. To utilize this function, we have to update the rv_step function signature. In order to switch running ELF programs, we have to cancel the browser main loop using emscripten_cancel_main_loop and do some clean up to recollect memory. _indirect_rv_halt is introduced to halt the RISC-V instance without exposing the RISC-V instance. assets directory will be used to store some required static web files. assets/html/index.html is a default main page of the ported wasm rv32emu. In order to switch running ELF programs, we have to delay some time for finishing emscripten_cancel_main_loop. I set delay to 1 second for now. TODO: more clean up have to be done, e.g., clear canvas, terminal and sound thread. Related to: sysprog21#75
bef66b8
to
07b86f6
Compare
Thank @ChinYikMing for contributing! |
Enable run video games using WebAssembly
To play sound effects and musics, we would use software synthesizer, here I choose Timidity. When doom and quake target are specified, the Timidity related data are downloaded and extracted. As previous dicussion in the issue forum, the web workers are not reaped after return, thus adding pthread_join to reap them. As I tested, the sound effects and musics are only playable using the emcc version 3.1.51 which will fetch specific version of SDL2_mixer library, thus warning the user if the emcc version is not 3.1.51.
We want to minimize the wasm size, thus only embed necessary files when building the wasm. For example, if doom target is specified, only doom related files are embeded to wasm. This could shorten the fetching time of wasm from the server.
Since we are running the wasm program inside web browser, we have to yield to the web browser in some interval, so emscripten_set_main_loop_arg provided by emscripten comes to help. To utilize this function, we have to update the rv_step function signature.
web-resources directory will be used to store some required static web files.
Note that this commit is not done yet, just want for quick code review before further anything wrong that not in consensus.