Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

Startup: load the world tables while the handoff's CPU work runs

Ludovic Maried5e348e8e84e
diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs
index 3721e78f3..0f1f34315 100644
--- a/crates/horizon-client/src/game.rs
+++ b/crates/horizon-client/src/game.rs
@@ -19343,23 +19343,6 @@ fn load_resources(
started.elapsed().as_millis()
);
}
- // Finish fallible CPU preparation before starting the tail, so an error
- // cannot detach a tail worker that races the next pack-loader generation.
- let prepared_at = Instant::now();
- let game_cpu = menu
- .then(|| startup::time("handoff.game_cpu", || GameCpuResources::load(&root)))
- .transpose()?;
- let renderer_cpu = menu.then(|| {
- startup::time("handoff.renderer_textures", || {
- prepare_renderer_textures(&pack)
- })
- });
- if menu {
- log::info!(
- "Horizon: handoff CPU resources prepared on worker in {} ms",
- prepared_at.elapsed().as_millis()
- );
- }
// The block entity renderer's face visibility: the meshes' own, whose
// shapes already hold their faces, not a second load of the same tables.
let visibility = pack.context.tables.visibility.clone();
@@ -19418,6 +19401,37 @@ fn load_resources(
.map_err(|_| "world resources already loaded")?;
None
};
+ // The world tables load (above) while the handoff's CPU work is done: the
+ // world renderer's textures beside the game's own tables. A failure here
+ // waits for the tail, so no tail worker outlives its pack-loader generation.
+ let prepared_at = Instant::now();
+ let (game_cpu, renderer_cpu) = if menu {
+ let (game_cpu, renderer_cpu) = std::thread::scope(|scope| {
+ let textures = Step::spawn(scope, parallel, || {
+ startup::time("handoff.renderer_textures", || {
+ prepare_renderer_textures(&pack)
+ })
+ });
+ let game_cpu = startup::time("handoff.game_cpu", || GameCpuResources::load(&root));
+ (game_cpu, textures.join())
+ });
+ let game_cpu = match game_cpu {
+ Ok(game_cpu) => game_cpu,
+ Err(error) => {
+ if let Some(tail) = rest_loader {
+ let _ = tail.handle.join();
+ }
+ return Err(error);
+ }
+ };
+ log::info!(
+ "Horizon: handoff CPU resources prepared on worker in {} ms",
+ prepared_at.elapsed().as_millis()
+ );
+ (Some(game_cpu), Some(renderer_cpu))
+ } else {
+ (None, None)
+ };
Ok(Loaded {
game_cpu,
renderer_cpu,