magma_ecs/lib.rs
1/*!
2This crate provides the Entity-Component-System of the [Magma3D-Engine](https://dynamicgoose.github.io/magma3d-engine/).
3
4The crate provides a [`World`] struct with [`Resources`](resources::Resources) and [`Entities`](entities::Entities).
5An entity is just an index into the component storage.
6A resource is like a global component, independent of the [`Entities`](entities::Entities).
7
8# Usage Example
9
10```
11use magma_ecs::World;
12
13fn main() -> Result<(), Box<dyn std::error::Error>> {
14 let mut world = World::new();
15
16 // Register component types.
17 world.register_component::<Name>();
18 world.register_component::<Health>();
19 world.register_component::<Npc>();
20
21 // Add a resource.
22 world.add_resource(String::from("This is an example resource!"))?;
23
24 // create a couple of entities with registered components
25 for _ in 0..10 {
26 world.create_entity((Name("Enemy".to_owned()), Health(20), Npc::Enemy))?;
27 }
28 Ok(())
29}
30
31// Components can be any type that implements `Send + Sync` (or just any if you disable the `multithreading` feature).
32struct Name(String);
33struct Health(u32);
34enum Npc {
35 Ally,
36 Enemy,
37}
38```
39*/
40
41#[cfg(feature = "multithreading")]
42pub use rayon;
43pub use world::World;
44
45mod events;
46mod send_sync;
47mod world;
48
49/// Provides the [`Entities`](entities::Entities) struct as well as [`query_entity`](entities::query_entity) modules.
50pub mod entities;
51/// Error types
52pub mod error;
53/// Provides the [`Resources`](resources::Resources) struct.
54pub mod resources;
55/// Provides the [`Systems`](systems::Systems) struct, from which a [`Dispatcher`](systems::dispatcher::Dispatcher) can be created.
56pub mod systems;