[PR #537] [MERGED] Split Resources into shared read-only data and per-game pack state #2630

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

📋 Pull Request Information

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

Base: main ← Head: perf/resources-shared-split


📝 Commits (1)

  • c57c409 Split Resources into shared read-only data and per-game pack state

📊 Changes

100 files changed (+563 additions, -582 deletions)

View changed files

📝 crates/horizon-client/src/fog.rs (+0 -16)
📝 crates/horizon-client/src/game.rs (+188 -161)
📝 crates/horizon-client/src/game/advancements.rs (+5 -5)
📝 crates/horizon-client/src/game/advancements_screen.rs (+9 -9)
📝 crates/horizon-client/src/game/agent.rs (+1 -1)
📝 crates/horizon-client/src/game/armor_stands.rs (+5 -5)
📝 crates/horizon-client/src/game/backdrop.rs (+4 -4)
📝 crates/horizon-client/src/game/beacon.rs (+5 -11)
📝 crates/horizon-client/src/game/beehives.rs (+2 -2)
📝 crates/horizon-client/src/game/block_entity_anims.rs (+1 -1)
📝 crates/horizon-client/src/game/block_items.rs (+1 -1)
📝 crates/horizon-client/src/game/blockctl.rs (+3 -3)
📝 crates/horizon-client/src/game/boats.rs (+0 -1)
📝 crates/horizon-client/src/game/books.rs (+4 -4)
📝 crates/horizon-client/src/game/cartography.rs (+3 -3)
📝 crates/horizon-client/src/game/chat.rs (+14 -16)
📝 crates/horizon-client/src/game/command_blocks.rs (+7 -7)
📝 crates/horizon-client/src/game/commands.rs (+8 -8)
📝 crates/horizon-client/src/game/commands/compute.rs (+1 -1)
📝 crates/horizon-client/src/game/commands/data.rs (+1 -1)

...and 80 more files

📄 Description

What and why

First step of running single player's world on its own "Server thread", as vanilla's IntegratedServer does (#495, #494). That needs a second Game (the server) on another thread, reading the same loaded data as the window's game. Today Game holds &mut Resources, and three things mutate it: resource-pack reload, the fog state and the font/skin atlas.

This PR splits it, with no behaviour change:

  • Resources: what is loaded once and never changes (block facts, items, recipes, biomes, environments, mobs, behaviours, stations, animate/fog/music/ambient tables, and now the collision and motion data). The game holds it behind an Arc; a test asserts it is Send + Sync.
  • PackResources: what a resource-pack reload replaces (assets, meshing context, item renderer, names, panorama, clouds, forcefield, layer names). One loader, PackResources::load, is used at startup and by reload_packs, which used to repeat that code. Cloning it shares the loaded data, so a server can start from the client's and keep it when the client reloads packs (vanilla's server never sees resource packs either).
  • Per-game state: the HUD atlas (its font cache is a RefCell, and skins are written into it), the FogState and the screen effects become fields of Game. FogRenderer was only those tables and that state, so it is gone; setup_fog takes both.

One piece of shared data does change with the packs: the villager hat metadata from #521. MobData.villager_hats is now an RwLock, which a pack reload writes and mob rendering reads, so Resources stays shareable.

Most of the diff is the mechanical rename of self.res.atlas → self.atlas and self.res.assets (and the other pack fields) → self.pack.assets across game/. Review: git diff --stat shows 100 files, but only game.rs (the two structs, PackResources::load, run()), game/packs.rs (reload), game/render_tick.rs (fog), fog.rs and mobs/data.rs hold logic.

Vanilla reference

None: an internal split. It prepares IntegratedServer (MinecraftServer on its own thread, reading the same registries as the client).

Measurements

A refactor with no runtime change: same work per frame and per tick (the Arc deref replaces a &mut deref). The frame-time effect comes with the PRs stacked on this one (#544, #545).

Checks

  • cargo fmt --all --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: ok
  • cargo test -p horizon-client --lib: 759 passed, 0 failed, 7 ignored (on the top of the stack, rebased on main at a08add23)
  • cargo test -p horizon-client --bin horizon-client: 55 passed (new: shared_resources_can_cross_threads)
  • clippy also run on this commit and on #538 alone
  • Local parity, tools/parity.py --changed origin/main, run once on the top of the stack (this PR and the three above it): 84 passed, 0 failed (includes dedicated_server, lan, save_roundtrip, world_reopen and every single-player harness), on the stack rebased on main at a08add23

Stack: this PR → #538 → #544 → #545.

Refs #495

🤖 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/537 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/resources-shared-split` --- ### 📝 Commits (1) - [`c57c409`](https://github.com/horizon-rust/horizon/commit/c57c409f40cb7a7b1e6939e0c61476a5134d9411) Split Resources into shared read-only data and per-game pack state ### 📊 Changes **100 files changed** (+563 additions, -582 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/fog.rs` (+0 -16) 📝 `crates/horizon-client/src/game.rs` (+188 -161) 📝 `crates/horizon-client/src/game/advancements.rs` (+5 -5) 📝 `crates/horizon-client/src/game/advancements_screen.rs` (+9 -9) 📝 `crates/horizon-client/src/game/agent.rs` (+1 -1) 📝 `crates/horizon-client/src/game/armor_stands.rs` (+5 -5) 📝 `crates/horizon-client/src/game/backdrop.rs` (+4 -4) 📝 `crates/horizon-client/src/game/beacon.rs` (+5 -11) 📝 `crates/horizon-client/src/game/beehives.rs` (+2 -2) 📝 `crates/horizon-client/src/game/block_entity_anims.rs` (+1 -1) 📝 `crates/horizon-client/src/game/block_items.rs` (+1 -1) 📝 `crates/horizon-client/src/game/blockctl.rs` (+3 -3) 📝 `crates/horizon-client/src/game/boats.rs` (+0 -1) 📝 `crates/horizon-client/src/game/books.rs` (+4 -4) 📝 `crates/horizon-client/src/game/cartography.rs` (+3 -3) 📝 `crates/horizon-client/src/game/chat.rs` (+14 -16) 📝 `crates/horizon-client/src/game/command_blocks.rs` (+7 -7) 📝 `crates/horizon-client/src/game/commands.rs` (+8 -8) 📝 `crates/horizon-client/src/game/commands/compute.rs` (+1 -1) 📝 `crates/horizon-client/src/game/commands/data.rs` (+1 -1) _...and 80 more files_ </details> ### 📄 Description ## What and why First step of running single player's world on its own "Server thread", as vanilla's `IntegratedServer` does (#495, #494). That needs a second `Game` (the server) on another thread, reading the same loaded data as the window's game. Today `Game` holds `&mut Resources`, and three things mutate it: resource-pack reload, the fog state and the font/skin atlas. This PR splits it, with no behaviour change: - **`Resources`**: what is loaded once and never changes (block facts, items, recipes, biomes, environments, mobs, behaviours, stations, animate/fog/music/ambient tables, and now the collision and motion data). The game holds it behind an `Arc`; a test asserts it is `Send + Sync`. - **`PackResources`**: what a resource-pack reload replaces (assets, meshing context, item renderer, names, panorama, clouds, forcefield, layer names). One loader, `PackResources::load`, is used at startup and by `reload_packs`, which used to repeat that code. Cloning it shares the loaded data, so a server can start from the client's and keep it when the client reloads packs (vanilla's server never sees resource packs either). - **Per-game state**: the HUD atlas (its font cache is a `RefCell`, and skins are written into it), the `FogState` and the screen effects become fields of `Game`. `FogRenderer` was only those tables and that state, so it is gone; `setup_fog` takes both. One piece of shared data does change with the packs: the villager hat metadata from #521. `MobData.villager_hats` is now an `RwLock`, which a pack reload writes and mob rendering reads, so `Resources` stays shareable. Most of the diff is the mechanical rename of `self.res.atlas` → `self.atlas` and `self.res.assets` (and the other pack fields) → `self.pack.assets` across `game/`. Review: `git diff --stat` shows 100 files, but only `game.rs` (the two structs, `PackResources::load`, `run()`), `game/packs.rs` (reload), `game/render_tick.rs` (fog), `fog.rs` and `mobs/data.rs` hold logic. ## Vanilla reference None: an internal split. It prepares `IntegratedServer` (`MinecraftServer` on its own thread, reading the same registries as the client). ## Measurements A refactor with no runtime change: same work per frame and per tick (the `Arc` deref replaces a `&mut` deref). The frame-time effect comes with the PRs stacked on this one (#544, #545). ## Checks - `cargo fmt --all --check`: ok - `cargo clippy --workspace --all-targets -- -D warnings`: ok - `cargo test -p horizon-client --lib`: 759 passed, 0 failed, 7 ignored (on the top of the stack, rebased on main at a08add23) - `cargo test -p horizon-client --bin horizon-client`: 55 passed (new: `shared_resources_can_cross_threads`) - clippy also run on this commit and on #538 alone - Local parity, `tools/parity.py --changed origin/main`, run once on the top of the stack (this PR and the three above it): 84 passed, 0 failed (includes `dedicated_server`, `lan`, `save_roundtrip`, `world_reopen` and every single-player harness), on the stack rebased on main at a08add23 Stack: this PR → #538 → #544 → #545. Refs #495 🤖 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:57:46 +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#2630
No description provided.