[PR #1929] [MERGED] Mod API: capability render (experimental): HUD shapes and camera shake #3870

Closed
opened 2026-11-03 04:12:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1929
Author: @ludovic111
Created: 10/25/2026
Status: ✅ Merged
Merged: 10/26/2026
Merged by: @ludovic111

Base: main ← Head: feat/mod-render


📝 Commits (2)

  • 61c44c2 Mod API: capability render (experimental): HUD shapes and camera shake
  • 07f1bcf Merge main: render beside main's command capability

📊 Changes

15 files changed (+582 additions, -14 deletions)

View changed files

📝 crates/cargo-horizon-mod/src/check.rs (+9 -0)
📝 crates/horizon-client/src/game.rs (+3 -0)
➕ crates/horizon-client/src/game/mod_render.rs (+176 -0)
📝 crates/horizon-client/src/game/mods.rs (+13 -2)
📝 crates/horizon-client/src/hud.rs (+6 -0)
📝 crates/horizon-mod-sdk/src/lib.rs (+1 -1)
📝 crates/horizon-mod-sdk/wit/horizon.wit (+82 -0)
📝 crates/horizon-mods/src/manifest.rs (+9 -2)
📝 crates/horizon-mods/src/runtime.rs (+81 -0)
📝 crates/horizon-mods/tests/sandbox.rs (+35 -3)
📝 crates/horizon-mods/tests/ui_guest/src/lib.rs (+68 -3)
📝 docs/api/mods-reference.md (+93 -1)
📝 docs/api/mods.md (+2 -0)
📝 docs/api/stability.md (+1 -0)
📝 docs/mods.md (+3 -2)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Stacked on #1864 (socksprox's ui, from their fork): until #1864 merges, this diff also shows #1864's commits. Review only the last commit, 61c44c22e. It uses #1864's experimental opt-in.

What a modder can do now

Mods draw on the HUD and shake the camera. The game's own renderer draws everything: a mod never supplies shader code, as the maintainers decided for mods. The interface is experimental: a manifest needs experimental = ["render"] beside capabilities = ["render"].

render::set_hud(&[
    Shape::Fill(FillShape { rect: Rect { x: 4.0, y: 4.0, w: 60.0, h: 20.0 }, color: 0x80FF0000 }),
    Shape::Text(TextShape { text: "Charging…".into(), at: Point { x: w / 2.0, y: 20.0 }, color: 0xFFFF55, centered: true, shadow: true }),
]);
render::shake(0.6, 1.5);
  • set-hud(shapes) takes up to 1024 shapes, kept until replaced (no call per frame). The shapes are fill, quad (any four corners, e.g. a wheel's segments), sprite (the game's GUI sprites: hud/heart/full, widget/button), item (scaled) and text. They're drawn over the HUD after the extras, under chat and screens, and hidden with F1. Colours are 0xAARRGGBB, text 0xRRGGBB like hud's lines.
  • gui-size() gives the screen in GUI pixels, as of this tick.
  • shake(strength, seconds) turns the view, not the player. Jolts fade out (squared), add up to 1 and turn at most 3° of yaw and 2° of pitch. The player's Distortion Effects scales them, and 0 turns them off. Values are clamped (strength 0–1, at most 10 s); 0 or NaN does nothing.
  • cargo horizon-mod check reports shakes and HUD shapes.

World-space shapes (lines, boxes, billboards) come in a later PR, on this same interface.

How it works

  • WIT interface render, imported by the SDK's world. The game links it from a render-host world, as #1864 does for ui.
  • horizon-mods: per-mod shapes (clipped: 1024 shapes, 256-character strings, item scale 0–16), Output::Shake, Snapshot::gui_size, Mods::hud_shapes().
  • game/mod_render.rs: draws the shapes into the HudBatch and keeps the jolts. shaken_view changes the view's yaw and pitch only while a jolt fades. HudBatch::fill_quad is new.
  • No mod drawing, no cost: draw_mod_shapes walks an empty iterator, and shaken_view returns after is_empty(). Without the mods feature both are empty functions.

How tested

  • cargo test -p horizon-mods --features runtime,pack: new render_shapes_and_shakes, with the ui test guest's /render_hud, /render_clear and /render_shake. It checks the mod reads gui-size, text is clipped to 256 characters, a clear empties the HUD, and a jolt is clamped to (1, 10) while 0 and NaN do nothing. manifest: render needs the opt-in.
  • horizon-client unit test a_jolt_fades_out_and_distortion_scales_it.
  • In game (--features mods, fresh HORIZON_HOME and XDG folders, HORIZON_NO_AUDIO=1), in-frame and on the server thread:
    • /render_hud draws a translucent red fill, a heart sprite, a diamond at 2×, a green quad and a centred yellow text.
    • /render_shake turns the view (the landscape moves between frames, the HUD doesn't) while the player's yaw stays the same.
    • /render_clear leaves the plain HUD.
    • No panic. Checked on screenshots.
  • Clippy -D warnings, with and without mods. The API reference is regenerated.

Self-check (against #1864's head):

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at befec1995, 8 min 10 s)

Check Result
Scope ✅ 15 files, +582 −14
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (5 s)
clippy ✅ (59 s)
tests: cargo-horizon-mod, horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest ✅ 1282 passed (4 min 4 s)
doc tests ✅ 1 passed (39 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (57 s)
launcher tests ✅ 126 passed (1 min 4 s)
Parity ➖ 107 affected, run in CI; locally camera, first_person, hud, screen_layout: 4 passed

Label skip-release: experimental, opt-in. No player sees a change without such a mod.

Leftovers

  • World-space lines, boxes and billboards (next PR).
  • Sprites from a content mod's own gui/ textures: they aren't in the GUI atlas yet.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/1929 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-render` --- ### 📝 Commits (2) - [`61c44c2`](https://github.com/horizon-rust/horizon/commit/61c44c22efe23f9cbc4ac00ef8c8f20a35b00aa4) Mod API: capability render (experimental): HUD shapes and camera shake - [`07f1bcf`](https://github.com/horizon-rust/horizon/commit/07f1bcff680844d3e30d7cdd233ec8fce67d57e0) Merge main: render beside main's command capability ### 📊 Changes **15 files changed** (+582 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `crates/cargo-horizon-mod/src/check.rs` (+9 -0) 📝 `crates/horizon-client/src/game.rs` (+3 -0) ➕ `crates/horizon-client/src/game/mod_render.rs` (+176 -0) 📝 `crates/horizon-client/src/game/mods.rs` (+13 -2) 📝 `crates/horizon-client/src/hud.rs` (+6 -0) 📝 `crates/horizon-mod-sdk/src/lib.rs` (+1 -1) 📝 `crates/horizon-mod-sdk/wit/horizon.wit` (+82 -0) 📝 `crates/horizon-mods/src/manifest.rs` (+9 -2) 📝 `crates/horizon-mods/src/runtime.rs` (+81 -0) 📝 `crates/horizon-mods/tests/sandbox.rs` (+35 -3) 📝 `crates/horizon-mods/tests/ui_guest/src/lib.rs` (+68 -3) 📝 `docs/api/mods-reference.md` (+93 -1) 📝 `docs/api/mods.md` (+2 -0) 📝 `docs/api/stability.md` (+1 -0) 📝 `docs/mods.md` (+3 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Stacked on #1864** (socksprox's `ui`, from their fork): until #1864 merges, this diff also shows #1864's commits. Review only the last commit, 61c44c22e. It uses #1864's `experimental` opt-in. ## What a modder can do now Mods draw on the HUD and shake the camera. The game's own renderer draws everything: **a mod never supplies shader code**, as the maintainers decided for mods. The interface is **experimental**: a manifest needs `experimental = ["render"]` beside `capabilities = ["render"]`. ```rust render::set_hud(&[ Shape::Fill(FillShape { rect: Rect { x: 4.0, y: 4.0, w: 60.0, h: 20.0 }, color: 0x80FF0000 }), Shape::Text(TextShape { text: "Charging…".into(), at: Point { x: w / 2.0, y: 20.0 }, color: 0xFFFF55, centered: true, shadow: true }), ]); render::shake(0.6, 1.5); ``` - **`set-hud(shapes)`** takes up to 1024 shapes, kept until replaced (no call per frame). The shapes are `fill`, `quad` (any four corners, e.g. a wheel's segments), `sprite` (the game's GUI sprites: `hud/heart/full`, `widget/button`), `item` (scaled) and `text`. They're drawn over the HUD after the extras, under chat and screens, and hidden with F1. Colours are 0xAARRGGBB, text 0xRRGGBB like `hud`'s lines. - **`gui-size()`** gives the screen in GUI pixels, as of this tick. - **`shake(strength, seconds)`** turns the view, not the player. Jolts fade out (squared), add up to 1 and turn at most 3° of yaw and 2° of pitch. The player's Distortion Effects scales them, and 0 turns them off. Values are clamped (strength 0–1, at most 10 s); 0 or NaN does nothing. - `cargo horizon-mod check` reports shakes and HUD shapes. World-space shapes (lines, boxes, billboards) come in a later PR, on this same interface. ## How it works - WIT `interface render`, imported by the SDK's world. The game links it from a `render-host` world, as #1864 does for `ui`. - `horizon-mods`: per-mod `shapes` (clipped: 1024 shapes, 256-character strings, item scale 0–16), `Output::Shake`, `Snapshot::gui_size`, `Mods::hud_shapes()`. - `game/mod_render.rs`: draws the shapes into the `HudBatch` and keeps the jolts. `shaken_view` changes the view's yaw and pitch only while a jolt fades. `HudBatch::fill_quad` is new. - **No mod drawing, no cost:** `draw_mod_shapes` walks an empty iterator, and `shaken_view` returns after `is_empty()`. Without the `mods` feature both are empty functions. ## How tested - `cargo test -p horizon-mods --features runtime,pack`: new `render_shapes_and_shakes`, with the ui test guest's `/render_hud`, `/render_clear` and `/render_shake`. It checks the mod reads `gui-size`, text is clipped to 256 characters, a clear empties the HUD, and a jolt is clamped to (1, 10) while 0 and NaN do nothing. `manifest`: `render` needs the opt-in. - `horizon-client` unit test `a_jolt_fades_out_and_distortion_scales_it`. - In game (`--features mods`, fresh `HORIZON_HOME` and XDG folders, `HORIZON_NO_AUDIO=1`), in-frame and on the server thread: - `/render_hud` draws a translucent red fill, a heart sprite, a diamond at 2×, a green quad and a centred yellow text. - `/render_shake` turns the view (the landscape moves between frames, the HUD doesn't) while the player's yaw stays the same. - `/render_clear` leaves the plain HUD. - No panic. Checked on screenshots. - Clippy `-D warnings`, with and without `mods`. The API reference is regenerated. **Self-check** (against #1864's head): **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at befec1995, 8 min 10 s) | Check | Result | | --- | --- | | Scope | ✅ 15 files, +582 −14 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (5 s) | | clippy | ✅ (59 s) | | tests: cargo-horizon-mod, horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest | ✅ 1282 passed (4 min 4 s) | | doc tests | ✅ 1 passed (39 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (57 s) | | launcher tests | ✅ 126 passed (1 min 4 s) | | Parity | ➖ 107 affected, run in CI; locally `camera`, `first_person`, `hud`, `screen_layout`: 4 passed | Label `skip-release`: experimental, opt-in. No player sees a change without such a mod. ## Leftovers - World-space lines, boxes and billboards (next PR). - Sprites from a content mod's own `gui/` textures: they aren't in the GUI atlas yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:12:55 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#3870
No description provided.