Skip to main content

run

Function run 

Source
pub async fn run<G: GameData>(config: AppConfig, start: Start<G>)
Expand description

Runs a game until it quits, as start says: the first frame shows its loading card, the next loads it (or shows why it can’t: a wrong command line, a broken asset), and each frame after, App reads the keyboard and controllers, steps the game, plays its sounds, music and voices and draws its frame. Closing the window lets the game save first.

The game’s context gets this build’s target’s facts (shuyi_ui::PlatformFacts): the target is SHUYI_TARGET when the build sets it (the Steam Deck’s export sets steam-deck), else web on the web and desktop elsewhere. A target this backend has no profile of is shown as the game’s error.

Frames come no faster than the game’s frame cap (shuyi_ui::frame_cap, 60 a second unless the game or the player says): after each frame is drawn, the loop waits until the next is due, unless vsync or the machine already keeps them that far apart, and reports how it paces to the game before the next. On the web the browser sets the rate: a frame before the due time shows the last one again, and its input waits for the next frame that runs.

A panic writes a crash report as AppConfig::crash says (crash). On native a panic of the game’s frame then stops the sound, adds the game’s record of its play to the report and ends the process with exit code 101; the game’s system hook isn’t called, so a broken game never saves.