Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swiiz/ecs
Simple Easy to use 🧰 Entity Component System in Rust 🦀
https://github.com/swiiz/ecs
Last synced: 18 days ago
JSON representation
Simple Easy to use 🧰 Entity Component System in Rust 🦀
- Host: GitHub
- URL: https://github.com/swiiz/ecs
- Owner: Swiiz
- Created: 2024-08-17T14:27:52.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-09-11T12:54:47.000Z (4 months ago)
- Last Synced: 2024-09-12T05:29:00.664Z (4 months ago)
- Language: Rust
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Swiiz's ECS
> An Entity Component System (ECS) is a design pattern in game development where entities are data containers, components hold data, and systems define behavior. This separation enhances flexibility, reusability, and performance in complex simulations.
## How to use ?
```rust
// examples/walkthrough.rsuse ecs::{Entities, Entity, Query};
pub struct Age(u8);
fn main() {
let mut entities = Entities::new();let mut a = entities.spawn();
a.set("Entity A");assert!(a.get::<&str>().is_some());
assert!(a.get::().is_none());entities.spawn().set("Entity B").set(Age(10));
let mut c = entities.spawn();
c.set(Age(20));assert!(c.get::<&str>().is_none());
assert!(c.get::().is_some());let unamed_entity_id = c.id();
// "c" is dropped here
for _ in 0..5 {
age_entities(&mut entities);
}print_entities(&mut entities);
let unamed_entity = entities.edit(unamed_entity_id).unwrap();
print!(
"Unamed entity age: {}",
unamed_entity.get::().unwrap().0
);
}fn age_entities(entities: &mut Entities) {
for entity in entities.with::().iter() {
entity.get_mut::().unwrap().0 += 1;
}
}fn print_entities(entities: &mut Entities) {
for entity in entities.with::<&str>().iter() {
let name = entity.get::<&str>().unwrap();let age = entity
.get::()
.map(|x| x.0.to_string())
.unwrap_or("Unknown".to_string());println!("{} has age {}", name, age);
}
}```