From 8365ea7ed29876f8c42785c517338c12127f390d Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 9 Jun 2024 23:24:12 -0500 Subject: [PATCH] Customize the web client HTML file Modify the client HTML file when copying it to the build directory to apply current CLIENTBIN and BASEGAME. It always loads engine/data from the current directory (no need to try to locate the build directory). --- Makefile | 14 +++++- README.md | 8 ++-- code/web/client.html | 96 ++++++++++++++++++++++++++++++++++++++++++ code/web/ioquake3.html | 71 ------------------------------- 4 files changed, 111 insertions(+), 78 deletions(-) create mode 100644 code/web/client.html delete mode 100644 code/web/ioquake3.html diff --git a/Makefile b/Makefile index 716500ea..19b2df83 100644 --- a/Makefile +++ b/Makefile @@ -291,6 +291,7 @@ LIBTOMCRYPTSRCDIR=$(AUTOUPDATERSRCDIR)/rsa_tools/libtomcrypt-1.17 TOMSFASTMATHSRCDIR=$(AUTOUPDATERSRCDIR)/rsa_tools/tomsfastmath-0.13.1 LOKISETUPDIR=misc/setup NSISDIR=misc/nsis +WEBDIR=$(MOUNT_DIR)/web SDLHDIR=$(MOUNT_DIR)/SDL2 LIBSDIR=$(MOUNT_DIR)/libs @@ -1069,8 +1070,6 @@ ifeq ($(PLATFORM),emscripten) BUILD_RENDERER_OPENGL1=0 BUILD_SERVER=0 - CLIENT_EXTRA_FILES+=code/web/ioquake3.html - CLIENT_CFLAGS+=-s USE_SDL=2 CLIENT_LDFLAGS+=-s TOTAL_MEMORY=256MB @@ -1231,6 +1230,8 @@ ifeq ($(PLATFORM),emscripten) endif ifneq ($(BUILD_CLIENT),0) + TARGETS += $(B)/$(CLIENTBIN).html + ifneq ($(USE_RENDERER_DLOPEN),0) GENERATEDTARGETS += $(B)/$(CLIENTBIN).$(ARCH).wasm ifeq ($(EMSCRIPTEN_PRELOAD_FILE),1) @@ -3086,6 +3087,15 @@ $(B)/$(MISSIONPACK)/qcommon/%.asm: $(CMDIR)/%.c $(Q3LCC) $(DO_Q3LCC_MISSIONPACK) +############################################################################# +# EMSCRIPTEN +############################################################################# + +$(B)/$(CLIENTBIN).html: $(WEBDIR)/client.html + $(echo_cmd) "SED $@" + $(Q)sed 's/__CLIENTBIN__/$(CLIENTBIN)/g;s/__BASEGAME__/$(BASEGAME)/g' < $< > $@ + + ############################################################################# # MISC ############################################################################# diff --git a/README.md b/README.md index 322c358d..dd374263 100644 --- a/README.md +++ b/README.md @@ -102,16 +102,14 @@ For macOS, building a Universal Binary 2 (macOS 10.9+, arm64, x86_64) For Web, building with Emscripten 1. Follow the installation instructions for the Emscripten SDK including setting up the environment with emsdk_env. - 2. Run `emmake make debug` (or release, but if you do both then you will - need to pass an extra URL parameter to the HTML file to select the - build you want). + 2. Run `emmake make debug` (or release). 3. Copy or symlink your baseq3 pk3 files into the `build/debug-emscripten-wasm32/baseq3` directory so they can be loaded at run-time. Only game files listed in `ioq3-config.json` will be loaded. 4. Start a web server serving this directory. `python3 -m http.server` is an easy default that you may already have installed. - 5. Open `code/web/ioquake3.html` in a web browser. Open the developer - console to see errors and warnings. + 5. Open `http://localhost:8000/build/debug-emscripten-wasm32/ioquake3.html` + in a web browser. Open the developer console to see errors and warnings. 6. Debugging the C code is possible using a Chrome extension. For details see https://developer.chrome.com/blog/wasm-debugging-2020 diff --git a/code/web/client.html b/code/web/client.html new file mode 100644 index 00000000..3814ad6c --- /dev/null +++ b/code/web/client.html @@ -0,0 +1,96 @@ + +__CLIENTBIN__ Emscripten demo + + + + + diff --git a/code/web/ioquake3.html b/code/web/ioquake3.html deleted file mode 100644 index 93923cd5..00000000 --- a/code/web/ioquake3.html +++ /dev/null @@ -1,71 +0,0 @@ - -ioquake3 Emscripten demo - - - - -