multithreaded/
main.rs

1use std::{thread, time::Duration};
2
3use matrix_engine::engine::{
4    events::MatrixEventable,
5    plugins::{window_plugin::WindowPlugin, Plugin},
6    query::{ReadC, WriteC},
7    runtimes::multi_threading::MultiThreaded,
8    Engine, EngineArgs,
9};
10
11struct ExamplePlugin;
12
13impl<CustomEvents: MatrixEventable> Plugin<CustomEvents> for ExamplePlugin {
14    fn build(&self, scene: &mut matrix_engine::engine::scene::Scene<CustomEvents>) {
15        scene.add_send_system(|_data: &mut ReadC<u64>| {
16            println!("started1");
17            thread::sleep(Duration::from_secs(4));
18            println!("ended1")
19        });
20        scene.add_send_system(|_data: &mut ReadC<u64>, _data2: &mut WriteC<()>| {
21            println!("started2");
22            thread::sleep(Duration::from_secs(2));
23            println!("ended2")
24        });
25        scene.add_send_system(|_data: &mut ReadC<u64>, _data2: &mut WriteC<()>| {
26            println!("started3");
27            thread::sleep(Duration::from_secs(2));
28            println!("ended3")
29        });
30    }
31}
32
33fn main() {
34    let mut engine = <Engine>::new(EngineArgs::new(
35        MultiThreaded::with_cpu_count(),
36        MultiThreaded::with_cpu_count(),
37    ));
38
39    engine.add_scene_plugin(WindowPlugin::new("multithreaded"));
40
41    engine.add_scene_plugin(ExamplePlugin);
42
43    engine.run().unwrap();
44}