General game loop model
Moirai, when using it’s ready-to-go Jobs engine, it’s super easy to plug into your game, as all what you do is you create Jobs engine and store it in your game/engine resources.
use moirai::jobs::Jobs;
fn main() {
// Setup Moirai engine with default jobs system.
let engine = Engine {
jobs: Jobs::default(),
};
// Game frame loop.
loop {
// Typical game update logic would go here...
// Do single Moirai local jobs run to make progress on coroutines at the
// end of the frame. Single run suspends at any `.await` point.
engine.jobs.run_local();
}
}
struct Engine {
jobs: Jobs,
}
Default Jobs engine creates worker-threads for each CPU core. If you need only local jobs, like many games do for coroutines, you can always use Jobs::local_only().