71 lines
2.1 KiB
Bash
Executable file
71 lines
2.1 KiB
Bash
Executable file
#!/bin/bash
|
|
# Godot autoplay runner with two headless modes.
|
|
#
|
|
# RENDER_MODE=headless (default) — Godot --headless, no display server.
|
|
# Fastest. Screenshots blank. For bulk simulation / data collection.
|
|
#
|
|
# RENDER_MODE=weston — weston --backend=headless provides a virtual Wayland
|
|
# display with software rendering (llvmpipe). Screenshots work.
|
|
# Requires weston installed on the host.
|
|
set -uo pipefail
|
|
: "${AUTO_PLAY:=true}"
|
|
: "${AUTO_PLAY_DIR:=$HOME/tmp/ap_default}"
|
|
|
|
# Scoped cleanup: only kill prior processes for THIS AUTO_PLAY_DIR, so parallel
|
|
# sibling games (different AUTO_PLAY_DIR) are not disturbed.
|
|
pkill -f "AUTO_PLAY_DIR=$AUTO_PLAY_DIR " 2>/dev/null || true
|
|
pkill -f "AUTO_PLAY_DIR=$AUTO_PLAY_DIR\$" 2>/dev/null || true
|
|
sleep 1
|
|
|
|
: "${AUTO_PLAY_TURN_LIMIT:=500}"
|
|
: "${RENDER_MODE:=headless}"
|
|
|
|
mkdir -p "$AUTO_PLAY_DIR"
|
|
cd "$HOME/Code/@projects/@magic-civilization/src/game"
|
|
SAFETY=$((AUTO_PLAY_TURN_LIMIT * 2 + 300))
|
|
|
|
FLATPAK_ENVS=(
|
|
"--env=AUTO_PLAY=true"
|
|
"--env=AUTO_PLAY_DIR=$AUTO_PLAY_DIR"
|
|
"--env=AUTO_PLAY_TURN_LIMIT=$AUTO_PLAY_TURN_LIMIT"
|
|
)
|
|
if [ -n "${AUTO_PLAY_SEED:-}" ]; then
|
|
FLATPAK_ENVS+=("--env=AUTO_PLAY_SEED=$AUTO_PLAY_SEED")
|
|
fi
|
|
|
|
GODOT_ARGS=("--path" "." "--rendering-method" "gl_compatibility")
|
|
WESTON_PID=""
|
|
|
|
_cleanup() {
|
|
if [ -n "$WESTON_PID" ]; then
|
|
kill "$WESTON_PID" 2>/dev/null || true
|
|
wait "$WESTON_PID" 2>/dev/null || true
|
|
fi
|
|
}
|
|
trap _cleanup EXIT
|
|
|
|
if [ "$RENDER_MODE" = "weston" ]; then
|
|
if ! command -v weston >/dev/null 2>&1; then
|
|
echo "ERROR: RENDER_MODE=weston but weston not found" >&2
|
|
exit 1
|
|
fi
|
|
WESTON_SOCKET="godot-headless-$$"
|
|
weston --backend=headless --socket="$WESTON_SOCKET" --width=1920 --height=1080 \
|
|
>"$AUTO_PLAY_DIR/weston.log" 2>&1 &
|
|
WESTON_PID=$!
|
|
sleep 1
|
|
FLATPAK_ENVS+=(
|
|
"--socket=wayland"
|
|
"--env=WAYLAND_DISPLAY=$WESTON_SOCKET"
|
|
)
|
|
FLATPAK_ENVS+=("--filesystem=xdg-run/${WESTON_SOCKET}")
|
|
else
|
|
GODOT_ARGS+=("--headless")
|
|
fi
|
|
|
|
timeout "$SAFETY" flatpak run --user \
|
|
--filesystem=home \
|
|
"${FLATPAK_ENVS[@]}" \
|
|
org.godotengine.Godot "${GODOT_ARGS[@]}" 2>&1
|
|
EXIT=$?
|
|
echo "EXIT_CODE=$EXIT"
|