• Stars
    star
    2,382
  • Rank 18,606 (Top 0.4 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Specs - Parallel ECS

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

Link to the book

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.

More Repositories

1

amethyst

Data-oriented and data-driven game engine written in Rust
Rust
7,977
star
2

rlua

High level Lua bindings to Rust
C
1,628
star
3

legion

High performance Rust ECS library
Rust
1,579
star
4

bracket-lib

The Roguelike Toolkit (RLTK), implemented for Rust.
Rust
1,460
star
5

rustrogueliketutorial

Roguelike Tutorial in Rust - using RLTK
Rust
873
star
6

rendy

State of the art "build your own engine" kit powered by gfx-hal
Rust
817
star
7

distill

Asset pipeline system for game engines & editor suites.
Rust
359
star
8

shred

Shared resource dispatcher
Rust
230
star
9

evoli

An ecosystem-simulation game made with Amethyst
Rust
217
star
10

amethyst-starter-2d

Seed project for 2D games
Rust
200
star
11

space-menace

An action 2D platformer made with Amethyst game engine
Rust
180
star
12

shotcaller

A moddable RTS/MOBA game made with bracket-lib and minigene.
Rust
143
star
13

serde-diff

Utility for comparing two structs and re-applying the differences to other structs
Rust
118
star
14

hibitset

Hierarchical bit set container
Rust
107
star
15

voxel-mapper

Make beautiful voxel maps.
Rust
106
star
16

specs-physics

nphysics integration for the Specs entity component system
Rust
94
star
17

sheep

Modular and lightweight spritesheet packer πŸ‘
Rust
90
star
18

tools

Game development tools for the Amethyst engine
Rust
80
star
19

grumpy_visitors

πŸ§™β€β™‚οΈπŸ§™β€β™€οΈ A prototype of a top-down EvilInvasion-like 2D arcade/action (with co-op!)
Rust
77
star
20

amethyst-imgui

imgui integration for Amethyst
Rust
66
star
21

legion_transform

A Unity-inspired hierarchical transform implementation using Legion ECS
Rust
51
star
22

editor-core

Crate that allows an Amethyst game to communicate with an editor.
Rust
44
star
23

rfcs

RFCs are documents that contain major plans and decisions for the engine
32
star
24

dwarf_seeks_fortune

A 2D puzzle platformer made with the Amethyst game engine.
Rust
25
star
25

amethyst_iced

Iced rendering plugin for the Amethyst game engine
Rust
24
star
26

pong_wasm

WASM end-to-end proof of concept -- work in progress
Rust
22
star
27

web_worker

Rust
19
star
28

ludumdare42

A game made by the Amethyst team for Ludum Dare 42
Rust
16
star
29

website-legacy

Project website and blog (DEPRECATED)
HTML
11
star
30

website

Official Amethyst website
JavaScript
9
star
31

amethyst-rhusics

A bridge between Amethyst and rhusics (unmaintained)
Rust
9
star
32

awesome-specs

A curated list of projects that use or help with using Specs.
6
star
33

crystal-editor

Svelte
6
star
34

ludumdare43

Rust
2
star
35

resources

Files that are important to keep around but not tied to any specific code base
1
star
36

builder

The docker container used in amethyst's CI/CD infrastructure.
Dockerfile
1
star
37

wasm_rush_report

Report about adding WASM support to the Amethyst game engine.
1
star
38

laminar-ffi

Crate that exposes Laminar functionality to C
Rust
1
star
39

amethyst-docs-builder

Webhook server that builds amethyst's book and documentation
Go
1
star
40

amethystup

Setup script for Amethyst dependencies
Shell
1
star
41

documentation

Non-rustdoc documentation and policies
1
star