bevy/examples/app/custom_loop.rs
Carter Anderson 3a6f6de277
System Inputs, Outputs, Chaining, and Registration Ergo (#876)
System Inputs, Outputs, Chaining, and Registration Ergo
2020-11-16 18:18:00 -08:00

31 lines
768 B
Rust

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)
.run();
}