23 unstable releases (3 breaking)

0.6.6 Apr 3, 2024
0.6.5 Apr 3, 2024
0.6.0 Mar 19, 2024
0.5.1 Mar 18, 2024
0.1.6 Nov 20, 2022

#264 in Game dev

Download history 4/week @ 2024-02-27 523/week @ 2024-03-12 381/week @ 2024-03-19 1/week @ 2024-03-26 640/week @ 2024-04-02 213/week @ 2024-04-09

1,043 downloads per month

MIT license

23KB
485 lines

thallium

Latest Version Rust Documentation GitHub license

A basic game engine that ive been working on

Example code

use thallium::ecs::{App, Component, Entities, Query, Ref, RefMut, SystemSet};

#[derive(Component)]
struct Person {
    name: String,
    age: i32,
}

let mut app = App::new();

let person1 = app.create_entity();
app.add_component(person1, Person {
    name: "Alice".into(),
    age: 23,
});

let person2 = app.create_entity();
app.add_component(person2, Person {
    name: "Bob".into(),
    age: 25,
});

// create a system set that prints all people
let mut print_people = SystemSet::new();
print_people.register_system(|q: Query<Ref<Person>>| {
    for (_, person) in q.iter() {
        println!("'{}' is {} years old", person.name, person.age);
    }
});

// print out all the people
// should print:
//
// 'Alice' is 23 years old
// 'Bob' is 25 years old
app.run(&mut print_people);

// increment the ages of all people
app.run(|mut q: Query<RefMut<Person>>| {
    for (_, mut person) in q.iter_mut() {
        person.age += 1;
    }
});

// another way to increment the ages of all people would be
app.run(|entities: Entities<'_>, mut q: Query<RefMut<Person>>| {
    for entity in entities.iter() {
        if let Some(mut person) = q.get_mut(entity) {
            person.age += 1;
        }
    }
});

// print out all the people again
// should print:
//
// 'Alice' is 25 years old
// 'Bob' is 27 years old
app.run(&mut print_people);

Dependencies

~0–5.5MB