bevy/crates/bevy_ecs/examples/resources.rs
Trevor Lovell 464d35aef5
docs: update docs and comments that still refer to stages (#8156)
# Objective
Documentation should no longer be using pre-stageless terminology to
avoid confusion.

## Solution
- update all docs referring to stages to instead refer to sets/schedules
where appropriate
- also mention `apply_system_buffers` for anything system-buffer-related
that previously referred to buffers being applied "at the end of a
stage"
2023-03-27 21:50:21 +00:00

41 lines
1.1 KiB
Rust

use bevy_ecs::prelude::*;
use rand::Rng;
use std::ops::Deref;
// In this example we add a counter resource and increase it's value in one system,
// while a different system prints the current count to the console.
fn main() {
// Create a world
let mut world = World::new();
// Add the counter resource
world.insert_resource(Counter { value: 0 });
// Create a schedule
let mut schedule = Schedule::default();
// Add systems to increase the counter and to print out the current value
schedule.add_systems((increase_counter, print_counter).chain());
for iteration in 1..=10 {
println!("Simulating frame {iteration}/10");
schedule.run(&mut world);
}
}
// Counter resource to be increased and read by systems
#[derive(Debug, Resource)]
struct Counter {
pub value: i32,
}
fn increase_counter(mut counter: ResMut<Counter>) {
if rand::thread_rng().gen_bool(0.5) {
counter.value += 1;
println!(" Increased counter value");
}
}
fn print_counter(counter: Res<Counter>) {
println!(" {:?}", counter.deref());
}