[Scummvm-git-logs] scummvm master -> d5220a9624656039cbcb2cb21568c5a19efac2cf

sev- noreply at scummvm.org
Tue Feb 27 16:07:22 UTC 2024


This automated email contains information about 11 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
4ea65b1a96 EMSCRIPTEN: Update Emscripten and cleanup build scripts
12cbd72f20 EMSCRIPTEN: Remove Gamepad API Workaround
1b47c5bbc2 EMSCRIPTEN: Update Game Downloader Script
45c5f4673a EMSCRIPTEN: Cleanup file paths
bc73ee4b71 EMSCRIPTEN: Add support for saving logfiles
65bdafa0a0 EMSCRIPTEN: OPENGL: Disable OPENGL_DEBUG on Emscripten
7aa72a1633 EMSCRIPTEN: OPENGL: Disable GLAD
7bdadaefae EMSCRIPTEN: GRAPHICS: Fix screenshots
e36640efdf EMSCRIPTEN: GRAPHICS: Enable OpenGL graphics mode by default
82d0a4b06c EMSCRIPTEN: Load icons directly (not from an archive)
d5220a9624 FREESCAPE: Fix missing symbols when compiling against OpenGL ES 2.0


Commit: 4ea65b1a963fb6988117cf7b7ed94a03c6d7d101
    https://github.com/scummvm/scummvm/commit/4ea65b1a963fb6988117cf7b7ed94a03c6d7d101
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: Update Emscripten and cleanup build scripts

Changed paths:
  A backends/platform/sdl/emscripten/emscripten.mk
    configure
    dists/emscripten/README.md
    dists/emscripten/assets/scummvm_fs.js
    dists/emscripten/build-download_games.js
    dists/emscripten/build.sh
    dists/emscripten/custom_shell.html


diff --git a/backends/platform/sdl/emscripten/emscripten.mk b/backends/platform/sdl/emscripten/emscripten.mk
new file mode 100644
index 00000000000..67d0d09e42b
--- /dev/null
+++ b/backends/platform/sdl/emscripten/emscripten.mk
@@ -0,0 +1,32 @@
+
+# Special generic target for emscripten static file hosting bundle
+dist-emscripten: $(EXECUTABLE) $(PLUGINS)
+	mkdir -p ./build-emscripten/data
+	mkdir -p ./build-emscripten/doc
+	cp $(EXECUTABLE) ./build-emscripten/
+	cp $(EXECUTABLE:html=wasm) ./build-emscripten/
+	cp $(EXECUTABLE:html=js) ./build-emscripten/
+	cp $(DIST_FILES_DOCS) ./build-emscripten/doc
+	cp $(DIST_FILES_THEMES) ./build-emscripten/data
+ifdef DIST_FILES_ENGINEDATA
+	cp $(DIST_FILES_ENGINEDATA) ./build-emscripten/data
+endif
+ifdef DIST_FILES_NETWORKING
+	cp $(DIST_FILES_NETWORKING) ./build-emscripten/data
+endif
+ifdef DIST_FILES_VKEYBD
+	cp $(DIST_FILES_VKEYBD) ./build-emscripten/data
+endif
+ifdef DIST_FILES_SHADERS
+	mkdir -p ./build-emscripten/data/shaders
+	cp $(DIST_FILES_SHADERS) ./build-emscripten/data/shaders
+endif
+	$(EMSDK_NODE) "$(srcdir)/dists/emscripten/build-make_http_index.js" ./build-emscripten/data
+ifeq ($(DYNAMIC_MODULES),1)
+	mkdir -p ./build-emscripten/plugins/
+	@for i in $(PLUGINS); do cp $$i ./build-emscripten/plugins; done
+	$(EMSDK_NODE) "$(srcdir)/dists/emscripten/build-make_http_index.js" ./build-emscripten/plugins
+endif
+	cp "$(srcdir)/dists/emscripten/assets/"* ./build-emscripten/
+	cp "$(srcdir)/gui/themes/common-svg/logo.svg" ./build-emscripten/
+	cp "$(srcdir)/icons/scummvm.ico" ./build-emscripten/favicon.ico
diff --git a/configure b/configure
index 5e520161a5c..fa0aa30a092 100755
--- a/configure
+++ b/configure
@@ -3171,11 +3171,12 @@ EOF
 		append_var LIBS "-lnds9"
 		;;
 	emscripten)
-		# mandatory emscripten flags
-		append_var LDFLAGS "-s ALLOW_MEMORY_GROWTH=1 -s ASYNCIFY -s FORCE_FILESYSTEM=1"
-
 		append_var DEFINES "-DEMSCRIPTEN"
 		add_line_to_config_mk 'EMSCRIPTEN = 1'
+		_port_mk="backends/platform/sdl/emscripten/emscripten.mk"
+		append_var LDFLAGS "-s FORCE_FILESYSTEM"
+		append_var LDFLAGS "-s INITIAL_MEMORY=128MB -s TOTAL_STACK=32MB -s ALLOW_MEMORY_GROWTH=1"
+		append_var LDFLAGS "-s ASYNCIFY=1 -s ASYNCIFY_STACK_SIZE=1048576"
 
 		if test "$_debug_build" = yes; then
 			_optimization_level=-O2
@@ -3186,32 +3187,50 @@ EOF
 		fi
 
 		# activate emscripten-ports
-		if test "$_freetype2" != no; then
-			append_var LDFLAGS "-s USE_FREETYPE=1 -s SUPPORT_LONGJMP=1" # freetype requires setjmp
+		if test "$_sdl" != no; then # we enable SDL2 by default 
+			append_var LDFLAGS "-s USE_SDL=2 "
+		fi
+
+		# We explicitly disable optional libraries if not enabled. "auto" would depend
+		# on whether the port has been used before (and is detected) which is unpredictable.
+		if test "$_freetype2" = yes; then
 			# neither pkg-config nor freetype-config work, so we setup freetype manually
-			_freetypepath="$EMSCRIPTEN/cache/ports-builds/freetype/"
-			FREETYPE2_CFLAGS="-I$_freetypepath/include" # there were link errors / missing symbols without this
+			append_var LDFLAGS "-s USE_FREETYPE=1"
 			_freetype_found="true"
+			_freetypepath="$EMSDK/upstream/emscripten/cache/sysroot/include/freetype2/"
+			FREETYPE2_CFLAGS="-I$_freetypepath"
 		else
-			#use link time optimization to further reduce exe size (this can't be used with setjmp which freetype requires)
-			# TODO: Figure out why this is a conflict and/or if freetype can be built without setjmp
-			append_var CXXFLAGS "-flto"
-			append_var LDFLAGS "-flto"
+			_freetype2=no 
 		fi
-		if test "$_jpeg" != no; then
+		if test "$_gif" = yes; then
+		 	append_var LDFLAGS "-s USE_GIFLIB=1"
+		else
+			_gif=no 
+		fi
+		if test "$_jpeg" = yes; then
 			append_var LDFLAGS "-s USE_LIBJPEG=1"
+		else
+			_jpeg=no 
 		fi
-		if test "$_png" != no; then
-			append_var LDFLAGS "-s USE_LIBPNG=1"
+		if test "$_ogg" = yes; then
+			append_var LDFLAGS "-s USE_OGG=1" 
+		else
+			_ogg=no 
 		fi
-		if test "$_sdl" != no; then
-			append_var LDFLAGS "-s USE_SDL=2 "
+		if test "$_png" = yes; then
+			append_var LDFLAGS "-s USE_LIBPNG=1"
+		else
+			_png=no 
 		fi
-		if test "$_vorbis" != no; then
-			append_var LDFLAGS "-s USE_OGG=1" # vorbis needs to be linked against OGG (even if we use an external vorbis lib)
+		if test "$_vorbis" = yes; then
+			append_var LDFLAGS "-s USE_VORBIS=1" 
+		else
+			_vorbis=no 
 		fi
-		if test "$_zlib" != no; then
+		if test "$_zlib" = yes; then
 			append_var LDFLAGS "-s USE_ZLIB=1"
+		else
+			_zlib=no 
 		fi
 	;;
 	freebsd* | dragonfly*)
@@ -3552,6 +3571,7 @@ if test -n "$_host"; then
 			_sdlnet=no
 			_libcurl=no
 			_curl=no
+			_enet=no
 			_ar="emar cr"
 			_ranlib="emranlib"
 			;;
@@ -4861,7 +4881,7 @@ PLUGIN_LDFLAGS		+= -Wl,-T$(srcdir)/backends/plugins/ds/plugin.ld -mthumb -mthumb
 		append_var LIBS ""
 _mak_plugins='
 PLUGIN_EXTRA_DEPS =
-PLUGIN_LDFLAGS  += $(LDFLAGS) -s SIDE_MODULE=1 -s ASYNCIFY_IMPORTS=["*"] -s EXPORT_ALL=1
+PLUGIN_LDFLAGS  += -s SIDE_MODULE=1 -s ASYNCIFY=1 -s ASYNCIFY_IMPORTS=["*"] -s EXPORT_ALL=1
 PRE_OBJS_FLAGS  := -s MAIN_MODULE=1 -s EXPORT_ALL=1
 POST_OBJS_FLAGS :=
 '
@@ -6348,7 +6368,7 @@ if test "$_opengl_mode" != none ; then
 						emscripten)
 							_opengl_mode=gles2
 							_opengl_glad=no
-							append_var LDFLAGS "-s FULL_ES2=1 -s MAX_WEBGL_VERSION=1"
+							append_var OPENGL_LIBS "-s FULL_ES2=1 -s MAX_WEBGL_VERSION=1"
 							;;
 						*)
 							# As SDL2 supports everything, let the user choose if he wants to
@@ -7238,14 +7258,21 @@ case $_host_os in
 	emscripten)
 		append_var LDFLAGS "--pre-js ./dists/emscripten/custom_shell-pre.js --post-js ./dists/emscripten/custom_shell-post.js --shell-file ./dists/emscripten/custom_shell.html"
 		# we remove some linker flags for libs which will be added by emscripten from emscripten-ports to avoid duplicate symbols
+		if test "${LDFLAGS#*-s USE_GIFLIB=1}" != "$LDFLAGS"; then
+			LIBS=`echo ${LIBS} | sed 's/-lgif//g'`
+		fi
 		if test "${LDFLAGS#*-s USE_LIBJPEG=1}" != "$LDFLAGS"; then
     		LIBS=`echo ${LIBS} | sed 's/-ljpeg//g'`
 		fi
