https://github.com/rahix/eagre-ecs
A Rust entity-component system
https://github.com/rahix/eagre-ecs
Last synced: about 1 year ago
JSON representation
A Rust entity-component system
- Host: GitHub
- URL: https://github.com/rahix/eagre-ecs
- Owner: Rahix
- License: other
- Created: 2016-07-17T14:11:25.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-12-29T12:50:17.000Z (over 8 years ago)
- Last Synced: 2025-07-14T02:22:45.388Z (about 1 year ago)
- Language: Rust
- Size: 555 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[](https://travis-ci.org/Rahix/eagre-ecs)
eagre-ecs
=========
An Entity-Component System
## Installation ##
Add the following line to your `Cargo.toml`:
```toml
eagre-ecs = { git = "https://github.com/Rahix/eagre-ecs" }
```
## Example ##
```rust
extern crate eagre_ecs;
use eagre_ecs::prelude::*;
#[derive(Clone, Debug)]
struct Foo(i32);
#[derive(Clone, Debug)]
struct Bar(i32);
fn main() {
let mut system = System::new();
for i in 0..100 {
let ent = system.new_entity();
match i%2 {
0 => system.add(ent, Foo(i)).unwrap(),
1 => system.add(ent, Bar(i)).unwrap(),
_ => unreachable!(),
}
}
system.run_mut::(|sys: &mut System, ent: Entity| {
sys.borrow_mut::(ent).unwrap().0 += 1;
}).unwrap();
system.run_mut::(|sys: &mut System, ent: Entity| {
sys.borrow_mut::(ent).unwrap().0 -= 1;
}).unwrap();
system.run::(|sys: &System, ent: Entity| {
if sys.has::(ent) {
println!("Foo: {}", sys.borrow::(ent).unwrap().0);
} else {
println!("Bar: {}", sys.borrow::(ent).unwrap().0);
}
}).unwrap();
}
```
## License ##
eagre-ecs is licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.