mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 13:13:49 +00:00
c26be39719
# Objective - Since #4224, using labels which only refer to one system doesn't make sense. ## Solution - Remove some of those. ## Future work - We should remove the ability to use strings as system labels entirely. I haven't in this PR because there are tests which use this, and that's a lot of code to change. - The only use cases for labels are either intra-crate, which use #4224, or inter-crate, which should either use #4224 or explicit types. Neither of those should use strings.
44 lines
1.2 KiB
Rust
44 lines
1.2 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 and a stage
|
|
let mut schedule = Schedule::default();
|
|
let mut update = SystemStage::parallel();
|
|
|
|
// Add systems to increase the counter and to print out the current value
|
|
update.add_system(increase_counter);
|
|
update.add_system(print_counter.after(increase_counter));
|
|
schedule.add_stage("update", update);
|
|
|
|
for iteration in 1..=10 {
|
|
println!("Simulating frame {}/10", iteration);
|
|
schedule.run(&mut world);
|
|
}
|
|
}
|
|
|
|
// Counter resource to be increased and read by systems
|
|
#[derive(Debug)]
|
|
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());
|
|
}
|