libtcod icon indicating copy to clipboard operation
libtcod copied to clipboard

Emscripten Support.

Open HexDecimal opened this issue 5 years ago • 3 comments

Something that'd be really nice would be the ability to compile the samples to WebAssembly, and then make proper instructions on how to build WASM with other libtcod projects.

Right now I think the best method to attempt this would be to run Conan with an Emscripten profile.

I'm welcome for any suggestions on how to get this working. Anything preventing a WebAssembly build can be removed from libtcod.

Things I need to do:

  • [ ] Fix fullscreen toggle.
  • [ ] Update samples to use Emscripten.
  • [x] ~~Fix GLES2 renderer.~~ (The SDL2 renderer is good enough that this is no longer a requirement.)
  • [ ] Add fallback tileset (or at least set an error.)

HexDecimal avatar Feb 01 '20 03:02 HexDecimal

Tested using a modified frost sample. Updates are on the develop branch.

  • Libtcod successfully compiles to WASM using the wasm32-emscripten triplet on Vcpkg.
  • Samples compile, but have to be modified for Emscripten to run. This is expected.
  • No fallback tileset, one has to be manually given.
  • Frost sample runs correctly at a decent speed.
  • Fullscreen results in a crash when the window size is checked with SDL.
  • OpenGL2 renderer crahes. SDL2 and OpenGL1 works correctly.

HexDecimal avatar Jun 02 '21 08:06 HexDecimal

ubuntu@ip-172-26-1-83:~/workdir/ynoclient/build$ ninja
[2/2] Linking CXX executable index.html
FAILED: index.html
: && /home/ubuntu/workdir/buildscripts/emscripten/emsdk-portable/upstream/emscripten/em++  -O3 -DNDEBUG  -s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY -s ASYNCIFY_IGNORE_INDIRECT -s MINIFY_HTML=0 --pre-js /home/ubuntu/workdir/ynoclient/resources/emscripten/emscripten-pre.js --post-js /home/ubuntu/workdir/ynoclient/resources/emscripten/emscripten-post.js -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=['$autoResumeAudioContext','$dynCall'] --shell-file /home/ubuntu/workdir/ynoclient/resources/emscripten/emscripten-shell.html -s EXPORTED_FUNCTIONS='["_SwitchNpcSync","_SetSwitchSync","_SetSwitchSyncWhiteList","_LogSwitchSyncWhiteList","_SetSwitchSyncLogBlackList","_SetWSHost","_SetPlayersVolume","_SlashCommandSetSprite","_ChangeName","_gotMessage","_gotChatInfo","_isChatOpen","_updateTypeDisplayText","_updateTypeDisplayCaret","_trySendChat","_main"]' -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap","intArrayFromString","ALLOC_NORMAL","allocate"]' -s ASSERTIONS=1 CMakeFiles/EasyRPG_Player_exe.dir/src/main.cpp.o  -o index.html  libEasyRPG_Player.a  -lidbfs.js  -lwebsocket.js  /home/ubuntu/workdir/buildscripts/emscripten/lib/liblcf.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libicui18n.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libicuuc.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libicudata.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libexpat.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libpng.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libpixman-1.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libfmt.a  ../vcpkg/installed/wasm32-emscripten/lib/libtcod.a  ../vcpkg/installed/wasm32-emscripten/lib/libSDL2.a  -lm  ../vcpkg/installed/wasm32-emscripten/lib/libz.a  ../vcpkg/installed/wasm32-emscripten/lib/libglad.a  ../vcpkg/installed/wasm32-emscripten/lib/liblodepng-c.a  ../vcpkg/installed/wasm32-emscripten/lib/libutf8proc.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libspeexdsp.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libmpg123.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libsndfile.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libvorbisfile.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libvorbis.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libogg.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libopusfile.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libopus.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libfluidsynth.a  /home/ubuntu/workdir/buildscripts/emscripten/lib/libxmp-lite.a && :
error: undefined symbol: _ZN6EngineC1Ev (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZN6EngineC1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6EngineD1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN6EngineD1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/home/ubuntu/workdir/buildscripts/emscripten/emsdk-portable/node/14.18.2_64bit/bin/node /home/ubuntu/workdir/buildscripts/emscripten/emsdk-portable/upstream/emscripten/src/compiler.js /tmp/tmpjgf_440m.txt' failed (1)
ninja: build stopped: subcommand failed.

When I using “TCODConsole::initRoot(80,50,"libtcod C++ tutorial",false);”, It throws an error while compiling. Without this this line of code. It can works normally.

lychees avatar Feb 26 '22 03:02 lychees

TCODConsole::initRoot is deprecated. You might want to use tcod::new_context instead. See the getting started section.

error: undefined symbol: _ZN6EngineC1Ev

Libtcod doesn't actually have an Engine symbol (closest is TCOD_ctx.engine.) So I don't know what this refers to, but I know it isn't talking about TCODConsole::initRoot here. I can only assume this is your own Engine class constructor or something like that.

HexDecimal avatar Feb 26 '22 04:02 HexDecimal