[PR #5013] [MERGED] Dedicated server: send saved chunks past the view distance (max_view_distance) #6007

Closed
opened 2026-11-03 05:16:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5013
Author: @rdbtCVS
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: t3/adaptive-server-view-distance


📝 Commits (1)

  • 5bd13da Send saved chunks past the view distance (max_view_distance)

📊 Changes

14 files changed (+849 additions, -61 deletions)

View changed files

📝 crates/horizon-client/src/game/commands/terrain_cmds.rs (+1 -1)
📝 crates/horizon-client/src/game/dedicated.rs (+28 -0)
📝 crates/horizon-client/src/game/lan.rs (+1 -0)
📝 crates/horizon-client/src/lan/chunks.rs (+43 -0)
➕ crates/horizon-client/src/lan/far.rs (+429 -0)
📝 crates/horizon-client/src/lan/guest.rs (+3 -0)
📝 crates/horizon-client/src/lan/hub.rs (+237 -59)
📝 crates/horizon-client/src/lan/mod.rs (+1 -0)
📝 crates/horizon-client/src/save.rs (+72 -0)
📝 crates/horizon-server/src/config.rs (+11 -1)
📝 crates/horizon-server/src/settings.rs (+1 -0)
📝 docs/api/server-reference.md (+1 -0)
📝 docs/hosting.md (+18 -0)
📝 docs/pregeneration.md (+3 -0)

📄 Description

🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally.

Fixes #5008

A dedicated server can now send players chunks past its view_distance without generating, loading or ticking them. The new server.toml setting max_view_distance is off by default (0). When it is above view_distance, each player also gets the chunks the world has already saved, out to the smaller of max_view_distance and their own render distance. The server reads each chunk from the save, sends it, then drops it. Only its position stays in the player's sent_chunks, so these chunks cost about what a pregenerated world costs on disk, not what loaded chunks cost. The docs send players to /pregen to fill that ring.

How it works

  • Config: max_view_distance (0..=32) under [server] reaches the game as horizon-max-view-distance in server.properties, like the other horizon- keys. defaults_are_vanilla skips horizon- keys and checks that they are 0. docs/api/server-reference.md is regenerated.

  • Radius sent to clients (Hub::chunk_radius): when the ring is on, Login and SetChunkCacheRadius send max(view, max_view_distance). Without that, a vanilla client would drop and not draw what we send past the view. The vanilla client still draws min(its render distance, that).

  • Two queues per player: chunk_queue stays the view's, exactly as before. The new far_queue holds the ring tracked at reach and not at view (requeue_ring), closest first. update_view forgets only what leaves reach.

  • Batches (next_batch): the view's chunks go first, through the same quota and unacknowledged-batch pacing as vanilla's PlayerChunkSender. Only what is left of the quota goes to the ring.

    • The ring looks at no more than 64 of its closest entries per tick. It skips any chunk past the brake's current limit().
    • If the level holds a chunk, it is sent like any other: encoded once per tick and shared between batches.
    • Otherwise the chunk comes from the save (lan/far.rs).
    • A chunk the save doesn't have leaves the queue unsent. It comes back once the player changes chunk; until then, a negative cache keeps it from being read again for 30 s.
  • Reads (lan/far.rs, SaveDir::load_far):

    • Two "Far chunk reader" threads read at most 32 chunks at a time across all players.
    • Reads check the pending writes first, then the region's sector bitmap (lod_saved). They never fill the gameplay region cache.
    • Only full chunks saved with their light (isLightOn) are taken: no light engine runs for the ring.
    • Each level gets an encoder with its own caches (ChunkEncoder::detached). body_alone leaves nothing of the chunk cached once it is encoded.
    • Nothing is read while the save's writer has more than 512 chunks waiting.
  • Kept bodies: bodies sent are kept for 5 minutes, 96 MB at most, for players walking back. They are dropped:

    • when their column changes (block log, light log, resend_biomes);
    • when a level has no players left in it, since nothing logs its changes then.

    A read that a change overtakes while it is still in flight is dropped as stale.

  • The brake (Far::brake, once a second from the dedicated tick loop, on the clock's average):

    • Above 40 ms per tick, it pulls the ring in by 2 chunks, never inside view_distance.
    • After 30 s under 25 ms, it lets the ring out by 1 chunk every 5 s, up to max_view_distance.
    • Far chunks already sent stay when it pulls in.
    • Slow clients already slow their own ring through the existing acknowledgement pacing.
  • Not changed: entity tracking range, simulation distance, chunk tickets and loading, LAN and integrated servers (Hub::far is set only by dedicated.rs).

Size

At ~850 lines (about 200 of them tests and 25 docs), this is over the usual ~500. It was asked for as a single PR: the config, the reads, the cache, the brake and the hub's queues only work together.

Tests

  • lan::far::tests::the_brake_pulls_in_fast_and_lets_out_slowly: steps, the floor at the view, the hold band, the calm wait, regrowth to max.
  • lan::far::tests::reads_are_kept_until_their_column_changes: walking back reads nothing again; changed and forget_level drop the kept body.
  • lan::far::tests::a_read_overtaken_by_a_change_is_dropped
  • lan::hub::tests::the_far_ring_queues_what_the_view_leaves: near and far queues partition the reach's queue, closest first, with sent chunks out of both.
  • lan::chunks::tests::a_body_alone_leaves_nothing_cached
  • save::tests::far_reads_take_saved_lit_chunks_only (with HORIZON_TEST_RESOURCES): a lit saved chunk reads back; a chunk saved without light, or not saved at all, doesn't; the region cache stays empty.
  • cargo test -p horizon-server (60) and cargo test -p horizon-client --lib lan:: (95+) pass locally.

The worktree I ran in has no .local/, so pr_ready ran with --quick and CI's parity job picks the affected harnesses.

pr_ready (tools/pr_ready.py --quick on archlinux, against origin/main at 03fc2d3f2, 3 min 43 s)

Check Result
Scope ⚠️ 14 files, +849 −61; 888 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (35 s)
rustfmt ✅ (7 s)
clippy ✅ (1 min 7 s)
tests: horizon-client, horizon-server ✅ 1392 passed (1 min 13 s)
doc tests ✅ 0 passed (41 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/5013 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `t3/adaptive-server-view-distance` --- ### 📝 Commits (1) - [`5bd13da`](https://github.com/horizon-rust/horizon/commit/5bd13dad8062e090423592c9e58fe16a69cfc6e2) Send saved chunks past the view distance (max_view_distance) ### 📊 Changes **14 files changed** (+849 additions, -61 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands/terrain_cmds.rs` (+1 -1) 📝 `crates/horizon-client/src/game/dedicated.rs` (+28 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+1 -0) 📝 `crates/horizon-client/src/lan/chunks.rs` (+43 -0) ➕ `crates/horizon-client/src/lan/far.rs` (+429 -0) 📝 `crates/horizon-client/src/lan/guest.rs` (+3 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+237 -59) 📝 `crates/horizon-client/src/lan/mod.rs` (+1 -0) 📝 `crates/horizon-client/src/save.rs` (+72 -0) 📝 `crates/horizon-server/src/config.rs` (+11 -1) 📝 `crates/horizon-server/src/settings.rs` (+1 -0) 📝 `docs/api/server-reference.md` (+1 -0) 📝 `docs/hosting.md` (+18 -0) 📝 `docs/pregeneration.md` (+3 -0) </details> ### 📄 Description > 🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally. Fixes #5008 A dedicated server can now send players chunks past its `view_distance` without generating, loading or ticking them. The new `server.toml` setting `max_view_distance` is **off by default (0)**. When it is above `view_distance`, each player also gets the chunks the world has already saved, out to the smaller of `max_view_distance` and their own render distance. The server reads each chunk from the save, sends it, then drops it. Only its position stays in the player's `sent_chunks`, so these chunks cost about what a pregenerated world costs on disk, not what loaded chunks cost. The docs send players to `/pregen` to fill that ring. ### How it works - **Config**: `max_view_distance` (0..=32) under `[server]` reaches the game as `horizon-max-view-distance` in `server.properties`, like the other `horizon-` keys. `defaults_are_vanilla` skips `horizon-` keys and checks that they are 0. `docs/api/server-reference.md` is regenerated. - **Radius sent to clients** (`Hub::chunk_radius`): when the ring is on, Login and SetChunkCacheRadius send `max(view, max_view_distance)`. Without that, a vanilla client would drop and not draw what we send past the view. The vanilla client still draws `min(its render distance, that)`. - **Two queues per player**: `chunk_queue` stays the view's, exactly as before. The new `far_queue` holds the ring tracked at `reach` and not at `view` (`requeue_ring`), closest first. `update_view` forgets only what leaves `reach`. - **Batches** (`next_batch`): the view's chunks go first, through the same quota and unacknowledged-batch pacing as vanilla's PlayerChunkSender. Only what is left of the quota goes to the ring. - The ring looks at no more than 64 of its closest entries per tick. It skips any chunk past the brake's current `limit()`. - If the level holds a chunk, it is sent like any other: encoded once per tick and shared between batches. - Otherwise the chunk comes from the save (`lan/far.rs`). - A chunk the save doesn't have leaves the queue unsent. It comes back once the player changes chunk; until then, a negative cache keeps it from being read again for 30 s. - **Reads** (`lan/far.rs`, `SaveDir::load_far`): - Two "Far chunk reader" threads read at most 32 chunks at a time across all players. - Reads check the pending writes first, then the region's sector bitmap (`lod_saved`). They never fill the gameplay region cache. - Only full chunks saved with their light (`isLightOn`) are taken: no light engine runs for the ring. - Each level gets an encoder with its own caches (`ChunkEncoder::detached`). `body_alone` leaves nothing of the chunk cached once it is encoded. - Nothing is read while the save's writer has more than 512 chunks waiting. - **Kept bodies**: bodies sent are kept for 5 minutes, 96 MB at most, for players walking back. They are dropped: - when their column changes (block log, light log, `resend_biomes`); - when a level has no players left in it, since nothing logs its changes then. A read that a change overtakes while it is still in flight is dropped as stale. - **The brake** (`Far::brake`, once a second from the dedicated tick loop, on the clock's average): - Above 40 ms per tick, it pulls the ring in by 2 chunks, never inside `view_distance`. - After 30 s under 25 ms, it lets the ring out by 1 chunk every 5 s, up to `max_view_distance`. - Far chunks already sent stay when it pulls in. - Slow clients already slow their own ring through the existing acknowledgement pacing. - **Not changed**: entity tracking range, simulation distance, chunk tickets and loading, LAN and integrated servers (`Hub::far` is set only by `dedicated.rs`). ### Size At ~850 lines (about 200 of them tests and 25 docs), this is over the usual ~500. It was asked for as a single PR: the config, the reads, the cache, the brake and the hub's queues only work together. ### Tests - `lan::far::tests::the_brake_pulls_in_fast_and_lets_out_slowly`: steps, the floor at the view, the hold band, the calm wait, regrowth to max. - `lan::far::tests::reads_are_kept_until_their_column_changes`: walking back reads nothing again; `changed` and `forget_level` drop the kept body. - `lan::far::tests::a_read_overtaken_by_a_change_is_dropped` - `lan::hub::tests::the_far_ring_queues_what_the_view_leaves`: near and far queues partition the reach's queue, closest first, with sent chunks out of both. - `lan::chunks::tests::a_body_alone_leaves_nothing_cached` - `save::tests::far_reads_take_saved_lit_chunks_only` (with `HORIZON_TEST_RESOURCES`): a lit saved chunk reads back; a chunk saved without light, or not saved at all, doesn't; the region cache stays empty. - `cargo test -p horizon-server` (60) and `cargo test -p horizon-client --lib lan::` (95+) pass locally. The worktree I ran in has no `.local/`, so `pr_ready` ran with `--quick` and CI's parity job picks the affected harnesses. **pr_ready** (`tools/pr_ready.py --quick` on archlinux, against origin/main at 03fc2d3f2, 3 min 43 s) | Check | Result | | --- | --- | | Scope | ⚠️ 14 files, +849 −61; 888 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (35 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 7 s) | | tests: horizon-client, horizon-server | ✅ 1392 passed (1 min 13 s) | | doc tests | ✅ 0 passed (41 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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 05:16:34 +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#6007
No description provided.