+		if test "${LDFLAGS#*-s USE_OGG=1}" != "$LDFLAGS"; then
+			LIBS=`echo ${LIBS} | sed 's/-logg//g'`
+		fi
 		if test "${LDFLAGS#*-s USE_LIBPNG=1}" != "$LDFLAGS"; then
 			LIBS=`echo ${LIBS} | sed 's/-lpng -lz//g'`
 		fi
-		if test "${LDFLAGS#*-s USE_OGG=1}" != "$LDFLAGS"; then
-			LIBS=`echo ${LIBS} | sed 's/-logg//g'`
+		if test "${LDFLAGS#*-s USE_VORBIS=1}" != "$LDFLAGS"; then
+			LIBS=`echo ${LIBS} | sed 's/-lvorbisfile//g;'`
+			LIBS=`echo ${LIBS} | sed 's/-lvorbis//g'`
 		fi
 		if test "${LDFLAGS#*-s USE_ZLIB=1}" != "$LDFLAGS"; then
 			LIBS=`echo ${LIBS} | sed 's/-lz//g'`
diff --git a/dists/emscripten/README.md b/dists/emscripten/README.md
index a3aa333d311..94e5363605c 100644
--- a/dists/emscripten/README.md
+++ b/dists/emscripten/README.md
@@ -69,20 +69,18 @@ In general, ScummVM runs in the browser sufficiently to run all demos and freewa
 ScummVM relies heavily on Asyncify (see note above), and this comes with a quite heavy performance penalty. Possible optimizations in this regard could be:
 *   Specify a `ASYNCIFY_ONLY` list in `configure` to  make asyncify only instrument functions in the call path as described in [emscripten.org: Asyncify](https://emscripten.org/docs/porting/asyncify.html)
 *   Limit asyncify overhead by having a more specific setting for `ASYNCIFY_IMPORTS` in `configure`. This is especailly critical for plugins as when plugins are enabled, we currently add all functions as imports. 
-*   🐞 We currently can't update beyond Emscripten 3.1.8 as the build fails since WebAssembly/binaryen#4567  if plugins enabled (because all functions become locals with `ASYNCIFY_IMPORTS=[*]`)
-*   Don't use asyncify but rewrite main loop to improve performance
-*   Look into emscripten-core/emscripten#16779 as an alternative
+*   Don't use asyncify but rewrite main loop to improve performance.
+*   Look into Stack Switching (emscripten-core/emscripten#16779) or multithreading as an alternative to Asyncify.
 
 ### Storage Integration
 *   BrowserFS seems abandoned and never did a stable 2.0.0 release. It's worth replacing it.  
     * `scummvm_fs.js` is an early prototype for a custom FS which can be adopted for ScummVM specific needs, i.e.
       * Download all game assets in background once the game has started
-      * Presist last game and last plugin for offline use
+      * Persist last game and last plugin for offline use
       * Pre-load assets asynchronously (not blocking) - i.e. rest of the data of a game which has been launched
       * Loading indicators (doesn't work with the current synchronous/blocking filesystem)
 *   Add support for save games (and game data?) on personal cloud storage (Dropbox, Google Drive).
 
-
 Emscripten is currently re-doing their filesystem code, which could help address some of the above issues ( emscripten-core/emscripten#15041 ).
 
 ### UI Integration
diff --git a/dists/emscripten/assets/scummvm_fs.js b/dists/emscripten/assets/scummvm_fs.js
index bdae7e67bcc..fc184cedb99 100644
--- a/dists/emscripten/assets/scummvm_fs.js
+++ b/dists/emscripten/assets/scummvm_fs.js
@@ -294,11 +294,11 @@ export class ScummvmFS {
                 nlink: 1,
                 uid: 0,
                 gid: 0,
-                rdev: undefined,
+                rdev: 0,
                 size: node.size,
-                atime: new Date(node.timestamp),
-                mtime: new Date(node.timestamp),
-                ctime: new Date(node.timestamp),
+                atime: new Date(),
+                mtime: new Date(),
+                ctime: new Date(),
                 blksize: 4096,
                 blocks: 0,
             };
diff --git a/dists/emscripten/build-download_games.js b/dists/emscripten/build-download_games.js
index 824d8e97eba..e4267903de1 100644
--- a/dists/emscripten/build-download_games.js
+++ b/dists/emscripten/build-download_games.js
@@ -16,16 +16,16 @@ const args_games = process.argv.slice(2);
 const SHEET_URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vQamumX0p-DYQa5Umi3RxX-pHM6RZhAj1qvUP0jTmaqutN9FwzyriRSXlO9rq6kR60pGIuPvCDzZL3s/pub?output=tsv';
 const SHEET_IDS = {
     'platforms': '1061029686',
-    'compatibility': '854570757',
-    'games': '1946612063',
+    'compatibility': '1989596967',
+    'games': '1775285192',
     'engines': '0',
     'companies': '226191984',
     'versions': '1225902887',
-    'game_demos': '713475305',
+    'game_demos': '1303420306',
     'series': '1095671818',
-    'screenshots': '1985243204',
+    'screenshots': '168506355',
     'scummvm_downloads': '1057392663',
-    'game_downloads': '1287892109',
+    'game_downloads': '810295288',
     'director_demos': '1256563740',
 }
 
@@ -144,7 +144,6 @@ const download_all_games = async (gameIds) => {
         if (gameId.startsWith("http")) {
             var  url = gameId
             var filename = url.substring(url.lastIndexOf("/") + 1)
-
             console.log(filename)
             if (!fs.existsSync(filename)) {
                 await download_file(url, filename)
@@ -157,6 +156,7 @@ const download_all_games = async (gameIds) => {
             if (gameId.includes("/")) {
                 gameId = gameId.substring(0, gameId.lastIndexOf("/"))
             }
+            gameId = gameId.substring(gameId.lastIndexOf(":")+1)// remove target from target:gameId
             var filename = url.substring(url.lastIndexOf("/") + 1)
             if (!filename.startsWith(gameId)) { filename = gameId + "-" + filename }
             console.log(filename)
diff --git a/dists/emscripten/build.sh b/dists/emscripten/build.sh
index e91c0796ab7..3099dff8882 100755
--- a/dists/emscripten/build.sh
+++ b/dists/emscripten/build.sh
@@ -20,15 +20,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-# print commands
-if [[ "$_verbose" = true ]]; then
-  set -o xtrace
-fi
+
 
 # exit when any command fails
 set -e
 
-EMSDK_VERSION="3.1.8"
 ROOT_FOLDER=$(pwd)
 DIST_FOLDER="$ROOT_FOLDER/dists/emscripten"
 LIBS_FOLDER="$DIST_FOLDER/libs"
@@ -36,7 +32,8 @@ TASKS=()
 CONFIGURE_ARGS=()
 _bundle_games=()
 _verbose=false
-EMSCRIPTEN_VERSION=$EMSDK_VERSION
+EMSDK_VERSION="3.1.51"
+EMSCRIPTEN_VERSION="$EMSDK_VERSION"
 
 usage="\
 Usage: ./dists/emscripten/build.sh [TASKS] [OPTIONS]
@@ -49,13 +46,40 @@ Tasks:
 Options:
   -h, --help         print this help, then exit
   --bundle-games=    comma-separated list of demos and freeware games to bundle. 
-  -v, --verbose          print all commands run by the script
+  -v, --verbose      print all commands run by the script
   --*                all other options are passed on to the configure script
+                     Note: --enable-a52, --enable-faad, --enable-mad, --enable-mpeg2
+                     and --enable-theoradec also fetches and builds these dependencies
 "
 
+_liba52=false
+_libfaad=false
+_libmad=false
+_libmpeg2=false
+_libtheoradec=false
 # parse inputs
 for i in "$@"; do
   case $i in
+  --enable-a52)
+    _liba52=true
+    CONFIGURE_ARGS+=" $i"
+    ;;
+  --enable-faad)
+    _libfaad=true
+    CONFIGURE_ARGS+=" $i"
+    ;;
+  --enable-mad)
+    _libmad=true
+    CONFIGURE_ARGS+=" $i"
+    ;;
+  --enable-mpeg2)
+    _libmpeg2=true
+    CONFIGURE_ARGS+=" $i"
+    ;;
+  --enable-theoradec)
+    _libtheoradec=true
+    CONFIGURE_ARGS+=" $i"
+    ;;
   --bundle-games=*)
     str="${i#*=}"
     _bundle_games="${str//,/ }"
@@ -84,56 +108,57 @@ if [[ -z "$TASKS" ]]; then
   exit
 fi
 
+# print commands
+if [[ "$_verbose" = true ]]; then
+  set -o xtrace
+fi
+
 #################################
 # Setup Toolchain
 #################################
 
-if [[ "setup" =~ $(echo ^\(${TASKS}\)$) || "build" =~ $(echo ^\(${TASKS}\)$) ]]; then
-
-  # Activate Emscripten
-  if [[ ! -d "$DIST_FOLDER/emsdk-$EMSDK_VERSION" ]]; then
-    echo "$DIST_FOLDER/emsdk-$EMSDK_VERSION not found. Installing Emscripten"
-    cd "$DIST_FOLDER"
-    if [[ "$EMSDK_VERSION" = "tot" ]]; then
-      git clone "https://github.com/emscripten-core/emsdk/" emsdk-tot
-    else
-      wget -nc --content-disposition "https://github.com/emscripten-core/emsdk/archive/refs/tags/${EMSDK_VERSION}.tar.gz"
-      tar -xf "emsdk-${EMSDK_VERSION}.tar.gz"
-    fi
-    cd "$DIST_FOLDER/emsdk-${EMSDK_VERSION}"
-    ./emsdk install ${EMSCRIPTEN_VERSION}
-    # We currently require a few patches for unreleased changes Emscripten, see https://github.com/chkuendig/scummvm-demo/tree/main/patches
-    if [[ "$EMSCRIPTEN_VERSION" == "3.1.8" ]]; then
-      echo "Patching Emscripten"
-      cd upstream/emscripten
-      # until https://github.com/emscripten-core/emscripten/pull/15893 gets merged and released, we need to manually patch it
-      wget -nc https://raw.githubusercontent.com/chkuendig/scummvm-demo/main/patches/emscripten-15893.patch  -O "$DIST_FOLDER/emscripten-15893.patch" || true 
-      patch -p1 --verbose <"$DIST_FOLDER/emscripten-15893.patch"
-      # until https://github.com/emscripten-core/emscripten/pull/16559 gets merged and released, we need to manually patch it
-      wget -nc https://raw.githubusercontent.com/chkuendig/scummvm-demo/main/patches/emscripten-16559.patch  -O "$DIST_FOLDER/emscripten-16559.patch" || true 
-      patch -p1 --verbose <"$DIST_FOLDER/emscripten-16559.patch"
-      # until https://github.com/emscripten-core/emscripten/pull/16687 gets merged and released, we need to manually patch it
-      wget -nc https://raw.githubusercontent.com/chkuendig/scummvm-demo/main/patches/emscripten-16687.patch  -O "$DIST_FOLDER/emscripten-16687.patch" || true 
-      patch -p1 --verbose <"$DIST_FOLDER/emscripten-16687.patch"
-    fi
-
-    cd "$DIST_FOLDER/emsdk-${EMSDK_VERSION}"
-    ./emsdk activate ${EMSCRIPTEN_VERSION}
-
-    # install some required npm packages
-    source "$DIST_FOLDER/emsdk-$EMSDK_VERSION/emsdk_env.sh"
-    EMSDK_NPM=$(dirname $EMSDK_NODE)/npm
-    export NODE_PATH=$(dirname $EMSDK_NODE)/../lib/node_modules/
-    "$EMSDK_NPM" -g install "puppeteer at 13.5.1"
-    "$EMSDK_NPM" -g install "request at 2.88.2"
-    "$EMSDK_NPM" -g install "node-static at 0.7.11"
+# Activate Emscripten
+if [[ ! -d "$DIST_FOLDER/emsdk-$EMSDK_VERSION" ]]; then
+  echo "$DIST_FOLDER/emsdk-$EMSDK_VERSION not found. Installing Emscripten"
+  cd "$DIST_FOLDER"
+  if [[ "$EMSDK_VERSION" = "tot" ]]; then
+    git clone "https://github.com/emscripten-core/emsdk/" emsdk-tot
+  else
+    wget -nc --content-disposition --no-check-certificate "https://github.com/emscripten-core/emsdk/archive/refs/tags/${EMSDK_VERSION}.tar.gz"
+    tar -xf "emsdk-${EMSDK_VERSION}.tar.gz"
   fi
+
+fi
+
+cd "$DIST_FOLDER/emsdk-${EMSDK_VERSION}"
+ret=0 # https://stackoverflow.com/questions/18621990/bash-get-exit-status-of-command-when-set-e-is-active
+./emsdk activate ${EMSCRIPTEN_VERSION} || ret=$?
+if [[ $ret != 0 ]]; then
+  echo "install missing emscripten version"
+  cd "$DIST_FOLDER/emsdk-${EMSDK_VERSION}"
+  ./emsdk install ${EMSCRIPTEN_VERSION}
+
+  cd "$DIST_FOLDER/emsdk-${EMSDK_VERSION}"
+  ./emsdk activate ${EMSCRIPTEN_VERSION}
+
+  # install some required npm packages
+  source "$DIST_FOLDER/emsdk-$EMSDK_VERSION/emsdk_env.sh"
+  EMSDK_NPM=$(dirname $EMSDK_NODE)/npm
+  EMSDK_PYTHON="${EMSDK_PYTHON:-python3}"
+  export NODE_PATH=$(dirname $EMSDK_NODE)/../lib/node_modules/
+  "$EMSDK_NODE" "$EMSDK_NPM" -g install "puppeteer at 13.5.1"
+  "$EMSDK_NODE" "$EMSDK_NPM" -g install "request at 2.88.2"
+  "$EMSDK_NODE" "$EMSDK_NPM" -g install "node-static at 0.7.11"
+
 fi
+
 source "$DIST_FOLDER/emsdk-$EMSDK_VERSION/emsdk_env.sh"
 
 # export node_path - so we can use all node_modules bundled with emscripten (e.g. requests)
 EMSDK_NPM=$(dirname $EMSDK_NODE)/npm
-export NODE_PATH=$(dirname $EMSDK_NODE)/../lib/node_modules/
+EMSDK_PYTHON="${EMSDK_PYTHON:-python3}"
+EMSDK_NPX=$(dirname $EMSDK_NODE)/npx
+export NODE_PATH="$(dirname $EMSDK_NODE)/../lib/node_modules/"
 LIBS_FLAGS=""
 
 cd "$ROOT_FOLDER"
@@ -143,101 +168,91 @@ cd "$ROOT_FOLDER"
 if [[ "clean" =~ $(echo ^\(${TASKS}\)$) ]]; then
   emmake make clean || true
   emmake make distclean || true
-  rm -rf ./dists/emscripten/libs/build || true
-  rm -rf ./dists/emscripten/libs/*/ || true
+  emcc --clear-ports --clear-cache
   rm -rf ./build-emscripten/ || true
   rm scummvm.debug.wasm || true
-  find . -name "*.o" || true
-  find . -name "*.a" || true
-  find . -name "*.wasm" || true
-  exit 0
+  rm scummvm.wasm || true
+  rm scummvm.js || true
 fi
 
 #################################
-# Download + Install Libraries
+# Download + Install Libraries (if not part of Emscripten-Ports, these are handled by configure)
 #################################
-if [[ "libs" =~ $(echo ^\(${TASKS}\)$) || "build" =~ $(echo ^\(${TASKS}\)$) ]]; then
-
-  if [[ ! -d "$LIBS_FOLDER/build" ]]; then
-    mkdir -p "$LIBS_FOLDER/build"
-  fi
 
-  # Emscripten has an official port for vorbis, but it doesn't properly link vorbisfile https://github.com/emscripten-core/emscripten/pull/14005
-  if [[ ! -f "$LIBS_FOLDER/build/lib/libvorbis.a" ]]; then
-    echo "building libvorbis-1.3.7"
-    cd "$LIBS_FOLDER"
-    wget -nc "https://downloads.xiph.org/releases/vorbis/libvorbis-1.3.7.tar.gz"
-    tar -xf libvorbis-1.3.7.tar.gz
-    cd "$LIBS_FOLDER/libvorbis-1.3.7"
-    CFLAGS="-fPIC -s USE_OGG=1" emconfigure ./configure --host=wasm32-unknown-none --build=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/"
-    emmake make -j 3
-    emmake make install
-  fi
-  LIBS_FLAGS="${LIBS_FLAGS} --with-vorbis-prefix=$LIBS_FOLDER/build/"
+if [[ ! -d "$LIBS_FOLDER/build" ]]; then
+  mkdir -p "$LIBS_FOLDER/build"
+fi
 
-  if [[ ! -f "$LIBS_FOLDER/build/lib/libtheora.a" ]]; then
-    echo "build libtheora-1.1.1"
+if [ "$_liba52" = true ]; then
+  if [[ ! -f "$LIBS_FOLDER/build/lib/liba52.a" ]]; then
+    echo "building a52dec-0.7.4"
     cd "$LIBS_FOLDER"
-    wget -nc "https://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.xz"
-    tar -xf libtheora-1.1.1.tar.xz
-    cd "$LIBS_FOLDER/libtheora-1.1.1/"
-    CFLAGS="-fPIC -s USE_OGG=1" emconfigure ./configure --host=wasm32-unknown-none --build=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/" --disable-asm
-    emmake make -j 3
+    wget -nc "https://liba52.sourceforge.io/files/a52dec-0.7.4.tar.gz"
+    tar -xf a52dec-0.7.4.tar.gz
+    cd "$LIBS_FOLDER/a52dec-0.7.4/"
+    CFLAGS="-fPIC -Oz" emconfigure ./configure --host=wasm32-unknown-none --build=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/"
+    emmake make -j 5
     emmake make install
   fi
-  LIBS_FLAGS="${LIBS_FLAGS} --with-theoradec-prefix=$LIBS_FOLDER/build/"
+  LIBS_FLAGS="${LIBS_FLAGS} --with-a52-prefix=$LIBS_FOLDER/build"
+fi
 
+if [ "$_libfaad" = true ]; then
   if [[ ! -f "$LIBS_FOLDER/build/lib/libfaad.a" ]]; then
     echo "building faad2-2.8.8"
     cd "$LIBS_FOLDER"
     wget -nc "https://sourceforge.net/projects/faac/files/faad2-src/faad2-2.8.0/faad2-2.8.8.tar.gz"
     tar -xf faad2-2.8.8.tar.gz
     cd "$LIBS_FOLDER/faad2-2.8.8/"
-    CFLAGS="-fPIC" emconfigure ./configure --host=wasm32-unknown-none --build=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/"
-    emmake make
+    CFLAGS="-fPIC -Oz" emconfigure ./configure --host=wasm32-unknown-none --build=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/"
+    emmake make -j 5
     emmake make install
   fi
-  LIBS_FLAGS="${LIBS_FLAGS} --with-faad-prefix=$LIBS_FOLDER/build/"
+  LIBS_FLAGS="${LIBS_FLAGS} --with-faad-prefix=$LIBS_FOLDER/build"
+fi
 
+if [ "$_libmad" = true ]; then
   if [[ ! -f "$LIBS_FOLDER/build/lib/libmad.a" ]]; then
     echo "building libmad-0.15.1b"
     cd "$LIBS_FOLDER"
     wget -nc "https://downloads.sourceforge.net/mad/libmad-0.15.1b.tar.gz"
-    # libmad needs patching: https://stackoverflow.com/questions/14015747/gccs-fforce-mem-option
-    wget -nc "https://raw.githubusercontent.com/chkuendig/scummvm-demo/main/patches/libmad-0.15.1b-fixes-1.patch" -O "$DIST_FOLDER/libmad-0.15.1b-fixes-1.patch" || true
-    rm -rf "$LIBS_FOLDER/libmad-0.15.1b/"
     tar -xf libmad-0.15.1b.tar.gz
     cd "$LIBS_FOLDER/libmad-0.15.1b/"
-    patch -Np1 -i "$DIST_FOLDER/libmad-0.15.1b-fixes-1.patch"
-    emconfigure ./configure --host=wasm32-unknown-none --build=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/" --with-pic --enable-fpm=no
-    emmake make
+    # libmad needs patching as -fforce-mem has been removed in GCC 4.3 and later
+    sed -i -e 's/-fforce-mem//g' configure
+    CFLAGS="-Oz" emconfigure ./configure --host=wasm32-unknown-none --build=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/" --with-pic --enable-fpm=no
+    emmake make -j 5
     emmake make install
   fi
-  LIBS_FLAGS="${LIBS_FLAGS} --with-mad-prefix=$LIBS_FOLDER/build/"
+  LIBS_FLAGS="${LIBS_FLAGS} --with-mad-prefix=$LIBS_FOLDER/build"
+fi
 
+if [ "$_libmpeg2" = true ]; then
   if [[ ! -f "$LIBS_FOLDER/build/lib/libmpeg2.a" ]]; then
     echo "building libmpeg2-0.5.1"
     cd "$LIBS_FOLDER"
     wget -nc "http://libmpeg2.sourceforge.net/files/libmpeg2-0.5.1.tar.gz"
     tar -xf libmpeg2-0.5.1.tar.gz
     cd "$LIBS_FOLDER/libmpeg2-0.5.1/"
-    CFLAGS="-fPIC" emconfigure ./configure --host=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/" --disable-sdl
-    emmake make
+    CFLAGS="-fPIC -Oz" emconfigure ./configure --host=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/" --disable-sdl
+    emmake make -j 5
     emmake make install
   fi
-  LIBS_FLAGS="${LIBS_FLAGS} --with-mpeg2-prefix=$LIBS_FOLDER/build/"
+  LIBS_FLAGS="${LIBS_FLAGS} --with-mpeg2-prefix=$LIBS_FOLDER/build"
+fi
 
-  if [[ ! -f "$LIBS_FOLDER/build/lib/liba52.a" ]]; then
-    echo "building a52dec-0.7.4"
+if [ "$_libtheoradec" = true ]; then
+  if [[ ! -f "$LIBS_FOLDER/build/lib/libtheora.a" ]]; then
+    echo "build libtheora-1.1.1"
     cd "$LIBS_FOLDER"
-    wget -nc "https://liba52.sourceforge.io/files/a52dec-0.7.4.tar.gz"
-    tar -xf a52dec-0.7.4.tar.gz
-    cd "$LIBS_FOLDER/a52dec-0.7.4/"
-    CFLAGS="-fPIC" emconfigure ./configure --host=wasm32-unknown-none --build=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/"
-    emmake make -j 3
+    wget -nc "https://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.xz"
+    tar -xf libtheora-1.1.1.tar.xz
+    cd "$LIBS_FOLDER/libtheora-1.1.1/"
+    CFLAGS="-fPIC -s USE_OGG=1 -Oz" emconfigure ./configure --host=wasm32-unknown-none --build=wasm32-unknown-none --prefix="$LIBS_FOLDER/build/" --disable-asm
+    emmake make -j 5
     emmake make install
   fi
-  LIBS_FLAGS="${LIBS_FLAGS} --with-a52-prefix=$LIBS_FOLDER/build/"
+  LIBS_FLAGS="${LIBS_FLAGS} --with-theoradec-prefix=$LIBS_FOLDER/build"
 fi
 
 #################################
@@ -260,12 +275,19 @@ if [[ "make" =~ $(echo ^\(${TASKS}\)$) || "build" =~ $(echo ^\(${TASKS}\)$) ]];
   cd "${ROOT_FOLDER}"
   echo "Running make"
   emmake make
-  emmake make dist-generic
 fi
 
 # The following steps copy stuff to build-emscripten:
 mkdir -p "${ROOT_FOLDER}/build-emscripten/"
 
+#################################
+# Bundle everything into a neat package
+#################################
+if [[ "dist" =~ $(echo ^\(${TASKS}\)$) || "build" =~ $(echo ^\(${TASKS}\)$) ]]; then
+  echo "Bundle ScummVM for static file hosting"
+  emmake make dist-emscripten
+fi
+
 #################################
 # Create Games & Testbed Data
 #################################
@@ -302,38 +324,6 @@ if [[ "games" =~ $(echo ^\(${TASKS}\)$) || "build" =~ $(echo ^\(${TASKS}\)$) ]];
   cd "${ROOT_FOLDER}/build-emscripten/games/"
   "$EMSDK_NODE" "$DIST_FOLDER/build-make_http_index.js" >index.json
 fi
-
-#################################
-# Bundle everything into a neat package
-#################################
-if [[ "dist" =~ $(echo ^\(${TASKS}\)$) || "build" =~ $(echo ^\(${TASKS}\)$) ]]; then
-  cd "${ROOT_FOLDER}"
-  mv "${ROOT_FOLDER}"/scummvm.* "${ROOT_FOLDER}"/build-emscripten/ || true
-
-  # prepare data
-  if [[ -d "${ROOT_FOLDER}/dist-generic/scummvm/data" ]]; then
-    echo "Bundle ScummVM + Data"
-    rm -rf "${ROOT_FOLDER}/build-emscripten/data"
-    mv "${ROOT_FOLDER}/dist-generic/scummvm/data" "${ROOT_FOLDER}/build-emscripten/"
-    cd "${ROOT_FOLDER}/build-emscripten/data"
-    "$EMSDK_NODE" "$DIST_FOLDER/build-make_http_index.js" >index.json
-    rm -rf "${ROOT_FOLDER}/dist-generic/"
-  fi
-
-  # bundle plugins
-  echo "Bundle Plugins"
-  mkdir -p "${ROOT_FOLDER}/build-emscripten/plugins"
-  mv "${ROOT_FOLDER}/plugins/"* "${ROOT_FOLDER}/build-emscripten/plugins/" || true
-  cd "${ROOT_FOLDER}/build-emscripten/plugins"
-  "$EMSDK_NODE" "$DIST_FOLDER/build-make_http_index.js" >index.json
-
-  # add logos and other assets
-  cd "${ROOT_FOLDER}"
-  cp "$DIST_FOLDER/assets/"* "${ROOT_FOLDER}/build-emscripten/"
-  cp "$ROOT_FOLDER/gui/themes/common-svg/logo.svg" "${ROOT_FOLDER}/build-emscripten/"
-  cp "$ROOT_FOLDER/icons/scummvm.ico" "${ROOT_FOLDER}/build-emscripten/favicon.ico"
-fi
-
 #################################
 # Add icons
 #################################
@@ -343,7 +333,7 @@ if [[ "icons" =~ $(echo ^\(${TASKS}\)$) || "build" =~ $(echo ^\(${TASKS}\)$) ]];
     echo "Adding files from icons repository "
     cp "${ROOT_FOLDER}/gui/themes/gui-icons.dat" "${ROOT_FOLDER}/build-emscripten/data"
     cd "${ROOT_FOLDER}/../scummvm-icons/"
-    ${EMSDK_PYTHON:-'python3'} gen-set.py
+    "$EMSDK_PYTHON" gen-set.py
     echo "add icons"
     zip -q -u "${ROOT_FOLDER}/build-emscripten/data/gui-icons.dat" icons/*
     echo "add xml"
@@ -374,8 +364,8 @@ if [[ "run" =~ $(echo ^\(${TASKS}\)$) ]]; then
   echo "Run ScummVM"
   cd "${ROOT_FOLDER}/build-emscripten/"
   # emrun doesn't support range requests. Once it will, we don't need node-static anymore
-  # emrun --browser=chrome scummvm.html
+  emrun --browser=chrome scummvm.html
 
-  EMSDK_NPX=$(dirname $EMSDK_NODE)/npx
-  $EMSDK_NPX -p node-static static .
+  # TODO: https://github.com/cloudhead/node-static/issues/241 means node-static doesn't work either.
+  # $EMSDK_NPX -p node-static static .
 fi
diff --git a/dists/emscripten/custom_shell.html b/dists/emscripten/custom_shell.html
index a1be6e017c9..5a1bd5c7eab 100644
--- a/dists/emscripten/custom_shell.html
+++ b/dists/emscripten/custom_shell.html
@@ -251,7 +251,7 @@
               if (err) return reject(err)
               BrowserFS.initialize(mfs);
               // BrowserFS is now ready to use!
-              var BFS = new BrowserFS.EmscriptenFS();
+              var BFS = new BrowserFS.EmscriptenFS(void 0,void 0,{"EPERM": 1,"ENOENT": 2,"EINVAL": 22},void 0); // working around Emscripten stripping ERRNO_CODES in optimized builds
               // Mount the file systems into Emscripten.
               FS.mkdir('/local');
               FS.mount(BFS, { root: '/' }, '/local');


Commit: 12cbd72f200aab9695b7985f91bf7d320e6f5aa7
    https://github.com/scummvm/scummvm/commit/12cbd72f200aab9695b7985f91bf7d320e6f5aa7
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: Remove Gamepad API Workaround

As of 3a3da1b ScummVM launches even if joystick init fails

Changed paths:
    dists/emscripten/custom_shell-pre.js


diff --git a/dists/emscripten/custom_shell-pre.js b/dists/emscripten/custom_shell-pre.js
index af6ed9490ac..a1c7545cc15 100644
--- a/dists/emscripten/custom_shell-pre.js
+++ b/dists/emscripten/custom_shell-pre.js
@@ -2,12 +2,6 @@
 Module["arguments"] = [];
 Module["arguments"].push("--config=/local/scummvm.ini");
 
-// https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API only works in secure contexts and supported browsers. 
-// This disables joystick support to avoid a crash when initializing the sdl subsystem without the gamepad API being available.
-if (!navigator.getGamepads && !navigator.webkitGetGamepads) {
-    Module["arguments"].push("--joystick=-1")
-}
-
 // Add all parameters passed via the fragment identifier
 if (window.location.hash.length > 0) {
     params = decodeURI(window.location.hash.substring(1)).split(" ")


Commit: 1b47c5bbc2282d45f17ba1077233e152108acd5b
    https://github.com/scummvm/scummvm/commit/1b47c5bbc2282d45f17ba1077233e152108acd5b
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: Update Game Downloader Script

Changed paths:
    dists/emscripten/build-download_games.js
    dists/emscripten/build-make_http_index.js
    dists/emscripten/build.sh


diff --git a/dists/emscripten/build-download_games.js b/dists/emscripten/build-download_games.js
index e4267903de1..56de2e69737 100644
--- a/dists/emscripten/build-download_games.js
+++ b/dists/emscripten/build-download_games.js
@@ -70,11 +70,14 @@ function get_freeware_games() {
                 return
             }
             parseTSV(body).forEach((downloads) => {
-                if (downloads['category'] == "games" && !(downloads['game_id'] in games)) {
-                    games[downloads['game_id']] = "/frs/extras/" + downloads['url']
+                var gameId = downloads['game_id'];
+                if (downloads['category'] == "games" && !(gameId in games)) {
+                    games[gameId] = "/frs/extras/" + downloads['url']
+                    games[gameId.substring(gameId.lastIndexOf(":") + 1)] = "/frs/extras/" + downloads['url'] // allow specifying game names without target/engine name
                 }
                 filename = downloads['url'].substring(downloads['url'].lastIndexOf("/"))
-                games[downloads['game_id'] + filename] = "/frs/extras/" + downloads['url']
+                games[gameId + filename] = "/frs/extras/" + downloads['url']
+                games[gameId.substring(gameId.lastIndexOf(":") + 1) + filename] = "/frs/extras/" + downloads['url'] // allow specifying game names without target/engine name
             })
             resolve()
         })
@@ -91,11 +94,14 @@ function get_demos() {
                 return
             }
             parseTSV(body).forEach((downloads) => {
-                if (!(downloads['id'] in games)) {
-                    games[downloads['id']] = downloads['url']
+                var gameId = downloads['id']
+                if (!(gameId in games)) {
+                    games[gameId] = downloads['url']
+                    games[gameId.substring(gameId.lastIndexOf(":") + 1)] = downloads['url'] // allow specifying game names without target/engine name
                 }
                 filename = downloads['url'].substring(downloads['url'].lastIndexOf("/"))
-                games[downloads['id'] + filename] = downloads['url']
+                games[gameId + filename] = downloads['url']
+                games[gameId.substring(gameId.lastIndexOf(":") + 1) + filename] = downloads['url'] // allow specifying game names without target/engine name
             })
             resolve()
         })
@@ -112,11 +118,14 @@ function get_director_demos() {
                 return
             }
             parseTSV(body).forEach((downloads) => {
-                if (!(downloads['id'] in games)) {
-                    games[downloads['id']] = downloads['url']
+                var gameId = downloads['id']
+                if (!(gameId in games)) {
+                    games[gameId] = downloads['url']
+                    games[gameId.substring(gameId.lastIndexOf(":") + 1)] = downloads['url'] // allow specifying game names without target/engine name
                 }
                 filename = downloads['url'].substring(downloads['url'].lastIndexOf("/"))
-                games[downloads['id'] + filename] = downloads['url']
+                games[gameId + filename] = downloads['url']
+                games[gameId.substring(gameId.lastIndexOf(":") + 1) + filename] = downloads['url'] // allow specifying game names without target/engine name
             });
             resolve()
         });
@@ -142,7 +151,7 @@ var download_file = function (uri, filename) {
 const download_all_games = async (gameIds) => {
     for (var gameId of gameIds) {
         if (gameId.startsWith("http")) {
-            var  url = gameId
+            var url = gameId
             var filename = url.substring(url.lastIndexOf("/") + 1)
             console.log(filename)
             if (!fs.existsSync(filename)) {
@@ -156,7 +165,7 @@ const download_all_games = async (gameIds) => {
             if (gameId.includes("/")) {
                 gameId = gameId.substring(0, gameId.lastIndexOf("/"))
             }
-            gameId = gameId.substring(gameId.lastIndexOf(":")+1)// remove target from target:gameId
+            gameId = gameId.substring(gameId.lastIndexOf(":") + 1)// remove target from target:gameId
             var filename = url.substring(url.lastIndexOf("/") + 1)
             if (!filename.startsWith(gameId)) { filename = gameId + "-" + filename }
             console.log(filename)
diff --git a/dists/emscripten/build-make_http_index.js b/dists/emscripten/build-make_http_index.js
index 6dbc9c0aa21..ea012c57d07 100644
--- a/dists/emscripten/build-make_http_index.js
+++ b/dists/emscripten/build-make_http_index.js
@@ -44,16 +44,14 @@ function rdSync(dpath, tree, name) {
     });
     return tree;
 }
-const fsListing = JSON.stringify(rdSync(process.cwd(), {}, '/'));
 if (process.argv.length === 3) {
-    const fname = process.argv[2];
-    let parent = path.dirname(fname);
-    while (!fs.existsSync(parent)) {
-        fs.mkdirSync(parent);
-        parent = path.dirname(parent);
-    }
+    const rootFolder = process.argv[2];
+    const fsListing = JSON.stringify(rdSync(rootFolder, {}, '/'));
+    const fname = rootFolder + "/index.json"
     fs.writeFileSync(fname, fsListing, { encoding: 'utf8' });
 }
 else {
+    let rootFolder = process.cwd()
+    const fsListing = JSON.stringify(rdSync(rootFolder, {}, '/'));
     console.log(fsListing);
 }
\ No newline at end of file
diff --git a/dists/emscripten/build.sh b/dists/emscripten/build.sh
index 3099dff8882..5640ed85143 100755
--- a/dists/emscripten/build.sh
+++ b/dists/emscripten/build.sh
@@ -305,11 +305,12 @@ if [[ "games" =~ $(echo ^\(${TASKS}\)$) || "build" =~ $(echo ^\(${TASKS}\)$) ]];
   fi
 
   if [ -n "$_bundle_games" ]; then
+    echo "Fetching gmaes: $_bundle_games"
     mkdir -p "${DIST_FOLDER}/games/"
     cd "${DIST_FOLDER}/games/"
     files=$("$EMSDK_NODE" --unhandled-rejections=strict --trace-warnings "$DIST_FOLDER/build-download_games.js" ${_bundle_games})
-    for dir in "${ROOT_FOLDER}/build-emscripten/games/"*; do # cleanup games folder
-      if [ $(basename $dir) != "testbed" ]; then
+    for dir in "${ROOT_FOLDER}/build-emscripten/games/"*/; do # cleanup games folder
+      if [ "$(basename ${dir%*/})" != "testbed" ]; then
         rm -rf "$dir"
       fi
     done


Commit: 45c5f4673a86ede9ec9766f85246c4df837ef45b
    https://github.com/scummvm/scummvm/commit/45c5f4673a86ede9ec9766f85246c4df837ef45b
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: Cleanup file paths

Changed paths:
    backends/platform/sdl/emscripten/emscripten.cpp
    backends/platform/sdl/emscripten/emscripten.h
    backends/platform/sdl/emscripten/emscripten.mk
    configure
    dists/emscripten/assets/scummvm.ini
    dists/emscripten/custom_shell-pre.js
    dists/emscripten/custom_shell.html


diff --git a/backends/platform/sdl/emscripten/emscripten.cpp b/backends/platform/sdl/emscripten/emscripten.cpp
index 0570eada84a..8eda512d063 100644
--- a/backends/platform/sdl/emscripten/emscripten.cpp
+++ b/backends/platform/sdl/emscripten/emscripten.cpp
@@ -23,9 +23,11 @@
 
 
 #define FORBIDDEN_SYMBOL_EXCEPTION_FILE
+#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
 #include <emscripten.h>
 
 #include "backends/platform/sdl/emscripten/emscripten.h"
+#include "common/file.h"
 
 // Inline JavaScript, see https://emscripten.org/docs/api_reference/emscripten.h.html#inline-assembly-javascript for details
 EM_JS(bool, isFullscreen, (), {
@@ -68,4 +70,8 @@ void OSystem_Emscripten::setFeatureState(Feature f, bool enable) {
 	}
 }
 
+Common::Path OSystem_Emscripten::getDefaultConfigFileName() {
+	return Common::Path(Common::String::format("%s/scummvm.ini", getenv("HOME")));
+}
+
 #endif
diff --git a/backends/platform/sdl/emscripten/emscripten.h b/backends/platform/sdl/emscripten/emscripten.h
index bb3aa33328f..0204f4125a8 100644
--- a/backends/platform/sdl/emscripten/emscripten.h
+++ b/backends/platform/sdl/emscripten/emscripten.h
@@ -30,6 +30,8 @@ public:
 	void setFeatureState(Feature f, bool enable) override;
 	bool getFeatureState(Feature f) override;
 
+protected:
+	Common::Path getDefaultConfigFileName() override;
 };
 
 #endif
diff --git a/backends/platform/sdl/emscripten/emscripten.mk b/backends/platform/sdl/emscripten/emscripten.mk
index 67d0d09e42b..8ae26cbd0d9 100644
--- a/backends/platform/sdl/emscripten/emscripten.mk
+++ b/backends/platform/sdl/emscripten/emscripten.mk
@@ -2,6 +2,7 @@
 # Special generic target for emscripten static file hosting bundle
 dist-emscripten: $(EXECUTABLE) $(PLUGINS)
 	mkdir -p ./build-emscripten/data
+	mkdir -p ./build-emscripten/data/games
 	mkdir -p ./build-emscripten/doc
 	cp $(EXECUTABLE) ./build-emscripten/
 	cp $(EXECUTABLE:html=wasm) ./build-emscripten/
@@ -21,12 +22,11 @@ ifdef DIST_FILES_SHADERS
 	mkdir -p ./build-emscripten/data/shaders
 	cp $(DIST_FILES_SHADERS) ./build-emscripten/data/shaders
 endif
-	$(EMSDK_NODE) "$(srcdir)/dists/emscripten/build-make_http_index.js" ./build-emscripten/data
 ifeq ($(DYNAMIC_MODULES),1)
-	mkdir -p ./build-emscripten/plugins/
-	@for i in $(PLUGINS); do cp $$i ./build-emscripten/plugins; done
-	$(EMSDK_NODE) "$(srcdir)/dists/emscripten/build-make_http_index.js" ./build-emscripten/plugins
+	mkdir -p ./build-emscripten/data/plugins
+	@for i in $(PLUGINS); do cp $$i ./build-emscripten/data/plugins; done
 endif
+	$(EMSDK_NODE) "$(srcdir)/dists/emscripten/build-make_http_index.js" ./build-emscripten/data
 	cp "$(srcdir)/dists/emscripten/assets/"* ./build-emscripten/
 	cp "$(srcdir)/gui/themes/common-svg/logo.svg" ./build-emscripten/
 	cp "$(srcdir)/icons/scummvm.ico" ./build-emscripten/favicon.ico
diff --git a/configure b/configure
index fa0aa30a092..0ebf8e9b470 100755
--- a/configure
+++ b/configure
@@ -6951,6 +6951,9 @@ case $_host in
 		;;
 	ds)
 		;;
+	*-emscripten)
+		append_var DEFINES "-DPLUGIN_DIRECTORY=\\\"$datadir/plugins\\\""
+		;;
 	openpandora)
 		# Add ../plugins as a path so plugins can be found when running from a .PND.
 		append_var DEFINES "-DPLUGIN_DIRECTORY=\\\"../plugins\\\""
