Files
vpinball-wasm/scripts/build.sh
T
valknar 487ca40a44 Phase D/F/H: embedding shell - loading progress, fullscreen, file upload, touch controls
package/src/index.ts: fixes a real pre-existing bug (start()/loadTable()
never actually called vpinball_wasm_start with a table path argument),
adds byte-level download progress (onProgress) and requestFullscreen().

package/src/touch-controls.ts: new on-screen virtual flipper/plunger/start
button overlay that synthesizes the actual default keyboard scancodes
(SDL_SCANCODE_LSHIFT/RSHIFT/RETURN, read from InputManager.cpp) as real
KeyboardEvents dispatched on window, matching SDL3's Emscripten keyboard
target - keeps the native input path completely unmodified.

examples/basic/index.html: a real demo page - progress bar, a user-gesture
"Start" button (required for both audio autoplay and fullscreen), a file
picker for self-contained .vpx uploads, and the touch overlay shown on
touch-capable devices.

scripts/build.sh: two real bugs found and fixed via actual browser testing:
- MODULARIZE=1 without EXPORT_ES6=1 produces a classic script, not an ES
  module with a default export - `await import(...)).default` was always
  undefined. Fixes with -sEXPORT_ES6=1.
- --closure 1 silently stripped FS.writeFile/readFile/mkdir down to just
  low-level node ops, breaking runtime table loading with no compile-time
  warning. Dropped until root-caused; -O2 alone is kept.

Verified end-to-end in Chrome: full load->progress->start flow with no
errors, fullscreen actually engaging (document.fullscreenElement true),
and a file-picker-selected table loading correctly (LoadGameFromFilename
/tables/uploaded.vpx in the boot log, followed by a normal render).

README updated to reflect what's now validated vs. still open (real-device
input/audio confirmation remains the main open item).
2026-08-22 16:45:04 +02:00

88 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Configures and builds vpinball itself for the new GL-emscripten CMake
# target, producing dist/vpinball.{js,wasm}.
#
# Requires: scripts/setup.sh and scripts/build-deps.sh have already run.
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "$ROOT_DIR/scripts/versions.sh"
VPINBALL_DIR="$ROOT_DIR/vendor/vpinball"
DEPS_DIR="$ROOT_DIR/build/deps-wasm32"
BUILD_DIR="$ROOT_DIR/build/vpinball-wasm"
DIST_DIR="$ROOT_DIR/dist"
BUILD_TYPE="Release"
if [ "${1:-}" = "--debug" ]; then
BUILD_TYPE="Debug"
fi
if [ ! -d "$VPINBALL_DIR" ]; then
echo "ERROR: vendor/vpinball missing. Run scripts/setup.sh first." >&2
exit 1
fi
if [ ! -d "$DEPS_DIR/lib" ] || [ -z "$(ls -A "$DEPS_DIR/lib" 2>/dev/null)" ]; then
echo "ERROR: build/deps-wasm32 missing/empty. Run scripts/build-deps.sh first." >&2
exit 1
fi
if ! command -v emcc >/dev/null 2>&1; then
echo "ERROR: emcc not on PATH. Run: source $ROOT_DIR/emsdk/emsdk_env.sh" >&2
exit 1
fi
NUM_PROCS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)"
EMSCRIPTEN_LINK_FLAGS=(
-sUSE_WEBGL2=1
-sFULL_ES3=1
-sMIN_WEBGL_VERSION=2
-sMAX_WEBGL_VERSION=2
-sALLOW_MEMORY_GROWTH=1
-sMODULARIZE=1
-sEXPORT_ES6=1
-sEXPORT_NAME=VPinballModule
-sENVIRONMENT=web
-sEXPORTED_RUNTIME_METHODS=FS,ccall,cwrap
-sFORCE_FILESYSTEM=1
-sEXPORTED_FUNCTIONS=_main,_vpinball_wasm_start,_vpinball_wasm_stop,_vpinball_wasm_dispose
-sEXIT_RUNTIME=0
--use-preload-cache
)
if [ "$BUILD_TYPE" = "Debug" ]; then
EMSCRIPTEN_LINK_FLAGS+=(-sASSERTIONS=1 -O0)
else
# CMAKE_BUILD_TYPE=Release only optimizes the compile step; emcc's link
# step needs its own -O level to actually run wasm-opt/dead-code
# elimination. NOTE: --closure 1 was tried here but strips FS.writeFile/
# readFile/mkdir (the FS convenience wrappers EXPORTED_RUNTIME_METHODS=FS
# is supposed to guarantee) down to just low-level node ops - dropped
# until that's root-caused, since a smaller JS glue isn't worth a broken
# runtime table-loading API.
EMSCRIPTEN_LINK_FLAGS+=(-O2)
fi
emcmake cmake \
-S "$VPINBALL_DIR" \
-B "$BUILD_DIR" \
-DRENDERER=GL \
-DPLATFORM=emscripten \
-DARCH=wasm32 \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DVPINBALL_WASM_DEPS_DIR="$DEPS_DIR" \
-DCMAKE_EXE_LINKER_FLAGS="${EMSCRIPTEN_LINK_FLAGS[*]}"
cmake --build "$BUILD_DIR" -- -j"$NUM_PROCS"
mkdir -p "$DIST_DIR"
cp "$BUILD_DIR"/vpinball.js "$DIST_DIR/" 2>/dev/null || true
cp "$BUILD_DIR"/vpinball.wasm "$DIST_DIR/" 2>/dev/null || true
cp "$BUILD_DIR"/vpinball.data "$DIST_DIR/" 2>/dev/null || true
mkdir -p "$ROOT_DIR/package/assets"
cp "$VPINBALL_DIR/tests/assets/test000-default-table.vpx" "$ROOT_DIR/package/assets/default.vpx" 2>/dev/null || true
echo ""
echo "== build.sh complete =="
ls -la "$DIST_DIR"