#ecs #game #component #entity #full #part

entity_component

Provides the Entity and Component part of a full ECS

8 releases (stable)

1.1.2 Mar 29, 2021
1.1.1 Mar 27, 2021
0.100.0 Jan 3, 2021
0.99.0 Dec 20, 2020

#1513 in Game dev

Download history 1/week @ 2024-02-16 16/week @ 2024-02-23 13/week @ 2024-03-01 17/week @ 2024-03-08 10/week @ 2024-03-15 6/week @ 2024-03-22 77/week @ 2024-03-29

112 downloads per month
Used in 2 crates

Apache-2.0

28KB
492 lines

Support an Open Source Developer! ♥️

Become a patron

Entity Component

The entity-component part of a full ECS (Entity-Component-System).

Why would you use this ECS library?

  • Compatible with all platforms, including WASM!
  • Minimal amount of dependencies.
  • Small code size.
  • Stable, tested, benchmarked, 100% completed.

Usage

Add the following to you Cargo.toml file:

entity_component = "*"

Use it like so:

use entity_component::*;

fn main() {
    // Creating components
    struct A(f32);
    struct B(f32);
    // Creating entity repository
    let mut entities = Entities::default();
    // Creating component storages
    let mut storage = Components::<A>::default();
    let mut storage2 = Components::<B>::default();
    // Create entities and add components
    for i in 0..10000 {
        let e = entities.create();
        if i % 5 == 0 {
            storage.insert(e, A(1.0));
        }
        if i % 6 == 0 {
            storage2.insert(e, B(1.0));
        }
    }
    // Join on all entities having both A and B.
    // We take a mutable reference to the A component and an immutable
    // reference to the B component.
    join!(&mut storage && &storage2)
        .for_each(|(s, s2)| s.unwrap().0 += s2.unwrap().0);

    // Same thing, but we also get the entities id that align with the
    // matched components.
    join!(&entities && &mut storage && &storage2)
        .for_each(|(_e, s, s2)| s.unwrap().0 += s2.unwrap().0);
}

Maintainer Information

  • Maintainer: Jojolepro
  • Contact: jojolepro [at] jojolepro [dot] com
  • Website: jojolepro.com
  • Patreon: patreon

Dependencies

~485–670KB
~14K SLoC