spoutn1k / mcmap

Pixel-art map visualizer for Minecraft. Maps are drawn from an isometric perspective.
GNU General Public License v3.0
312 stars 45 forks source link

[suggestion] move /scripts to a separate repo or do some other thing to support cross-compile #93

Open RadND opened 1 year ago

RadND commented 1 year ago

TLDR : i'm trying to compile mcmap to wasm using emscripten , /scripts makes it hard to do that "cross-compile"

Rencently , player of my creative server want to render some small part of map (e.g. a single floor of a big building ) , due to the truncate on y-axis this can't be achieved by dynmap. So I plan to compile mcmap to wasm to make they render thier building in browser. The problem here is because tools in /scripts got compiled to wasm format , too. It can't run when called in MakeFile.

I know I can tell players to use the Windows GUI one, but it's difficult for them to read English , and it seems the program isn't able to read spigot server world (except overworld , other show error "... not a save folder")

Make json->bson optional also helps ,since it's the only tool got called by now.

This change will make cross-compile easier in general , not only c++->wasm

spoutn1k commented 1 year ago

Hey that's super cool ! I thought about using wasm too recently but got busy.

Moving the scripts would be a major pain, I am sure we can figure out a way to do it without moving them. Would you be able to share what you are doing to compile so that I can take a look and configure/update the build system ?

The json->bson tool is also essential, as it allows to have the colors in plain text in the source code. I can make it optional if the BSON file has already been generated - but having a binary blob in the sources is a no-go.

EDIT: I believe I added a log window in the GUI. If you could open it and see what the error is when opening other dimension that would be really helpful.

RadND commented 1 year ago

my environment is wsl Ubuntu 22.04.2 LTS

  1. install emscripten (I choose to clone their SDK repo)
  2. download/git clone all code of dependencies when search the web i found zlib-ng , it can be ABI compatible to zlib ,so I choose it. Can you change zlib to zlib-ng ? start another issue i guess.
  3. loop{compile,see errors,change} I failed to make any header-only lib working,so I change them to "normal"(can't figure out a word to describe this version) one in all CMakeList.txt in mcmap/

at the end of the day the workspace look like this:

/mnt/c/Users/radnd/Documents/Code/
  /emsdk
  /fmt-master
  /libpng
  /spdlog-1.x
  /mcmap
  /zlib-ng

compile command like this , cd to their ./build folder first

#zlib-ng
emcmake cmake .. -DZLIB_COMPAT=on -DBUILD_SHARED_LIBS=OFF
cmake --build ..

#lib-png
emcmake cmake .. -DPNG_SHARED=OFF -DPNG_STATIC=ON -DZLIB_LIBRARY="../../zlib-ng" -DZLIB_INCLUDE_DIR="../../zlib-ng"

#fmt
emcmake cmake .. -DBUILD_SHARED_LIBS=OFF -DFMT_TEST=OFF -DCMAKE_CXX_COMPILER="/mnt/c/Users/radnd/Documents/Code/emsdk/upstream/emscripten/em++"

#spdlog
emcmake cmake .. -DSPDLOG_FMT_EXTERNAL=ON -DSPDLOG_BUILD_EXAMPLE=OFF -DSPDLOG_BUILD_TESTS=OFF

#mcmap
#I didn't managed to make relative path work
emcmake cmake .. -DCMAKE_BUILD_TYPE=Release -DZLIB_LIBRARY="/mnt/c/Users/radnd/Documents/Code/zlib-ng/build/libz.a" -DZLIB_INCLUDE_DIR="/mnt/c/Users/radnd/Documents/Code/zlib-ng/build/" -DPNG_PNG_INCLUDE_DIR="/mnt/c/Users/radnd/Documents/Code/libpng/build" -DPNG_LIBRARY="/mnt/c/Users/radnd/Documents/Code/libpng/build" 

We never try to build in nether/end , so it's actually not a problem to me , would be good to make code handle this special case anyway,here is the log i reproduced on my temp local server

\world-dir\
  \world
    level.dat
    \region
    ...
  \world_nether
    level.dat
    \DIM-1
      \region
    ...
  \world_the_end
    \DIM1
    ...

blahblah... world-dir/world_nether\region' is of an unexpected format           #when in \world_nether
blahblah... world-dir/world_nether/DIM-1\level.dat': No such file or directory  #when in \world_nether\DIM-1
spoutn1k commented 1 year ago

I got mcmap to compile using the following steps.

json2bson compiles but fails to execute; the rest of the scripts create an error when compiled, I need to add a CMake flag to skip them. However, json2bson's sole purpose is to use the JSON library to compile the color JSON to BSON (and embed it in the binary). This is bypassed if the BSON file already exists; you can either do that like the above gist or by creating a file src/colors.bson with the contents of this gist.

The core library mcmap_core compiles but you will need to create a WASM interface to use it.