zcomponents

Crates.iozcomponents
lib.rszcomponents
version0.2.0
sourcesrc
created_at2018-08-09 12:49:57.198622
updated_at2021-06-17 16:39:08.971994
descriptionZComponents is a stupid component storage
homepagehttps://github.com/ozkriff/zemeroth/tree/master/zcomponents
repositoryhttps://github.com/ozkriff/zemeroth
max_upload_size
id78506
size21,309
Andréy Lesnikóv (ozkriff)

documentation

https://docs.rs/zcomponents/

README

ZComponents - a stupid component storage

Crates.io Docs.rs

I find "serious" ECS to be an overkill for turn-based game logic, so I've created this simple library that does only one thing: stores your components.

Basic Example

use zcomponents::zcomponents_storage;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash, Default)]
pub struct Id(i32);

#[derive(Clone, Debug)]
pub struct SomeComponent(pub i32);

#[derive(Clone, Debug)]
pub struct SomeFlag;

zcomponents_storage!(Storage<Id>: {
    component: SomeComponent,
    flag: SomeFlag,
});

let mut storage = Storage::new();

let id0 = storage.alloc_id();
storage.component.insert(id0, SomeComponent(0));

let id1 = storage.alloc_id();
storage.component.insert(id1, SomeComponent(1));
storage.flag.insert(id1, SomeFlag);

storage.component.get_mut(id0).0 += 1;

if let Some(component) = storage.component.get_opt_mut(id1) {
    component.0 += 1;
}

storage.flag.remove(id1);

storage.remove(id0);

See a more advanced example in crate's documentation.

Implementation

It's implemented as a simple macro and a bunch of naive HashMaps so don't expect any outstanding performance.

Commit count: 878

cargo fmt