Make emscripten --preload-file opt-in

This commit is contained in:
Zack Middleton 2024-06-10 20:50:48 -05:00
parent ab8f7eb0bd
commit 41ec9ae05f
2 changed files with 12 additions and 19 deletions

View file

@ -1090,9 +1090,11 @@ ifeq ($(PLATFORM),emscripten)
# For more flexibility, game data files can be loaded from a web server at runtime by listing
# them in ioq3-config.json. This way they don't have to be present at build time and can be
# changed later.
ifneq ($(wildcard $(BASEGAME)/*),)
ifeq ($(EMSCRIPTEN_PRELOAD_FILE),1)
ifeq ($(wildcard $(BASEGAME)/*),)
$(error "No files in '$(BASEGAME)' directory for emscripten to preload.")
endif
CLIENT_LDFLAGS+=--preload-file $(BASEGAME)
EMSCRIPTEN_PRELOAD_FILE=1
CLIENT_EXTRA_FILES+=code/web/empty/ioq3-config.json
else
CLIENT_EXTRA_FILES+=code/web/$(BASEGAME)/ioq3-config.json
@ -1613,18 +1615,6 @@ endif
$(call print_list, $(NAKED_TARGETS))
$(call print_list, $(NAKED_GENERATEDTARGETS))
@echo ""
ifeq ($(PLATFORM),emscripten)
ifneq ($(EMSCRIPTEN_PRELOAD_FILE),1)
@echo " Warning: Game files not found in '$(BASEGAME)'."
@echo " They will not be packaged by Emscripten or preloaded."
@echo " To run this build you must serve the game files from a web server"
@echo " and list their paths in ioq3-config.json."
@echo " To make a build that automatically loads the game files, create a"
@echo " directory called '$(BASEGAME)' and copy your game files into it, then"
@echo " 'emmake make clean' and rebuild."
@echo ""
endif
endif
ifneq ($(TARGETS),)
ifndef DEBUG_MAKEFILE
@$(MAKE) $(TARGETS) $(B).zip V=$(V)

View file

@ -102,13 +102,12 @@ 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. Copy or symlink your baseq3 directory into this directory so Emscripten
can package your game files. (Alternatively, you can build without this,
and provide the game data files at runtime. For this, game files should
be listed in `ioq3-config.json`)
3. Run `emmake make debug` (or release, but if you do both then you will
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).
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
@ -177,6 +176,10 @@ Makefile.local:
DEBUG_CFLAGS - C compiler flags to use for building debug version
COPYDIR - the target installation directory
TEMPDIR - specify user defined directory for temp files
EMSCRIPTEN_PRELOAD_FILE - set to 1 to package 'baseq3' (BASEGAME) directory
containing pk3s and loose files as a single
.data file that is loaded instead of listing
individual files in ioq3-config.json
```
The defaults for these variables differ depending on the target platform.