Crates.io | retaker |
lib.rs | retaker |
version | |
source | src |
created_at | 2024-01-07 07:00:36.804401 |
updated_at | 2024-11-08 22:14:21.869297 |
description | a simple ecs implementation |
homepage | |
repository | https://github.com/jjmartinodev/retaker |
max_upload_size | |
id | 1091526 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Retaker is an ECS(very wip) that aims for simplicity and just enough performance to use ECS.
use retaker::{
aoc::AOCStorage,
scheduler::{Scheduler, System},
world::{EntityStorage, World},
};
#[derive(Debug)]
pub struct Name(String);
pub struct Person;
pub struct Dog;
pub struct Age(u32);
pub struct IsBirthday;
fn add_dogs(world: &mut World) {
let snowflake = world.create_entity();
world.insert_component2(&snowflake, Name(String::from("Snowflake")), Dog);
let some_dog = world.create_entity();
world.insert_component(&some_dog, Dog);
}
fn add_people(world: &mut World) {
let francis = world.create_entity();
world.insert_component3(&francis, Name(String::from("Francis")), Person, Age(18));
let camila = world.create_entity();
world.insert_component4(
&camila,
Name(String::from("Camila")),
Person,
Age(12),
IsBirthday,
);
}
fn greet_people(world: &mut World) {
for entity in world.query::<Person>() {
let person = world.ref_entity(&entity);
if let Some(name) = person.component::<Name>() {
println!("good morning {}!", name.0);
if let Some(age) = person.component::<Age>() {
println!("{}, {} years old", name.0, age.0);
}
} else {
println!("this person doesn't have a name!")
}
}
}
fn greet_dogs(world: &mut World) {
for entity in world.query::<Dog>() {
let dog = world.ref_entity(&entity);
if let Some(name) = dog.component::<Name>() {
println!("awww, hi {}!", name.0)
} else {
println!("this dog doesn't have a name!")
}
}
}
fn celebrate_birthday(world: &mut World) {
for entity in world.query::<IsBirthday>() {
let mut someone = world.mut_entity(&entity);
if let Some(name) = someone.component::<Name>() {
println!("happy birthday {}!", name.0);
if let Some(age) = someone.mut_component::<Age>() {
age.0 += 1;
}
} else {
println!("happy birthday to you!")
}
}
}
fn main() {
let world = World::new(EntityStorage::AOC(AOCStorage::new()));
let mut scheduler = Scheduler::new(world);
scheduler.add_systems([
System::Start(add_dogs),
System::Start(add_people),
System::Start(greet_people),
System::Start(celebrate_birthday),
System::Start(greet_dogs),
]);
scheduler.run();
}