davidjoffe / dave_gnukem

Dave Gnukem is a cross-platform 2D scrolling platform shooter inspired by Duke Nukem 1
GNU General Public License v2.0
76 stars 24 forks source link

emscripten fails to compile #205

Open enderandrew opened 8 months ago

enderandrew commented 8 months ago

This may be because the project has moved to SDL2.

If I try to run:

make -f Makefile.em I get:

em++ -Wall -Wno-switch -DDEBUG  -s WASM=1 -s USE_SDL_MIXER=1 --preload-file ./data -s ALLOW_MEMORY_GROWTH=1 --use-preload-plugins -s STB_IMAGE=1 -c src/main.cpp -o src/main.o
em++: warning: linker setting ignored during compilation: 'WASM' [-Wunused-command-line-argument]
em++: warning: linker setting ignored during compilation: 'ALLOW_MEMORY_GROWTH' [-Wunused-command-line-argument]
em++: warning: linker setting ignored during compilation: 'STB_IMAGE' [-Wunused-command-line-argument]
em++: warning: linker flag ignored during compilation: '--preload-file' [-Wunused-command-line-argument]
em++: warning: linker flag ignored during compilation: '--use-preload-plugins' [-Wunused-command-line-argument]
In file included from src/main.cpp:36:
In file included from src/djinput.h:15:
/mnt/d/Development/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl/SDL_events.h:1:2: error: "To use the emscripten port of SDL use -sUSE_SDL or -sUSE_SDL=2"
    1 | #error "To use the emscripten port of SDL use -sUSE_SDL or -sUSE_SDL=2"

If I had the flag of -sUSE_SDL like this:

FLAGS=-s WASM=1 -s USE_SDL=1 -s USE_SDL_MIXER=1 --preload-file ./data -s ALLOW_MEMORY_GROWTH=1 --use-preload-plugins -s STB_IMAGE=1

I now get errors with it somehow pulling in both SDL 1 and 2 headers. Trying to change the flags to USE_SDL=2 and USE_SDL2_MIXER also combines SDL 1 and SDL 2 headers.

In file included from /mnt/d/Development/emsdk/upstream/emscripten/cache/sysroot/include/SDL2/SDL_mixer.h:32: /mnt/d/Development/emsdk/upstream/emscripten/cache/sysroot/include/SDL2/SDL_stdinc.h:182:5: error: redefinition of enumerator 'SDL_FALSE' 182 | SDL_FALSE = 0, | ^ /mnt/d/Development/emsdk/upstream/emscripten/cache/sysroot/include/SDL/SDL_stdinc.h:117:5: note: previous definition is here 117 | SDL_FALSE = 0,

davidjoffe commented 7 months ago

Hi! Thanks for this report .. see comment: https://github.com/davidjoffe/dave_gnukem/issues/160#issuecomment-2063995700

midzer commented 7 months ago

Okay, I've managed to fix compiler errors and get game running at ~18 FPS.

Could not get it run at more FPS, because game update logic is tightly linked to FPS right now.

Feel free to pick relevant changes from my fork https://github.com/midzer/dave_gnukem/tree/emscripten