test: add reproducible 720p visual capture

This commit is contained in:
goose
2026-10-08 22:33:52 -04:00
parent cf102e1e95
commit 23acd47495
6 changed files with 166 additions and 16 deletions
+29 -10
View File
@@ -13,11 +13,16 @@ import sys
import zlib
from pathlib import Path
WIDTH = 1920
HEIGHT = 1080
# Central dungeon measurement region, proportionally equivalent to the former
# 16:9 reference crop while excluding the anchored HUD panels.
VIEWPORT = (384, 60, 1536, 1017)
REFERENCE_WIDTH = 1920
REFERENCE_HEIGHT = 1080
EXPECTED_DIMENSIONS = {
"visual-check.png": (REFERENCE_WIDTH, REFERENCE_HEIGHT),
"visual-check-exit.png": (REFERENCE_WIDTH, REFERENCE_HEIGHT),
"visual-check-compact.png": (1280, 720),
}
# Central dungeon measurement region in the reference 1920×1080 artboard.
# It excludes the anchored HUD panels and is scaled for the real 720p capture.
REFERENCE_VIEWPORT = (384, 60, 1536, 1017)
UNKNOWN = (1, 2, 5)
# Captured explored tiles are texture modulated, so classify their blue-black
# pixels by palette range rather than expecting one flat overlay color.
@@ -70,8 +75,14 @@ def read_png(path: Path) -> tuple[int, int, list[bytes]]:
if header is None or not saw_iend or offset != len(data):
fail("incomplete PNG")
width, height, depth, color_type, compression, filtering, interlace = header
if (width, height) != (WIDTH, HEIGHT):
fail(f"expected {WIDTH}x{HEIGHT} PNG, got {width}x{height}")
expected_dimensions = EXPECTED_DIMENSIONS.get(path.name)
if expected_dimensions is None:
fail(f"unsupported visual capture name: {path.name}")
if (width, height) != expected_dimensions:
fail(
f"expected {expected_dimensions[0]}x{expected_dimensions[1]} PNG, "
f"got {width}x{height}"
)
if depth != 8 or color_type not in (2, 6):
fail("visual capture must be an 8-bit RGB or RGBA PNG")
if (compression, filtering, interlace) != (0, 0, 0):
@@ -162,12 +173,20 @@ def is_explored(pixel: tuple[int, int, int]) -> bool:
return 4 <= red <= 14 and 8 <= green <= 22 and 17 <= blue <= 32 and blue >= green + 4 and green >= red + 3
def viewport_for(width: int, height: int) -> tuple[int, int, int, int]:
scale_x = width / REFERENCE_WIDTH
scale_y = height / REFERENCE_HEIGHT
return tuple(round(coordinate * (scale_x if index % 2 == 0 else scale_y)) for index, coordinate in enumerate(REFERENCE_VIEWPORT))
def measure(path: Path) -> None:
width, height = EXPECTED_DIMENSIONS[path.name]
observed = list(pixels(path))
viewport = viewport_for(width, height)
dungeon_pixels = [
observed[y * WIDTH + x]
for y in range(VIEWPORT[1], VIEWPORT[3])
for x in range(VIEWPORT[0], VIEWPORT[2])
observed[y * width + x]
for y in range(viewport[1], viewport[3])
for x in range(viewport[0], viewport[2])
]
non_black = sum(pixel != (0, 0, 0) for pixel in dungeon_pixels)
unknown_pixels = [pixel for pixel in dungeon_pixels if pixel == UNKNOWN]
+7 -1
View File
@@ -302,6 +302,8 @@ func _get_capture_mode() -> String:
var arguments := OS.get_cmdline_user_args()
if "--capture-exit" in arguments:
return "exit"
if "--visual-check-compact" in arguments:
return "compact"
if "--capture" in arguments:
return "initial"
return ""
@@ -315,7 +317,11 @@ func _capture_visual_check(capture_mode: String) -> void:
await get_tree().process_frame
await get_tree().process_frame
await RenderingServer.frame_post_draw
var filename := "visual-check-exit.png" if capture_mode == "exit" else "visual-check.png"
var filename := "visual-check.png"
if capture_mode == "exit":
filename = "visual-check-exit.png"
elif capture_mode == "compact":
filename = "visual-check-compact.png"
var capture_path := ProjectSettings.globalize_path("res://artifacts/" + filename)
DirAccess.make_dir_recursive_absolute(capture_path.get_base_dir())
var image := get_viewport().get_texture().get_image()
+1 -1
View File
@@ -33,7 +33,7 @@ func _ready() -> void:
func _get_capture_mode() -> bool:
var arguments := OS.get_cmdline_user_args()
return "--capture" in arguments or "--capture-exit" in arguments
return "--capture" in arguments or "--capture-exit" in arguments or "--visual-check-compact" in arguments
func _show_character_creation() -> void:
menu.visible = false
+9 -2
View File
@@ -18,7 +18,8 @@ mkdir -p artifacts
log_path="artifacts/visual-check.log"
initial_capture_path="artifacts/visual-check.png"
exit_capture_path="artifacts/visual-check-exit.png"
rm -f "$initial_capture_path" "$exit_capture_path"
compact_capture_path="artifacts/visual-check-compact.png"
rm -f "$initial_capture_path" "$exit_capture_path" "$compact_capture_path"
: > "$log_path"
runner=()
@@ -34,8 +35,9 @@ fi
run_capture() {
local label="$1"
local capture_argument="$2"
shift 2
set +e
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . -- --"$capture_argument" >>"$log_path" 2>&1
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . "$@" -- --"$capture_argument" >>"$log_path" 2>&1
local status=$?
set -e
if (( status != 0 )); then
@@ -46,6 +48,10 @@ run_capture() {
run_capture "initial" "capture"
run_capture "exit" "capture-exit"
# This is a real 1280×720 window capture, not a unit-level HUD relayout call.
# The fixed window size makes the compact artboard and PNG reproducible under
# Xvfb as well as an interactive DISPLAY.
run_capture "compact" "visual-check-compact" --windowed --resolution 1280x720
# Godot's SCRIPT ERROR / Parse Error diagnostics are actionable application
# failures. Do not treat unrelated backend diagnostics (for example the
# expected xkbcommon Compose warnings emitted by some Snap/Xvfb setups) as an
@@ -65,3 +71,4 @@ measure_capture() {
measure_capture "$initial_capture_path"
measure_capture "$exit_capture_path"
measure_capture "$compact_capture_path"