magicciv/scripts/render-driver-server.sh

55 lines
2.1 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
# Rendered-game launch for the MCP render driver (p2-86).
#
# Unlike player-api-server.sh (a --headless state bench), this boots the REAL
# game WITH rendering so the driver's `screenshot` command captures real frames.
# MC_AUTO_START=1 skips the menu into an interactive seeded game;
# MC_MCP_RENDER=1 activates mcp_render_driver.gd, which listens on MC_MCP_PORT
# (default 8787). The client (RenderClient) connects over TCP — stdout is not
# used for the protocol (Godot block-buffers windowed stdout).
#
# Env:
# MC_MCP_PORT — driver TCP port (default 8787)
# MC_AUTOSTART_SEED — game seed (default 42)
# MC_AUTOSTART_PLAYERS / MC_AUTOSTART_MAP_SIZE — optional overrides
#
# Linux note: rendered mode needs a display server (weston/xvfb on a GPU node,
# per MAGIC_CIV_CLOUD_HANDOFF.md). macOS renders directly via the windowing
# system. Headless state play is unchanged (player-api-server.sh).
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
: "${MC_MCP_PORT:=8787}"
: "${MC_AUTOSTART_SEED:=42}"
export MC_AUTO_START=1 MC_MCP_RENDER=1 MC_MCP_PORT MC_AUTOSTART_SEED \
MC_AUTOSTART_PLAYERS MC_AUTOSTART_MAP_SIZE
case "$(uname -s)" in
Darwin)
GODOT_BIN="${GODOT_BIN:-godot}"
if ! command -v "$GODOT_BIN" >/dev/null 2>&1; then
echo "ERROR: no godot binary on PATH (set GODOT_BIN or 'brew install godot')." >&2
exit 1
fi
exec "$GODOT_BIN" \
--path "$PROJECT_DIR/src/game" \
--rendering-method gl_compatibility
;;
*)
# Linux: flatpak Godot. Rendered mode requires a display (weston/xvfb);
# the caller is responsible for providing WAYLAND_DISPLAY / DISPLAY.
exec flatpak run --user \
--env=MC_AUTO_START=1 \
--env=MC_MCP_RENDER=1 \
--env=MC_MCP_PORT="$MC_MCP_PORT" \
--env=MC_AUTOSTART_SEED="$MC_AUTOSTART_SEED" \
org.godotengine.Godot \
--path "$PROJECT_DIR/src/game" \
--rendering-method gl_compatibility
;;
esac