From c41a053c15526b3273365a887c39962991186453 Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Sat, 24 Oct 2026 23:53:29 +0100 Subject: [PATCH] refactor: separate client world entry from authoritative loading Give integrated and dedicated startup a synchronous loading entry point without client deferral or integrated-server selection. Keep client orchestration and background loading unchanged. Co-Authored-By: OpenAI Codex GPT-6.1 --- crates/horizon-client/src/game.rs | 21 ++++++++++--------- crates/horizon-client/src/game/dedicated.rs | 6 +++--- crates/horizon-client/src/game/integrated.rs | 5 +++-- .../horizon-client/src/game/world_loading.rs | 17 +++++++++++++++ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index c46b86032..38fdb9e37 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -7501,7 +7501,7 @@ impl Game<'_> { (sky.star_brightness > 0.0).then(|| (frame(sky.star_angle), sky.star_brightness)); (out, stars) } - /// Load (or create) a world folder under saves/ and start streaming it. + /// Enter a local world from the client, selecting its simulation mode. fn open_world( &mut self, folder: &str, @@ -7524,16 +7524,9 @@ impl Game<'_> { if integrated::wanted(&self.options, &save_root) { return self.open_integrated(folder, name, seed, creative, create); } - self.perf.world_opening(); - let request = world_loading::WorldRequest { - save_root, - folder: folder.to_owned(), - name: name.map(str::to_owned), - seed, - creative, - create: create.cloned(), - }; + let request = world_loading::WorldRequest::new(folder, name, seed, creative, create)?; if self.window.is_some() { + self.perf.world_opening(); if self.title.is_none() { self.title = Some(Title::new( std::env::current_dir()?.join("saves"), @@ -7549,6 +7542,14 @@ impl Game<'_> { )?); return Ok(()); } + self.load_world(request) + } + + /// Load authoritative world state synchronously, without client entry or + /// integrated-server selection. Server startup must use this entry point. + fn load_world(&mut self, request: world_loading::WorldRequest) -> Result<()> { + self.join_world_rest()?; + self.perf.world_opening(); let prepared = request.prepare(&self.res, &self.pack, &self.options, &self.settings)?; self.finish_open_world(prepared) } diff --git a/crates/horizon-client/src/game/dedicated.rs b/crates/horizon-client/src/game/dedicated.rs index eee12fe3f..4c436c60c 100644 --- a/crates/horizon-client/src/game/dedicated.rs +++ b/crates/horizon-client/src/game/dedicated.rs @@ -6,7 +6,7 @@ //! its simulation and the play-state hub that LAN hosting uses, configured //! from server.properties, with the operator, whitelist and ban lists and a //! console on standard input. -use super::{Game, Options, lan::LanSettings}; +use super::{Game, Options, lan::LanSettings, world_loading::WorldRequest}; use horizon_client::{ Result, lan::{LoginGate, NetConfig, NetLog, OnlineMode, hub::HubConfig}, @@ -546,13 +546,13 @@ impl Game<'_> { let lists = Arc::new(Mutex::new(lists)); log("INFO", &format!("Preparing level \"{level_name}\"")); let folder = world_dir.to_string_lossy().into_owned(); - self.open_world( + self.load_world(WorldRequest::new( &folder, Some(&level_name), Some(props.seed), game_mode == 1, None, - )?; + )?)?; if new_world { self.level.hardcore = props.hardcore; } diff --git a/crates/horizon-client/src/game/integrated.rs b/crates/horizon-client/src/game/integrated.rs index 44df5fe20..4cbe41ccf 100644 --- a/crates/horizon-client/src/game/integrated.rs +++ b/crates/horizon-client/src/game/integrated.rs @@ -13,6 +13,7 @@ use super::{ Game, Options, PackResources, Resources, UiResources, lan::{LanSettings, Owner}, + world_loading::WorldRequest, }; use horizon_client::{ Result, @@ -287,13 +288,13 @@ impl Game<'_> { tasks: Receiver, ready: &Sender, ) -> Result<()> { - self.open_world( + self.load_world(WorldRequest::new( &launch.folder, launch.name.as_deref(), launch.seed, launch.creative, launch.create.as_ref(), - )?; + )?)?; let saved = Box::new(self.level.clone()); // Math.max(2, options.renderDistance): past vanilla's 32 when the // window's render distance is (Horizon's options go to 64). diff --git a/crates/horizon-client/src/game/world_loading.rs b/crates/horizon-client/src/game/world_loading.rs index bd9ae7caa..3db3b733d 100644 --- a/crates/horizon-client/src/game/world_loading.rs +++ b/crates/horizon-client/src/game/world_loading.rs @@ -22,6 +22,23 @@ pub(super) struct PreparedWorld { } impl WorldRequest { + pub fn new( + folder: &str, + name: Option<&str>, + seed: Option, + creative: bool, + create: Option<&horizon_client::title::WorldOptions>, + ) -> Result { + Ok(Self { + save_root: std::env::current_dir()?.join("saves").join(folder), + folder: folder.to_owned(), + name: name.map(str::to_owned), + seed, + creative, + create: create.cloned(), + }) + } + pub fn prepare( self, res: &Resources,