examples/systems/
system_time_interval.rs1use crate::z_ignore_test_common::*;
2
3use flecs_ecs::prelude::*;
4#[derive(Component)]
7struct Timeout {
8 pub value: f32,
9}
10
11fn tick(mut it: TableIter) {
12 while it.next() {
13 println!("{}", it.system().name());
14 }
15}
16
17fn main() {
18 let world = World::new();
19
20 world.set(Timeout { value: 3.5 });
21
22 world
23 .system::<&mut Timeout>()
24 .each_iter(|it, _index, timeout| {
25 timeout.value -= it.delta_time();
26 });
27
28 world.system_named::<()>("Tick").interval(1.0).run(tick);
29
30 world.system_named::<()>("FastTick").interval(0.5).run(tick);
31
32 world.set_target_fps(60.0);
34
35 while world.progress() {
36 if world.map::<&Timeout, _>(|timeout| timeout.value <= 0.0) {
37 println!("Timed out!");
38 break;
39 }
40 }
41
42 }
55
56#[cfg(feature = "flecs_nightly_tests")]
57#[test]
58fn test() {
59 let output_capture = OutputCapture::capture().unwrap();
60 main();
61 assert!(output_capture.output_string().contains("Timed out!"));
62}