| 1 |
|
| 2 |
|
| 3 |
use bevy::{ |
| 4 |
ecs::{ |
| 5 |
error::{BevyError, ErrorContext}, |
| 6 |
schedule::{FixedBitSet, SystemExecutor, SystemSchedule}, |
| 7 |
}, |
| 8 |
prelude::*, |
| 9 |
}; |
| 10 |
|
| 11 |
#[derive(Default)] |
| 12 |
struct CustomExecutor; |
| 13 |
|
| 14 |
impl SystemExecutor for CustomExecutor { |
| 15 |
fn init(&mut self, _schedule: &SystemSchedule) {} |
| 16 |
|
| 17 |
fn run( |
| 18 |
&mut self, |
| 19 |
schedule: &mut SystemSchedule, |
| 20 |
world: &mut World, |
| 21 |
_skip_systems: Option<&FixedBitSet>, |
| 22 |
_error_handler: fn(BevyError, ErrorContext), |
| 23 |
) { |
| 24 |
#[expect(unsafe_code, reason = "CustomExecutor's require unsafe")] |
| 25 |
|
| 26 |
for entry in unsafe { schedule.systems_mut().iter_mut() } { |
| 27 |
let _ = entry.run((), world); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
fn set_apply_final_deferred(&mut self, _value: bool) {} |
| 32 |
} |
| 33 |
|
| 34 |
#[derive(Resource, Default)] |
| 35 |
struct Counter(u32); |
| 36 |
|
| 37 |
fn increment(mut counter: ResMut<Counter>) { |
| 38 |
counter.0 += 1; |
| 39 |
} |
| 40 |
|
| 41 |
fn print_counter(counter: Res<Counter>) { |
| 42 |
println!("Counter: {}", counter.0); |
| 43 |
} |
| 44 |
|
| 45 |
fn main() { |
| 46 |
let mut world = World::new(); |
| 47 |
world.init_resource::<Counter>(); |
| 48 |
|
| 49 |
let mut schedule = Schedule::default(); |
| 50 |
schedule.set_executor(CustomExecutor); |
| 51 |
schedule.add_systems((increment, print_counter).chain()); |
| 52 |
|
| 53 |
for _ in 0..5 { |
| 54 |
schedule.run(&mut world); |
| 55 |
} |
| 56 |
} |