diff --git a/dists/emscripten/assets/scummvm.ini b/dists/emscripten/assets/scummvm.ini
index 95125efb8cb..aa2633bef80 100644
--- a/dists/emscripten/assets/scummvm.ini
+++ b/dists/emscripten/assets/scummvm.ini
@@ -1,6 +1,5 @@
 [scummvm]
 gfx_mode=opengl
-pluginspath=/plugins
 grouping=company
 renderer=opengl_shaders
 gui_launcher_chooser=grid
diff --git a/dists/emscripten/custom_shell-pre.js b/dists/emscripten/custom_shell-pre.js
index a1c7545cc15..4423f0289a8 100644
--- a/dists/emscripten/custom_shell-pre.js
+++ b/dists/emscripten/custom_shell-pre.js
@@ -1,6 +1,5 @@
 /*global Module*/
 Module["arguments"] = [];
-Module["arguments"].push("--config=/local/scummvm.ini");
 
 // Add all parameters passed via the fragment identifier
 if (window.location.hash.length > 0) {
diff --git a/dists/emscripten/custom_shell.html b/dists/emscripten/custom_shell.html
index 5a1bd5c7eab..c26e907fcb7 100644
--- a/dists/emscripten/custom_shell.html
+++ b/dists/emscripten/custom_shell.html
@@ -253,8 +253,7 @@
               // BrowserFS is now ready to use!
               var BFS = new BrowserFS.EmscriptenFS(void 0,void 0,{"EPERM": 1,"ENOENT": 2,"EINVAL": 22},void 0); // working around Emscripten stripping ERRNO_CODES in optimized builds
               // Mount the file systems into Emscripten.
-              FS.mkdir('/local');
-              FS.mount(BFS, { root: '/' }, '/local');
+              FS.mount(BFS, { root: '/' }, '/home/web_user');
               return resolve()
             })
           })
