add basic example of a custom update loop (#799)

This commit is contained in:
easynam 2020-11-09 21:04:27 +00:00 committed by GitHub
parent b324f66135
commit 31a433b69e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -148,6 +148,10 @@ path = "examples/3d/texture.rs"
name = "z_sort_debug" name = "z_sort_debug"
path = "examples/3d/z_sort_debug.rs" path = "examples/3d/z_sort_debug.rs"
[[example]]
name = "custom_loop"
path = "examples/app/custom_loop.rs"
[[example]] [[example]]
name = "empty_defaults" name = "empty_defaults"
path = "examples/app/empty_defaults.rs" path = "examples/app/empty_defaults.rs"

View file

@ -0,0 +1,31 @@
use bevy::prelude::*;
use std::{io, io::BufRead};
struct Input(String);
/// This example demonstrates you can create a custom runner (to update an app manually). It reads
/// lines from stdin and prints them from within the ecs.
fn my_runner(mut app: App) {
app.initialize();
println!("Type stuff into the console");
for line in io::stdin().lock().lines() {
{
let mut input = app.resources.get_mut::<Input>().unwrap();
input.0 = line.unwrap();
}
app.update();
}
}
fn print_system(input: Res<Input>) {
println!("You typed: {}", input.0);
}
fn main() {
App::build()
.add_resource(Input(String::new()))
.set_runner(my_runner)
.add_system(print_system.system())
.run();
}