Skip to main content

spawn_threaded_world

Function spawn_threaded_world 

Source
pub fn spawn_threaded_world<T>(
    host: &mut World,
    name: &'static str,
    command_capacity: usize,
    tick: T,
) -> WorldHandle
where T: FnMut(&mut World, &ThreadControl, f32) -> bool + Send + 'static,
Expand description

Spawn a threaded world on a fresh thread, driven by tick.

The thread’s loop drains the jobs queued for the world, then runs tick once, then publishes what the world’s subscriptions collected; a tick that returns false ends the thread. A job that panics is a tick panic: it is reported and ends the thread. The handle returned carries the handle every later job goes through, and dropping the host entity it names stops the thread.

tick takes the whole seconds since the previous tick, so a tick body can advance by the time that really passed rather than assume the rate it asked to be woken at.

name labels the world for a bridge that lists the host’s worlds; it lands on the proxy entity as a WorldName.