@@ -271,7 +270,6 @@
       setupLocalFilesystem().then(() => {
 
         setupHTTPFilesystem("games")
-        setupHTTPFilesystem("plugins")
         setupHTTPFilesystem("data")
 
         removeRunDependency('scummvm-fs-setup');


Commit: bc73ee4b71f5ccd6bdbc1a52cbb236c051f83332
    https://github.com/scummvm/scummvm/commit/bc73ee4b71f5ccd6bdbc1a52cbb236c051f83332
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: Add support for saving logfiles

Changed paths:
    backends/platform/sdl/emscripten/emscripten.cpp
    backends/platform/sdl/emscripten/emscripten.h


diff --git a/backends/platform/sdl/emscripten/emscripten.cpp b/backends/platform/sdl/emscripten/emscripten.cpp
index 8eda512d063..8c04a93eea7 100644
--- a/backends/platform/sdl/emscripten/emscripten.cpp
+++ b/backends/platform/sdl/emscripten/emscripten.cpp
@@ -44,6 +44,25 @@ EM_JS(void, toggleFullscreen, (bool enable), {
 	}
 });
 
+EM_JS(void, downloadFile, (const char *filenamePtr, char *dataPtr, int dataSize), {
+	const view = new Uint8Array(Module.HEAPU8.buffer, dataPtr, dataSize);
+	const blob = new Blob([view], {
+			type:
+				'octet/stream'
+		});
+	const filename = UTF8ToString(filenamePtr);
+	setTimeout(() => {
+		const a = document.createElement('a');
+		a.style = 'display:none';
+		document.body.appendChild(a);
+		const url = window.URL.createObjectURL(blob);
+		a.href = url;
+		a.download = filename;
+		a.click();
+		window.URL.revokeObjectURL(url);
+		document.body.removeChild(a);
+	}, 0);
+});
 
 // Overridden functions
 bool OSystem_Emscripten::hasFeature(Feature f) {
@@ -70,8 +89,37 @@ void OSystem_Emscripten::setFeatureState(Feature f, bool enable) {
 	}
 }
 
+Common::Path OSystem_Emscripten::getDefaultLogFileName() {
+	return Common::Path("/tmp/scummvm.log");
+}
+
 Common::Path OSystem_Emscripten::getDefaultConfigFileName() {
 	return Common::Path(Common::String::format("%s/scummvm.ini", getenv("HOME")));
 }
 
+bool OSystem_Emscripten::displayLogFile() {
+	if (_logFilePath.empty())
+		return false;
+
+	exportFile(_logFilePath);
+	return true;
+}
+
+
+void OSystem_Emscripten::exportFile(const Common::Path &filename) {
+	Common::File file;
+	Common::FSNode node(filename);
+	file.open(node);
+	if (!file.isOpen()) {
+		warning("Could not open file %s!", filename.toString(Common::Path::kNativeSeparator).c_str());
+		return;
+	}
+	Common::String exportName = filename.getLastComponent().toString(Common::Path::kNativeSeparator);
+	const int32 size = file.size();
+	char *bytes = new char[size + 1];
+	file.read(bytes, size);
+	file.close();
+	downloadFile(exportName.c_str(), bytes, size);
+	delete[] bytes;
+}
 #endif
diff --git a/backends/platform/sdl/emscripten/emscripten.h b/backends/platform/sdl/emscripten/emscripten.h
index 0204f4125a8..4e38f698cc5 100644
--- a/backends/platform/sdl/emscripten/emscripten.h
+++ b/backends/platform/sdl/emscripten/emscripten.h
@@ -29,9 +29,12 @@ public:
 	bool hasFeature(Feature f) override;
 	void setFeatureState(Feature f, bool enable) override;
 	bool getFeatureState(Feature f) override;
+	bool displayLogFile() override;
+	void exportFile(const Common::Path &filename);
 
 protected:
 	Common::Path getDefaultConfigFileName() override;
+	Common::Path getDefaultLogFileName() override;
 };
 
 #endif


