Skip to main content

nya_ecs/
lib.rs

1//! Small simple ECS
2//!
3//! An [Entity Component System](https://en.wikipedia.org/wiki/Entity_component_system) is a
4//! pattern in which entities are composed of simple data components and "systems" that manipulate said components.
5//!
6//! A system can be a function called every frame that manipulates a specific entity,
7//! a query of entities with a certain set of components or whatever.
8
9pub(crate) use std::any::{Any, TypeId};
10
11/// Entity ID
12pub type Entity = usize;
13
14pub mod component;
15pub use component::{Component, ComponentKey};
16
17mod world;
18pub use world::World;
19
20pub mod query;
21pub use query::{Exclude, Filter, Query, Queryable};
22
23pub mod system;
24pub use system::{QuerySystem, System, SystemManager};
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    struct Tag;
31    crate::component!(Tag);
32    #[allow(dead_code)]
33    struct Name(String);
34    crate::component!(Name);
35    #[allow(dead_code)]
36    struct Point(i32, i32);
37    crate::component!(Point);
38
39    #[test]
40    fn stress() {
41        let mut world = World::new();
42
43        for i in 0..10000 {
44            let entity = world.spawn();
45            world.add(entity, Tag);
46            world.add(entity, Point(i, 65));
47            world.add(entity, Name("Cronus".to_string()));
48        }
49
50        assert!(world.has::<Tag>(3));
51    }
52}