perf(client): read the loot tables while joining a server

On a server's world the loot tables were first read on the game thread by
the first block placed (StepContext's loot), a ~0.6 s freeze on a phone.
They are now read on a helper thread as the connection starts, like the
world screens' preload does for local worlds, and kept from then on.
This commit is contained in:
feeldev committed 2026-10-27 16:54:03 -05:00
1 parent 1feb28c045
commit fdefcfeac0
2 files changed
+22

No files matched your search

+1
View File
@@ -302,6 +302,7 @@ impl Game<'_> {
name: &str,
cookies: Option<horizon_client::net::Cookies>,
) -> Result<()> {
super::world_loading::preload_server_loot(&self.options.resources);
if self.defer_world_entry(super::PendingWorldEntry::Server {
address: address.to_owned(),
name: name.to_owned(),
@@ -279,6 +279,27 @@ pub(super) fn world_data_used() {
*PRELOAD.lock().unwrap_or_else(|e| e.into_inner()) = Preload::Used;
}
/// A server's world opens: the loot tables its first placed block or broken
/// container needs (`loot_data`) are read on a helper thread while the
/// connection is made, so the game thread never waits on them (~0.6 s on a
/// phone). Kept from then on, as a local world keeps them.
pub(super) fn preload_server_loot(resources: &std::path::Path) {
world_data_used();
if horizon_client::structure_blocks::loaded_loot_data().is_some() {
return;
}
let resources = resources.to_owned();
let spawned = std::thread::Builder::new()
.name("Loot preload".into())
.spawn(move || {
horizon_threads::behind_server();
let _ = horizon_client::structure_blocks::loot_data(&resources);
});
if let Err(e) = spawned {
log::warn!("Horizon: loot preload: {e}");
}
}
pub(super) fn make_streaming(
res: &Resources,
pack: &PackResources,