An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

[![Build Status](https://travis-ci.org/Rahix/eagre-ecs.svg?branch=master)](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.