I spent few weeks just to rework on the code again and again, to archive what call “super-clean-and-easy-to-change” code but that uneccessary anymore
I’m writting about a more fun thing that I do, to export this crappy birb game to Web, thanks for Raylib for supporting this. But get the game run on browser is not easy as changing the build target as I thought. So here are few things that I tried.
A common cmake command that I have to run:
cmake -B build -S . -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=~/Workspace/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_TOOLCHAIN_FILE=~/Workspace/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=wasm32-emscripten -DPLATFORM=Web
I have try to not use vcpkg and build libraries manually and install the to a location. I will write about the reason in following points.
But using vcpkg is great, and simple. Sadly, version 3 of box2d hasn’t been ported to vcpkg yet open issue
if (DEFINED PLATFORM AND ${PLATFORM} STREQUAL "Web")
target_compile_options(flappy PRIVATE -DPLATFORM_WEB)
target_link_options(flappy PRIVATE --preload-file config.txt@resources/config.txt)
endif()
I now know how to check a defined flag and check variable value. Also, I learn about one way to copy file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.txt ${CMAKE_CURRENT_BINARY_DIR}/config.txt COPYONLY)
Only copy from
file to to
file, and it doesn’t make target recompiled (still need to verify)
--shell-file
: to use html file as base template
--preload-file
: to tell wasm that a file can be accessed from code
--pre-js
, --post-js
: add custom javascript to our wasm module, beside C/C++ code.
When C++ code throw an exception, in browser console there’s a stack trace but the stacktrace is useless for app developer, it only used to debug wasm related stuff.
To actually debug where’s the problem at, I have to:
You can try the crappy birb here