Commit: 65bdafa0a0935dc438ae28569693d251323b36b5
    https://github.com/scummvm/scummvm/commit/65bdafa0a0935dc438ae28569693d251323b36b5
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: OPENGL: Disable OPENGL_DEBUG on Emscripten

863988f was causing a 10x increase in frame times regressing GRIM from 55fps to 3-5 fps.

Changed paths:
    graphics/opengl/debug.h


diff --git a/graphics/opengl/debug.h b/graphics/opengl/debug.h
index a39dfc68ac4..8b6647ac464 100644
--- a/graphics/opengl/debug.h
+++ b/graphics/opengl/debug.h
@@ -24,7 +24,9 @@
 
 #include "graphics/opengl/context.h"
 
+#ifndef __EMSCRIPTEN__
 #define OPENGL_DEBUG
+#endif
 
 namespace OpenGL {
 void clearGLError();


Commit: 7aa72a163376336dfa100101bd329a9915144ddc
    https://github.com/scummvm/scummvm/commit/7aa72a163376336dfa100101bd329a9915144ddc
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: OPENGL: Disable GLAD

Changed paths:
    configure
    graphics/opengl/debug.cpp
    graphics/opengl/system_headers.h


diff --git a/configure b/configure
index 0ebf8e9b470..50aa26c3403 100755
--- a/configure
+++ b/configure
@@ -6351,6 +6351,7 @@ if test "$_opengl_mode" != none ; then
 		sdl)
 			# This case is for pure SDL backend. Many platforms overload it and create a new backend
 			# They still make use of SDL but it's handled below in the default case
