No description
Find a file
2021-06-07 11:16:13 -04:00
.github trimmed white space 2019-11-25 07:14:02 -08:00
benches Merge pull request #726 from Imberflur/fetch-bench 2021-04-03 02:11:43 +01:00
docs Merge #694 2020-05-28 00:00:03 +00:00
examples Run rustfmt 2020-02-19 19:20:24 +01:00
scripts Add derive flag 2020-02-25 18:29:54 +01:00
specs-derive Remove cloning of ids. Use zip of ids where shared between ser and de. 2020-05-27 16:34:46 -07:00
src Merge pull request #730 from zesterer/master 2021-03-21 16:36:15 +00:00
tests update hashbrown and shred 2021-06-07 10:49:12 +02:00
.gitignore Add website, add reference, rename book to tutorials 2019-05-04 11:12:43 +02:00
.rustfmt.toml Update rustfmt options 2019-06-28 10:00:17 +02:00
.travis.yml Cleanup error types 2020-02-19 17:55:07 +01:00
bors.toml Remove Reviewable garbage from merge commits 2019-01-03 09:42:06 -07:00
Cargo.toml bump minor version. 2021-06-07 11:16:13 -04:00
CHANGELOG.md Ordered links in CHANGELOG.md. 2020-02-26 17:42:02 +13:00
CODE_OF_CONDUCT.md Add CoC 2019-01-12 10:28:00 +01:00
codecov.yml Add code coverage via GitLab CI 2019-03-31 14:27:27 +02:00
CONTRIBUTING.md Update links in CONTRIBUTING.md 2019-12-12 12:10:50 +01:00
LICENSE-APACHE Relicense under Apache-2.0/MIT 2017-12-26 20:08:32 -08:00
LICENSE-MIT Relicense under Apache-2.0/MIT 2017-12-26 20:08:32 -08:00
netlify.toml Use correct BASE_URL 2019-05-04 12:39:46 +02:00
PULL_REQUEST_TEMPLATE.md Create PULL_REQUEST_TEMPLATE.md 2019-01-12 11:43:45 +01:00
README.md Cleanup error types 2020-02-19 17:55:07 +01:00

Specs

Specs Parallel ECS

Build Status Crates.io Gitter MIT/Apache Docs.rs Code coverage LoC

Specs is an Entity-Component System written in Rust. Unlike most other ECS libraries out there, it provides

  • easy parallelism
  • high flexibility
    • contains 5 different storages for components, which can be extended by the user
    • its types are mostly not coupled, so you can easily write some part yourself and still use Specs
    • Systems may read from and write to components and resources, can depend on each other and you can use barriers to force several stages in system execution
  • high performance for real-world applications

Minimum Rust version: 1.40

Example

use specs::prelude::*;

// A component contains data
// which is associated with an entity.
#[derive(Debug)]
struct Vel(f32);

impl Component for Vel {
    type Storage = VecStorage<Self>;
}

#[derive(Debug)]
struct Pos(f32);

impl Component for Pos {
    type Storage = VecStorage<Self>;
}

struct SysA;

impl<'a> System<'a> for SysA {
    // These are the resources required for execution.
    // You can also define a struct and `#[derive(SystemData)]`,
    // see the `full` example.
    type SystemData = (WriteStorage<'a, Pos>, ReadStorage<'a, Vel>);

    fn run(&mut self, (mut pos, vel): Self::SystemData) {
        // The `.join()` combines multiple component storages,
        // so we get access to all entities which have
        // both a position and a velocity.
        for (pos, vel) in (&mut pos, &vel).join() {
            pos.0 += vel.0;
        }
    }
}

fn main() {
    // The `World` is our
    // container for components
    // and other resources.
    let mut world = World::new();
    world.register::<Pos>();
    world.register::<Vel>();

    // An entity may or may not contain some component.

    world.create_entity().with(Vel(2.0)).with(Pos(0.0)).build();
    world.create_entity().with(Vel(4.0)).with(Pos(1.6)).build();
    world.create_entity().with(Vel(1.5)).with(Pos(5.4)).build();

    // This entity does not have `Vel`, so it won't be dispatched.
    world.create_entity().with(Pos(2.0)).build();

    // This builds a dispatcher.
    // The third parameter of `with` specifies
    // logical dependencies on other systems.
    // Since we only have one, we don't depend on anything.
    // See the `full` example for dependencies.
    let mut dispatcher = DispatcherBuilder::new().with(SysA, "sys_a", &[]).build();
    // This will call the `setup` function of every system.
    // In this example this has no effect since we already registered our components.
    dispatcher.setup(&mut world);

    // This dispatches all the systems in parallel (but blocking).
    dispatcher.dispatch(&mut world);
}

Please look into the examples directory for more.

Public dependencies

crate version
hibitset hibitset
rayon rayon
shred shred
shrev shrev

Contribution

Contribution is very welcome! If you didn't contribute before, just filter for issues with "easy" or "good first issue" label. Please note that your contributions are assumed to be dual-licensed under Apache-2.0/MIT.