[PR #35] [MERGED] Drive the Rust client from scripts with horizon-ctl #2284

Closed
opened 2026-11-02 15:54:37 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: t3code/rewrite-minecraft-rust ← Head: t3code/horizon-ctl


📝 Commits (1)

  • 77f9c07 Add a control socket and horizon-ctl to drive the client from scripts

📊 Changes

8 files changed (+959 additions, -81 deletions)

View changed files

📝 crates/horizon-client/Cargo.toml (+1 -0)
➕ crates/horizon-client/src/bin/horizon-ctl.rs (+203 -0)
➕ crates/horizon-client/src/control.rs (+137 -0)
📝 crates/horizon-client/src/game.rs (+122 -80)
➕ crates/horizon-client/src/game/control.rs (+399 -0)
📝 crates/horizon-client/src/gfx.rs (+70 -1)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 docs/native-client.md (+26 -0)

📄 Description

Adds a control CLI so the game can be tested, played and benchmarked without anyone at the keyboard.

What it does

  • horizon-client --control opens a Unix socket at $XDG_RUNTIME_DIR/horizon-control.sock; --control-socket PATH sets another path.
  • horizon-ctl sends commands and prints one JSON reply per command:
    • state: status
    • input: key, mouse, look, turn, hotbar
    • world: tp, give, render-distance, time, resume, open, save, quit
    • capture: screenshot PATH (PNG of the next presented frame), stats, bench SECONDS (avg/1%-low FPS, p50/p95/p99/max frame times)
  • Commands that run only in the CLI:
    • launch: start the game and wait for its socket.
    • hold KEY SECONDS
    • wait-ready: wait until the player has spawned and no chunks are pending.
    • -: run a script from stdin, with sleep.
  • Under control, losing window focus no longer pauses the game or clears held keys.
  • Key presses and play-screen mouse buttons move into key_pressed and play_mouse, so the window and the socket share one code path.
  • Documented in docs/native-client.md.

Tested on ludodesktop (RTX 4080, Wayland)

  • Launched, waited for spawn, and walked with hold w 2 (the player moved).
  • give diamond_pickaxe plus hotbar 1 showed the item as held.
  • A screenshot came back as a correct 1280×720 frame.
  • bench 5, a stdin script, quit (world saved, socket removed), and the error replies with exit status 1 all worked.
  • clippy reports no new warnings in the changed code.

Finding for the performance work

bench shows exactly 60 FPS at render distance 32 once chunks have loaded (p50 16.66 ms), even with Mailbox present mode. On Wayland, winit paces RedrawRequested to compositor frame callbacks, so the client can't exceed the display rate. Uncapped rendering is the next optimization step.

🤖 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/35 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/8/2026 **Status:** ✅ Merged **Merged:** 10/8/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `t3code/rewrite-minecraft-rust` ← **Head:** `t3code/horizon-ctl` --- ### 📝 Commits (1) - [`77f9c07`](https://github.com/horizon-rust/horizon/commit/77f9c075ca511c11110f73df1b254abaf3dac770) Add a control socket and horizon-ctl to drive the client from scripts ### 📊 Changes **8 files changed** (+959 additions, -81 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/Cargo.toml` (+1 -0) ➕ `crates/horizon-client/src/bin/horizon-ctl.rs` (+203 -0) ➕ `crates/horizon-client/src/control.rs` (+137 -0) 📝 `crates/horizon-client/src/game.rs` (+122 -80) ➕ `crates/horizon-client/src/game/control.rs` (+399 -0) 📝 `crates/horizon-client/src/gfx.rs` (+70 -1) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `docs/native-client.md` (+26 -0) </details> ### 📄 Description Adds a control CLI so the game can be tested, played and benchmarked without anyone at the keyboard. ## What it does - `horizon-client --control` opens a Unix socket at `$XDG_RUNTIME_DIR/horizon-control.sock`; `--control-socket PATH` sets another path. - `horizon-ctl` sends commands and prints one JSON reply per command: - state: `status` - input: `key`, `mouse`, `look`, `turn`, `hotbar` - world: `tp`, `give`, `render-distance`, `time`, `resume`, `open`, `save`, `quit` - capture: `screenshot PATH` (PNG of the next presented frame), `stats`, `bench SECONDS` (avg/1%-low FPS, p50/p95/p99/max frame times) - Commands that run only in the CLI: - `launch`: start the game and wait for its socket. - `hold KEY SECONDS` - `wait-ready`: wait until the player has spawned and no chunks are pending. - `-`: run a script from stdin, with `sleep`. - Under control, losing window focus no longer pauses the game or clears held keys. - Key presses and play-screen mouse buttons move into `key_pressed` and `play_mouse`, so the window and the socket share one code path. - Documented in `docs/native-client.md`. ## Tested on ludodesktop (RTX 4080, Wayland) - Launched, waited for spawn, and walked with `hold w 2` (the player moved). - `give diamond_pickaxe` plus `hotbar 1` showed the item as held. - A screenshot came back as a correct 1280×720 frame. - `bench 5`, a stdin script, `quit` (world saved, socket removed), and the error replies with exit status 1 all worked. - clippy reports no new warnings in the changed code. ## Finding for the performance work `bench` shows exactly 60 FPS at render distance 32 once chunks have loaded (p50 16.66 ms), even with Mailbox present mode. On Wayland, winit paces `RedrawRequested` to compositor frame callbacks, so the client can't exceed the display rate. Uncapped rendering is the next optimization step. 🤖 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-02 15:54:37 +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#2284
No description provided.