diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 6ef14a633..f706e9348 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -12949,10 +12949,10 @@ pub fn run() -> Result<()> { if options.dedicated.is_some() && !dedicated::preflight(&mut options)? { return Ok(()); } - if options.dedicated.is_some() { - // Before any worker starts: on Linux they go behind the server thread. - horizon_threads::put_helpers_behind(); - } else { + // Before any worker starts: on Linux they go behind the server thread + // and the render thread. + horizon_threads::put_helpers_behind(); + if options.dedicated.is_none() { // The render thread, like the server thread, ahead of the workers on // macOS and Windows. While terrain loads, the worker pools (two with // single player's server thread) and other programs outnumber the diff --git a/crates/horizon-client/src/lan/conn.rs b/crates/horizon-client/src/lan/conn.rs index 7a92040f2..a8ec46dad 100644 --- a/crates/horizon-client/src/lan/conn.rs +++ b/crates/horizon-client/src/lan/conn.rs @@ -778,7 +778,7 @@ fn play(c: Connection, shared: &Arc, parts: Parts, address: std::net::So std::thread::Builder::new() .name(format!("horizon-lan-out-{conn_id}")) .spawn(move || { - // A dedicated server's tick comes first (horizon_threads). + // Ticks and frames come first (horizon_threads). horizon_threads::behind_server(); write_loop(writer, rx, alive, latency, pending) }) diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 858d05d30..5d5839539 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -436,7 +436,7 @@ impl Streaming { thread::Builder::new() .name(format!("horizon-worker-{i}")) .spawn(move || { - // A dedicated server's tick comes first (horizon_threads). + // Ticks and frames come first (horizon_threads). horizon_threads::behind_server(); let mut worker = generator.worker(); // The face visibility table and its occlusion cache stay with diff --git a/crates/horizon-threads/src/lib.rs b/crates/horizon-threads/src/lib.rs index 6af6818cc..ae4cc753f 100644 --- a/crates/horizon-threads/src/lib.rs +++ b/crates/horizon-threads/src/lib.rs @@ -41,30 +41,30 @@ fn favour() -> bool { false } -/// Set once by a dedicated server, before its helper threads start: they -/// then go behind its server thread (`behind_server`). +/// Set once as the game starts, before its helper threads do: they then go +/// behind the server thread and the render thread (`behind_server`). static HELPERS_BEHIND: AtomicBool = AtomicBool::new(false); /// How many nice levels a helper thread goes below the process on Linux. #[cfg(target_os = "linux")] const BEHIND: i32 = 10; -/// A dedicated server: from now on, the helper threads that call -/// `behind_server` as they start go behind the server thread. Call it -/// before they start. +/// From now on, the helper threads that call `behind_server` as they start +/// go behind the server thread (a dedicated server's or single player's) +/// and the render thread. Call it before they start. pub fn put_helpers_behind() { HELPERS_BEHIND.store(true, Ordering::Relaxed); } -/// Called by a helper thread as it starts (world generation and lighting, -/// a connection's packet writer): work the tick never waits for. In a -/// dedicated server (`put_helpers_behind`) on Linux, where the server thread -/// can't be raised (`favour_current`), the helper lowers itself instead, -/// which an unprivileged thread may: 10 nice levels below the process, or, -/// where nice runs out (a server started under nice 10 or more), the idle -/// class, which runs the thread only when no ordinary thread wants its core. -/// The server thread then gets a core when its tick starts instead of -/// waiting behind them. Nothing elsewhere. Whether the OS took it. +/// Called by a helper thread as it starts (world generation, lighting and +/// meshing, a connection's packet writer): work no tick or frame waits for. +/// Once `put_helpers_behind` was called, on Linux, where the server and +/// render threads can't be raised (`favour_current`), the helper lowers +/// itself instead, which an unprivileged thread may: 10 nice levels below +/// the process, or, where nice runs out (a game started under nice 10 or +/// more), the idle class, which runs the thread only when no ordinary thread +/// wants its core. A tick or a frame then gets a core when it starts instead +/// of waiting behind them. Nothing elsewhere. Whether the OS took it. pub fn behind_server() -> bool { HELPERS_BEHIND.load(Ordering::Relaxed) && behind() }