From 70fd996383b71a7ad29bb32a1436fb25d919c6c3 Mon Sep 17 00:00:00 2001 From: queenkjuul Date: Sun, 31 Dec 2023 09:17:16 -0600 Subject: [PATCH] new Dockerfile, new build arguments for default screen dimensions --- Dockerfile | 34 +++++++++++++++++++++++++++++++++- Makefile | 6 ++++++ README.md | 34 ++++++++++++++++++++++++++++++++++ src/pc/gfx/gfx_screen_config.h | 12 ++++++++++-- 4 files changed, 83 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 587cb06b..fc28c994 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,9 @@ RUN apt-get update && \ git \ libglew-dev \ libsdl2-dev \ - python3 + python3 \ + python-is-python3 + RUN mkdir /sm64ex WORKDIR /sm64ex @@ -15,3 +17,33 @@ ENV PATH="/sm64ex/tools:${PATH}" CMD echo 'Usage: docker run --rm -v ${PWD}:/sm64ex sm64ex make BETTERCAMERA=1 EXTERNAL_DATA=1 -j4\n' \ 'See https://github.com/sm64pc/sm64ex/wiki/Compiling-on-Docker for more information' + +FROM build AS web + +WORKDIR / + +RUN git clone https://github.com/emscripten-core/emsdk.git + +RUN /emsdk/emsdk install 1.39.5 +RUN /emsdk/emsdk activate 1.39.5 + +# normally you'd run 'source $EMSDK/emsdk_env.sh' to load the emsdk environment +# both Dockerfile and Makefile run each process in a separate subshell so I don't think something like +# RUN . /emsdk/emsdk_env.sh +# will work, nor would doing the same within the Makefile +# wouldn't be an issue on a bare metal build as the user would have already sourced the file per emsdk docs +# also, the env script only works in bash, not sh, and I'm not sure about changing shells in Docker +# versions are pinned, so we can live with it, I guess. node version will change if emsdk is updated +# run +# docker run --rm sm64ex bash -c '. /emsdk/emsdk_env.sh' +# to print the emsdk environment after a version change +ENV EMSDK="/emsdk" +ENV EM_CACHE="/emsdk/upstream/emscripten/cache" +ENV EM_CONFIG="/emsdk/.emscripten" +ENV EMSDK_NODE="/emsdk/node/16.20.0_64bit/bin/node" +ENV PATH="${EMSDK}:${EMSDK_NODE}:${EMSDK}/upstream/emscripten:${PATH}" + +WORKDIR /sm64ex + +CMD echo 'Usage: docker run --rm -v ${PWD}:/sm64ex sm64ex make BETTERCAMERA=1 EXTERNAL_DATA=1 -j4\n' \ + 'See https://github.com/sm64pc/sm64ex/wiki/Compiling-on-Docker for more information' diff --git a/Makefile b/Makefile index 287ad961..2a1cf8fe 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,10 @@ BASEPACK ?= base.zip WINDOWS_BUILD ?= 0 +# default screen size +WINDOW_WIDTH ?= 640 +WINDOW_HEIGHT ?= 480 + # Attempt to detect OS ifeq ($(OS),Windows_NT) @@ -227,6 +231,8 @@ COMPARE := 0 ifeq ($(TARGET_WEB),1) VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_WEB -DUSE_GLES + VERSION_CFLAGS += -DWINDOW_WIDTH=$(WINDOW_WIDTH) + VERSION_CFLAGS += -DWINDOW_HEIGHT=$(WINDOW_HEIGHT) endif # Check backends diff --git a/README.md b/README.md index 47a4904a..3592b41c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,37 @@ +# sm64ex-web + +Modifications to original project Dockerfile to build the emscripten web version of sm64ex + +You can probably do this on bare metal by installing emsdk version 1.39.5 along with all normal sm64ex dependencies, but easier to use docker + +Instructions: + +``` +git clone https://github.com/queenkjuul/sm64ex-web.git +cd sm64ex-web +cp /path/to/your/baserom.us.z64 . +docker build . -t sm64ex --target web +docker run --rm -v $(pwd):/sm64ex sm64ex make TARGET_WEB=1 -j$(nproc) +docker run --rm -v $(pwd):/sm64ex sm64ex make TARGET_WEB=1 -j$(nproc) +``` + +Yes, that one command is run twice. No idea why that is necessary, but it is. + +After successful build, you can easily test if you have Node installed: + +``` +cd build/us_web +npx http-server +``` + +## Additional features + +I can't get fullscreen working, or real time canvas resizing, but I did add build flags that let you specify the width and height: + +``` +docker run --rm -v $(pwd):/sm64ex sm64ex make TARGET_WEB=1 WINDOW_WIDTH=1280 WINDOW_HEIGHT=720 -j$(nproc) +``` + # sm64ex Fork of [sm64-port/sm64-port](https://github.com/sm64-port/sm64-port) with additional features. diff --git a/src/pc/gfx/gfx_screen_config.h b/src/pc/gfx/gfx_screen_config.h index 5b933f85..85147df8 100644 --- a/src/pc/gfx/gfx_screen_config.h +++ b/src/pc/gfx/gfx_screen_config.h @@ -1,7 +1,15 @@ #ifndef GFX_SCREEN_CONFIG_H #define GFX_SCREEN_CONFIG_H +#ifdef WINDOW_WIDTH +#define DESIRED_SCREEN_WIDTH WINDOW_WIDTH +#else #define DESIRED_SCREEN_WIDTH 640 -#define DESIRED_SCREEN_HEIGHT 480 - +#endif + +#ifdef WINDOW_HEIGHT +#define DESIRED_SCREEN_HEIGHT WINDOW_HEIGHT +#else +#define DESIRED_SCREEN_HEIGHT 480 +#endif #endif