[PR #538] [MERGED] Build the game in Game::new instead of inside run() #2633

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

📋 Pull Request Information

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

Base: main ← Head: perf/game-constructor


📝 Commits (2)

  • c57c409 Split Resources into shared read-only data and per-game pack state
  • c2f4ecc Build the game in Game::new instead of inside run()

📊 Changes

100 files changed (+873 additions, -875 deletions)

View changed files

📝 crates/horizon-client/src/fog.rs (+0 -16)
📝 crates/horizon-client/src/game.rs (+498 -454)
📝 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

Second step towards single player on its own "Server thread" (#495). run() built the whole Game inline: a 300-line struct literal between loading the resources and starting the event loop. The integrated server needs to build a second game on its own thread from the same shared resources, so that literal moves into a constructor:

impl<'a> Game<'a> {
    fn new(res: &'a Arc<Resources>, pack: PackResources, atlas: HudAtlas,
           options: Options, settings: Settings, audio: Audio) -> Result<Self>
}

run() loads the resources and the pack, then calls Game::new. The struct literal moves unchanged (re-indented; world_frames from #515 comes along). Options derives Clone so a server can start from the client's options.

No behaviour change.

Vanilla reference

None: an internal move. It prepares IntegratedServer construction.

Measurements

None: the same code runs once at startup.

Checks

  • cargo fmt --all --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: ok, on this commit alone and on the top of the stack
  • cargo test -p horizon-client --lib: 759 passed, 0 failed, 7 ignored (top of the stack)
  • Local parity, run once on the top of the stack: see #544

Stack: #537 → this PR → #544 → #545. Review the diff with git diff -w or --color-moved: it is almost all a move.

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/538 **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/game-constructor` --- ### 📝 Commits (2) - [`c57c409`](https://github.com/horizon-rust/horizon/commit/c57c409f40cb7a7b1e6939e0c61476a5134d9411) Split Resources into shared read-only data and per-game pack state - [`c2f4ecc`](https://github.com/horizon-rust/horizon/commit/c2f4ecc188d8fa49909550c4ab61eef85e75be7e) Build the game in Game::new instead of inside run() ### 📊 Changes **100 files changed** (+873 additions, -875 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/fog.rs` (+0 -16) 📝 `crates/horizon-client/src/game.rs` (+498 -454) 📝 `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 Second step towards single player on its own "Server thread" (#495). `run()` built the whole `Game` inline: a 300-line struct literal between loading the resources and starting the event loop. The integrated server needs to build a second game on its own thread from the same shared resources, so that literal moves into a constructor: ```rust impl<'a> Game<'a> { fn new(res: &'a Arc<Resources>, pack: PackResources, atlas: HudAtlas, options: Options, settings: Settings, audio: Audio) -> Result<Self> } ``` `run()` loads the resources and the pack, then calls `Game::new`. The struct literal moves unchanged (re-indented; `world_frames` from #515 comes along). `Options` derives `Clone` so a server can start from the client's options. No behaviour change. ## Vanilla reference None: an internal move. It prepares `IntegratedServer` construction. ## Measurements None: the same code runs once at startup. ## Checks - `cargo fmt --all --check`: ok - `cargo clippy --workspace --all-targets -- -D warnings`: ok, on this commit alone and on the top of the stack - `cargo test -p horizon-client --lib`: 759 passed, 0 failed, 7 ignored (top of the stack) - Local parity, run once on the top of the stack: see #544 Stack: #537 → this PR → #544 → #545. Review the diff with `git diff -w` or `--color-moved`: it is almost all a move. 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:48 +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#2633
No description provided.