+			_opengl_glad=yes
 			case $_sdlversion in
 				1.2.*)
 					# Stock SDL 1.2 only supports OpenGL contexts.
@@ -6367,7 +6368,7 @@ if test "$_opengl_mode" != none ; then
 							;;
 						emscripten)
 							_opengl_mode=gles2
-							_opengl_glad=no
+							_opengl_glad=no # https://github.com/Dav1dde/glad-web/issues/12
 							append_var OPENGL_LIBS "-s FULL_ES2=1 -s MAX_WEBGL_VERSION=1"
 							;;
 						*)
@@ -6377,7 +6378,6 @@ if test "$_opengl_mode" != none ; then
 					esac
 					;;
 			esac
-			_opengl_glad=yes
 			;;
 		switch)
 			_opengl_mode=gles2
diff --git a/graphics/opengl/debug.cpp b/graphics/opengl/debug.cpp
index c5273cb7bb4..6b0d95278b4 100644
--- a/graphics/opengl/debug.cpp
+++ b/graphics/opengl/debug.cpp
@@ -39,10 +39,19 @@ Common::String getGLErrStr(GLenum error) {
 		return "GL_INVALID_VALUE";
 	case GL_INVALID_OPERATION:
 		return "GL_INVALID_OPERATION";
+// OpenGL ES 2.0 doesn't have GL_STACK_OVERFLOW and GL_STACK_UNDERFLOW
+// see https://registry.khronos.org/OpenGL/api/GLES2/gl2.h and https://registry.khronos.org/OpenGL/api/GLES2/gl2ext.h
+#ifdef USE_FORCED_GLES2
+	case GL_STACK_OVERFLOW_KHR:
+		return "GL_STACK_OVERFLOW_KHR";
+	case GL_STACK_UNDERFLOW_KHR:
+		return "GL_STACK_UNDERFLOW_KHR";
+#else
 	case GL_STACK_OVERFLOW:
 		return "GL_STACK_OVERFLOW";
 	case GL_STACK_UNDERFLOW:
 		return "GL_STACK_UNDERFLOW";
+#endif
 	case GL_OUT_OF_MEMORY:
 		return "GL_OUT_OF_MEMORY";
 	default:
diff --git a/graphics/opengl/system_headers.h b/graphics/opengl/system_headers.h
index f26fc141b5f..145b38221d7 100644
--- a/graphics/opengl/system_headers.h
+++ b/graphics/opengl/system_headers.h
@@ -84,6 +84,14 @@
 		#define GL_MAX_SAMPLES 0x8D57
 	#endif
 
+	#if !defined(GL_STACK_OVERFLOW_KHR)
+		#define GL_STACK_OVERFLOW_KHR 0x0503
+	#endif
+
+	#if !defined(GL_STACK_UNDERFLOW_KHR)
+		#define GL_STACK_UNDERFLOW_KHR 0x0504
+	#endif
+
 #elif USE_FORCED_GLES
 
 	#define GL_GLEXT_PROTOTYPES


Commit: 7bdadaefae07d0342e43f548874b0cb4ab7bc74a
    https://github.com/scummvm/scummvm/commit/7bdadaefae07d0342e43f548874b0cb4ab7bc74a
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: GRAPHICS: Fix screenshots

Changed paths:
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/openglsdl/openglsdl-graphics.cpp
    backends/graphics/openglsdl/openglsdl-graphics.h
    backends/graphics/sdl/sdl-graphics.cpp
    backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
    backends/graphics3d/openglsdl/openglsdl-graphics3d.h
    backends/platform/sdl/emscripten/emscripten.cpp
    backends/platform/sdl/emscripten/emscripten.h


diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 56d5b970d14..a122b1dc5d4 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -1746,7 +1746,11 @@ bool OpenGLGraphicsManager::saveScreenshot(const Common::Path &filename) const {
 	// GL_PACK_ALIGNMENT is 4 so each row must be aligned to 4 bytes boundary
 	// A line of a BMP image must also have a size divisible by 4.
 	// Calculate lineSize as the next multiple of 4 after the real line size
+#ifdef EMSCRIPTEN
+	const uint lineSize        = width * 4; // RGBA (see comment below)
+#else
 	const uint lineSize        = (width * 3 + 3) & ~3;
+#endif
 
 	Common::DumpFile out;
 	if (!out.open(filename)) {
@@ -1755,12 +1759,21 @@ bool OpenGLGraphicsManager::saveScreenshot(const Common::Path &filename) const {
 
 	Common::Array<uint8> pixels;
 	pixels.resize(lineSize * height);
+#ifdef EMSCRIPTEN	
+	// WebGL doesn't support GL_RGB, see https://registry.khronos.org/webgl/specs/latest/1.0/#5.14.12:
+	// "Only two combinations of format and type are accepted. The first is format RGBA and type UNSIGNED_BYTE. 
+	// The second is an implementation-chosen format. " and the implementation-chosen formats are buggy:
+	// https://github.com/KhronosGroup/WebGL/issues/2747
+	GL_CALL(glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels.front()));
+	const Graphics::PixelFormat format(4, 8, 8, 8, 8, 0, 8, 16, 24);
+#else
 	GL_CALL(glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &pixels.front()));
 
 #ifdef SCUMM_LITTLE_ENDIAN
 	const Graphics::PixelFormat format(3, 8, 8, 8, 0, 0, 8, 16, 0);
 #else
 	const Graphics::PixelFormat format(3, 8, 8, 8, 0, 16, 8, 0, 0);
+#endif
 #endif
 	Graphics::Surface data;
 	data.init(width, height, lineSize, &pixels.front(), format);
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index aae6035c19b..163d476b682 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -437,6 +437,12 @@ bool OpenGLSdlGraphicsManager::loadVideoMode(uint requestedWidth, uint requested
 
 void OpenGLSdlGraphicsManager::refreshScreen() {
 	// Swap OpenGL buffers
+#ifdef EMSCRIPTEN
+	if (_queuedScreenshot) {
+		SdlGraphicsManager::saveScreenshot();
+		_queuedScreenshot = false;
+	}
+#endif 
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 	SDL_GL_SwapWindow(_window->getSDLWindow());
 #else
@@ -449,6 +455,12 @@ void OpenGLSdlGraphicsManager::handleResizeImpl(const int width, const int heigh
 	SdlGraphicsManager::handleResizeImpl(width, height);
 }
 
+#ifdef EMSCRIPTEN
+void OpenGLSdlGraphicsManager::saveScreenshot() {
+	_queuedScreenshot = true;
+}
+#endif
+
 bool OpenGLSdlGraphicsManager::saveScreenshot(const Common::Path &filename) const {
 	return OpenGLGraphicsManager::saveScreenshot(filename);
 }
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h
index 712ca26c540..d8774628478 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.h
+++ b/backends/graphics/openglsdl/openglsdl-graphics.h
@@ -69,6 +69,21 @@ private:
 #else
 	uint32 _lastVideoModeLoad;
 #endif
+
+#ifdef EMSCRIPTEN
+	/** 
+	 * See https://registry.khronos.org/webgl/specs/latest/1.0/#2 :
+	 * " By default, after compositing the contents of the drawing buffer shall be cleared to their default values [...]
+	 *   Techniques like synchronous drawing buffer access (e.g., calling readPixels or toDataURL in the same function
+	 *   that renders to the drawing buffer) can be used to get the contents of the drawing buffer "
+	 * 
+	 * This means we need to take the screenshot at the correct time, which we do by queueing taking the screenshot
+	 * for the next frame instead of taking it right away.
+	 */
+	bool _queuedScreenshot = false;
+	void saveScreenshot() override;
+#endif
+
 	OpenGL::ContextType _glContextType;
 
 	uint _lastRequestedWidth;
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index ec25f84d576..e6026e941b6 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -34,6 +34,9 @@
 #include "common/translation.h"
 #endif
 
+#ifdef EMSCRIPTEN
+#include "backends/platform/sdl/emscripten/emscripten.h"
+#endif
 SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window)
 	: _eventSource(source), _window(window), _hwScreen(nullptr)
 #if SDL_VERSION_ATLEAST(2, 0, 0)
@@ -363,6 +366,12 @@ void SdlGraphicsManager::saveScreenshot() {
 		if (!ConfMan.getBool("disable_saved_screenshot_osd"))
 			displayMessageOnOSD(Common::U32String::format(_("Saved screenshot '%s'"), filename.c_str()));
 #endif
+
+#ifdef EMSCRIPTEN
+		// Users can't access the virtual emscripten filesystem in the browser, so we export the generated screenshot file via OSystem_Emscripten::exportFile.
+		OSystem_Emscripten *emscripten_g_system = dynamic_cast<OSystem_Emscripten*>(g_system);
+		emscripten_g_system->exportFile(screenshotsPath.appendComponent(filename));
+#endif
 	} else {
 		if (screenshotsPath.empty())
 			warning("Could not save screenshot in current directory");
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
index e1974ba4f87..bafc0541519 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
@@ -654,6 +654,13 @@ void OpenGLSdlGraphics3dManager::updateScreen() {
 		drawOverlay();
 	}
 
+#ifdef EMSCRIPTEN
+	if (_queuedScreenshot) {
+		SdlGraphicsManager::saveScreenshot();
+		_queuedScreenshot = false;
+	}
+#endif 
+
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 	SDL_GL_SwapWindow(_window->getSDLWindow());
 #else
@@ -789,13 +796,23 @@ void OpenGLSdlGraphics3dManager::deinitializeRenderer() {
 }
 #endif // SDL_VERSION_ATLEAST(2, 0, 0)
 
+#ifdef EMSCRIPTEN
+void OpenGLSdlGraphics3dManager::saveScreenshot() {
+	_queuedScreenshot = true;
+}
+#endif
+
 bool OpenGLSdlGraphics3dManager::saveScreenshot(const Common::Path &filename) const {
 	// Largely based on the implementation from ScummVM
 	uint width = _overlayScreen->getWidth();
 	uint height = _overlayScreen->getHeight();
 
+#ifdef EMSCRIPTEN
+	const uint lineSize        = width * 4; // RGBA (see comment below)
+#else
 	uint linePaddingSize = width % 4;
 	uint lineSize = width * 3 + linePaddingSize;
+#endif
 
 	Common::DumpFile out;
 	if (!out.open(filename)) {
@@ -804,6 +821,14 @@ bool OpenGLSdlGraphics3dManager::saveScreenshot(const Common::Path &filename) co
 
 	Common::Array<uint8> pixels;
 	pixels.resize(lineSize * height);
+#ifdef EMSCRIPTEN	
+	// WebGL doesn't support GL_RGB, see https://registry.khronos.org/webgl/specs/latest/1.0/#5.14.12:
+	// "Only two combinations of format and type are accepted. The first is format RGBA and type UNSIGNED_BYTE. 
+	// The second is an implementation-chosen format. " and the implementation-chosen formats are buggy:
+	// https://github.com/KhronosGroup/WebGL/issues/2747
+	glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels.front());
+	const Graphics::PixelFormat format(4, 8, 8, 8, 8, 0, 8, 16, 24);
+#else
 
 	if (_frameBuffer) {
 		_frameBuffer->detach();
@@ -818,6 +843,8 @@ bool OpenGLSdlGraphics3dManager::saveScreenshot(const Common::Path &filename) co
 #else
 	const Graphics::PixelFormat format(3, 8, 8, 8, 0, 16, 8, 0, 0);
 #endif
+#endif
+
 	Graphics::Surface data;
 	data.init(width, height, lineSize, &pixels.front(), format);
 	data.flipVertical(Common::Rect(width, height));
diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
index d83e19715cc..e3861177bf9 100644
--- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
+++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h
@@ -151,6 +151,20 @@ protected:
 
 	void handleResizeImpl(const int width, const int height) override;
 
+#ifdef EMSCRIPTEN
+	/** 
+	 * See https://registry.khronos.org/webgl/specs/latest/1.0/#2 :
+	 * " By default, after compositing the contents of the drawing buffer shall be cleared to their default values [...]
+	 *   Techniques like synchronous drawing buffer access (e.g., calling readPixels or toDataURL in the same function
+	 *   that renders to the drawing buffer) can be used to get the contents of the drawing buffer "
+	 * 
+	 * This means we need to take the screenshot at the correct time, which we do by queueing taking the screenshot
+	 * for the next frame instead of taking it right away.
+	 */
+	bool _queuedScreenshot = false;
+	void saveScreenshot() override;
+#endif
+
 	bool saveScreenshot(const Common::Path &filename) const override;
 
 	uint _engineRequestedWidth, _engineRequestedHeight;
diff --git a/backends/platform/sdl/emscripten/emscripten.cpp b/backends/platform/sdl/emscripten/emscripten.cpp
index 8c04a93eea7..bf61dc155f4 100644
--- a/backends/platform/sdl/emscripten/emscripten.cpp
+++ b/backends/platform/sdl/emscripten/emscripten.cpp
@@ -97,6 +97,10 @@ Common::Path OSystem_Emscripten::getDefaultConfigFileName() {
 	return Common::Path(Common::String::format("%s/scummvm.ini", getenv("HOME")));
 }
 
+Common::Path OSystem_Emscripten::getScreenshotsPath() {
+	return Common::Path("/tmp/");
+}
+
 bool OSystem_Emscripten::displayLogFile() {
 	if (_logFilePath.empty())
 		return false;
diff --git a/backends/platform/sdl/emscripten/emscripten.h b/backends/platform/sdl/emscripten/emscripten.h
index 4e38f698cc5..0028cef4e9d 100644
--- a/backends/platform/sdl/emscripten/emscripten.h
+++ b/backends/platform/sdl/emscripten/emscripten.h
@@ -30,6 +30,7 @@ public:
 	void setFeatureState(Feature f, bool enable) override;
 	bool getFeatureState(Feature f) override;
 	bool displayLogFile() override;
+	Common::Path getScreenshotsPath() override;
 	void exportFile(const Common::Path &filename);
 
 protected:


Commit: e36640efdfa1cd3840b04a7ec79b61fa5b7f1a18
    https://github.com/scummvm/scummvm/commit/e36640efdfa1cd3840b04a7ec79b61fa5b7f1a18
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: GRAPHICS: Enable OpenGL graphics mode by default

Changed paths:
    backends/platform/sdl/emscripten/emscripten.cpp
    backends/platform/sdl/emscripten/emscripten.h
    dists/emscripten/assets/scummvm.ini


diff --git a/backends/platform/sdl/emscripten/emscripten.cpp b/backends/platform/sdl/emscripten/emscripten.cpp
index bf61dc155f4..cae6c095425 100644
--- a/backends/platform/sdl/emscripten/emscripten.cpp
+++ b/backends/platform/sdl/emscripten/emscripten.cpp
@@ -109,6 +109,11 @@ bool OSystem_Emscripten::displayLogFile() {
 	return true;
 }
 
+#ifdef USE_OPENGL
+OSystem_SDL::GraphicsManagerType OSystem_Emscripten::getDefaultGraphicsManager() const {
+	return GraphicsManagerOpenGL;
+}
+#endif
 
 void OSystem_Emscripten::exportFile(const Common::Path &filename) {
 	Common::File file;
diff --git a/backends/platform/sdl/emscripten/emscripten.h b/backends/platform/sdl/emscripten/emscripten.h
index 0028cef4e9d..20d9f807a03 100644
--- a/backends/platform/sdl/emscripten/emscripten.h
+++ b/backends/platform/sdl/emscripten/emscripten.h
@@ -31,6 +31,9 @@ public:
 	bool getFeatureState(Feature f) override;
 	bool displayLogFile() override;
 	Common::Path getScreenshotsPath() override;
+#ifdef USE_OPENGL
+	GraphicsManagerType getDefaultGraphicsManager() const override;
+#endif
 	void exportFile(const Common::Path &filename);
 
 protected:
diff --git a/dists/emscripten/assets/scummvm.ini b/dists/emscripten/assets/scummvm.ini
index aa2633bef80..5338ebb7306 100644
--- a/dists/emscripten/assets/scummvm.ini
+++ b/dists/emscripten/assets/scummvm.ini
@@ -1,6 +1,4 @@
 [scummvm]
-gfx_mode=opengl
 grouping=company
-renderer=opengl_shaders
 gui_launcher_chooser=grid
 


Commit: 82d0a4b06c6755fa4e21b2fce744f081e4de19e3
    https://github.com/scummvm/scummvm/commit/82d0a4b06c6755fa4e21b2fce744f081e4de19e3
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
EMSCRIPTEN: Load icons directly (not from an archive)

Changed paths:
    backends/platform/sdl/emscripten/emscripten.cpp
    backends/platform/sdl/emscripten/emscripten.h
    dists/emscripten/build.sh
    gui/gui-manager.cpp


diff --git a/backends/platform/sdl/emscripten/emscripten.cpp b/backends/platform/sdl/emscripten/emscripten.cpp
index cae6c095425..705ce128be2 100644
--- a/backends/platform/sdl/emscripten/emscripten.cpp
+++ b/backends/platform/sdl/emscripten/emscripten.cpp
@@ -101,6 +101,10 @@ Common::Path OSystem_Emscripten::getScreenshotsPath() {
 	return Common::Path("/tmp/");
 }
 
+Common::Path OSystem_Emscripten::getDefaultIconsPath() {
+	return Common::Path(DATA_PATH"/gui-icons/");
+}
+
 bool OSystem_Emscripten::displayLogFile() {
 	if (_logFilePath.empty())
 		return false;
diff --git a/backends/platform/sdl/emscripten/emscripten.h b/backends/platform/sdl/emscripten/emscripten.h
index 20d9f807a03..4524067c5f6 100644
--- a/backends/platform/sdl/emscripten/emscripten.h
+++ b/backends/platform/sdl/emscripten/emscripten.h
@@ -31,6 +31,7 @@ public:
 	bool getFeatureState(Feature f) override;
 	bool displayLogFile() override;
 	Common::Path getScreenshotsPath() override;
+	Common::Path getDefaultIconsPath() override;
 #ifdef USE_OPENGL
 	GraphicsManagerType getDefaultGraphicsManager() const override;
 #endif
diff --git a/dists/emscripten/build.sh b/dists/emscripten/build.sh
index 5640ed85143..4780f5cce94 100755
--- a/dists/emscripten/build.sh
+++ b/dists/emscripten/build.sh
@@ -329,23 +329,25 @@ fi
 # Add icons
 #################################
 if [[ "icons" =~ $(echo ^\(${TASKS}\)$) || "build" =~ $(echo ^\(${TASKS}\)$) ]]; then
-
-  if [[ -d "${ROOT_FOLDER}/../scummvm-icons/" ]]; then
+  _icons_dir="${ROOT_FOLDER}/../scummvm-icons/"
+  if [[ -d "$_icons_dir" ]]; then
     echo "Adding files from icons repository "
-    cp "${ROOT_FOLDER}/gui/themes/gui-icons.dat" "${ROOT_FOLDER}/build-emscripten/data"
     cd "${ROOT_FOLDER}/../scummvm-icons/"
+    cd "$_icons_dir"
     "$EMSDK_PYTHON" gen-set.py
     echo "add icons"
-    zip -q -u "${ROOT_FOLDER}/build-emscripten/data/gui-icons.dat" icons/*
+    mkdir -p "${ROOT_FOLDER}/build-emscripten/data/gui-icons"
+    cp -r "$_icons_dir/icons" "${ROOT_FOLDER}/build-emscripten/data/gui-icons/"
     echo "add xml"
-    zip -q -u "${ROOT_FOLDER}/build-emscripten/data/gui-icons.dat" *.xml
+    cp -r "$_icons_dir/"*.xml "${ROOT_FOLDER}/build-emscripten/data/gui-icons/"
     echo "update index"
+    cd "${ROOT_FOLDER}/build-emscripten/data/gui-icons"
+    "$EMSDK_NODE" "$DIST_FOLDER/build-make_http_index.js" >index.json
     cd "${ROOT_FOLDER}/build-emscripten/data"
     "$EMSDK_NODE" "$DIST_FOLDER/build-make_http_index.js" >index.json
   else
     echo "Icons repository not found"
   fi
-
 fi
 
 #################################
diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp
index 34627ade5ba..73125db1289 100644
--- a/gui/gui-manager.cpp
+++ b/gui/gui-manager.cpp
@@ -112,8 +112,14 @@ void GuiManager::initIconsSet() {
 	Common::StackLock lock(_iconsMutex);
 
 	_iconsSet.clear();
-
+#ifdef EMSCRIPTEN
+	Common::Path iconsPath = ConfMan.getPath("iconspath");
+	_iconsSet = Common::SearchSet();
+	_iconsSet.addDirectory("gui-icons/", iconsPath, 0, 3, false);
+	_iconsSetChanged = true;
+#else
 	_iconsSetChanged = Common::generateZipSet(_iconsSet, "gui-icons.dat", "gui-icons*.dat");
+#endif
 }
 
 void GuiManager::computeScaleFactor() {


Commit: d5220a9624656039cbcb2cb21568c5a19efac2cf
    https://github.com/scummvm/scummvm/commit/d5220a9624656039cbcb2cb21568c5a19efac2cf
Author: Christian Kündig (christian at kuendig.info)
Date: 2024-02-27T17:07:13+01:00

Commit Message:
FREESCAPE: Fix missing symbols when compiling against OpenGL ES 2.0

Changed paths:
    engines/freescape/gfx_opengl.cpp
    engines/freescape/gfx_opengl.h


diff --git a/engines/freescape/gfx_opengl.cpp b/engines/freescape/gfx_opengl.cpp
index f1f95c6e848..8a31660df67 100644
--- a/engines/freescape/gfx_opengl.cpp
+++ b/engines/freescape/gfx_opengl.cpp
@@ -31,6 +31,8 @@
 #include "freescape/gfx_opengl.h"
 #include "freescape/gfx_opengl_texture.h"
 
+#ifdef USE_OPENGL_GAME
+
 namespace Freescape {
 
 Renderer *CreateGfxOpenGL(int screenW, int screenH, Common::RenderMode renderMode) {
@@ -497,3 +499,5 @@ Graphics::Surface *OpenGLRenderer::getScreenshot() {
 }
 
 } // End of namespace Freescape
+
+#endif
diff --git a/engines/freescape/gfx_opengl.h b/engines/freescape/gfx_opengl.h
index ef4b3ac612a..e450a39cb41 100644
--- a/engines/freescape/gfx_opengl.h
+++ b/engines/freescape/gfx_opengl.h
@@ -28,6 +28,8 @@
 
 #include "freescape/gfx.h"
 
+#ifdef USE_OPENGL_GAME
+
 namespace Freescape {
 
 class OpenGLRenderer : public Renderer {
@@ -115,4 +117,6 @@ public:
 
 } // End of namespace Freescape
 
+#endif
+
 #endif // FREESCAPE_GFX_OPENGL_H




More information about the Scummvm-git-logs mailing list