summaryrefslogtreecommitdiff
path: root/ecs/examples/simple.rs
blob: b58d2ba95cc0dcf39a8f1846f71fae6a55e4e4f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use ecs::{Query, World};

struct SomeData
{
    num: u64,
}

fn say_hello(mut query: Query<(SomeData, String)>)
{
    for (data, text) in query.iter_mut() {
        println!("Hello {}: {}", text, data.num);
    }
}

#[derive(Debug, PartialEq, Eq, Hash)]
enum Event
{
    Start,
}

fn main()
{
    let mut world = World::<Event>::new();

    world.register_system(Event::Start, say_hello);

    world.create_entity((SomeData { num: 987_654 }, "Yoo".to_string()));

    world.create_entity((SomeData { num: 345 }, "Haha".to_string()));

    world.emit(&Event::Start);
}