diff --git a/README.md b/README.md index 46e1efa8..5ccbbd7e 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ HoppysAdventureArcade.exe -- --booth --route=heroes_vs_villains ./HoppysAdventureArcade.x86_64 -- --booth --route=heroes_vs_villains # Linux ``` -Booth mode runs fullscreen and ignores the menu's **Quit Game**, so staff close the window instead. After 90 seconds without input, any game returns to the hub's attract screen, and a lost game sends the player there after a thank-you card instead of offering endless retries. [Run it at a booth](docs/builds.md#run-it-at-a-booth) lists every route and flag. +Booth mode runs fullscreen with no **Quit Game** on the hub, so staff close the window instead, and the hub shows a small QR code to the event's link. After 90 seconds without input, any game returns to the hub's attract screen, and a lost game sends the player there after a thank-you card instead of offering endless retries. [Run it at a booth](docs/builds.md#run-it-at-a-booth) lists every route and flag. For a machine that runs unattended all day, follow the [booth runbook](docs/booth-runbook.md). It sets up a watchdog that restarts the game if it closes or freezes, along with the Mac's kiosk settings, and covers the staff checklist. diff --git a/docs/booth-runbook.md b/docs/booth-runbook.md index 0a548ae7..695f07ad 100644 --- a/docs/booth-runbook.md +++ b/docs/booth-runbook.md @@ -27,7 +27,7 @@ The setup does the following: - It keeps the Mac awake and turns it back on after a power cut. - It turns off the screen saver, automatic updates and crash dialogs. -Booth mode itself runs fullscreen and ignores the menu's **Quit Game**. A game nobody has touched for 90 seconds goes back to the hub's attract screen, and so does a lost game, after a thank-you card for the player ([details](builds.md#run-it-at-a-booth)). +Booth mode itself runs fullscreen, with no **Quit Game** on the hub. A game nobody has touched for 90 seconds goes back to the hub's attract screen, and so does a lost game, after a thank-you card for the player ([details](builds.md#run-it-at-a-booth)). ## Every morning diff --git a/docs/builds.md b/docs/builds.md index dacdeca6..a50c0f3a 100644 --- a/docs/builds.md +++ b/docs/builds.md @@ -33,12 +33,13 @@ open -a "Hoppy’s Adventure Arcade.app" --args -- --booth --route=heroes_vs_vil ``` - **Fullscreen.** The game starts fullscreen without changing the saved settings. -- **Booth QR code.** A scannable, branded CodeRabbit link stays in the top-right corner on every route in booth mode. The provided code points to `https://coderabbit.link/ato26-ad?qr=1`, which identifies QR scans for attribution. To change the destination, regenerate `hoppys-adventure-arcade/Assets/booth/booth_qr.png` from the repository root with `swift hoppys-adventure-arcade/tools/booth/generate_qr.swift` and pass the output path and URL as optional arguments, then rebuild the game. +- **Booth QR code.** In booth mode the hub shows a small, borderless QR code between the title and Hoppy, clear of every tile and label; games don't show it. It points to `https://coderabbit.link/aidevnyc-26-booth-arcade`, the event's coupon short link for this game (`utm_content=booth-arcade`), so scans the arcade drives are counted apart from the booth's other touchpoints. For another event, create that event's own short link for the arcade, regenerate `hoppys-adventure-arcade/Assets/booth/booth_qr.png` from the repository root with `swift hoppys-adventure-arcade/tools/booth/generate_qr.swift`, passing the output path and URL as optional arguments, then rebuild the game. - **How-to-play cards.** Each visitor's first entry into a game opens its how-to-play card. Its pages turn by themselves every 7 seconds (28 seconds at most), so it starts play on its own and never holds off the idle reset. A new visitor starts whenever the hub opens. See [main-menu.md](main-menu.md#how-to-play-cards). - **Idle reset.** After 90 seconds with no keyboard, mouse, touch or controller input, any game returns to the hub, whose rotating previews act as the attract screen. (The old `--attract=` flag is still accepted so saved booth configs keep launching; it logs a warning and changes nothing.) - **Game over.** A lost game doesn't offer unlimited retries. A player gets `--retries=` retries (default 0); after that, the game shows no retry screen. Instead a **GAME OVER** card thanks the player, shows their score and counts down six seconds, then the hub opens for the next player. The count starts again whenever the hub opens. Every game takes part: Heroes vs. Villains, Code City Brawl, the platformer levels and the Endless Runner. Without `--booth`, every game keeps its own retry screen. -- **No quitting from the menu.** The menu's **Quit Game** does nothing in booth mode; staff close the window (Cmd+Q, Alt+F4). +- **No quitting from the menu.** In booth mode the hub has no **Quit Game** button or Esc quit prompt, and Esc opens nothing; staff close the window (Cmd+Q, Alt+F4). - **Launch route.** `--route=` opens a route at launch (`heroes_vs_villains`, `code_city_brawl`, `bay_area_blitz`, `orbital_ops`, `enchanted_repo`, `runner_game`, `credits`, `hub`), with or without `--booth`. An unknown name logs an error and opens the hub. +- **Low-GPU mode.** For a weak GPU such as a Raspberry Pi 5's. `--low-gpu` renders the window at the project's 1280x720 and scales it to the screen, renders the Endless Runner's 3D at 0.4 of the window's width and height instead of 0.85, turns off its glow and its corridor's two fill lights (raising the ambient light in their place), and draws its full-screen grade as a lighter overlay: the vignette, pursuit edge and letterbox stay, while the color grade, grain and speed effects go. It turns on by itself on a V3D GPU (the Pi 5), so a Pi booth needs no new flag; `--full-gpu` keeps it off there. With it on, the game logs one `LowGpu:` line with its settings at startup. `--low-gpu==,...` overrides single settings for measuring, for example `--low-gpu=scale=0.75,post=full`; the keys are in `app/low_gpu.gd`. Elsewhere, and without the flag, nothing changes. - **Keep it running.** `tools/booth/watchdog.sh` relaunches the game whenever it exits and restarts it when it hangs. The watchdog passes `--heartbeat=`, which makes the game rewrite that file with the current time every two seconds; a file that stops changing means the game is stuck. On a Mac, `tools/booth/macos/setup.sh` installs the watchdog as a login item and applies the kiosk settings. The [booth runbook](booth-runbook.md) walks staff through setup, the show days and recovery. - **Session log.** Booth mode records each game session's start and end in `user://booth/`, one file per run of the game (`sessions--.jsonl`). Each entry records the game, the local start and end times, the duration, how the session ended (`menu`, `idle`, `game_over` or `quit`), how many times the player re-entered the game, and how many times they lost (`game_overs`, stage retries included). It records nothing about players and never uses the network. A start with no end means the game stopped without quitting: a crash, a power cut or a forced kill. The game prints its file's full path at startup. `--session-log=` writes to another folder and works without `--booth`, for playtests. diff --git a/docs/main-menu.md b/docs/main-menu.md index 314d7076..54592012 100644 --- a/docs/main-menu.md +++ b/docs/main-menu.md @@ -23,7 +23,7 @@ The hub shows every game as a tile, three columns by two rows, so a visitor star - **Catalog.** `scenes/main_menu/game_catalog.gd` lists the tiles in grid order: route, family eyebrow (Platformer, Endless Runner, Beat'em Up), one-line tagline, the `preview.gd` indices the tile and the showcase use (the first is the tile's art), and the Hoppy reaction. Adding a game means adding an entry there; the grid, the showcase groups and the focus map follow. - **Tile.** `game_tile.gd` is a Button (it extends `menu_button.gd`, so it grows 5% on focus or hover) with its stage art cover-cropped inside the border, a lower scrim, the family, title and tagline, and an "ENTER / A PLAY" prompt while focused or hovered. The art is the same stage plates and runner stills the background previews use, loaded once through `preview.gd`; no separate tile art exists. -- **Navigation.** Left and right wrap within a row. Up and down step between the rows and, past them, to the utility button in the same column (Settings, Quit Game, Credits), which lead back onto the grid. Tab follows the order tiles, Settings, Quit Game, Credits (`main_menu.gd` `buttons`). Mouse hover focuses nothing but drives the preview and Hoppy; a click launches. +- **Navigation.** Left and right wrap within a row. Up and down step between the rows and, past them, to the utility button in the same column (Settings, Quit Game, Credits; booth mode has no Quit Game), which lead back onto the grid. Tab follows the order tiles, Settings, Quit Game, Credits (`main_menu.gd` `buttons`). Mouse hover focuses nothing but drives the preview and Hoppy; a click launches. - **Launch and return.** A tile calls `AppRouter.go()` with its gameplay route, so the first entry opens the game's how-to-play card. The hub is the only menu: the per-genre menus of the three-button hub (`platformer_menu`, `runner_menu`, `beatem_menu`) and their routes (`platformer`, `runner`, `beatem_up`) are gone, and every way out of a game lands here. **Main Menu** on a game's pause menu, results, game-over or victory screen, the booth's idle return and its next-player card all call `AppRouter.go("hub")`. The runner's leaderboard moved into its pause menu (see [Pause menu](#pause-menu)). - **Hoppy.** The menu mascot stands top right, beside the title, at two thirds of its old size. The hovered tile's family picks the reaction: platformer jump, 3D runner, brawler jab. diff --git a/docs/previews/booth-hub-before-after.jpg b/docs/previews/booth-hub-before-after.jpg new file mode 100644 index 00000000..2e500637 Binary files /dev/null and b/docs/previews/booth-hub-before-after.jpg differ diff --git a/hoppys-adventure-arcade/Assets/booth/booth_qr.png b/hoppys-adventure-arcade/Assets/booth/booth_qr.png index 377fd627..84af2588 100644 Binary files a/hoppys-adventure-arcade/Assets/booth/booth_qr.png and b/hoppys-adventure-arcade/Assets/booth/booth_qr.png differ diff --git a/hoppys-adventure-arcade/Assets/booth/booth_qr_logo.png b/hoppys-adventure-arcade/Assets/booth/booth_qr_logo.png deleted file mode 100644 index e8179d9b..00000000 Binary files a/hoppys-adventure-arcade/Assets/booth/booth_qr_logo.png and /dev/null differ diff --git a/hoppys-adventure-arcade/Assets/booth/booth_qr_logo.png.import b/hoppys-adventure-arcade/Assets/booth/booth_qr_logo.png.import deleted file mode 100644 index a46fda9a..00000000 --- a/hoppys-adventure-arcade/Assets/booth/booth_qr_logo.png.import +++ /dev/null @@ -1,40 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://dp1njvgw18v7c" -path="res://.godot/imported/booth_qr_logo.png-8be0cf10ff0693dea7aa858282c39071.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://Assets/booth/booth_qr_logo.png" -dest_files=["res://.godot/imported/booth_qr_logo.png-8be0cf10ff0693dea7aa858282c39071.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/uastc_level=0 -compress/rdo_quality_loss=0.0 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/channel_remap/red=0 -process/channel_remap/green=1 -process/channel_remap/blue=2 -process/channel_remap/alpha=3 -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 diff --git a/hoppys-adventure-arcade/app/app_router.gd b/hoppys-adventure-arcade/app/app_router.gd index c375b39c..abf5c706 100644 --- a/hoppys-adventure-arcade/app/app_router.gd +++ b/hoppys-adventure-arcade/app/app_router.gd @@ -3,7 +3,7 @@ const BoothLog := preload("res://app/booth_log.gd") const BoothHeartbeat := preload("res://app/booth_heartbeat.gd") const NextPlayerCard := preload("res://app/next_player_card.gd") const BoothSoak := preload("res://app/booth_soak.gd") -const BoothQrOverlay := preload("res://app/booth_qr_overlay.gd") +const LowGpu := preload("res://app/low_gpu.gd") const HowToPlay := preload("res://app/how_to_play.gd") const HowToPlayData := preload("res://app/how_to_play_data.gd") const ROUTES := { @@ -20,10 +20,10 @@ const ROUTES := { ## nonzero on the first failure. tools/build/export_game.py runs it against each export. const SMOKE_FLAG := "--smoke-routes" const SMOKE_FRAMES := 30 -## Booth mode (` -- --booth`) is for unattended kiosks: the game runs fullscreen, the menu's -## Quit does nothing, and after IDLE_SECONDS without input any route returns to the hub, whose -## rotating previews are the attract screen. `--route=` opens a route at launch, with or -## without --booth. Both are off unless passed. +## Booth mode (` -- --booth`) is for unattended kiosks: the game runs fullscreen, the hub +## offers no way to quit and shows the booth QR code, and after IDLE_SECONDS without input any route +## returns to the hub, whose rotating previews are the attract screen. `--route=` opens a +## route at launch, with or without --booth. Both are off unless passed. const BOOTH_FLAG := "--booth" const ROUTE_PREFIX := "--route=" const IDLE_SECONDS := 90.0 @@ -62,7 +62,6 @@ var next_player: NextPlayerCard var next_player_left := 0.0 ## The soak test (app/booth_soak.gd), when the game was launched with `--soak=`. var soak: BoothSoak -var booth_qr: Control ## How-to-play cards (app/how_to_play.gd): the first time a visitor enters a game, its card opens ## over it. A visitor starts when the hub opens, so retries and restarts skip the card. Test suites ## run with --script and get no cards unless they set this; soaks get none either. @@ -81,11 +80,13 @@ func _ready() -> void: veil.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) veil.mouse_filter = Control.MOUSE_FILTER_IGNORE veil.modulate.a = 0 - booth_qr = BoothQrOverlay.new() - booth_qr.visible = false - add_child(booth_qr) add_child(veil) var args := OS.get_cmdline_user_args() + # Low-GPU mode (app/low_gpu.gd): `--low-gpu`, or a V3D GPU unless `--full-gpu`. + LowGpu.configure(args, RenderingServer.get_video_adapter_name()) + LowGpu.apply_window(get_tree().root) + if LowGpu.enabled or LowGpu.OFF_FLAG in args: + print(LowGpu.summary()) if SMOKE_FLAG in args: smoke_routes.call_deferred() return @@ -250,8 +251,6 @@ func set_booth(enabled: bool) -> void: # A card counting down over a paused, finished game would strand it: hand off right away. var finishing := not enabled and next_player != null and next_player.visible booth = enabled - if booth_qr: - booth_qr.visible = enabled idle_seconds = 0.0 AudioService.set_attract(enabled) game_overs = 0 diff --git a/hoppys-adventure-arcade/app/booth_qr_overlay.gd b/hoppys-adventure-arcade/app/booth_qr_overlay.gd deleted file mode 100644 index 28cdcb2b..00000000 --- a/hoppys-adventure-arcade/app/booth_qr_overlay.gd +++ /dev/null @@ -1,56 +0,0 @@ -extends Control - -const QR_TEXTURE: Texture2D = preload("res://Assets/booth/booth_qr.png") - -func _ready() -> void: - set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) - mouse_filter = Control.MOUSE_FILTER_IGNORE - var panel := PanelContainer.new() - panel.name = "BoothQrPanel" - panel.set_anchors_preset(Control.PRESET_TOP_RIGHT) - panel.offset_left = -208 - panel.offset_top = 24 - panel.offset_right = -24 - panel.offset_bottom = 230 - panel.mouse_filter = Control.MOUSE_FILTER_IGNORE - var panel_style := StyleBoxFlat.new() - panel_style.bg_color = Color("fffaf2") - panel_style.border_color = Color("182432") - panel_style.set_border_width_all(2) - panel_style.set_corner_radius_all(8) - panel_style.content_margin_left = 10 - panel_style.content_margin_right = 10 - panel_style.content_margin_top = 8 - panel_style.content_margin_bottom = 8 - panel.add_theme_stylebox_override("panel", panel_style) - add_child(panel) - - var content := VBoxContainer.new() - content.alignment = BoxContainer.ALIGNMENT_CENTER - content.add_theme_constant_override("separation", 4) - content.mouse_filter = Control.MOUSE_FILTER_IGNORE - panel.add_child(content) - - var heading := Label.new() - heading.text = "SCAN TO LEARN MORE" - heading.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER - heading.add_theme_font_size_override("font_size", 11) - heading.add_theme_color_override("font_color", Color("182432")) - heading.mouse_filter = Control.MOUSE_FILTER_IGNORE - content.add_child(heading) - - var code := TextureRect.new() - code.texture = QR_TEXTURE - code.custom_minimum_size = Vector2(148, 148) - code.expand_mode = TextureRect.EXPAND_IGNORE_SIZE - code.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED - code.mouse_filter = Control.MOUSE_FILTER_IGNORE - content.add_child(code) - - var attribution := Label.new() - attribution.text = "CODERABBIT.LINK" - attribution.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER - attribution.add_theme_font_size_override("font_size", 10) - attribution.add_theme_color_override("font_color", Color("536271")) - attribution.mouse_filter = Control.MOUSE_FILTER_IGNORE - content.add_child(attribution) diff --git a/hoppys-adventure-arcade/app/booth_qr_overlay.gd.uid b/hoppys-adventure-arcade/app/booth_qr_overlay.gd.uid deleted file mode 100644 index ad0e3809..00000000 --- a/hoppys-adventure-arcade/app/booth_qr_overlay.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://bxotudq7alix7 diff --git a/hoppys-adventure-arcade/app/low_gpu.gd b/hoppys-adventure-arcade/app/low_gpu.gd new file mode 100644 index 00000000..6e313ecc --- /dev/null +++ b/hoppys-adventure-arcade/app/low_gpu.gd @@ -0,0 +1,122 @@ +extends RefCounted +## Low-GPU mode, for weak GPUs such as the Raspberry Pi 5's V3D. ` -- --low-gpu` trades some +## image quality for frame rate and leaves everything else as it was. It also turns on by itself on +## a V3D GPU (AUTO_ADAPTERS), so a Pi booth needs no new launch flag; `--full-gpu` keeps it off +## there. Elsewhere it is off unless passed. AppRouter configures it once at launch, and the scenes +## it changes read it while they build: +## cap The window renders at the project's 1280x720 (its aspect expanded, as before) and is +## scaled up to the screen, so a 1080p or 4K TV costs what 720p does. Window content scale +## mode "viewport" instead of "canvas_items". +## scale The runner's 3D renders at most at this fraction of the window (its own retro scale is +## 0.85), with the same bilinear upscale. 0.4 by default. +## glow The runner's glow (bloom) pass; off in low-GPU mode. +## fog The runner's depth fog; kept, it costs almost nothing. +## adjust The runner's color adjustment; kept. +## post The runner's full-screen grade (scenes/runner/ui/post_fx.gd). "lite" draws it as a blended +## overlay without reading the screen, which skips the backbuffer copy: the pursuit edge and +## bars, letterbox and vignette stay, the color grade, grain, aberration and speed spokes go. +## "full" keeps the original, "off" hides it. +## omni The runner corridor's two fill lights (the deck bounce and the key light). The +## Compatibility renderer shades each omni light per pixel for every object it reaches; +## off, the default, hides both and raises the ambient light by OMNI_AMBIENT in their place. +## `--low-gpu==,...` turns the mode on with single settings overridden, for measuring, +## for example `--low-gpu=scale=0.75,post=full`. +const FLAG := "--low-gpu" +const OPTIONS_PREFIX := "--low-gpu=" +const OFF_FLAG := "--full-gpu" +const AUTO_ADAPTERS := ["V3D"] +const DEFAULTS := {"cap": true, "scale": 0.4, "glow": false, "fog": true, "adjust": true, "post": "lite", + "omni": false} +const POST_MODES := ["full", "lite", "off"] +const MIN_SCALE := 0.25 +## Ambient energy added to the runner's environment when its fill lights are off. +const OMNI_AMBIENT := 0.2 + +static var enabled := false +## Why the mode is on or off, for the launch log. +static var reason := "off" +static var settings: Dictionary = DEFAULTS.duplicate() + +## Reads the user args and the GPU's name. Called by AppRouter at launch; tests call it directly. +static func configure(args: PackedStringArray, adapter: String) -> void: + enabled = false + reason = "off" + settings = DEFAULTS.duplicate() + if OFF_FLAG in args: + reason = OFF_FLAG + return + for arg in args: + if arg == FLAG: + enabled = true + reason = FLAG + elif arg.begins_with(OPTIONS_PREFIX): + enabled = true + reason = arg + _parse(arg.substr(OPTIONS_PREFIX.length())) + if enabled: + return + for name: String in AUTO_ADAPTERS: + if adapter.to_upper().contains(name): + enabled = true + reason = "GPU %s" % adapter + return + +static func _parse(options: String) -> void: + for pair in options.split(",", false): + var parts := pair.split("=", true, 1) + var key := parts[0].strip_edges() + var value := parts[1].strip_edges().to_lower() if parts.size() == 2 else "" + match key: + "cap", "glow", "fog", "adjust", "omni": + if value in ["1", "true", "on", "yes"]: + settings[key] = true + elif value in ["0", "false", "off", "no"]: + settings[key] = false + else: + push_warning("LowGpu: %s wants on or off, not '%s'" % [key, value]) + "scale": + if value.is_valid_float(): + settings.scale = clampf(value.to_float(), MIN_SCALE, 1.0) + else: + push_warning("LowGpu: scale wants a number, not '%s'" % value) + "post": + if value in POST_MODES: + settings.post = value + else: + push_warning("LowGpu: post wants one of %s, not '%s'" % [POST_MODES, value]) + _: + push_warning("LowGpu: unknown setting '%s'" % key) + +static func summary() -> String: + if not enabled: + return "LowGpu: off (%s)" % reason + return "LowGpu: on (%s): cap=%s scale=%s glow=%s fog=%s adjust=%s post=%s omni=%s" % [reason, + settings.cap, settings.scale, settings.glow, settings.fog, settings.adjust, settings.post, settings.omni] + +## The window's render cap; AppRouter applies it to the root window at launch. +static func apply_window(window: Window) -> void: + if enabled and bool(settings.cap): + window.content_scale_mode = Window.CONTENT_SCALE_MODE_VIEWPORT + +## The 3D render scale for a scene that asks for `base`. +static func render_scale(base: float) -> float: + return minf(base, float(settings.scale)) if enabled else base + +## Applies the environment settings to the runner's Environment. +static func apply_environment(environment: Environment) -> void: + if not enabled or environment == null: + return + if not bool(settings.glow): + environment.glow_enabled = false + if not bool(settings.fog): + environment.fog_enabled = false + if not bool(settings.adjust): + environment.adjustment_enabled = false + +## "full", "lite" or "off" for the runner's full-screen grade; "full" when the mode is off. +static func post_mode() -> String: + return String(settings.post) if enabled else "full" + +## Whether the runner corridor keeps its omni fill lights; always when the mode is off. +static func keep_omni_lights() -> bool: + return not enabled or bool(settings.omni) diff --git a/hoppys-adventure-arcade/app/low_gpu.gd.uid b/hoppys-adventure-arcade/app/low_gpu.gd.uid new file mode 100644 index 00000000..42b33965 --- /dev/null +++ b/hoppys-adventure-arcade/app/low_gpu.gd.uid @@ -0,0 +1 @@ +uid://blnc42adnbl5r diff --git a/hoppys-adventure-arcade/scenes/main_menu/main_menu.gd b/hoppys-adventure-arcade/scenes/main_menu/main_menu.gd index d54f2317..17200aff 100644 --- a/hoppys-adventure-arcade/scenes/main_menu/main_menu.gd +++ b/hoppys-adventure-arcade/scenes/main_menu/main_menu.gd @@ -5,10 +5,16 @@ const Prompts := preload("res://app/controller_prompts.gd") const GameCatalog = preload("res://scenes/main_menu/game_catalog.gd") const GameTile = preload("res://scenes/main_menu/game_tile.gd") const TITLE_Y := 46.0 +## Booth mode's QR code (tools/booth/generate_qr.swift): the event's coupon short link for this game, +## drawn 1:1 in the band between the title and Hoppy, its top level with the eyebrow and its left +## edge with the third tile column, so it covers no tile, label or Hoppy. +const BOOTH_QR: Texture2D = preload("res://Assets/booth/booth_qr.png") +const BOOTH_QR_POSITION := Vector2(841, 30) @onready var showcase = $Showcase @onready var hoppy = $Interface/Hoppy var ui: Control -## The six game tiles in grid order, then Settings, Quit Game and Credits. +## The six game tiles in grid order, then Settings, Quit Game and Credits. Booth mode has no Quit +## Game: staff close the window instead. var buttons: Array[Button] = [] var tiles: Array[Button] = [] var utilities: Array[Button] = [] @@ -24,6 +30,7 @@ var footer_shade: TextureRect var title: VBoxContainer var elapsed := 0.0 var save_warning: Label +var booth_qr: Control func _ready() -> void: ui = Control.new() @@ -92,14 +99,14 @@ func _ready() -> void: # Wider than the focus arrow's 25 px reach, so it never sits on the neighbouring button. utility_row.add_theme_constant_override("separation", 28) ui.add_child(utility_row) - for i in 2: - var button := Style.button("Settings" if i == 0 else "Quit Game", 46) + for text in ["Settings"] if AppRouter.booth else ["Settings", "Quit Game"]: + var button := Style.button(text, 46) button.custom_minimum_size.x = 160 utility_row.add_child(button) buttons.append(button) utilities.append(button) _connect_button(button, -1) - button.pressed.connect(_open_settings.bind(button) if i == 0 else _open_quit.bind(button)) + button.pressed.connect(_open_settings.bind(button) if text == "Settings" else _open_quit.bind(button)) # Last in `buttons`, so the tiles come first and Settings and Quit Game keep their places. var credits := Style.button("Credits", 46) credits.name = "CreditsButton" @@ -112,8 +119,8 @@ func _ready() -> void: _wire_focus() var footer := Style.label("", 12, Color("9baebc")) Prompts.track(footer, func() -> String: - return "← → ↑ ↓ SELECT %s PLAY %s QUIT" % [ - Prompts.either("ENTER", &"ui_accept", true), Prompts.either("ESC", &"ui_cancel", true)]) + var play := "← → ↑ ↓ SELECT %s PLAY" % Prompts.either("ENTER", &"ui_accept", true) + return play if AppRouter.booth else play + " %s QUIT" % Prompts.either("ESC", &"ui_cancel", true)) footer.position = Vector2(76, 672) ui.add_child(footer) caption = Style.label("", 18) @@ -131,6 +138,8 @@ func _ready() -> void: preview_note.size.x = 563 preview_note.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT ui.add_child(preview_note) + if AppRouter.booth: + _add_booth_qr() showcase.preview_changed.connect(_preview_changed) _preview_changed(showcase.active_index) get_viewport().size_changed.connect(_layout) @@ -199,10 +208,33 @@ func _input(event: InputEvent) -> void: if event.is_action_pressed("ui_cancel"): if modal: _close_modal() - else: + elif not AppRouter.booth: _open_quit(utilities[1]) get_viewport().set_input_as_handled() +## Small and borderless: the code in the title's cream, with a muted caption to its left. +func _add_booth_qr() -> void: + booth_qr = Control.new() + booth_qr.name = "BoothQr" + booth_qr.position = BOOTH_QR_POSITION + booth_qr.size = BOOTH_QR.get_size() + booth_qr.mouse_filter = Control.MOUSE_FILTER_IGNORE + ui.add_child(booth_qr) + var code := TextureRect.new() + code.name = "Code" + code.texture = BOOTH_QR + code.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST + code.self_modulate = Style.CREAM + code.mouse_filter = Control.MOUSE_FILTER_IGNORE + booth_qr.add_child(code) + var label := Style.label("SCAN TO\nLEARN MORE", 11, Color("9baebc")) + label.name = "Caption" + label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + label.position = Vector2(-130, 0) + label.size = Vector2(120, BOOTH_QR.get_height()) + booth_qr.add_child(label) + func _connect_button(button: Button, group: int, arrow_marker := true) -> void: if arrow_marker: var arrow := Style.label("›", 26, Style.MINT) @@ -323,7 +355,7 @@ func _open_settings(invoker: Control) -> void: first.grab_focus() func _open_quit(invoker: Control) -> void: - if modal or AppRouter.busy: return + if modal or AppRouter.busy or AppRouter.booth: return var column := _make_modal(invoker, "LEAVING THE ARCADE?") column.add_child(Style.label("There's always another adventure.", 16)) var cancel := Style.button("Keep playing") diff --git a/hoppys-adventure-arcade/scenes/runner/environment/corridor.gd b/hoppys-adventure-arcade/scenes/runner/environment/corridor.gd index daefa2e3..1b4d29cf 100644 --- a/hoppys-adventure-arcade/scenes/runner/environment/corridor.gd +++ b/hoppys-adventure-arcade/scenes/runner/environment/corridor.gd @@ -12,6 +12,7 @@ var _pillar_material: ShaderMaterial var _rack_batches: Array[MultiMesh] = [] var _racks: MultiMesh const Atlas = preload("res://scenes/runner/environment/hifi/wall_atlas.gd") +const LowGpu = preload("res://app/low_gpu.gd") @export_range(0.25, 1.0, 0.05) var retro_scale := 0.5 var phase: StringName = &"idle" var boss_arena := false @@ -60,6 +61,7 @@ func _ready() -> void: var env := WorldEnvironment.new() env.name = "Env" _environment = Materials.environment() + LowGpu.apply_environment(_environment) env.environment = _environment add_child(env) _sun = DirectionalLight3D.new() @@ -322,14 +324,16 @@ func _apply_retro_scale() -> void: if not _scaling_owners.has(viewport_id): _scaling_owners[viewport_id] = [] var owners: Array = _scaling_owners[viewport_id] + # Low-GPU mode (app/low_gpu.gd) may render the 3D smaller still. + var applied := LowGpu.render_scale(retro_scale) owners.append({ "id": get_instance_id(), "previous_scale": _viewport.scaling_3d_scale, "previous_mode": _viewport.scaling_3d_mode, - "applied_scale": retro_scale, + "applied_scale": applied, }) _viewport.scaling_3d_mode = Viewport.SCALING_3D_MODE_BILINEAR - _viewport.scaling_3d_scale = retro_scale + _viewport.scaling_3d_scale = applied _scaling_registered = true func _exit_tree() -> void: diff --git a/hoppys-adventure-arcade/scenes/runner/environment/starship/starship_corridor.gd b/hoppys-adventure-arcade/scenes/runner/environment/starship/starship_corridor.gd index d5dbfb0c..e3325058 100644 --- a/hoppys-adventure-arcade/scenes/runner/environment/starship/starship_corridor.gd +++ b/hoppys-adventure-arcade/scenes/runner/environment/starship/starship_corridor.gd @@ -38,6 +38,12 @@ func _ready() -> void: key.process_mode = Node.PROCESS_MODE_PAUSABLE key.physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF add_child(key) + if not LowGpu.keep_omni_lights(): + # Low-GPU mode (app/low_gpu.gd): each omni light adds lighting work to every pixel it reaches, + # so ambient light stands in for the two fill lights. + key.visible = false + starship.deck_light.visible = false + _environment.ambient_light_energy += LowGpu.OMNI_AMBIENT set_pursuit(_pursuit) starship.sync(_offset,_clock,global_transform,boss_arena,0.0) diff --git a/hoppys-adventure-arcade/scenes/runner/shaders/post_grade_lite.gdshader b/hoppys-adventure-arcade/scenes/runner/shaders/post_grade_lite.gdshader new file mode 100644 index 00000000..e56ef662 --- /dev/null +++ b/hoppys-adventure-arcade/scenes/runner/shaders/post_grade_lite.gdshader @@ -0,0 +1,38 @@ +shader_type canvas_item; +render_mode unshaded, blend_mix; + +// Low-GPU stand-in for post_grade.gdshader (app/low_gpu.gd), driven by the same uniforms from +// post_fx.gd. It never reads the screen, so the renderer skips the backbuffer copy, and it draws as +// one blended overlay. The vignette, pursuit edge, pursuit bars and letterbox come out exactly as +// in the full grade; the color grade, grain, aberration, Nitro lift and speed spokes are left out. +uniform float clock = 0.0; +uniform float grain_seed = 17.0; +uniform float grade : hint_range(0.0, 1.0) = 0.85; +uniform float grain : hint_range(0.0, 0.03) = 0.018; +uniform float vignette : hint_range(0.0, 1.0) = 0.16; +uniform float strength : hint_range(0.0, 1.0) = 0.0; +uniform vec4 color : source_color = vec4(1.0, 0.302, 0.239, 1.0); +uniform float corner_bars : hint_range(0.0, 1.0) = 0.0; +uniform float pulse = 0.0; +uniform float scanlines = 0.0; +uniform float aberration : hint_range(0.0, 1.0) = 0.0; +uniform float letterbox : hint_range(0.0, 1.0) = 0.0; +uniform float speed : hint_range(0.0, 1.0) = 0.0; +uniform float bloom_lift : hint_range(0.0, 1.0) = 0.0; + +void fragment() { + vec2 uv = SCREEN_UV; + vec2 centered = uv - 0.5; + float edge = smoothstep(0.25, 1.25, length(centered * 2.0)); + float pursuit_alpha = clamp(edge * strength * (0.8 + 0.2 * pulse), 0.0, 0.72); + float border = min(uv.y, 1.0 - uv.y); + float pursuit_bars = (1.0 - smoothstep(corner_bars * 0.06, corner_bars * 0.06 + SCREEN_PIXEL_SIZE.y, border)) * step(0.001, corner_bars) * 0.65; + float cinema_bars = (1.0 - smoothstep(letterbox * 0.065, letterbox * 0.065 + SCREEN_PIXEL_SIZE.y, border)) * step(0.001, letterbox); + float bars = max(pursuit_bars, cinema_bars); + // The full grade computes ((src * (1 - edge * vignette)) mixed toward color * 0.28 by + // pursuit_alpha) * (1 - bars). As a mix blend, out = rgb * a + src * (1 - a), that is: + float keep = (1.0 - edge * vignette) * (1.0 - pursuit_alpha) * (1.0 - bars); + float a = 1.0 - keep; + vec3 tint = color.rgb * 0.28 * pursuit_alpha * (1.0 - bars); + COLOR = vec4(a > 0.0001 ? tint / a : vec3(0.0), a); +} diff --git a/hoppys-adventure-arcade/scenes/runner/shaders/post_grade_lite.gdshader.uid b/hoppys-adventure-arcade/scenes/runner/shaders/post_grade_lite.gdshader.uid new file mode 100644 index 00000000..a73cf8b8 --- /dev/null +++ b/hoppys-adventure-arcade/scenes/runner/shaders/post_grade_lite.gdshader.uid @@ -0,0 +1 @@ +uid://ctxlx83561hn8 diff --git a/hoppys-adventure-arcade/scenes/runner/ui/post_fx.gd b/hoppys-adventure-arcade/scenes/runner/ui/post_fx.gd index 6dcc53fc..2c1db09e 100644 --- a/hoppys-adventure-arcade/scenes/runner/ui/post_fx.gd +++ b/hoppys-adventure-arcade/scenes/runner/ui/post_fx.gd @@ -1,6 +1,8 @@ extends CanvasLayer ## A single Compatibility post draw. Mount above world and below ungraded UI (layer > 9). const PostGrade = preload("res://scenes/runner/shaders/post_grade.gdshader") +const PostGradeLite = preload("res://scenes/runner/shaders/post_grade_lite.gdshader") +const LowGpu = preload("res://app/low_gpu.gd") const DEFAULT_SETTINGS := {"grade": true, "grain": true, "vignette": true, "pursuit": false, "aberration": true, "letterbox": true, "speed": true, "bloom_lift": true} var settings: Dictionary = DEFAULT_SETTINGS.duplicate() var material := ShaderMaterial.new() @@ -31,7 +33,10 @@ func _init() -> void: layer = 9 process_mode = Node.PROCESS_MODE_PAUSABLE physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF - material.shader = PostGrade + # Low-GPU mode (app/low_gpu.gd) swaps in the overlay without a screen read, or hides the pass. + var post := LowGpu.post_mode() + material.shader = PostGradeLite if post == "lite" else PostGrade + screen.visible = post != "off" screen.name = "PostPass" screen.material = material screen.mouse_filter = Control.MOUSE_FILTER_IGNORE diff --git a/hoppys-adventure-arcade/scenes/runner/warmup/gpu_warmup.gd b/hoppys-adventure-arcade/scenes/runner/warmup/gpu_warmup.gd index 3d4f4661..34fe44e6 100644 --- a/hoppys-adventure-arcade/scenes/runner/warmup/gpu_warmup.gd +++ b/hoppys-adventure-arcade/scenes/runner/warmup/gpu_warmup.gd @@ -43,6 +43,8 @@ const FX_SIGNALS: Array[StringName] = [&"boss_attack_planned", &"boss_attack_tel const Vignette = preload("res://scenes/runner/shaders/vignette.gdshader") const Scanline = preload("res://scenes/runner/shaders/scanline_portrait.gdshader") const PostGrade = preload("res://scenes/runner/shaders/post_grade.gdshader") +const PostGradeLite = preload("res://scenes/runner/shaders/post_grade_lite.gdshader") +const LowGpu = preload("res://app/low_gpu.gd") ## Frame 1 compiles draw and particle-process shaders, frame 2 draws particles that emitted. const FRAMES := 2 ## Copies of each batch sit at these distances down the track from Hoppy, so every light @@ -567,7 +569,9 @@ func _canvas() -> void: var swatch := GradientTexture2D.new() swatch.width = 8 swatch.height = 8 - for shader: Shader in [Vignette, Scanline, PostGrade]: + # Low-GPU mode's lite grade (app/low_gpu.gd) replaces the screen-reading one. + var grade: Shader = PostGradeLite if LowGpu.post_mode() == "lite" else PostGrade + for shader: Shader in [Vignette, Scanline, grade]: for textured in [false, true]: var rect: Control = TextureRect.new() if textured else ColorRect.new() if textured: rect.set(&"texture", swatch) diff --git a/hoppys-adventure-arcade/tests/booth_hub.gd b/hoppys-adventure-arcade/tests/booth_hub.gd new file mode 100644 index 00000000..75150479 --- /dev/null +++ b/hoppys-adventure-arcade/tests/booth_hub.gd @@ -0,0 +1,115 @@ +extends SceneTree +## The hub in booth mode: no Quit Game button or Esc prompt, Esc opens nothing, and the booth QR code +## is drawn 1:1, unframed, and clear of every tile (even grown), button, label and Hoppy. Outside +## booth mode the hub has no QR code. Canvas-items stretch scales the 1280x720 frame as a whole, so +## a layout clear at 1280x720 is clear at 1920x1080 too. +## Run headless with --path --script res://tests/booth_hub.gd. +const GameCatalog := preload("res://scenes/main_menu/game_catalog.gd") +const MAIN_MENU := "res://scenes/main_menu/main_menu.tscn" +## menu_button.gd grows a hovered or focused tile by this much about its centre. +const TILE_GROW := 1.05 +var failures := 0 +var router: Node + +func _initialize() -> void: + call_deferred("run") + +func check(ok: bool, message: String) -> void: + print("PASS: " if ok else "FAIL: ", message) + if not ok: + failures += 1 + +func wait(seconds: float) -> void: + await create_timer(seconds).timeout + +func open_hub() -> Node: + change_scene_to_file(MAIN_MENU) + await wait(0.3) + return current_scene + +## Rect2 of a sprite in the hub's frame, from its texture, offset and transform. +func sprite_rect(item: Node2D, texture: Texture2D, offset: Vector2, frame: Control) -> Rect2: + var local := Rect2(offset - texture.get_size() * 0.5, texture.get_size()) + var to_frame := frame.get_global_transform().affine_inverse() * item.get_global_transform() + return to_frame * local + +func frame_rect(control: Control, frame: Control) -> Rect2: + return frame.get_global_transform().affine_inverse() * control.get_global_rect() + +func run() -> void: + router = root.get_node("AppRouter") + var menu: Node = await open_hub() + check(menu.get_node_or_null("Interface").find_child("BoothQr", true, false) == null, + "Outside booth mode the hub shows no QR code") + check(menu.buttons.any(func(b: Button) -> bool: return b.text == "Quit Game"), + "Outside booth mode the hub keeps Quit Game") + + router.set_booth(true) + menu = await open_hub() + var frame: Control = menu.ui + var texts: Array = menu.buttons.map(func(b: Button) -> String: return b.text) + check(texts.size() == GameCatalog.GAMES.size() + 2 and not texts.has("Quit Game") + and texts[-2] == "Settings" and texts[-1] == "Credits", + "Booth mode's hub has Settings and Credits but no Quit Game") + var labels: Array[Label] = [] + labels.assign(frame.find_children("*", "Label", true, false)) + check(not labels.any(func(l: Label) -> bool: return "QUIT" in l.text.to_upper()), + "No label on the booth hub mentions quitting") + + var cancel := InputEventAction.new() + cancel.action = &"ui_cancel" + cancel.pressed = true + Input.parse_input_event(cancel) + await wait(0.2) + check(menu.modal == null, "Esc on the booth hub opens nothing") + + var qr: Control = menu.booth_qr + check(qr != null and qr.is_visible_in_tree(), "Booth mode's hub shows the QR code") + var code: TextureRect = qr.get_node("Code") + var caption: Label = qr.get_node("Caption") + check(code.size == code.texture.get_size() and code.texture_filter == CanvasItem.TEXTURE_FILTER_NEAREST, + "The QR code is drawn 1:1 with crisp modules") + check(code.texture.get_width() <= 100, "The QR code stays small (%d px)" % code.texture.get_width()) + check(qr.find_children("*", "PanelContainer", true, false).is_empty() + and qr.find_children("*", "Panel", true, false).is_empty(), "The QR code has no card or border") + + var caption_text := caption.get_theme_font("font").get_multiline_string_size(caption.text, + HORIZONTAL_ALIGNMENT_RIGHT, -1, caption.get_theme_font_size("font_size")) + var caption_rect := frame_rect(caption, frame) + check(caption_text.x <= caption_rect.size.x, "The caption fits its box, so it never runs into the code") + var occupied: Array[Rect2] = [frame_rect(code, frame), caption_rect] + var screen := Rect2(Vector2.ZERO, Vector2(1280, 720)) + for rect in occupied: + check(screen.encloses(rect), "The QR code and caption sit inside the 1280x720 frame") + + var others := {} + for tile in menu.tiles: + var rect := frame_rect(tile, frame) + others["tile " + tile.name] = rect.grow_individual( + rect.size.x * (TILE_GROW - 1) / 2, rect.size.y * (TILE_GROW - 1) / 2, + rect.size.x * (TILE_GROW - 1) / 2, rect.size.y * (TILE_GROW - 1) / 2) + for button in menu.utilities: + others["button " + button.text] = frame_rect(button, frame) + for i in labels.size(): + var label := labels[i] + if not qr.is_ancestor_of(label) and label.is_visible_in_tree() and label.text != "": + others["label %d %s" % [i, label.text.left(24)]] = frame_rect(label, frame) + var hoppy: Node2D = menu.hoppy + var sprite: AnimatedSprite2D = hoppy.sprite + others["Hoppy"] = sprite_rect(sprite, sprite.sprite_frames.get_frame_texture(sprite.animation, + sprite.frame), sprite.offset, frame) + others["Hoppy's runner portrait"] = sprite_rect(hoppy.runner_image, hoppy.runner_image.texture, + hoppy.runner_image.offset, frame) + var clear := true + for name in others: + for rect in occupied: + if rect.intersects(others[name]): + clear = false + print(" overlaps %s: %s vs %s" % [name, rect, others[name]]) + check(clear, "The QR code and caption overlap nothing else on the hub (%d items)" % others.size()) + + router.set_booth(false) + router.idle_limit = router.IDLE_SECONDS + await root.get_node("AudioService").settle() + print("Booth hub failures: ", failures) + quit(1 if failures else 0) diff --git a/hoppys-adventure-arcade/tests/booth_hub.gd.uid b/hoppys-adventure-arcade/tests/booth_hub.gd.uid new file mode 100644 index 00000000..ac351972 --- /dev/null +++ b/hoppys-adventure-arcade/tests/booth_hub.gd.uid @@ -0,0 +1 @@ +uid://4t45jbpfuvto diff --git a/hoppys-adventure-arcade/tests/low_gpu.gd b/hoppys-adventure-arcade/tests/low_gpu.gd new file mode 100644 index 00000000..089dae38 --- /dev/null +++ b/hoppys-adventure-arcade/tests/low_gpu.gd @@ -0,0 +1,122 @@ +extends SceneTree +## Low-GPU mode (app/low_gpu.gd): off unless passed or on a V3D GPU, `--full-gpu` keeps it off, +## `--low-gpu==,...` overrides single settings, and with it on the runner's corridor and +## post pass build lighter while without it they build exactly as before. The launch flag is checked +## by launching the game as a child process, so AppRouter's own argument handling is covered. +## Run headless with --script res://tests/low_gpu.gd. +const LowGpu := preload("res://app/low_gpu.gd") +const PostFx := preload("res://scenes/runner/ui/post_fx.gd") +const PostGrade := preload("res://scenes/runner/shaders/post_grade.gdshader") +const PostGradeLite := preload("res://scenes/runner/shaders/post_grade_lite.gdshader") +const Corridor := preload("res://scenes/runner/environment/corridor.tscn") +var failures := 0 + +func _initialize() -> void: + call_deferred("run") + +func check(ok: bool, message: String) -> void: + print("PASS: " if ok else "FAIL: ", message) + if not ok: + failures += 1 + +func launch(user_args: Array[String]) -> Dictionary: + var args: Array[String] = ["--headless", "--path", ProjectSettings.globalize_path("res://"), + "--fixed-fps", "60", "--quit-after", "30", "--"] + args.append_array(user_args) + var output: Array = [] + var code := OS.execute(OS.get_executable_path(), args, output, true) + return {"code": code, "log": "\n".join(output)} + +func configure(args: Array[String], adapter := "") -> void: + LowGpu.configure(PackedStringArray(args), adapter) + +func post_pass() -> Dictionary: + var fx: CanvasLayer = PostFx.new() + var result := {"shader": fx.material.shader, "visible": fx.screen.visible} + fx.free() + return result + +## Mounts the runner's corridor in the root viewport and reports what it applied. +func corridor() -> Dictionary: + var viewport := root + var before := {"scale": viewport.scaling_3d_scale, "mode": viewport.scaling_3d_mode} + var node: Node3D = Corridor.instantiate() + root.add_child(node) + var env: Environment = node._environment + var result := {"scale": viewport.scaling_3d_scale, "glow": env.glow_enabled, + "fog": env.fog_enabled, "adjust": env.adjustment_enabled, "ambient": env.ambient_light_energy, + "key_light": node.get_node("StarshipKeyLight").visible, + "deck_light": node.starship.deck_light.visible} + root.remove_child(node) + node.free() + result.restored = is_equal_approx(viewport.scaling_3d_scale, before.scale) \ + and viewport.scaling_3d_mode == before.mode + return result + +func run() -> void: + configure([]) + check(not LowGpu.enabled, "Off without the flag") + configure([], "Apple M3 Pro") + check(not LowGpu.enabled, "Off on other GPUs") + configure(["--booth"], "V3D 7.1.10.2") + check(LowGpu.enabled and LowGpu.reason.contains("V3D"), "On by itself on a Pi 5's V3D GPU") + configure(["--booth", "--full-gpu"], "V3D 7.1.10.2") + check(not LowGpu.enabled, "--full-gpu keeps it off on a V3D GPU") + configure(["--low-gpu"]) + check(LowGpu.enabled and LowGpu.settings == LowGpu.DEFAULTS, "--low-gpu turns it on with the defaults") + configure(["--low-gpu=scale=0.75,post=full,glow=on,cap=off"]) + check(LowGpu.enabled and is_equal_approx(LowGpu.settings.scale, 0.75) and LowGpu.settings.post == "full" + and LowGpu.settings.glow and not LowGpu.settings.cap and LowGpu.settings.fog, + "--low-gpu==,... overrides single settings and keeps the rest") + configure(["--low-gpu=scale=0.05,post=sparkle"]) + check(is_equal_approx(LowGpu.settings.scale, LowGpu.MIN_SCALE) and LowGpu.settings.post == "lite", + "Out-of-range or unknown values are clamped or ignored") + + configure([]) + check(is_equal_approx(LowGpu.render_scale(0.85), 0.85), "Off: the runner keeps its 3D scale") + var window := Window.new() + var mode := window.content_scale_mode + LowGpu.apply_window(window) + check(window.content_scale_mode == mode, "Off: the window's content scale mode is untouched") + var plain_post := post_pass() + check(plain_post.shader == PostGrade and plain_post.visible, "Off: the runner keeps its full post grade") + var plain := corridor() + check(is_equal_approx(plain.scale, 0.85) and plain.glow and plain.fog and plain.adjust, + "Off: the corridor renders at 0.85 with glow, fog and adjustment") + check(plain.restored, "Off: the corridor restores the viewport's scale when it leaves") + check(plain.key_light and plain.deck_light, "Off: the corridor keeps both fill lights") + + configure(["--low-gpu"]) + check(is_equal_approx(LowGpu.render_scale(0.85), 0.4) and is_equal_approx(LowGpu.render_scale(0.3), 0.3), + "On: 3D renders at 0.4 at most, never larger than a scene asks for") + LowGpu.apply_window(window) + check(window.content_scale_mode == Window.CONTENT_SCALE_MODE_VIEWPORT, + "On: the window renders at the project size and is scaled to the screen") + window.free() + var lite_post := post_pass() + check(lite_post.shader == PostGradeLite and lite_post.visible, "On: the post grade draws without a screen read") + var light := corridor() + check(is_equal_approx(light.scale, 0.4) and not light.glow and light.fog and light.adjust, + "On: the corridor renders at 0.4 without glow, keeping fog and adjustment") + check(light.restored, "On: the corridor restores the viewport's scale when it leaves") + check(not light.key_light and not light.deck_light + and is_equal_approx(light.ambient, plain.ambient + LowGpu.OMNI_AMBIENT), + "On: both fill lights go by default and the ambient light rises instead") + configure(["--low-gpu=omni=on"]) + var lit := corridor() + check(lit.key_light and lit.deck_light and is_equal_approx(lit.ambient, plain.ambient), + "omni=on keeps both fill lights") + configure(["--low-gpu=post=off"]) + check(not post_pass().visible, "post=off hides the post pass") + configure([]) + + var off_log := launch([]) + check(off_log.code == 0 and not off_log.log.contains("LowGpu:"), "A plain launch leaves low-GPU mode off") + var on_log := launch(["--low-gpu=scale=0.7"]) + check(on_log.code == 0 and on_log.log.contains("LowGpu: on (--low-gpu=scale=0.7)") + and on_log.log.contains("scale=0.7"), "Launching with --low-gpu turns it on and logs the settings") + var opt_out := launch(["--full-gpu"]) + check(opt_out.code == 0 and opt_out.log.contains("LowGpu: off (--full-gpu)"), "--full-gpu is logged") + + print("low_gpu: %d failures" % failures) + quit(1 if failures > 0 else 0) diff --git a/hoppys-adventure-arcade/tests/low_gpu.gd.uid b/hoppys-adventure-arcade/tests/low_gpu.gd.uid new file mode 100644 index 00000000..ed2b598d --- /dev/null +++ b/hoppys-adventure-arcade/tests/low_gpu.gd.uid @@ -0,0 +1 @@ +uid://sqqerrukcuxm diff --git a/hoppys-adventure-arcade/tools/booth/generate_qr.swift b/hoppys-adventure-arcade/tools/booth/generate_qr.swift index c20a7e5c..79695735 100644 --- a/hoppys-adventure-arcade/tools/booth/generate_qr.swift +++ b/hoppys-adventure-arcade/tools/booth/generate_qr.swift @@ -1,45 +1,60 @@ import AppKit +import CoreImage import CoreImage.CIFilterBuiltins import Foundation -let defaultURL = "https://coderabbit.link/ato26-ad?qr=1" +// The booth hub's QR: the event's coupon short link for this game, so scans it drives are counted +// apart from the booth's other touchpoints. Plain black on white, low error correction for the +// fewest modules, and drawn at exactly `moduleScale` pixels per module with a `quietModules` light +// margin, which the hub shows 1:1 with nearest filtering. +let defaultURL = "https://coderabbit.link/aidevnyc-26-booth-arcade" +let moduleScale = 3 +let quietModules = 2 let scriptDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent() let projectDirectory = scriptDirectory.deletingLastPathComponent().deletingLastPathComponent() let defaultOutput = projectDirectory.appendingPathComponent("Assets/booth/booth_qr.png").path -let logoPath = projectDirectory.appendingPathComponent("Assets/booth/booth_qr_logo.png").path let output = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : defaultOutput let value = CommandLine.arguments.count > 2 ? CommandLine.arguments[2] : defaultURL let filter = CIFilter.qrCodeGenerator() filter.message = Data(value.utf8) -filter.correctionLevel = "H" - -guard let image = filter.outputImage?.transformed(by: CGAffineTransform(scaleX: 12, y: 12)) else { +filter.correctionLevel = "L" +guard let symbol = filter.outputImage, + let cgImage = CIContext().createCGImage(symbol, from: symbol.extent) else { fatalError("Could not generate QR code") } -let qr = NSBitmapImageRep(ciImage: image) -guard let logo = NSImage(contentsOfFile: logoPath), - let logoTiff = logo.tiffRepresentation, - let logoBitmap = NSBitmapImageRep(data: logoTiff) else { - fatalError("Could not load QR or CodeRabbit logo image") -} -let size = NSSize(width: qr.pixelsWide, height: qr.pixelsHigh) -let composite = NSImage(size: size) -composite.lockFocus() -NSColor.white.setFill() -NSRect(origin: .zero, size: size).fill() -qr.draw(in: NSRect(origin: .zero, size: size)) -let logoSize = size.width * 0.223 -let logoRect = NSRect(x: (size.width - logoSize) / 2, y: (size.height - logoSize) / 2, - width: logoSize, height: logoSize) -logoBitmap.draw(in: logoRect) -composite.unlockFocus() +// Read the generator's one-pixel-per-module image, then trim whatever margin it adds. +let source = NSBitmapImageRep(cgImage: cgImage) +func dark(_ x: Int, _ y: Int) -> Bool { + (source.colorAt(x: x, y: y)?.usingColorSpace(.deviceGray)?.whiteComponent ?? 1) < 0.5 +} +let darkCells = (0..= 0 && row >= 0 && column < modules && row < modules + pixels[y * side + x] = inside && dark(left + column, top + row) ? 0 : 255 + } +} +guard let png = bitmap.representation(using: .png, properties: [:]) else { fatalError("Could not encode QR code as PNG") } try png.write(to: URL(fileURLWithPath: output)) -print("Wrote \(output) for \(value)") +print("Wrote \(output) for \(value): \(modules) modules, \(side)x\(side) px")